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

Commit 8e0e1d76 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Moving come helper methods to corresponding classes

> Moving isPackageEnabled to InstallShortcutReceiver
> Moving the deep shortcut map to the data model
> Removing appInfo.flags. Instead fetching the flags when needed

Change-Id: I654dd8acefa7b7d183b0419afbe112bef001d536
parent 5fe414f9
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import java.util.List;
/**
 * Stores the list of all applications for the all apps view.
 */
class AllAppsList {
public class AllAppsList {
    public static final int DEFAULT_APPLICATIONS_NUMBER = 42;

    /** The list off all apps. */
@@ -112,8 +112,7 @@ class AllAppsList {
        final List<AppInfo> data = this.data;
        for (int i = data.size() - 1; i >= 0; i--) {
            AppInfo info = data.get(i);
            final ComponentName component = info.intent.getComponent();
            if (info.user.equals(user) && packageName.equals(component.getPackageName())) {
            if (info.user.equals(user) && packageName.equals(info.componentName.getPackageName())) {
                removed.add(info);
                data.remove(i);
            }
@@ -127,7 +126,7 @@ class AllAppsList {
        final List<AppInfo> data = this.data;
        for (int i = data.size() - 1; i >= 0; i--) {
            AppInfo info = data.get(i);
            if (matcher.matches(info, info.intent.getComponent())) {
            if (matcher.matches(info, info.componentName)) {
                info.isDisabled = op.apply(info.isDisabled);
                modified.add(info);
            }
+0 −20
Original line number Diff line number Diff line
@@ -52,11 +52,6 @@ public class AppInfo extends ItemInfo {

    public ComponentName componentName;

    static final int DOWNLOADED_FLAG = 1;
    static final int UPDATED_SYSTEM_APP_FLAG = 2;

    int flags = 0;

    /**
     * {@see ShortcutInfo#isDisabled}
     */
@@ -88,7 +83,6 @@ public class AppInfo extends ItemInfo {
            IconCache iconCache, boolean quietModeEnabled) {
        this.componentName = info.getComponentName();
        this.container = ItemInfo.NO_ID;
        flags = initFlags(info);
        if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) {
            isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
        }
@@ -101,25 +95,11 @@ public class AppInfo extends ItemInfo {
        this.user = user;
    }

    public static int initFlags(LauncherActivityInfoCompat info) {
        int appFlags = info.getApplicationInfo().flags;
        int flags = 0;
        if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
            flags |= DOWNLOADED_FLAG;

            if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
                flags |= UPDATED_SYSTEM_APP_FLAG;
            }
        }
        return flags;
    }

    public AppInfo(AppInfo info) {
        super(info);
        componentName = info.componentName;
        title = Utilities.trim(info.title);
        intent = new Intent(info.intent);
        flags = info.flags;
        isDisabled = info.isDisabled;
        iconBitmap = info.iconBitmap;
    }
+2 −1
Original line number Diff line number Diff line
@@ -226,7 +226,8 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                String packageName = pendingInfo.getTargetPackage();
                if (!TextUtils.isEmpty(packageName)) {
                    UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle();
                    if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) {
                    if (!LauncherAppsCompat.getInstance(context)
                            .isPackageEnabledForProfile(packageName, myUserHandle)) {
                        if (DBG) Log.d(TAG, "Ignoring shortcut for absent package: "
                                + pendingInfo.launchIntent);
                        continue;
+9 −64
Original line number Diff line number Diff line
@@ -93,7 +93,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.Executor;

@@ -145,9 +144,6 @@ public class LauncherModel extends BroadcastReceiver
    // Entire list of widgets.
    private final WidgetsModel mBgWidgetsModel;

    // Maps all launcher activities to the id's of their shortcuts (if they have any).
    private final MultiHashMap<ComponentKey, String> mBgDeepShortcutMap = new MultiHashMap<>();

    private boolean mHasShortcutHostPermission;
    // Runnable to check if the shortcuts permission has changed.
    private final Runnable mShortcutPermissionCheckRunnable = new Runnable() {
@@ -316,15 +312,7 @@ public class LauncherModel extends BroadcastReceiver
                            ComponentName cn = si.getTargetComponent();
                            if (si.isPromise() && (cn != null)
                                    && packageName.equals(cn.getPackageName())) {
                                if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
                                    // For auto install apps update the icon as well as label.
                                    mIconCache.getTitleAndIcon(si,
                                            si.promisedIntent, user,
                                            si.shouldUseLowResIcon());
                                } else {
                                    // Only update the icon for restored apps.
                                si.updateIcon(mIconCache);
                                }
                                updates.add(si);
                            }
                        }
@@ -2647,14 +2635,14 @@ public class LauncherModel extends BroadcastReceiver
                Log.d(TAG, "loadAndBindDeepShortcuts mDeepShortcutsLoaded=" + mDeepShortcutsLoaded);
            }
            if (!mDeepShortcutsLoaded) {
                mBgDeepShortcutMap.clear();
                sBgDataModel.deepShortcutMap.clear();
                mHasShortcutHostPermission = mDeepShortcutManager.hasHostPermission();
                if (mHasShortcutHostPermission) {
                    for (UserHandleCompat user : mUserManager.getUserProfiles()) {
                        if (mUserManager.isUserUnlocked(user)) {
                            List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager
                                    .queryForAllShortcuts(user);
                            updateDeepShortcutMap(null, user, shortcuts);
                            sBgDataModel.updateDeepShortcutMap(null, user, shortcuts);
                        }
                    }
                }
@@ -2678,36 +2666,9 @@ public class LauncherModel extends BroadcastReceiver
        }
    }

    /**
     * Clear all the shortcuts for the given package, and re-add the new shortcuts.
     */
    private void updateDeepShortcutMap(
            String packageName, UserHandleCompat user, List<ShortcutInfoCompat> shortcuts) {
        if (packageName != null) {
            Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator();
            while (keysIter.hasNext()) {
                ComponentKey next = keysIter.next();
                if (next.componentName.getPackageName().equals(packageName)
                        && next.user.equals(user)) {
                    keysIter.remove();
                }
            }
        }

        // Now add the new shortcuts to the map.
        for (ShortcutInfoCompat shortcut : shortcuts) {
            boolean shouldShowInContainer = shortcut.isEnabled()
                    && (shortcut.isDeclaredInManifest() || shortcut.isDynamic());
            if (shouldShowInContainer) {
                ComponentKey targetComponent
                        = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle());
                mBgDeepShortcutMap.addToList(targetComponent, shortcut.getId());
            }
        }
    }

    public void bindDeepShortcuts() {
        final MultiHashMap<ComponentKey, String> shortcutMapCopy = mBgDeepShortcutMap.clone();
        final MultiHashMap<ComponentKey, String> shortcutMapCopy =
                sBgDataModel.deepShortcutMap.clone();
        Runnable r = new Runnable() {
            @Override
            public void run() {
@@ -2989,11 +2950,6 @@ public class LauncherModel extends BroadcastReceiver
                                        }
                                    }

                                    // Restore the shortcut.
                                    if (appInfo != null) {
                                        si.flags = appInfo.flags;
                                    }

                                    si.intent = si.promisedIntent;
                                    si.promisedIntent = null;
                                    si.status = ShortcutInfo.DEFAULT;
@@ -3221,7 +3177,7 @@ public class LauncherModel extends BroadcastReceiver

            if (mUpdateIdMap) {
                // Update the deep shortcut map if the list of ids has changed for an activity.
                updateDeepShortcutMap(mPackageName, mUser, mShortcuts);
                sBgDataModel.updateDeepShortcutMap(mPackageName, mUser, mShortcuts);
                bindDeepShortcuts();
            }
        }
@@ -3289,7 +3245,7 @@ public class LauncherModel extends BroadcastReceiver
            }

            // Remove shortcut id map for that user
            Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator();
            Iterator<ComponentKey> keysIter = sBgDataModel.deepShortcutMap.keySet().iterator();
            while (keysIter.hasNext()) {
                if (keysIter.next().user.equals(mUser)) {
                    keysIter.remove();
@@ -3297,7 +3253,8 @@ public class LauncherModel extends BroadcastReceiver
            }

            if (isUserUnlocked) {
                updateDeepShortcutMap(null, mUser, mDeepShortcutManager.queryForAllShortcuts(mUser));
                sBgDataModel.updateDeepShortcutMap(
                        null, mUser, mDeepShortcutManager.queryForAllShortcuts(mUser));
            }
            bindDeepShortcuts();
        }
@@ -3338,15 +3295,6 @@ public class LauncherModel extends BroadcastReceiver
        return !launcherApps.isPackageEnabledForProfile(packageName, user);
    }

    public static boolean isValidPackage(Context context, String packageName,
            UserHandleCompat user) {
        if (packageName == null) {
            return false;
        }
        final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
        return launcherApps.isPackageEnabledForProfile(packageName, user);
    }

    /**
     * Make an ShortcutInfo object for a restored application or shortcut item that points
     * to a package that is not yet installed on the system.
@@ -3454,9 +3402,6 @@ public class LauncherModel extends BroadcastReceiver
        info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
        info.user = user;
        info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
        if (lai != null) {
            info.flags = AppInfo.initFlags(lai);
        }
        return info;
    }

+1 −1
Original line number Diff line number Diff line
@@ -1014,7 +1014,7 @@ public class LauncherProvider extends ContentProvider {

        public void checkId(String table, ContentValues values) {
            long id = values.getAsLong(LauncherSettings.BaseLauncherColumns._ID);
            if (table == WorkspaceScreens.TABLE_NAME) {
            if (WorkspaceScreens.TABLE_NAME.equals(table)) {
                mMaxScreenId = Math.max(id, mMaxScreenId);
            }  else {
                mMaxItemId = Math.max(id, mMaxItemId);
Loading