|
|
|
@@ -17,6 +17,7 @@
|
|
|
|
|
package com.android.launcher3.pm;
|
|
|
|
|
|
|
|
|
|
import static com.android.launcher3.Utilities.getPrefs;
|
|
|
|
|
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
@@ -31,6 +32,7 @@ import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
import androidx.annotation.WorkerThread;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.LauncherSettings;
|
|
|
|
|
import com.android.launcher3.SessionCommitReceiver;
|
|
|
|
@@ -39,10 +41,10 @@ import com.android.launcher3.config.FeatureFlags;
|
|
|
|
|
import com.android.launcher3.model.ItemInstallQueue;
|
|
|
|
|
import com.android.launcher3.util.IntArray;
|
|
|
|
|
import com.android.launcher3.util.IntSet;
|
|
|
|
|
import com.android.launcher3.util.LooperExecutor;
|
|
|
|
|
import com.android.launcher3.util.MainThreadInitializedObject;
|
|
|
|
|
import com.android.launcher3.util.PackageManagerHelper;
|
|
|
|
|
import com.android.launcher3.util.PackageUserKey;
|
|
|
|
|
import com.android.launcher3.util.Preconditions;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@@ -65,27 +67,27 @@ public class InstallSessionHelper {
|
|
|
|
|
|
|
|
|
|
private final LauncherApps mLauncherApps;
|
|
|
|
|
private final Context mAppContext;
|
|
|
|
|
private final IntSet mPromiseIconIds;
|
|
|
|
|
|
|
|
|
|
private final PackageInstaller mInstaller;
|
|
|
|
|
private final HashMap<String, Boolean> mSessionVerifiedMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private IntSet mPromiseIconIds;
|
|
|
|
|
|
|
|
|
|
public InstallSessionHelper(Context context) {
|
|
|
|
|
mInstaller = context.getPackageManager().getPackageInstaller();
|
|
|
|
|
mAppContext = context.getApplicationContext();
|
|
|
|
|
mLauncherApps = context.getSystemService(LauncherApps.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@WorkerThread
|
|
|
|
|
private IntSet getPromiseIconIds() {
|
|
|
|
|
Preconditions.assertWorkerThread();
|
|
|
|
|
if (mPromiseIconIds != null) {
|
|
|
|
|
return mPromiseIconIds;
|
|
|
|
|
}
|
|
|
|
|
mPromiseIconIds = IntSet.wrap(IntArray.fromConcatString(
|
|
|
|
|
getPrefs(context).getString(PROMISE_ICON_IDS, "")));
|
|
|
|
|
getPrefs(mAppContext).getString(PROMISE_ICON_IDS, "")));
|
|
|
|
|
|
|
|
|
|
cleanUpPromiseIconIds();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static UserHandle getUserHandle(SessionInfo info) {
|
|
|
|
|
return Utilities.ATLEAST_Q ? info.getUser() : Process.myUserHandle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void cleanUpPromiseIconIds() {
|
|
|
|
|
IntArray existingIds = new IntArray();
|
|
|
|
|
for (SessionInfo info : getActiveSessions().values()) {
|
|
|
|
|
existingIds.add(info.getSessionId());
|
|
|
|
@@ -100,6 +102,7 @@ public class InstallSessionHelper {
|
|
|
|
|
for (int i = idsToRemove.size() - 1; i >= 0; --i) {
|
|
|
|
|
mPromiseIconIds.getArray().removeValue(idsToRemove.get(i));
|
|
|
|
|
}
|
|
|
|
|
return mPromiseIconIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HashMap<PackageUserKey, SessionInfo> getActiveSessions() {
|
|
|
|
@@ -126,7 +129,7 @@ public class InstallSessionHelper {
|
|
|
|
|
|
|
|
|
|
private void updatePromiseIconPrefs() {
|
|
|
|
|
getPrefs(mAppContext).edit()
|
|
|
|
|
.putString(PROMISE_ICON_IDS, mPromiseIconIds.getArray().toConcatString())
|
|
|
|
|
.putString(PROMISE_ICON_IDS, getPromiseIconIds().getArray().toConcatString())
|
|
|
|
|
.apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -184,13 +187,15 @@ public class InstallSessionHelper {
|
|
|
|
|
return info.getInstallReason() == PackageManager.INSTALL_REASON_DEVICE_RESTORE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@WorkerThread
|
|
|
|
|
public boolean promiseIconAddedForId(int sessionId) {
|
|
|
|
|
return mPromiseIconIds.contains(sessionId);
|
|
|
|
|
return getPromiseIconIds().contains(sessionId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@WorkerThread
|
|
|
|
|
public void removePromiseIconId(int sessionId) {
|
|
|
|
|
if (mPromiseIconIds.contains(sessionId)) {
|
|
|
|
|
mPromiseIconIds.getArray().removeValue(sessionId);
|
|
|
|
|
if (promiseIconAddedForId(sessionId)) {
|
|
|
|
|
getPromiseIconIds().getArray().removeValue(sessionId);
|
|
|
|
|
updatePromiseIconPrefs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -203,6 +208,7 @@ public class InstallSessionHelper {
|
|
|
|
|
* - The app is not already installed
|
|
|
|
|
* - A promise icon for the session has not already been created
|
|
|
|
|
*/
|
|
|
|
|
@WorkerThread
|
|
|
|
|
void tryQueuePromiseAppIcon(PackageInstaller.SessionInfo sessionInfo) {
|
|
|
|
|
if (FeatureFlags.PROMISE_APPS_NEW_INSTALLS.get()
|
|
|
|
|
&& SessionCommitReceiver.isEnabled(mAppContext)
|
|
|
|
@@ -210,25 +216,24 @@ public class InstallSessionHelper {
|
|
|
|
|
&& sessionInfo.getInstallReason() == PackageManager.INSTALL_REASON_USER
|
|
|
|
|
&& sessionInfo.getAppIcon() != null
|
|
|
|
|
&& !TextUtils.isEmpty(sessionInfo.getAppLabel())
|
|
|
|
|
&& !mPromiseIconIds.contains(sessionInfo.getSessionId())
|
|
|
|
|
&& !promiseIconAddedForId(sessionInfo.getSessionId())
|
|
|
|
|
&& new PackageManagerHelper(mAppContext).getApplicationInfo(
|
|
|
|
|
sessionInfo.getAppPackageName(), getUserHandle(sessionInfo), 0) == null) {
|
|
|
|
|
ItemInstallQueue.INSTANCE.get(mAppContext)
|
|
|
|
|
.queueItem(sessionInfo.getAppPackageName(), getUserHandle(sessionInfo));
|
|
|
|
|
|
|
|
|
|
mPromiseIconIds.add(sessionInfo.getSessionId());
|
|
|
|
|
getPromiseIconIds().add(sessionInfo.getSessionId());
|
|
|
|
|
updatePromiseIconPrefs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InstallSessionTracker registerInstallTracker(
|
|
|
|
|
InstallSessionTracker.Callback callback, LooperExecutor executor) {
|
|
|
|
|
public InstallSessionTracker registerInstallTracker(InstallSessionTracker.Callback callback) {
|
|
|
|
|
InstallSessionTracker tracker = new InstallSessionTracker(this, callback);
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
|
|
|
|
mInstaller.registerSessionCallback(tracker, executor.getHandler());
|
|
|
|
|
mInstaller.registerSessionCallback(tracker, MODEL_EXECUTOR.getHandler());
|
|
|
|
|
} else {
|
|
|
|
|
mLauncherApps.registerPackageInstallerSessionCallback(executor, tracker);
|
|
|
|
|
mLauncherApps.registerPackageInstallerSessionCallback(MODEL_EXECUTOR, tracker);
|
|
|
|
|
}
|
|
|
|
|
return tracker;
|
|
|
|
|
}
|
|
|
|
@@ -240,4 +245,8 @@ public class InstallSessionHelper {
|
|
|
|
|
mLauncherApps.unregisterPackageInstallerSessionCallback(tracker);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static UserHandle getUserHandle(SessionInfo info) {
|
|
|
|
|
return Utilities.ATLEAST_Q ? info.getUser() : Process.myUserHandle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|