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

Commit ff05f437 authored by Kenny Guy's avatar Kenny Guy Committed by Rubin Xu
Browse files

Respond to managed profile availabilty Intents.

Grey out applications when managed profile is
not available.

Change-Id: I9bb9442cd0b3d0d207062716bfd6b179e3ba8489
parent 44cba696
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -78,12 +78,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
@@ -2652,7 +2652,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
@@ -107,6 +107,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
@@ -1230,7 +1230,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();
        }
@@ -1741,8 +1742,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;
@@ -1796,6 +1800,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) {
@@ -2728,12 +2735,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
@@ -116,6 +116,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