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

Commit fafe5257 authored by Hai Zhang's avatar Hai Zhang
Browse files

Call into role controller asynchronously when holding mPackages.

For other cases calling synchronously is better, because callers might
expect the next get call to return the right browser. However in the
case of installing a browser app, we are holding the mPackages lock
and should not be calling into higher level components synchronously,
so use a new async call for this. This fixes the system-hang until
timeout when installing a new browser app.

Bug: 124452117
Bug: 123775970
Test: manual
Change-Id: Ib820e65c79c2315f41ff0e31268631c973af4511
parent 89b58a49
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -160,6 +160,14 @@ public abstract class PackageManagerInternal {
         * @return whether the default browser was successfully set.
         */
        boolean setDefaultBrowser(@Nullable String packageName, @UserIdInt int userId);

        /**
         * Set the package name of the default browser asynchronously.
         *
         * @param packageName package name of the default browser, or {@code null} to remove
         * @param userId the user id
         */
        void setDefaultBrowserAsync(@Nullable String packageName, @UserIdInt int userId);
    }

    /**
+18 −1
Original line number Diff line number Diff line
@@ -1935,7 +1935,7 @@ public class PackageManagerService extends IPackageManager.Stub
                            final PackageSetting pkgSetting = mSettings.mPackages.get(packageName);
                            if (pkgSetting.getInstallReason(userId)
                                    != PackageManager.INSTALL_REASON_DEVICE_RESTORE) {
                                setDefaultBrowserPackageName(null, userId);
                                setDefaultBrowserAsyncLPw(null, userId);
                            }
                        }
@@ -13687,6 +13687,23 @@ public class PackageManagerService extends IPackageManager.Stub
        return true;
    }
    private void setDefaultBrowserAsyncLPw(@Nullable String packageName, @UserIdInt int userId) {
        if (userId == UserHandle.USER_ALL) {
            return;
        }
        if (mDefaultBrowserProvider == null) {
            Slog.e(TAG, "mDefaultBrowserProvider is null");
            return;
        }
        mDefaultBrowserProvider.setDefaultBrowserAsync(packageName, userId);
        if (packageName != null) {
            synchronized (mPackages) {
                mDefaultPermissionPolicy.grantDefaultPermissionsToDefaultBrowser(packageName,
                        userId);
            }
        }
    }
    @Override
    public String getDefaultBrowserPackageName(int userId) {
        if (UserHandle.getCallingUserId() != userId) {
+19 −0
Original line number Diff line number Diff line
@@ -743,6 +743,25 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
                return false;
            }
        }

        @Override
        public void setDefaultBrowserAsync(@Nullable String packageName, @UserIdInt int userId) {
            IRoleManagerCallback callback = new IRoleManagerCallback.Stub() {
                @Override
                public void onSuccess() {}
                @Override
                public void onFailure() {
                    Slog.e(LOG_TAG, "Failed to set default browser: " + packageName);
                }
            };
            if (packageName != null) {
                getOrCreateControllerService(userId).onAddRoleHolder(RoleManager.ROLE_BROWSER,
                        packageName, 0, callback);
            } else {
                getOrCreateControllerService(userId).onClearRoleHolders(RoleManager.ROLE_BROWSER, 0,
                        callback);
            }
        }
    }

    private class DefaultHomeProvider implements PackageManagerInternal.DefaultHomeProvider {