mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 16:26:47 +00:00
Key by both package and user for list of active install sessions.
This fixes the bug where items are left on the home screen for the wrong user. Bug: 139281702 Change-Id: I03c31bb308fc496b9fc633c2fde23ae4568f8c44
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.launcher3.compat;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInstaller;
|
||||
import android.content.pm.PackageInstaller.SessionInfo;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
|
||||
@@ -29,6 +30,7 @@ import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
|
||||
public abstract class PackageInstallerCompat {
|
||||
|
||||
@@ -52,19 +54,19 @@ public abstract class PackageInstallerCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public static UserHandle getUserHandle(PackageInstaller.SessionInfo info) {
|
||||
public static UserHandle getUserHandle(SessionInfo info) {
|
||||
return Utilities.ATLEAST_Q ? info.getUser() : Process.myUserHandle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map of active installs to their progress
|
||||
*/
|
||||
public abstract HashMap<String, PackageInstaller.SessionInfo> updateAndGetActiveSessionCache();
|
||||
public abstract HashMap<PackageUserKey, SessionInfo> updateAndGetActiveSessionCache();
|
||||
|
||||
/**
|
||||
* @return an active SessionInfo for {@param pkg} or null if none exists.
|
||||
*/
|
||||
public abstract PackageInstaller.SessionInfo getActiveSessionInfo(UserHandle user, String pkg);
|
||||
public abstract SessionInfo getActiveSessionInfo(UserHandle user, String pkg);
|
||||
|
||||
public abstract void onStop();
|
||||
|
||||
@@ -75,7 +77,7 @@ public abstract class PackageInstallerCompat {
|
||||
public final int progress;
|
||||
public final UserHandle user;
|
||||
|
||||
private PackageInstallInfo(@NonNull PackageInstaller.SessionInfo info) {
|
||||
private PackageInstallInfo(@NonNull SessionInfo info) {
|
||||
this.state = STATUS_INSTALLING;
|
||||
this.packageName = info.getAppPackageName();
|
||||
this.componentName = new ComponentName(packageName, "");
|
||||
@@ -91,7 +93,7 @@ public abstract class PackageInstallerCompat {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public static PackageInstallInfo fromInstallingState(PackageInstaller.SessionInfo info) {
|
||||
public static PackageInstallInfo fromInstallingState(SessionInfo info) {
|
||||
return new PackageInstallInfo(info);
|
||||
}
|
||||
|
||||
@@ -101,7 +103,7 @@ public abstract class PackageInstallerCompat {
|
||||
|
||||
}
|
||||
|
||||
public abstract List<PackageInstaller.SessionInfo> getAllVerifiedSessions();
|
||||
public abstract List<SessionInfo> getAllVerifiedSessions();
|
||||
|
||||
/**
|
||||
* Returns true if a promise icon was already added to the home screen for {@param sessionId}.
|
||||
|
||||
@@ -90,12 +90,13 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, SessionInfo> updateAndGetActiveSessionCache() {
|
||||
HashMap<String, SessionInfo> activePackages = new HashMap<>();
|
||||
public HashMap<PackageUserKey, SessionInfo> updateAndGetActiveSessionCache() {
|
||||
HashMap<PackageUserKey, SessionInfo> activePackages = new HashMap<>();
|
||||
for (SessionInfo info : getAllVerifiedSessions()) {
|
||||
addSessionInfoToCache(info, getUserHandle(info));
|
||||
if (info.getAppPackageName() != null) {
|
||||
activePackages.put(info.getAppPackageName(), info);
|
||||
activePackages.put(new PackageUserKey(info.getAppPackageName(),
|
||||
getUserHandle(info)), info);
|
||||
mActiveSessions.put(info.getSessionId(),
|
||||
new PackageUserKey(info.getAppPackageName(), getUserHandle(info)));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.util.MultiHashMap;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -34,6 +35,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static android.os.Process.myUserHandle;
|
||||
|
||||
/**
|
||||
* Helper class to send broadcasts to package installers that have:
|
||||
* - Items on the first screen
|
||||
@@ -60,7 +63,7 @@ public class FirstScreenBroadcast {
|
||||
|
||||
private final MultiHashMap<String, String> mPackagesForInstaller;
|
||||
|
||||
public FirstScreenBroadcast(HashMap<String, SessionInfo> sessionInfoForPackage) {
|
||||
public FirstScreenBroadcast(HashMap<PackageUserKey, SessionInfo> sessionInfoForPackage) {
|
||||
mPackagesForInstaller = getPackagesForInstaller(sessionInfoForPackage);
|
||||
}
|
||||
|
||||
@@ -69,11 +72,13 @@ public class FirstScreenBroadcast {
|
||||
* of packages with active sessions for that installer.
|
||||
*/
|
||||
private MultiHashMap<String, String> getPackagesForInstaller(
|
||||
HashMap<String, SessionInfo> sessionInfoForPackage) {
|
||||
HashMap<PackageUserKey, SessionInfo> sessionInfoForPackage) {
|
||||
MultiHashMap<String, String> packagesForInstaller = new MultiHashMap<>();
|
||||
for (Map.Entry<String, SessionInfo> entry : sessionInfoForPackage.entrySet()) {
|
||||
packagesForInstaller.addToList(entry.getValue().getInstallerPackageName(),
|
||||
entry.getKey());
|
||||
for (Map.Entry<PackageUserKey, SessionInfo> entry : sessionInfoForPackage.entrySet()) {
|
||||
if (myUserHandle().equals(entry.getKey().mUser)) {
|
||||
packagesForInstaller.addToList(entry.getValue().getInstallerPackageName(),
|
||||
entry.getKey().mPackageName);
|
||||
}
|
||||
}
|
||||
return packagesForInstaller;
|
||||
}
|
||||
|
||||
@@ -34,10 +34,12 @@ import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
|
||||
import com.android.launcher3.util.GridOccupancy;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
@@ -970,8 +972,9 @@ public class GridSizeMigrationTask {
|
||||
.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
|
||||
validPackages.add(info.packageName);
|
||||
}
|
||||
validPackages.addAll(PackageInstallerCompat.getInstance(context)
|
||||
.updateAndGetActiveSessionCache().keySet());
|
||||
PackageInstallerCompat.getInstance(context)
|
||||
.updateAndGetActiveSessionCache().keySet()
|
||||
.forEach(packageUserKey -> validPackages.add(packageUserKey.mPackageName));
|
||||
return validPackages;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.launcher3.model;
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_SAFEMODE;
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED;
|
||||
import static com.android.launcher3.compat.PackageInstallerCompat.getUserHandle;
|
||||
import static com.android.launcher3.model.LoaderResults.filterCurrentWorkspaceItems;
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
@@ -72,6 +73,7 @@ import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.LooperIdleLock;
|
||||
import com.android.launcher3.util.MultiHashMap;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.util.TraceHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -281,8 +283,9 @@ public class LoaderTask implements Runnable {
|
||||
synchronized (mBgDataModel) {
|
||||
mBgDataModel.clear();
|
||||
|
||||
final HashMap<String, SessionInfo> installingPkgs =
|
||||
final HashMap<PackageUserKey, SessionInfo> installingPkgs =
|
||||
mPackageInstaller.updateAndGetActiveSessionCache();
|
||||
final PackageUserKey tempPackageKey = new PackageUserKey(null, null);
|
||||
mFirstScreenBroadcast = new FirstScreenBroadcast(installingPkgs);
|
||||
|
||||
Map<ShortcutKey, ShortcutInfo> shortcutKeyToPinnedShortcuts = new HashMap<>();
|
||||
@@ -419,9 +422,10 @@ public class LoaderTask implements Runnable {
|
||||
// installed later.
|
||||
FileLog.d(TAG, "package not yet restored: " + targetPkg);
|
||||
|
||||
tempPackageKey.update(targetPkg, c.user);
|
||||
if (c.hasRestoreFlag(WorkspaceItemInfo.FLAG_RESTORE_STARTED)) {
|
||||
// Restore has started once.
|
||||
} else if (installingPkgs.containsKey(targetPkg)) {
|
||||
} else if (installingPkgs.containsKey(tempPackageKey)) {
|
||||
// App restore has started. Update the flag
|
||||
c.restoreFlag |= WorkspaceItemInfo.FLAG_RESTORE_STARTED;
|
||||
c.updater().put(LauncherSettings.Favorites.RESTORED,
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PackageUserKey {
|
||||
update(packageName, user);
|
||||
}
|
||||
|
||||
private void update(String packageName, UserHandle user) {
|
||||
public void update(String packageName, UserHandle user) {
|
||||
mPackageName = packageName;
|
||||
mUser = user;
|
||||
mHashCode = Arrays.hashCode(new Object[] {packageName, user});
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.android.launcher3.tapl.Workspace;
|
||||
import com.android.launcher3.ui.AbstractLauncherUiTest;
|
||||
import com.android.launcher3.ui.TestViewHelpers;
|
||||
import com.android.launcher3.util.ContentWriter;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.util.rule.ShellCommandRule;
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo;
|
||||
import com.android.launcher3.widget.WidgetHostViewLoader;
|
||||
@@ -54,7 +55,9 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Tests for bind widget flow.
|
||||
@@ -326,9 +329,12 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
|
||||
int count = 0;
|
||||
String pkg = invalidPackage;
|
||||
|
||||
Set<String> activePackage = getOnUiThread(() ->
|
||||
PackageInstallerCompat.getInstance(mTargetContext)
|
||||
.updateAndGetActiveSessionCache().keySet());
|
||||
Set<String> activePackage = getOnUiThread(() -> {
|
||||
Set<String> packages = new HashSet<>();
|
||||
PackageInstallerCompat.getInstance(mTargetContext).updateAndGetActiveSessionCache()
|
||||
.keySet().forEach(packageUserKey -> packages.add(packageUserKey.mPackageName));
|
||||
return packages;
|
||||
});
|
||||
while(true) {
|
||||
try {
|
||||
mTargetContext.getPackageManager().getPackageInfo(
|
||||
|
||||
Reference in New Issue
Block a user