Adds unit tests for AppWidgetsRestoredReceiver

- Makes slight adjustments (no behavior changes) to RestoreDbTask and its tests for proper separation

Test: ran unit tests
Bug: 294386159
Flag: none

Change-Id: I3d882f5edcb6a0161a203ef46a5258e9c4ffe18e
This commit is contained in:
Charlie Anderson committed 2023-10-23 14:21:50 -04:00
1 parent a96537fa65
commit 65f1fc806c
4 files changed
+189 -13

No files matched your search

@@ -1,17 +1,20 @@
package com.android.launcher3;
import static com.android.launcher3.LauncherPrefs.APP_WIDGET_IDS;
import static com.android.launcher3.LauncherPrefs.OLD_APP_WIDGET_IDS;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.widget.LauncherWidgetHolder;
public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
private static final String TAG = "AWRestoredReceiver";
private static final String TAG = "AppWidgetsRestoredReceiver";
@Override
public void onReceive(final Context context, Intent intent) {
@@ -25,7 +28,9 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
final int[] oldIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_OLD_IDS);
final int[] newIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (oldIds != null && newIds != null && oldIds.length == newIds.length) {
RestoreDbTask.setRestoredAppWidgetIds(context, oldIds, newIds);
LauncherPrefs.get(context).putSync(
OLD_APP_WIDGET_IDS.to(IntArray.wrap(oldIds).toConcatString()),
APP_WIDGET_IDS.to(IntArray.wrap(newIds).toConcatString()));
} else {
Log.e(TAG, "Invalid host restored received");
}