Loading core/java/android/content/pm/PackageManagerInternal.java +10 −0 Original line number Diff line number Diff line Loading @@ -843,4 +843,14 @@ public abstract class PackageManagerInternal { * {@code token} can be completed. */ public abstract void finishPackageInstall(int token, boolean didLaunch); /** * Remove the default browser stored in the legacy package settings. * * @param userId the user id * * @return the package name of the default browser, or {@code null} if none */ @Nullable public abstract String removeLegacyDefaultBrowserPackageName(int userId); } core/res/res/values/config.xml +0 −8 Original line number Diff line number Diff line Loading @@ -1933,14 +1933,6 @@ the platform will search for an SMS app and use that (if there is one)--> <string name="default_sms_application" translatable="false">com.android.messaging</string> <!-- Default web browser. This is the package name of the application that will be the default browser when the device first boots. Afterwards the user can select whatever browser app they wish to use as the default. If this string is empty or the specified package does not exist, then the behavior will be as though no app was named as an explicit default. --> <string name="default_browser" translatable="false"></string> <!-- Default role holders. This will be an array of roles and package names of their default holders, with each item in the format of "ROLE_NAME: PACKAGE_NAME_1, PACKAGE_NAME_2". --> <string-array name="config_defaultRoleHolders" translatable="false"> Loading core/res/res/values/symbols.xml +0 −1 Original line number Diff line number Diff line Loading @@ -1023,7 +1023,6 @@ <java-symbol type="string" name="sipAddressTypeOther" /> <java-symbol type="string" name="sipAddressTypeWork" /> <java-symbol type="string" name="default_sms_application" /> <java-symbol type="string" name="default_browser" /> <java-symbol type="string" name="sms_control_message" /> <java-symbol type="string" name="sms_control_title" /> <java-symbol type="string" name="sms_control_no" /> Loading services/core/java/com/android/server/pm/PackageManagerService.java +40 −77 Original line number Diff line number Diff line Loading @@ -131,6 +131,8 @@ import android.app.ResourcesManager; import android.app.admin.IDevicePolicyManager; import android.app.admin.SecurityLog; import android.app.backup.IBackupManager; import android.app.role.RoleManager; import android.app.role.RoleManagerCallback; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; Loading Loading @@ -288,6 +290,7 @@ import com.android.internal.os.SomeArgs; import com.android.internal.os.Zygote; import com.android.internal.telephony.CarrierAppUtils; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import com.android.internal.util.ConcurrentUtils; import com.android.internal.util.DumpUtils; import com.android.internal.util.FastXmlSerializer; Loading Loading @@ -369,8 +372,10 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; Loading Loading @@ -1927,7 +1932,7 @@ public class PackageManagerService extends IPackageManager.Stub final PackageSetting pkgSetting = mSettings.mPackages.get(packageName); if (pkgSetting.getInstallReason(userId) != PackageManager.INSTALL_REASON_DEVICE_RESTORE) { mSettings.setDefaultBrowserPackageNameLPw(null, userId); setDefaultBrowserPackageName(null, userId); } } Loading Loading @@ -2941,7 +2946,6 @@ public class PackageManagerService extends IPackageManager.Stub if (!onlyCore && (mPromoteSystemApps || mFirstBoot)) { for (UserInfo user : sUserManager.getUsers(true)) { mSettings.applyDefaultPreferredAppsLPw(user.id); applyFactoryDefaultBrowserLPw(user.id); primeDomainVerificationsLPw(user.id); } } Loading Loading @@ -3014,8 +3018,6 @@ public class PackageManagerService extends IPackageManager.Stub ver.fingerprint = Build.FINGERPRINT; } checkDefaultBrowser(); // clear only after permissions and other defaults have been updated mExistingSystemPackages.clear(); mPromoteSystemApps = false; Loading Loading @@ -3670,58 +3672,6 @@ public class PackageManagerService extends IPackageManager.Stub scheduleWriteSettingsLocked(); } @GuardedBy("mPackages") private void applyFactoryDefaultBrowserLPw(int userId) { // The default browser app's package name is stored in a string resource, // with a product-specific overlay used for vendor customization. String browserPkg = mContext.getResources().getString( com.android.internal.R.string.default_browser); if (!TextUtils.isEmpty(browserPkg)) { // non-empty string => required to be a known package PackageSetting ps = mSettings.mPackages.get(browserPkg); if (ps == null) { Slog.e(TAG, "Product default browser app does not exist: " + browserPkg); browserPkg = null; } else { mSettings.setDefaultBrowserPackageNameLPw(browserPkg, userId); } } // Nothing valid explicitly set? Make the factory-installed browser the explicit // default. If there's more than one, just leave everything alone. if (browserPkg == null) { calculateDefaultBrowserLPw(userId); } } @GuardedBy("mPackages") private void calculateDefaultBrowserLPw(int userId) { List<String> allBrowsers = resolveAllBrowserApps(userId); final String browserPkg = (allBrowsers.size() == 1) ? allBrowsers.get(0) : null; mSettings.setDefaultBrowserPackageNameLPw(browserPkg, userId); } private List<String> resolveAllBrowserApps(int userId) { // Resolve the canonical browser intent and check that the handleAllWebDataURI boolean is set List<ResolveInfo> list = queryIntentActivitiesInternal(sBrowserIntent, null, PackageManager.MATCH_ALL, userId); final int count = list.size(); List<String> result = new ArrayList<>(count); for (int i=0; i<count; i++) { ResolveInfo info = list.get(i); if (info.activityInfo == null || !info.handleAllWebDataURI || (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 || result.contains(info.activityInfo.packageName)) { continue; } result.add(info.activityInfo.packageName); } return result; } private boolean packageIsBrowser(String packageName, int userId) { List<ResolveInfo> list = queryIntentActivitiesInternal(sBrowserIntent, null, PackageManager.MATCH_ALL, userId); Loading @@ -3735,20 +3685,6 @@ public class PackageManagerService extends IPackageManager.Stub return false; } private void checkDefaultBrowser() { final int myUserId = UserHandle.myUserId(); final String packageName = getDefaultBrowserPackageName(myUserId); if (packageName != null) { PackageInfo info = getPackageInfo(packageName, 0, myUserId); if (info == null) { Slog.w(TAG, "Default browser no longer installed: " + packageName); synchronized (mPackages) { applyFactoryDefaultBrowserLPw(myUserId); // leaves ambiguous when > 1 } } } } @Override public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { Loading Loading @@ -13646,14 +13582,33 @@ public class PackageManagerService extends IPackageManager.Stub android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } if (userId == UserHandle.USER_ALL) { return false; } RoleManager roleManager = mContext.getSystemService(RoleManager.class); UserHandle user = UserHandle.of(userId); RoleManagerCallback.Future future = new RoleManagerCallback.Future(); if (packageName != null) { Binder.withCleanCallingIdentity(() -> roleManager.addRoleHolderAsUser( RoleManager.ROLE_BROWSER, packageName, user, AsyncTask.THREAD_POOL_EXECUTOR, future)); } else { Binder.withCleanCallingIdentity(() -> roleManager.clearRoleHoldersAsUser( RoleManager.ROLE_BROWSER, user, AsyncTask.THREAD_POOL_EXECUTOR, future)); } try { future.get(5, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { Slog.e(TAG, "Exception while setting default browser package name: " + packageName, e); return false; } synchronized (mPackages) { boolean result = mSettings.setDefaultBrowserPackageNameLPw(packageName, userId); if (packageName != null) { mDefaultPermissionPolicy.grantDefaultPermissionsToDefaultBrowser( packageName, userId); } return result; } return true; } @Override Loading @@ -13665,9 +13620,10 @@ public class PackageManagerService extends IPackageManager.Stub if (getInstantAppPackageName(Binder.getCallingUid()) != null) { return null; } synchronized (mPackages) { return mSettings.getDefaultBrowserPackageNameLPw(userId); } RoleManager roleManager = mContext.getSystemService(RoleManager.class); List<String> packageNames = Binder.withCleanCallingIdentity(() -> roleManager.getRoleHoldersAsUser(RoleManager.ROLE_BROWSER, UserHandle.of(userId))); return CollectionUtils.firstOrNull(packageNames); } /** Loading Loading @@ -19419,7 +19375,7 @@ public class PackageManagerService extends IPackageManager.Stub // significant refactoring to keep all default apps in the package // manager (cleaner but more work) or have the services provide // callbacks to the package manager to request a default app reset. applyFactoryDefaultBrowserLPw(userId); setDefaultBrowserPackageName(null, userId); clearIntentFilterVerificationsLPw(userId); primeDomainVerificationsLPw(userId); resetUserChangesToRuntimePermissionsAndFlagsLPw(userId); Loading Loading @@ -22761,7 +22717,6 @@ public class PackageManagerService extends IPackageManager.Stub synchronized (mPackages) { scheduleWritePackageRestrictionsLocked(userId); scheduleWritePackageListLocked(userId); applyFactoryDefaultBrowserLPw(userId); primeDomainVerificationsLPw(userId); } } Loading Loading @@ -23959,6 +23914,14 @@ public class PackageManagerService extends IPackageManager.Stub public void finishPackageInstall(int token, boolean didLaunch) { PackageManagerService.this.finishPackageInstall(token, didLaunch); } @Nullable @Override public String removeLegacyDefaultBrowserPackageName(int userId) { synchronized (mPackages) { return mSettings.removeDefaultBrowserPackageNameLPw(userId); } } } @GuardedBy("mPackages") services/core/java/com/android/server/pm/Settings.java +2 −15 Original line number Diff line number Diff line Loading @@ -1327,21 +1327,8 @@ public final class Settings { return result; } boolean setDefaultBrowserPackageNameLPw(String packageName, int userId) { if (userId == UserHandle.USER_ALL) { return false; } if (packageName != null) { mDefaultBrowserApp.put(userId, packageName); } else { mDefaultBrowserApp.remove(userId); } writePackageRestrictionsLPr(userId); return true; } String getDefaultBrowserPackageNameLPw(int userId) { return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.get(userId); String removeDefaultBrowserPackageNameLPw(int userId) { return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.removeReturnOld(userId); } boolean setDefaultDialerPackageNameLPw(String packageName, int userId) { Loading Loading
core/java/android/content/pm/PackageManagerInternal.java +10 −0 Original line number Diff line number Diff line Loading @@ -843,4 +843,14 @@ public abstract class PackageManagerInternal { * {@code token} can be completed. */ public abstract void finishPackageInstall(int token, boolean didLaunch); /** * Remove the default browser stored in the legacy package settings. * * @param userId the user id * * @return the package name of the default browser, or {@code null} if none */ @Nullable public abstract String removeLegacyDefaultBrowserPackageName(int userId); }
core/res/res/values/config.xml +0 −8 Original line number Diff line number Diff line Loading @@ -1933,14 +1933,6 @@ the platform will search for an SMS app and use that (if there is one)--> <string name="default_sms_application" translatable="false">com.android.messaging</string> <!-- Default web browser. This is the package name of the application that will be the default browser when the device first boots. Afterwards the user can select whatever browser app they wish to use as the default. If this string is empty or the specified package does not exist, then the behavior will be as though no app was named as an explicit default. --> <string name="default_browser" translatable="false"></string> <!-- Default role holders. This will be an array of roles and package names of their default holders, with each item in the format of "ROLE_NAME: PACKAGE_NAME_1, PACKAGE_NAME_2". --> <string-array name="config_defaultRoleHolders" translatable="false"> Loading
core/res/res/values/symbols.xml +0 −1 Original line number Diff line number Diff line Loading @@ -1023,7 +1023,6 @@ <java-symbol type="string" name="sipAddressTypeOther" /> <java-symbol type="string" name="sipAddressTypeWork" /> <java-symbol type="string" name="default_sms_application" /> <java-symbol type="string" name="default_browser" /> <java-symbol type="string" name="sms_control_message" /> <java-symbol type="string" name="sms_control_title" /> <java-symbol type="string" name="sms_control_no" /> Loading
services/core/java/com/android/server/pm/PackageManagerService.java +40 −77 Original line number Diff line number Diff line Loading @@ -131,6 +131,8 @@ import android.app.ResourcesManager; import android.app.admin.IDevicePolicyManager; import android.app.admin.SecurityLog; import android.app.backup.IBackupManager; import android.app.role.RoleManager; import android.app.role.RoleManagerCallback; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; Loading Loading @@ -288,6 +290,7 @@ import com.android.internal.os.SomeArgs; import com.android.internal.os.Zygote; import com.android.internal.telephony.CarrierAppUtils; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import com.android.internal.util.ConcurrentUtils; import com.android.internal.util.DumpUtils; import com.android.internal.util.FastXmlSerializer; Loading Loading @@ -369,8 +372,10 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; Loading Loading @@ -1927,7 +1932,7 @@ public class PackageManagerService extends IPackageManager.Stub final PackageSetting pkgSetting = mSettings.mPackages.get(packageName); if (pkgSetting.getInstallReason(userId) != PackageManager.INSTALL_REASON_DEVICE_RESTORE) { mSettings.setDefaultBrowserPackageNameLPw(null, userId); setDefaultBrowserPackageName(null, userId); } } Loading Loading @@ -2941,7 +2946,6 @@ public class PackageManagerService extends IPackageManager.Stub if (!onlyCore && (mPromoteSystemApps || mFirstBoot)) { for (UserInfo user : sUserManager.getUsers(true)) { mSettings.applyDefaultPreferredAppsLPw(user.id); applyFactoryDefaultBrowserLPw(user.id); primeDomainVerificationsLPw(user.id); } } Loading Loading @@ -3014,8 +3018,6 @@ public class PackageManagerService extends IPackageManager.Stub ver.fingerprint = Build.FINGERPRINT; } checkDefaultBrowser(); // clear only after permissions and other defaults have been updated mExistingSystemPackages.clear(); mPromoteSystemApps = false; Loading Loading @@ -3670,58 +3672,6 @@ public class PackageManagerService extends IPackageManager.Stub scheduleWriteSettingsLocked(); } @GuardedBy("mPackages") private void applyFactoryDefaultBrowserLPw(int userId) { // The default browser app's package name is stored in a string resource, // with a product-specific overlay used for vendor customization. String browserPkg = mContext.getResources().getString( com.android.internal.R.string.default_browser); if (!TextUtils.isEmpty(browserPkg)) { // non-empty string => required to be a known package PackageSetting ps = mSettings.mPackages.get(browserPkg); if (ps == null) { Slog.e(TAG, "Product default browser app does not exist: " + browserPkg); browserPkg = null; } else { mSettings.setDefaultBrowserPackageNameLPw(browserPkg, userId); } } // Nothing valid explicitly set? Make the factory-installed browser the explicit // default. If there's more than one, just leave everything alone. if (browserPkg == null) { calculateDefaultBrowserLPw(userId); } } @GuardedBy("mPackages") private void calculateDefaultBrowserLPw(int userId) { List<String> allBrowsers = resolveAllBrowserApps(userId); final String browserPkg = (allBrowsers.size() == 1) ? allBrowsers.get(0) : null; mSettings.setDefaultBrowserPackageNameLPw(browserPkg, userId); } private List<String> resolveAllBrowserApps(int userId) { // Resolve the canonical browser intent and check that the handleAllWebDataURI boolean is set List<ResolveInfo> list = queryIntentActivitiesInternal(sBrowserIntent, null, PackageManager.MATCH_ALL, userId); final int count = list.size(); List<String> result = new ArrayList<>(count); for (int i=0; i<count; i++) { ResolveInfo info = list.get(i); if (info.activityInfo == null || !info.handleAllWebDataURI || (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 || result.contains(info.activityInfo.packageName)) { continue; } result.add(info.activityInfo.packageName); } return result; } private boolean packageIsBrowser(String packageName, int userId) { List<ResolveInfo> list = queryIntentActivitiesInternal(sBrowserIntent, null, PackageManager.MATCH_ALL, userId); Loading @@ -3735,20 +3685,6 @@ public class PackageManagerService extends IPackageManager.Stub return false; } private void checkDefaultBrowser() { final int myUserId = UserHandle.myUserId(); final String packageName = getDefaultBrowserPackageName(myUserId); if (packageName != null) { PackageInfo info = getPackageInfo(packageName, 0, myUserId); if (info == null) { Slog.w(TAG, "Default browser no longer installed: " + packageName); synchronized (mPackages) { applyFactoryDefaultBrowserLPw(myUserId); // leaves ambiguous when > 1 } } } } @Override public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { Loading Loading @@ -13646,14 +13582,33 @@ public class PackageManagerService extends IPackageManager.Stub android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } if (userId == UserHandle.USER_ALL) { return false; } RoleManager roleManager = mContext.getSystemService(RoleManager.class); UserHandle user = UserHandle.of(userId); RoleManagerCallback.Future future = new RoleManagerCallback.Future(); if (packageName != null) { Binder.withCleanCallingIdentity(() -> roleManager.addRoleHolderAsUser( RoleManager.ROLE_BROWSER, packageName, user, AsyncTask.THREAD_POOL_EXECUTOR, future)); } else { Binder.withCleanCallingIdentity(() -> roleManager.clearRoleHoldersAsUser( RoleManager.ROLE_BROWSER, user, AsyncTask.THREAD_POOL_EXECUTOR, future)); } try { future.get(5, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { Slog.e(TAG, "Exception while setting default browser package name: " + packageName, e); return false; } synchronized (mPackages) { boolean result = mSettings.setDefaultBrowserPackageNameLPw(packageName, userId); if (packageName != null) { mDefaultPermissionPolicy.grantDefaultPermissionsToDefaultBrowser( packageName, userId); } return result; } return true; } @Override Loading @@ -13665,9 +13620,10 @@ public class PackageManagerService extends IPackageManager.Stub if (getInstantAppPackageName(Binder.getCallingUid()) != null) { return null; } synchronized (mPackages) { return mSettings.getDefaultBrowserPackageNameLPw(userId); } RoleManager roleManager = mContext.getSystemService(RoleManager.class); List<String> packageNames = Binder.withCleanCallingIdentity(() -> roleManager.getRoleHoldersAsUser(RoleManager.ROLE_BROWSER, UserHandle.of(userId))); return CollectionUtils.firstOrNull(packageNames); } /** Loading Loading @@ -19419,7 +19375,7 @@ public class PackageManagerService extends IPackageManager.Stub // significant refactoring to keep all default apps in the package // manager (cleaner but more work) or have the services provide // callbacks to the package manager to request a default app reset. applyFactoryDefaultBrowserLPw(userId); setDefaultBrowserPackageName(null, userId); clearIntentFilterVerificationsLPw(userId); primeDomainVerificationsLPw(userId); resetUserChangesToRuntimePermissionsAndFlagsLPw(userId); Loading Loading @@ -22761,7 +22717,6 @@ public class PackageManagerService extends IPackageManager.Stub synchronized (mPackages) { scheduleWritePackageRestrictionsLocked(userId); scheduleWritePackageListLocked(userId); applyFactoryDefaultBrowserLPw(userId); primeDomainVerificationsLPw(userId); } } Loading Loading @@ -23959,6 +23914,14 @@ public class PackageManagerService extends IPackageManager.Stub public void finishPackageInstall(int token, boolean didLaunch) { PackageManagerService.this.finishPackageInstall(token, didLaunch); } @Nullable @Override public String removeLegacyDefaultBrowserPackageName(int userId) { synchronized (mPackages) { return mSettings.removeDefaultBrowserPackageNameLPw(userId); } } } @GuardedBy("mPackages")
services/core/java/com/android/server/pm/Settings.java +2 −15 Original line number Diff line number Diff line Loading @@ -1327,21 +1327,8 @@ public final class Settings { return result; } boolean setDefaultBrowserPackageNameLPw(String packageName, int userId) { if (userId == UserHandle.USER_ALL) { return false; } if (packageName != null) { mDefaultBrowserApp.put(userId, packageName); } else { mDefaultBrowserApp.remove(userId); } writePackageRestrictionsLPr(userId); return true; } String getDefaultBrowserPackageNameLPw(int userId) { return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.get(userId); String removeDefaultBrowserPackageNameLPw(int userId) { return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.removeReturnOld(userId); } boolean setDefaultDialerPackageNameLPw(String packageName, int userId) { Loading