From 0646dde2198aa6e0cc58aa3518dd8917023dc7cf Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Tue, 24 Nov 2020 11:35:24 -0800 Subject: [PATCH 1/3] Don't crash Launcher when attempting to endTransaction on an already-closed DB. Since the DB is already closed, if we can't end the transaction, it should not put the code in a bad state. Bug: 173162852 Test: manually tested backup and restore flow and existing tests Change-Id: I2692d98f0a8efc8aeb6bfd826fe738e4436c6ee4 --- .../android/launcher3/LauncherProvider.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 6af248cd78..23464d1c04 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -1105,11 +1105,20 @@ public class LauncherProvider extends ContentProvider { * @return the max _id in the provided table. */ @Thunk static int getMaxId(SQLiteDatabase db, String query, Object... args) { - int max = (int) DatabaseUtils.longForQuery(db, - String.format(Locale.ENGLISH, query, args), - null); - if (max < 0) { - throw new RuntimeException("Error: could not query max id"); + int max = 0; + try (SQLiteStatement prog = db.compileStatement( + String.format(Locale.ENGLISH, query, args))) { + max = (int) DatabaseUtils.longForQuery(prog, null); + if (max < 0) { + throw new RuntimeException("Error: could not query max id"); + } + } catch (IllegalArgumentException exception) { + String message = exception.getMessage(); + if (message.contains("re-open") && message.contains("already-closed")) { + // Don't crash trying to end a transaction an an already closed DB. See b/173162852. + } else { + throw exception; + } } return max; } From cfcefb0c47552c149d4c614d04ea3a560c5f7d23 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 10 Dec 2020 16:22:41 -0800 Subject: [PATCH 2/3] Synchronizing model data access Test: Presubmit Bug: 173328873 Change-Id: Ifc1724e17ebfa2ee5f21bb3f272986b8a14fdbc1 --- .../hybridhotseat/HotseatPredictionModel.java | 3 +-- .../graphics/LauncherPreviewRenderer.java | 12 +++++++----- .../android/launcher3/model/BgDataModel.java | 10 ++++++++++ src/com/android/launcher3/model/LoaderTask.java | 17 +++++++---------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionModel.java b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionModel.java index 8f31c22d15..080633a653 100644 --- a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionModel.java +++ b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionModel.java @@ -52,8 +52,7 @@ public class HotseatPredictionModel { public static Bundle convertDataModelToAppTargetBundle(Context context, BgDataModel dataModel) { Bundle bundle = new Bundle(); ArrayList events = new ArrayList<>(); - ArrayList workspaceItems = new ArrayList<>(dataModel.workspaceItems); - workspaceItems.addAll(dataModel.appWidgets); + ArrayList workspaceItems = dataModel.getAllWorkspaceItems(); for (ItemInfo item : workspaceItems) { AppTarget target = getAppTargetFromInfo(context, item); if (target != null && !isTrackedForPrediction(item)) continue; diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index effb3a4a0c..efc1201bba 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -629,11 +629,13 @@ public class LauncherPreviewRenderer extends ContextThemeWrapper private WorkspaceResult(BgDataModel dataModel, WidgetsModel widgetsModel, Map widgetProviderInfoMap) { - mWorkspaceItems = dataModel.workspaceItems; - mAppWidgets = dataModel.appWidgets; - mHotseatPredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION); - mWidgetsModel = widgetsModel; - mWidgetProvidersMap = widgetProviderInfoMap; + synchronized (dataModel) { + mWorkspaceItems = dataModel.workspaceItems; + mAppWidgets = dataModel.appWidgets; + mHotseatPredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION); + mWidgetsModel = widgetsModel; + mWidgetProvidersMap = widgetProviderInfoMap; + } } } } diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java index 49b40edb76..c217a475a1 100644 --- a/src/com/android/launcher3/model/BgDataModel.java +++ b/src/com/android/launcher3/model/BgDataModel.java @@ -375,6 +375,16 @@ public class BgDataModel { } } + /** + * Returns a list containing all workspace items including widgets. + */ + public synchronized ArrayList getAllWorkspaceItems() { + ArrayList items = new ArrayList<>(workspaceItems.size() + appWidgets.size()); + items.addAll(workspaceItems); + items.addAll(appWidgets); + return items; + } + /** * Calls the provided {@code op} for all workspaceItems in the in-memory model (both persisted * items and dynamic/predicted items for the provided {@code userHandle}. diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index b108788061..8e085ce52d 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -166,12 +166,7 @@ public class LoaderTask implements Runnable { private void sendFirstScreenActiveInstallsBroadcast() { ArrayList firstScreenItems = new ArrayList<>(); - - ArrayList allItems = new ArrayList<>(); - synchronized (mBgDataModel) { - allItems.addAll(mBgDataModel.workspaceItems); - allItems.addAll(mBgDataModel.appWidgets); - } + ArrayList allItems = mBgDataModel.getAllWorkspaceItems(); // Screen set is never empty final int firstScreen = mBgDataModel.collectWorkspaceScreens().get(0); @@ -858,10 +853,12 @@ public class LoaderTask implements Runnable { .call(contentResolver, LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS) .getIntArray(LauncherSettings.Settings.EXTRA_VALUE); - for (int folderId : deletedFolderIds) { - mBgDataModel.workspaceItems.remove(mBgDataModel.folders.get(folderId)); - mBgDataModel.folders.remove(folderId); - mBgDataModel.itemsIdMap.remove(folderId); + synchronized (mBgDataModel) { + for (int folderId : deletedFolderIds) { + mBgDataModel.workspaceItems.remove(mBgDataModel.folders.get(folderId)); + mBgDataModel.folders.remove(folderId); + mBgDataModel.itemsIdMap.remove(folderId); + } } // Remove any ghost widgets From e98f980a9826be66c8e8adf495a94478d4636025 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 10 Dec 2020 16:58:23 -0800 Subject: [PATCH 3/3] Ignoring crash if the 3p icon surface is no longer valid Test: Verified on device locally Change-Id: I5684731c3a66d5690f83878f3c4726d859349bd4 --- .../src/com/android/quickstep/FallbackSwipeHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java index ffb05dfed7..901040dcc6 100644 --- a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java @@ -294,8 +294,12 @@ public class FallbackSwipeHandler extends if (mSurfaceControl != null) { currentRect.roundOut(mTempRect); Transaction t = new Transaction(); - t.setGeometry(mSurfaceControl, null, mTempRect, Surface.ROTATION_0); - t.apply(); + try { + t.setGeometry(mSurfaceControl, null, mTempRect, Surface.ROTATION_0); + t.apply(); + } catch (RuntimeException e) { + // Ignore + } } }