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

Commit cfcefb0c authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Synchronizing model data access

Test: Presubmit
Bug: 173328873
Change-Id: Ifc1724e17ebfa2ee5f21bb3f272986b8a14fdbc1
parent cbf8fe08
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -52,8 +52,7 @@ public class HotseatPredictionModel {
    public static Bundle convertDataModelToAppTargetBundle(Context context, BgDataModel dataModel) {
        Bundle bundle = new Bundle();
        ArrayList<AppTargetEvent> events = new ArrayList<>();
        ArrayList<ItemInfo> workspaceItems = new ArrayList<>(dataModel.workspaceItems);
        workspaceItems.addAll(dataModel.appWidgets);
        ArrayList<ItemInfo> workspaceItems = dataModel.getAllWorkspaceItems();
        for (ItemInfo item : workspaceItems) {
            AppTarget target = getAppTargetFromInfo(context, item);
            if (target != null && !isTrackedForPrediction(item)) continue;
+7 −5
Original line number Diff line number Diff line
@@ -629,6 +629,7 @@ public class LauncherPreviewRenderer extends ContextThemeWrapper
        private WorkspaceResult(BgDataModel dataModel,
                WidgetsModel widgetsModel,
                Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
            synchronized (dataModel) {
                mWorkspaceItems = dataModel.workspaceItems;
                mAppWidgets = dataModel.appWidgets;
                mHotseatPredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
@@ -637,3 +638,4 @@ public class LauncherPreviewRenderer extends ContextThemeWrapper
            }
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -375,6 +375,16 @@ public class BgDataModel {
        }
    }

    /**
     * Returns a list containing all workspace items including widgets.
     */
    public synchronized ArrayList<ItemInfo> getAllWorkspaceItems() {
        ArrayList<ItemInfo> 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}.
+7 −10
Original line number Diff line number Diff line
@@ -166,12 +166,7 @@ public class LoaderTask implements Runnable {

    private void sendFirstScreenActiveInstallsBroadcast() {
        ArrayList<ItemInfo> firstScreenItems = new ArrayList<>();

        ArrayList<ItemInfo> allItems = new ArrayList<>();
        synchronized (mBgDataModel) {
            allItems.addAll(mBgDataModel.workspaceItems);
            allItems.addAll(mBgDataModel.appWidgets);
        }
        ArrayList<ItemInfo> allItems = mBgDataModel.getAllWorkspaceItems();
        // Screen set is never empty
        final int firstScreen = mBgDataModel.collectWorkspaceScreens().get(0);

@@ -858,11 +853,13 @@ public class LoaderTask implements Runnable {
                    .call(contentResolver,
                            LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS)
                    .getIntArray(LauncherSettings.Settings.EXTRA_VALUE);
            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
            LauncherSettings.Settings.call(contentResolver,