Merge "[pm/launcher] add back progress listening in PackageManagerInternal" into sc-dev

This commit is contained in:
Songchun Fan
2021-02-10 16:36:20 +00:00
committed by Android (Google) Code Review
3 changed files with 71 additions and 0 deletions

View File

@@ -997,6 +997,18 @@ public abstract class PackageManagerInternal {
*/
public abstract boolean isSuspendingAnyPackages(String suspendingPackage, int userId);
/**
* Register to listen for loading progress of an installed package.
* The listener is automatically unregistered when the app is fully loaded.
* @param packageName The name of the installed package
* @param callback To loading reporting progress
* @param userId The user under which to check.
* @return Whether the registration was successful. It can fail if the package has not been
* installed yet.
*/
public abstract boolean registerInstalledLoadingProgressCallback(@NonNull String packageName,
@NonNull InstalledLoadingProgressCallback callback, int userId);
/**
* Returns the string representation of a known package. For example,
* {@link #PACKAGE_SETUP_WIZARD} is represented by the string Setup Wizard.

View File

@@ -1317,6 +1317,10 @@ public class LauncherAppsService extends SystemService {
mListeners.finishBroadcast();
}
super.onPackageAdded(packageName, uid);
PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
pmi.registerInstalledLoadingProgressCallback(packageName,
new PackageLoadingProgressCallback(packageName, user),
user.getIdentifier());
}
@Override
@@ -1538,5 +1542,38 @@ public class LauncherAppsService extends SystemService {
checkCallbackCount();
}
}
class PackageLoadingProgressCallback extends
PackageManagerInternal.InstalledLoadingProgressCallback {
private String mPackageName;
private UserHandle mUser;
PackageLoadingProgressCallback(String packageName, UserHandle user) {
super(mCallbackHandler);
mPackageName = packageName;
mUser = user;
}
@Override
public void onLoadingProgressChanged(float progress) {
final int n = mListeners.beginBroadcast();
try {
for (int i = 0; i < n; i++) {
IOnAppsChangedListener listener = mListeners.getBroadcastItem(i);
BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i);
if (!isEnabledProfileOf(cookie.user, mUser, "onLoadingProgressChanged")) {
continue;
}
try {
listener.onPackageLoadingProgressChanged(mUser, mPackageName, progress);
} catch (RemoteException re) {
Slog.d(TAG, "Callback failed ", re);
}
}
} finally {
mListeners.finishBroadcast();
}
}
}
}
}

View File

@@ -27035,6 +27035,28 @@ public class PackageManagerService extends IPackageManager.Stub
return PackageManagerService.this.isSuspendingAnyPackages(suspendingPackage, userId);
}
@Override
public boolean registerInstalledLoadingProgressCallback(String packageName,
PackageManagerInternal.InstalledLoadingProgressCallback callback, int userId) {
final PackageSetting ps = getPackageSettingForUser(packageName, Binder.getCallingUid(),
userId);
if (ps == null) {
return false;
}
if (!ps.isPackageLoading()) {
Slog.w(TAG,
"Failed registering loading progress callback. Package is fully loaded.");
return false;
}
if (mIncrementalManager == null) {
Slog.w(TAG,
"Failed registering loading progress callback. Incremental is not enabled");
return false;
}
return mIncrementalManager.registerLoadingProgressCallback(ps.getPathString(),
(IPackageLoadingProgressCallback) callback.getBinder());
}
@Override
public IncrementalStatesInfo getIncrementalStatesInfo(
@NonNull String packageName, int filterCallingUid, int userId) {