2014-06-30 14:15:31 -07:00
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
2023-10-21 14:50:20 -04:00
|
|
|
import static com.android.launcher3.LauncherPrefs.APP_WIDGET_IDS;
|
|
|
|
|
import static com.android.launcher3.LauncherPrefs.OLD_APP_WIDGET_IDS;
|
|
|
|
|
|
2014-06-30 14:15:31 -07:00
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
2023-09-21 11:53:50 -04:00
|
|
|
import com.android.launcher3.logging.FileLog;
|
|
|
|
|
import com.android.launcher3.provider.RestoreDbTask;
|
2023-10-21 14:50:20 -04:00
|
|
|
import com.android.launcher3.util.IntArray;
|
2022-11-08 16:46:07 -08:00
|
|
|
import com.android.launcher3.widget.LauncherWidgetHolder;
|
2014-06-30 14:15:31 -07:00
|
|
|
|
2023-09-21 11:53:50 -04:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
2014-06-30 14:15:31 -07:00
|
|
|
public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
|
|
|
|
|
|
2023-10-21 14:50:20 -04:00
|
|
|
private static final String TAG = "AppWidgetsRestoredReceiver";
|
2014-06-30 14:15:31 -07:00
|
|
|
|
|
|
|
|
@Override
|
2017-01-10 15:29:18 -08:00
|
|
|
public void onReceive(final Context context, Intent intent) {
|
2014-06-30 14:15:31 -07:00
|
|
|
if (AppWidgetManager.ACTION_APPWIDGET_HOST_RESTORED.equals(intent.getAction())) {
|
2017-07-12 12:09:37 -07:00
|
|
|
int hostId = intent.getIntExtra(AppWidgetManager.EXTRA_HOST_ID, 0);
|
2023-09-21 11:53:50 -04:00
|
|
|
Log.d(TAG, "onReceive: Widget ID map received for host:" + hostId);
|
2022-10-25 15:17:58 -07:00
|
|
|
if (hostId != LauncherWidgetHolder.APPWIDGET_HOST_ID) {
|
2023-09-21 11:53:50 -04:00
|
|
|
Log.w(TAG, "onReceive: hostId does not match Launcher."
|
|
|
|
|
+ " Expected: " + LauncherWidgetHolder.APPWIDGET_HOST_ID
|
|
|
|
|
+ ", Actual: " + hostId);
|
2017-07-12 12:09:37 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 15:29:18 -08:00
|
|
|
final int[] oldIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_OLD_IDS);
|
|
|
|
|
final int[] newIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
|
2019-05-13 14:57:50 -07:00
|
|
|
if (oldIds != null && newIds != null && oldIds.length == newIds.length) {
|
2023-10-21 14:50:20 -04:00
|
|
|
LauncherPrefs.get(context).putSync(
|
|
|
|
|
OLD_APP_WIDGET_IDS.to(IntArray.wrap(oldIds).toConcatString()),
|
|
|
|
|
APP_WIDGET_IDS.to(IntArray.wrap(newIds).toConcatString()));
|
2023-09-21 11:53:50 -04:00
|
|
|
FileLog.d(TAG, "onReceive: Valid Widget IDs received."
|
|
|
|
|
+ " old IDs=" + Arrays.toString(oldIds)
|
|
|
|
|
+ ", new IDs=" + Arrays.toString(newIds));
|
|
|
|
|
if (!RestoreDbTask.isPending(context)) {
|
|
|
|
|
FileLog.w(TAG, "onReceive: Restored App Widget Ids received but Launcher"
|
|
|
|
|
+ " restore is not pending. New widget Ids might not get restored.");
|
|
|
|
|
}
|
2014-06-30 14:15:31 -07:00
|
|
|
} else {
|
2023-09-21 11:53:50 -04:00
|
|
|
Log.e(TAG, "onReceive: Invalid widget ids received for Launcher"
|
|
|
|
|
+ ", skipping restore of widget ids."
|
|
|
|
|
+ " newIds=" + Arrays.toString(newIds)
|
|
|
|
|
+ ", oldIds=" + Arrays.toString(oldIds));
|
2014-06-30 14:15:31 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-19 18:37:38 +00:00
|
|
|
}
|