Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1767e9e5 authored by Jon Miranda's avatar Jon Miranda Committed by android-build-merger
Browse files

Fix bug where work profile widgets are restored with main profile provider.

am: 3e90b4c7

Change-Id: Ied93479e1ef4bc08fd8187a55d505024df2c9e0f
parents 40d1a2d7 3e90b4c7
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import android.database.Cursor;
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 com.android.launcher3.util.ContentWriter;

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 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
                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 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
            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.