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

Commit e0b655e8 authored by Kenny Guy's avatar Kenny Guy Committed by Sunny Goyal
Browse files

Respond to managed profile availabilty Intents.

Grey out applications when managed profile is
not available.

Change-Id: I9bb9442cd0b3d0d207062716bfd6b179e3ba8489
(cherry picked from commit ff05f437)
parent 82fdb81d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -80,12 +80,22 @@ public class AppInfo extends ItemInfo {
     */
    public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
            IconCache iconCache) {
        this(context, info, user, iconCache,
                UserManagerCompat.getInstance(context).isQuietModeEnabled(user));
    }

    public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
            IconCache iconCache, boolean quietModeEnabled) {
        this.componentName = info.getComponentName();
        this.container = ItemInfo.NO_ID;
        flags = initFlags(info);
        if ((info.getApplicationInfo().flags & LauncherActivityInfoCompat.FLAG_SUSPENDED) != 0) {
            isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
        }
        if (quietModeEnabled) {
            isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
        }

        iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
        intent = makeLaunchIntent(context, info, user);
        this.user = user;
+2 −1
Original line number Diff line number Diff line
@@ -2676,7 +2676,8 @@ public class Launcher extends Activity
        final ShortcutInfo shortcut = (ShortcutInfo) tag;

        if (shortcut.isDisabled != 0) {
            if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0) {
            if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
                || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
                // Launch activity anyway, framework will tell the user why the app is suspended.
            } else {
                int error = R.string.activity_not_available;
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ public class LauncherAppState {
        // For handling managed profiles
        filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
        filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
        filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);

        sContext.registerReceiver(mModel, filter);
        UserManagerCompat.getInstance(sContext).enableAndResetCache();
+11 −4
Original line number Diff line number Diff line
@@ -1296,7 +1296,8 @@ public class LauncherModel extends BroadcastReceiver
                callbacks.bindSearchProviderChanged();
            }
        } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
                || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
                || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)
                || LauncherAppsCompat.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED.equals(action)) {
            UserManagerCompat.getInstance(context).enableAndResetCache();
            forceReload();
        }
@@ -1836,8 +1837,11 @@ public class LauncherModel extends BroadcastReceiver
                    final CursorIconInfo cursorIconInfo = new CursorIconInfo(c);

                    final LongSparseArray<UserHandleCompat> allUsers = new LongSparseArray<>();
                    final LongSparseArray<Boolean> quietMode = new LongSparseArray<>();
                    for (UserHandleCompat user : mUserManager.getUserProfiles()) {
                        allUsers.put(mUserManager.getSerialNumberForUser(user), user);
                        long serialNo = mUserManager.getSerialNumberForUser(user);
                        allUsers.put(serialNo, user);
                        quietMode.put(serialNo, mUserManager.isQuietModeEnabled(user));
                    }

                    ShortcutInfo info;
@@ -1891,6 +1895,9 @@ public class LauncherModel extends BroadcastReceiver
                                            if (isSuspended) {
                                                disabledState = ShortcutInfo.FLAG_DISABLED_SUSPENDED;
                                            }
                                            if (quietMode.get(serialNumber)) {
                                                disabledState |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
                                            }
                                        } else if (validPkg) {
                                            intent = null;
                                            if ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) {
@@ -2829,12 +2836,12 @@ public class LauncherModel extends BroadcastReceiver
                if (apps == null || apps.isEmpty()) {
                    return;
                }

                boolean quietMode = mUserManager.isQuietModeEnabled(user);
                // Create the ApplicationInfos
                for (int i = 0; i < apps.size(); i++) {
                    LauncherActivityInfoCompat app = apps.get(i);
                    // This builds the icon bitmaps.
                    mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache));
                    mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache, quietMode));
                }

                final ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user);
+5 −0
Original line number Diff line number Diff line
@@ -117,6 +117,11 @@ public class ShortcutInfo extends ItemInfo {
     */
    public static final int FLAG_DISABLED_SUSPENDED = 4;

    /**
     * Indicates that the icon is disabled as the user is in quiet mode.
     */
    public static final int FLAG_DISABLED_QUIET_USER = 8;

    /**
     * Could be disabled, if the the app is installed but unavailable (eg. in safe mode or when
     * sd-card is not available).
Loading