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

Commit a42b2830 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Handling IllegalStateException which can be thrown by the system when...

Merge "Handling IllegalStateException which can be thrown by the system when the user is locked" into ub-launcher3-calgary
parents 73a0a726 49f4f03d
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line
@@ -1729,17 +1729,24 @@ public class LauncherModel extends BroadcastReceiver
                        quietMode.put(serialNo, mUserManager.isQuietModeEnabled(user));

                        boolean userUnlocked = mUserManager.isUserUnlocked(user);
                        unlockedUsers.put(serialNo, userUnlocked);

                        // We can only query for shortcuts when the user is unlocked.
                        if (userUnlocked) {
                            List<ShortcutInfoCompat> pinnedShortcuts = mDeepShortcutManager
                                    .queryForPinnedShortcuts(null, user);
                            List<ShortcutInfoCompat> pinnedShortcuts =
                                    mDeepShortcutManager.queryForPinnedShortcuts(null, user);
                            if (mDeepShortcutManager.wasLastCallSuccess()) {
                                for (ShortcutInfoCompat shortcut : pinnedShortcuts) {
                                    shortcutKeyToPinnedShortcuts.put(ShortcutKey.fromInfo(shortcut),
                                            shortcut);
                                }
                            } else {
                                // Shortcut manager can fail due to some race condition when the
                                // lock state changes too frequently. For the purpose of the loading
                                // shortcuts, consider the user is still locked.
                                userUnlocked = false;
                            }
                        }
                        unlockedUsers.put(serialNo, userUnlocked);
                    }

                    ShortcutInfo info;
@@ -3383,10 +3390,18 @@ public class LauncherModel extends BroadcastReceiver

            HashMap<ShortcutKey, ShortcutInfoCompat> pinnedShortcuts = new HashMap<>();
            if (isUserUnlocked) {
                for (ShortcutInfoCompat shortcut :
                        mDeepShortcutManager.queryForPinnedShortcuts(null, mUser)) {
                List<ShortcutInfoCompat> shortcuts =
                        mDeepShortcutManager.queryForPinnedShortcuts(null, mUser);
                if (mDeepShortcutManager.wasLastCallSuccess()) {
                    for (ShortcutInfoCompat shortcut : shortcuts) {
                        pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
                    }
                } else {
                    // Shortcut manager can fail due to some race condition when the lock state
                    // changes too frequently. For the purpose of the update,
                    // consider it as still locked.
                    isUserUnlocked = false;
                }
            }

            // Update the workspace to reflect the changes to updated shortcuts residing on it.
+5 −5
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ public class DeepShortcutManager {
            try {
                mLauncherApps.pinShortcuts(packageName, pinnedIds, user.getUser());
                mWasLastCallSuccess = true;
            } catch (SecurityException e) {
            } catch (SecurityException|IllegalStateException e) {
                Log.w(TAG, "Failed to unpin shortcut", e);
                mWasLastCallSuccess = false;
            }
@@ -127,7 +127,7 @@ public class DeepShortcutManager {
            try {
                mLauncherApps.pinShortcuts(packageName, pinnedIds, user.getUser());
                mWasLastCallSuccess = true;
            } catch (SecurityException e) {
            } catch (SecurityException|IllegalStateException e) {
                Log.w(TAG, "Failed to pin shortcut", e);
                mWasLastCallSuccess = false;
            }
@@ -142,7 +142,7 @@ public class DeepShortcutManager {
                mLauncherApps.startShortcut(packageName, id, sourceBounds,
                        startActivityOptions, user.getUser());
                mWasLastCallSuccess = true;
            } catch (SecurityException e) {
            } catch (SecurityException|IllegalStateException e) {
                Log.e(TAG, "Failed to start shortcut", e);
                mWasLastCallSuccess = false;
            }
@@ -157,7 +157,7 @@ public class DeepShortcutManager {
                        shortcutInfo.getShortcutInfo(), density);
                mWasLastCallSuccess = true;
                return icon;
            } catch (SecurityException e) {
            } catch (SecurityException|IllegalStateException e) {
                Log.e(TAG, "Failed to get shortcut icon", e);
                mWasLastCallSuccess = false;
            }
@@ -208,7 +208,7 @@ public class DeepShortcutManager {
            try {
                shortcutInfos = mLauncherApps.getShortcuts(q, user.getUser());
                mWasLastCallSuccess = true;
            } catch (SecurityException e) {
            } catch (SecurityException|IllegalStateException e) {
                Log.e(TAG, "Failed to query for shortcuts", e);
                mWasLastCallSuccess = false;
            }