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

Commit 3971d145 authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm/launcher] add back progress listening in PackageManagerInternal

(This partially reverts ag/13481636)

Turns out Launcher still uses
LauncherApps.onPackageLoadingProgressChanged(), which relies on the
internal listener exposed via PackageManagerInternal. Adding it back.
We don't need the unregister method, because all the progress listeners
will be automatically removed when the app is fully loaded.

BUG: 175135603
Test: manual with incremental install via Phonesky
Change-Id: Ief09d3c7775080f35568b6ec51d6351a9373f04e
parent 084f3be4
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -996,6 +996,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
@@ -27039,6 +27039,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) {