Fix the issue "Turn on work profile?" dialog not displayed for

work profile deep shortcuts when disabled.

When work profile is locked, the state change doesn't propagated
into UserManagerService immediately. This CL remove that dependency,
rather than having Launcher calls UserManager#isUserUnlocked, the state
is passed into UserLockStateChangedTask by extracting user state from
broadcasted intent at the call-site.

Bug: 147210578
Test: manual
Change-Id: I87f3d0478df44df60e273189f77b61bc40dd2630
This commit is contained in:
Pinyao Ting
2020-04-06 18:11:29 -07:00
parent e8fade9140
commit 8e5db81c3b
2 changed files with 9 additions and 8 deletions

View File

@@ -20,7 +20,6 @@ import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
import android.content.Context;
import android.content.pm.ShortcutInfo;
import android.os.UserHandle;
import android.os.UserManager;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
@@ -43,18 +42,19 @@ import java.util.Iterator;
public class UserLockStateChangedTask extends BaseModelUpdateTask {
private final UserHandle mUser;
private boolean mIsUserUnlocked;
public UserLockStateChangedTask(UserHandle user) {
public UserLockStateChangedTask(UserHandle user, boolean isUserUnlocked) {
mUser = user;
mIsUserUnlocked = isUserUnlocked;
}
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
Context context = app.getContext();
boolean isUserUnlocked = context.getSystemService(UserManager.class).isUserUnlocked(mUser);
HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
if (isUserUnlocked) {
if (mIsUserUnlocked) {
QueryResult shortcuts = new ShortcutRequest(context, mUser)
.query(ShortcutRequest.PINNED);
if (shortcuts.wasSuccess()) {
@@ -65,7 +65,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask {
// 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;
mIsUserUnlocked = false;
}
}
@@ -77,7 +77,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask {
if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT
&& mUser.equals(itemInfo.user)) {
WorkspaceItemInfo si = (WorkspaceItemInfo) itemInfo;
if (isUserUnlocked) {
if (mIsUserUnlocked) {
ShortcutKey key = ShortcutKey.fromItemInfo(si);
ShortcutInfo shortcut = pinnedShortcuts.get(key);
// We couldn't verify the shortcut during loader. If its no longer available
@@ -108,7 +108,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask {
}
}
if (isUserUnlocked) {
if (mIsUserUnlocked) {
dataModel.updateDeepShortcutCounts(
null, mUser,
new ShortcutRequest(context, mUser).query(ShortcutRequest.ALL));