Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58e34307 authored by Songchun Fan's avatar Songchun Fan Committed by Android (Google) Code Review
Browse files

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

parents bf03ae3b 3971d145
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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.
+37 −0
Original line number Diff line number Diff line
@@ -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();
                }
            }
        }
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -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) {