Fix bug where work profile widgets are restored with main profile provider.
am: 3e90b4c7ae
Change-Id: Ied93479e1ef4bc08fd8187a55d505024df2c9e0f
diff --git a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
index d949141..e3ef5d6 100644
--- a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
+++ b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
@@ -11,6 +11,7 @@
import android.util.Log;
import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.provider.RestoreDbTask;
@@ -18,6 +19,8 @@
import androidx.annotation.WorkerThread;
+import static android.os.Process.myUserHandle;
+
public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
private static final String TAG = "AWRestoredReceiver";
@@ -77,9 +80,14 @@
state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
}
- String[] widgetIdParams = new String[] { Integer.toString(oldWidgetIds[i]) };
+ // b/135926478: Work profile widget restore is broken in platform. This forces us to
+ // recreate the widget during loading with the correct host provider.
+ long mainProfileId = UserManagerCompat.getInstance(context)
+ .getSerialNumberForUser(myUserHandle());
+ String oldWidgetId = Integer.toString(oldWidgetIds[i]);
int result = new ContentWriter(context, new ContentWriter.CommitParams(
- "appWidgetId=? and (restored & 1) = 1", widgetIdParams))
+ "appWidgetId=? and (restored & 1) = 1 and profileId=?",
+ new String[] { oldWidgetId, Long.toString(mainProfileId) }))
.put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i])
.put(LauncherSettings.Favorites.RESTORED, state)
.commit();
@@ -87,7 +95,7 @@
if (result == 0) {
Cursor cursor = cr.query(Favorites.CONTENT_URI,
new String[] {Favorites.APPWIDGET_ID},
- "appWidgetId=?", widgetIdParams, null);
+ "appWidgetId=?", new String[] { oldWidgetId }, null);
try {
if (!cursor.moveToFirst()) {
// The widget no long exists.