mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-03 17:36:49 +00:00
Explicit Nullbility in Launcher (Part 5)
This CL addresses the nullbility in LauncherModel and update tasks. Bug: 242895652 Test: manual Change-Id: Ied635c944c3656f0d493b295f772aa0329b354b9
This commit is contained in:
@@ -30,6 +30,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
@@ -51,38 +52,50 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Utility class to tracking install sessions
|
||||
*/
|
||||
public class InstallSessionHelper {
|
||||
|
||||
@NonNull
|
||||
private static final String LOG = "InstallSessionHelper";
|
||||
|
||||
// Set<String> of session ids of promise icons that have been added to the home screen
|
||||
// as FLAG_PROMISE_NEW_INSTALLS.
|
||||
@NonNull
|
||||
protected static final String PROMISE_ICON_IDS = "promise_icon_ids";
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
@NonNull
|
||||
public static final MainThreadInitializedObject<InstallSessionHelper> INSTANCE =
|
||||
new MainThreadInitializedObject<>(InstallSessionHelper::new);
|
||||
|
||||
@Nullable
|
||||
private final LauncherApps mLauncherApps;
|
||||
|
||||
@NonNull
|
||||
private final Context mAppContext;
|
||||
|
||||
@NonNull
|
||||
private final PackageInstaller mInstaller;
|
||||
|
||||
@NonNull
|
||||
private final HashMap<String, Boolean> mSessionVerifiedMap = new HashMap<>();
|
||||
|
||||
@Nullable
|
||||
private IntSet mPromiseIconIds;
|
||||
|
||||
public InstallSessionHelper(Context context) {
|
||||
public InstallSessionHelper(@NonNull final Context context) {
|
||||
mInstaller = context.getPackageManager().getPackageInstaller();
|
||||
mAppContext = context.getApplicationContext();
|
||||
mLauncherApps = context.getSystemService(LauncherApps.class);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@NonNull
|
||||
private IntSet getPromiseIconIds() {
|
||||
Preconditions.assertWorkerThread();
|
||||
if (mPromiseIconIds != null) {
|
||||
@@ -108,6 +121,7 @@ public class InstallSessionHelper {
|
||||
return mPromiseIconIds;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public HashMap<PackageUserKey, SessionInfo> getActiveSessions() {
|
||||
HashMap<PackageUserKey, SessionInfo> activePackages = new HashMap<>();
|
||||
for (SessionInfo info : getAllVerifiedSessions()) {
|
||||
@@ -117,6 +131,7 @@ public class InstallSessionHelper {
|
||||
return activePackages;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public SessionInfo getActiveSessionInfo(UserHandle user, String pkg) {
|
||||
for (SessionInfo info : getAllVerifiedSessions()) {
|
||||
boolean match = pkg.equals(info.getAppPackageName());
|
||||
@@ -136,11 +151,13 @@ public class InstallSessionHelper {
|
||||
.apply();
|
||||
}
|
||||
|
||||
SessionInfo getVerifiedSessionInfo(int sessionId) {
|
||||
@Nullable
|
||||
SessionInfo getVerifiedSessionInfo(final int sessionId) {
|
||||
return verify(mInstaller.getSessionInfo(sessionId));
|
||||
}
|
||||
|
||||
private SessionInfo verify(SessionInfo sessionInfo) {
|
||||
@Nullable
|
||||
private SessionInfo verify(@Nullable final SessionInfo sessionInfo) {
|
||||
if (sessionInfo == null
|
||||
|| sessionInfo.getInstallerPackageName() == null
|
||||
|| TextUtils.isEmpty(sessionInfo.getAppPackageName())) {
|
||||
@@ -167,9 +184,10 @@ public class InstallSessionHelper {
|
||||
return mSessionVerifiedMap.get(pkg) ? sessionInfo : null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<SessionInfo> getAllVerifiedSessions() {
|
||||
List<SessionInfo> list = new ArrayList<>(Utilities.ATLEAST_Q
|
||||
? mLauncherApps.getAllPackageInstallerSessions()
|
||||
? Objects.requireNonNull(mLauncherApps).getAllPackageInstallerSessions()
|
||||
: mInstaller.getAllSessions());
|
||||
Iterator<SessionInfo> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
@@ -201,12 +219,12 @@ public class InstallSessionHelper {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public boolean promiseIconAddedForId(int sessionId) {
|
||||
public boolean promiseIconAddedForId(final int sessionId) {
|
||||
return getPromiseIconIds().contains(sessionId);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public void removePromiseIconId(int sessionId) {
|
||||
public void removePromiseIconId(final int sessionId) {
|
||||
if (promiseIconAddedForId(sessionId)) {
|
||||
getPromiseIconIds().getArray().removeValue(sessionId);
|
||||
updatePromiseIconPrefs();
|
||||
@@ -222,7 +240,7 @@ public class InstallSessionHelper {
|
||||
* - A promise icon for the session has not already been created
|
||||
*/
|
||||
@WorkerThread
|
||||
void tryQueuePromiseAppIcon(PackageInstaller.SessionInfo sessionInfo) {
|
||||
void tryQueuePromiseAppIcon(@Nullable final PackageInstaller.SessionInfo sessionInfo) {
|
||||
if (TestProtocol.sDebugTracing) {
|
||||
Log.d(TestProtocol.MISSING_PROMISE_ICON, LOG + " tryQueuePromiseAppIcon"
|
||||
+ ", SessionCommitReceiveEnabled" + SessionCommitReceiver.isEnabled(mAppContext)
|
||||
@@ -244,7 +262,7 @@ public class InstallSessionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean verifySessionInfo(PackageInstaller.SessionInfo sessionInfo) {
|
||||
public boolean verifySessionInfo(@Nullable final PackageInstaller.SessionInfo sessionInfo) {
|
||||
if (TestProtocol.sDebugTracing) {
|
||||
boolean appNotInstalled = sessionInfo == null
|
||||
|| !new PackageManagerHelper(mAppContext)
|
||||
@@ -267,14 +285,15 @@ public class InstallSessionHelper {
|
||||
sessionInfo.getAppPackageName(), getUserHandle(sessionInfo));
|
||||
}
|
||||
|
||||
public InstallSessionTracker registerInstallTracker(InstallSessionTracker.Callback callback) {
|
||||
public InstallSessionTracker registerInstallTracker(
|
||||
@Nullable final InstallSessionTracker.Callback callback) {
|
||||
InstallSessionTracker tracker = new InstallSessionTracker(
|
||||
this, callback, mInstaller, mLauncherApps);
|
||||
tracker.register();
|
||||
return tracker;
|
||||
}
|
||||
|
||||
public static UserHandle getUserHandle(SessionInfo info) {
|
||||
public static UserHandle getUserHandle(@NonNull final SessionInfo info) {
|
||||
return Utilities.ATLEAST_Q ? info.getUser() : Process.myUserHandle();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user