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

Commit 9448536b authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding support to delete unrestored icons and widgets

Bug: 17584719
Change-Id: If8e76fc80ea885c9004c50b7b6a9353525a50105
parent 136882c1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -45,6 +45,11 @@ public class LauncherAppWidgetInfo extends ItemInfo {
     */
    public static final int FLAG_UI_NOT_READY = 4;

    /**
     * Indicates that the widget restore has started.
     */
    public static final int FLAG_RESTORE_STARTED = 8;

    /**
     * Indicates that the widget hasn't been instantiated yet.
     */
+46 −14
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ public class LauncherModel extends BroadcastReceiver
        implements LauncherAppsCompat.OnAppsChangedCallbackCompat {
    static final boolean DEBUG_LOADERS = false;
    private static final boolean DEBUG_RECEIVER = false;
    private static final boolean REMOVE_UNRESTORED_ICONS = true;

    static final String TAG = "Launcher.Model";

@@ -1885,7 +1886,8 @@ public class LauncherModel extends BroadcastReceiver

            synchronized (sBgLock) {
                clearSBgDataStructures();
                PackageInstallerCompat.getInstance(mContext).updateActiveSessionCache();
                final HashSet<String> installingPkgs = PackageInstallerCompat
                        .getInstance(mContext).updateAndGetActiveSessionCache();

                final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
                final ArrayList<Long> restoredRows = new ArrayList<Long>();
@@ -2014,6 +2016,25 @@ public class LauncherModel extends BroadcastReceiver
                                            // installed later.
                                            Launcher.addDumpLog(TAG,
                                                    "package not yet restored: " + cn, true);

                                            if ((promiseType & ShortcutInfo.FLAG_RESTORE_STARTED) != 0) {
                                                // Restore has started once.
                                            } else if (installingPkgs.contains(cn.getPackageName())) {
                                                // App restore has started. Update the flag
                                                promiseType |= ShortcutInfo.FLAG_RESTORE_STARTED;
                                                ContentValues values = new ContentValues();
                                                values.put(LauncherSettings.Favorites.RESTORED,
                                                        promiseType);
                                                String where = BaseColumns._ID + "= ?";
                                                String[] args = {Long.toString(id)};
                                                contentResolver.update(contentUri, values, where, args);

                                            } else if (REMOVE_UNRESTORED_ICONS) {
                                                Launcher.addDumpLog(TAG,
                                                        "Unrestored package removed: " + cn, true);
                                                itemsToRemove.add(id);
                                                continue;
                                            }
                                        } else if (isSdCardReady) {
                                            // Do not wait for external media load anymore.
                                            // Log the invalid package, and remove it
@@ -2221,6 +2242,19 @@ public class LauncherModel extends BroadcastReceiver
                                        appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId,
                                                component);
                                        appWidgetInfo.restoreStatus = restoreStatus;

                                        if ((restoreStatus & LauncherAppWidgetInfo.FLAG_RESTORE_STARTED) != 0) {
                                            // Restore has started once.
                                        } else if (installingPkgs.contains(component.getPackageName())) {
                                            // App restore has started. Update the flag
                                            appWidgetInfo.restoreStatus |=
                                                    LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
                                        } else if (REMOVE_UNRESTORED_ICONS) {
                                            Launcher.addDumpLog(TAG,
                                                    "Unrestored package removed: " + component, true);
                                            itemsToRemove.add(id);
                                            continue;
                                        }
                                    }

                                    appWidgetInfo.id = id;
@@ -2249,8 +2283,7 @@ public class LauncherModel extends BroadcastReceiver
                                        break;
                                    }

                                    if (isProviderReady) {
                                        String providerName = provider.provider.flattenToString();
                                    String providerName = appWidgetInfo.providerName.flattenToString();
                                    if (!providerName.equals(savedProvider) ||
                                            (appWidgetInfo.restoreStatus != restoreStatus)) {
                                        ContentValues values = new ContentValues();
@@ -2262,7 +2295,6 @@ public class LauncherModel extends BroadcastReceiver
                                        String[] args = {Long.toString(id)};
                                        contentResolver.update(contentUri, values, where, args);
                                    }
                                    }
                                    sBgItemsIdMap.put(appWidgetInfo.id, appWidgetInfo);
                                    sBgAppWidgets.add(appWidgetInfo);
                                }
+5 −0
Original line number Diff line number Diff line
@@ -54,6 +54,11 @@ public class ShortcutInfo extends ItemInfo {
     */
    public static final int FLAG_INSTALL_SESSION_ACTIVE = 4;

    /**
     * Indicates that the widget restore has started.
     */
    public static final int FLAG_RESTORE_STARTED = 8;

    /**
     * The intent used to start the application.
     */
+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.content.Context;

import com.android.launcher3.Utilities;

import java.util.HashSet;

public abstract class PackageInstallerCompat {

    public static final int STATUS_INSTALLED = 0;
@@ -42,7 +44,7 @@ public abstract class PackageInstallerCompat {
        }
    }

    public abstract void updateActiveSessionCache();
    public abstract HashSet<String> updateAndGetActiveSessionCache();

    public abstract void onPause();

+6 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import org.json.JSONStringer;
import org.json.JSONTokener;

import java.util.ArrayList;
import java.util.HashSet;

public class PackageInstallerCompatV16 extends PackageInstallerCompat {

@@ -76,9 +77,6 @@ public class PackageInstallerCompatV16 extends PackageInstallerCompat {
    @Override
    public void onStop() { }

    @Override
    public void updateActiveSessionCache() { }

    private void replayUpdates() {
        if (DEBUG) Log.d(TAG, "updates resumed");
        LauncherAppState app = LauncherAppState.getInstanceNoCreate();
@@ -169,4 +167,9 @@ public class PackageInstallerCompatV16 extends PackageInstallerCompat {
        }
        return value;
    }

    @Override
    public HashSet<String> updateAndGetActiveSessionCache() {
        return new HashSet<String>();
    }
}
Loading