mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-28 15:56:49 +00:00
Fix bug where work profile widgets are restored with main profile provider.
* Platform bug causes work profile widgets to be restored with main profile provider. * If we skip restore the widgets under the work profile during restore, then launcher will re-create the widget but with the correct profile provider. * Needs to be fixed in platform, but this launcher side change will work for now. Bug: 135926478 Change-Id: I80300c83e82cea9da84fdcdf7ad03188769b6cac
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user