[Telephony Mainline] Remove hidden API usages in CarrierAppUtils

Bug: 146904426
Test: Build
Change-Id: Ib307e565b85e7d9a142efc7e3348b823dc46643d
This commit is contained in:
Peter Wang
2020-01-24 08:15:38 +08:00
parent 4a58806789
commit 09014f1048
7 changed files with 219 additions and 136 deletions

View File

@@ -2253,6 +2253,7 @@ package android.content.pm {
method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setPackagesSuspended(@Nullable String[], boolean, @Nullable android.os.PersistableBundle, @Nullable android.os.PersistableBundle, @Nullable String);
method @Nullable @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setPackagesSuspended(@Nullable String[], boolean, @Nullable android.os.PersistableBundle, @Nullable android.os.PersistableBundle, @Nullable android.content.pm.SuspendDialogInfo);
method @RequiresPermission(value=android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE, conditional=true) public void setSyntheticAppDetailsActivityEnabled(@NonNull String, boolean);
method public void setSystemAppState(@NonNull String, int);
method @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) public abstract void setUpdateAvailable(@NonNull String, boolean);
method @RequiresPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS) public abstract boolean updateIntentVerificationStatusAsUser(@NonNull String, int, int);
method @RequiresPermission(anyOf={android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS, android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS}) public abstract void updatePermissionFlags(@NonNull String, @NonNull String, @android.content.pm.PackageManager.PermissionFlags int, @android.content.pm.PackageManager.PermissionFlags int, @NonNull android.os.UserHandle);
@@ -2331,6 +2332,10 @@ package android.content.pm {
field public static final int RESTRICTION_HIDE_FROM_SUGGESTIONS = 1; // 0x1
field public static final int RESTRICTION_HIDE_NOTIFICATIONS = 2; // 0x2
field public static final int RESTRICTION_NONE = 0; // 0x0
field public static final int SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN = 0; // 0x0
field public static final int SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_VISIBLE = 1; // 0x1
field public static final int SYSTEM_APP_STATE_INSTALLED = 2; // 0x2
field public static final int SYSTEM_APP_STATE_UNINSTALLED = 3; // 0x3
}
public abstract static class PackageManager.DexModuleRegisterCallback {
@@ -8802,7 +8807,6 @@ package android.os {
method @NonNull public android.os.TelephonyServiceManager.ServiceRegisterer getEuiccControllerService();
method @NonNull public android.os.TelephonyServiceManager.ServiceRegisterer getIccPhoneBookServiceRegisterer();
method @NonNull public android.os.TelephonyServiceManager.ServiceRegisterer getOpportunisticNetworkServiceRegisterer();
method @NonNull public android.os.TelephonyServiceManager.ServiceRegisterer getPackageManagerServiceRegisterer();
method @NonNull public android.os.TelephonyServiceManager.ServiceRegisterer getPhoneSubServiceRegisterer();
method @NonNull public android.os.TelephonyServiceManager.ServiceRegisterer getSmsServiceRegisterer();
method @NonNull public android.os.TelephonyServiceManager.ServiceRegisterer getSubscriptionServiceRegisterer();
@@ -9143,6 +9147,7 @@ package android.permission {
public final class PermissionManager {
method @IntRange(from=0) @RequiresPermission(android.Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY) public int getRuntimePermissionsVersion();
method @NonNull public java.util.List<android.permission.PermissionManager.SplitPermissionInfo> getSplitPermissions();
method @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS) public void grantDefaultPermissionsToEnabledCarrierApps(@NonNull String[], @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
method @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS) public void grantDefaultPermissionsToEnabledImsServices(@NonNull String[], @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
method @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS) public void grantDefaultPermissionsToEnabledTelephonyDataServices(@NonNull String[], @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
method @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS) public void grantDefaultPermissionsToLuiApp(@NonNull String, @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);

View File

@@ -131,7 +131,7 @@ public class ApplicationPackageManager extends PackageManager {
private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
// Default flags to use with PackageManager when no flags are given.
private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
private static final int sDefaultFlags = GET_SHARED_LIBRARY_FILES;
// Name of the resource which provides background permission button string
public static final String APP_PERMISSION_BUTTON_ALLOW_ALWAYS =
@@ -907,7 +907,7 @@ public class ApplicationPackageManager extends PackageManager {
@Override
public boolean hasSigningCertificate(
String packageName, byte[] certificate, @PackageManager.CertificateInputType int type) {
String packageName, byte[] certificate, @CertificateInputType int type) {
try {
return mPM.hasSigningCertificate(packageName, certificate, type);
} catch (RemoteException e) {
@@ -917,7 +917,7 @@ public class ApplicationPackageManager extends PackageManager {
@Override
public boolean hasSigningCertificate(
int uid, byte[] certificate, @PackageManager.CertificateInputType int type) {
int uid, byte[] certificate, @CertificateInputType int type) {
try {
return mPM.hasUidSigningCertificate(uid, certificate, type);
} catch (RemoteException e) {
@@ -1464,8 +1464,7 @@ public class ApplicationPackageManager extends PackageManager {
return getActivityIcon(intent.getComponent());
}
ResolveInfo info = resolveActivity(
intent, PackageManager.MATCH_DEFAULT_ONLY);
ResolveInfo info = resolveActivity(intent, MATCH_DEFAULT_ONLY);
if (info != null) {
return info.activityInfo.loadIcon(this);
}
@@ -1500,7 +1499,7 @@ public class ApplicationPackageManager extends PackageManager {
}
ResolveInfo info = resolveActivity(
intent, PackageManager.MATCH_DEFAULT_ONLY);
intent, MATCH_DEFAULT_ONLY);
if (info != null) {
return info.activityInfo.loadBanner(this);
}
@@ -1532,8 +1531,7 @@ public class ApplicationPackageManager extends PackageManager {
return getActivityLogo(intent.getComponent());
}
ResolveInfo info = resolveActivity(
intent, PackageManager.MATCH_DEFAULT_ONLY);
ResolveInfo info = resolveActivity(intent, MATCH_DEFAULT_ONLY);
if (info != null) {
return info.activityInfo.loadLogo(this);
}
@@ -2017,7 +2015,7 @@ public class ApplicationPackageManager extends PackageManager {
@Override
public int installExistingPackage(String packageName) throws NameNotFoundException {
return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
return installExistingPackage(packageName, INSTALL_REASON_UNKNOWN);
}
@Override
@@ -2029,7 +2027,7 @@ public class ApplicationPackageManager extends PackageManager {
@Override
public int installExistingPackageAsUser(String packageName, int userId)
throws NameNotFoundException {
return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
return installExistingPackageAsUser(packageName, INSTALL_REASON_UNKNOWN,
userId);
}
@@ -2404,7 +2402,7 @@ public class ApplicationPackageManager extends PackageManager {
public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
int flags, int userId) {
try {
mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
mPM.deletePackageAsUser(packageName, VERSION_CODE_HIGHEST,
observer, userId, flags);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -2651,11 +2649,11 @@ public class ApplicationPackageManager extends PackageManager {
public void setSyntheticAppDetailsActivityEnabled(String packageName, boolean enabled) {
try {
ComponentName componentName = new ComponentName(packageName,
PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME);
APP_DETAILS_ACTIVITY_CLASS_NAME);
mPM.setComponentEnabledSetting(componentName, enabled
? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP, getUserId());
? COMPONENT_ENABLED_STATE_DEFAULT
: COMPONENT_ENABLED_STATE_DISABLED,
DONT_KILL_APP, getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2665,10 +2663,10 @@ public class ApplicationPackageManager extends PackageManager {
public boolean getSyntheticAppDetailsActivityEnabled(String packageName) {
try {
ComponentName componentName = new ComponentName(packageName,
PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME);
APP_DETAILS_ACTIVITY_CLASS_NAME);
int state = mPM.getComponentEnabledSetting(componentName, getUserId());
return state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|| state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
return state == COMPONENT_ENABLED_STATE_ENABLED
|| state == COMPONENT_ENABLED_STATE_DEFAULT;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2742,6 +2740,30 @@ public class ApplicationPackageManager extends PackageManager {
}
}
/** @hide */
@Override
public void setSystemAppState(String packageName, @SystemAppState int state) {
try {
switch (state) {
case SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN:
mPM.setSystemAppHiddenUntilInstalled(packageName, true);
break;
case SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_VISIBLE:
mPM.setSystemAppHiddenUntilInstalled(packageName, false);
break;
case SYSTEM_APP_STATE_INSTALLED:
mPM.setSystemAppInstallState(packageName, true, getUserId());
break;
case SYSTEM_APP_STATE_UNINSTALLED:
mPM.setSystemAppInstallState(packageName, false, getUserId());
break;
default:
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
@Override
public KeySet getKeySetByAlias(String packageName, String alias) {

View File

@@ -3516,6 +3516,44 @@ public abstract class PackageManager {
@Disabled
public static final long FILTER_APPLICATION_QUERY = 135549675L;
/** {@hide} */
@IntDef(prefix = {"SYSTEM_APP_STATE_"}, value = {
SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN,
SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_VISIBLE,
SYSTEM_APP_STATE_INSTALLED,
SYSTEM_APP_STATE_UNINSTALLED
})
@Retention(RetentionPolicy.SOURCE)
public @interface SystemAppState {}
/**
* Constant for noting system app state as hidden before installation
* @hide
*/
@SystemApi
public static final int SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN = 0;
/**
* Constant for noting system app state as visible before installation
* @hide
*/
@SystemApi
public static final int SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_VISIBLE = 1;
/**
* Constant for noting system app state as installed
* @hide
*/
@SystemApi
public static final int SYSTEM_APP_STATE_INSTALLED = 2;
/**
* Constant for noting system app state as not installed
* @hide
*/
@SystemApi
public static final int SYSTEM_APP_STATE_UNINSTALLED = 3;
/** {@hide} */
public int getUserId() {
return UserHandle.myUserId();
@@ -6619,6 +6657,17 @@ public abstract class PackageManager {
public abstract boolean getApplicationHiddenSettingAsUser(@NonNull String packageName,
@NonNull UserHandle userHandle);
/**
* Sets system app state
* @param packageName Package name of the app.
* @param state State of the app.
* @hide
*/
@SystemApi
public void setSystemAppState(@NonNull String packageName, @SystemAppState int state) {
throw new RuntimeException("Not implemented. Must override in a subclass");
}
/**
* Return whether the device has been booted into safe mode.
*/

View File

@@ -190,14 +190,6 @@ public class TelephonyServiceManager {
return new ServiceRegisterer("euicc_card_controller");
}
/**
* Returns {@link ServiceRegisterer} for the package manager service.
*/
@NonNull
public ServiceRegisterer getPackageManagerServiceRegisterer() {
return new ServiceRegisterer("package");
}
/**
* Returns {@link ServiceRegisterer} for the ICC phone book service.
*/

View File

@@ -266,6 +266,28 @@ public final class PermissionManager {
}
}
/**
* Grant default permissions to currently enabled carrier apps
* @param packageNames Package names of the apps to be granted permissions
* @param user The user handle
* @param executor The executor for the callback
* @param callback The callback provided by caller to be notified when grant completes
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS)
public void grantDefaultPermissionsToEnabledCarrierApps(@NonNull String[] packageNames,
@NonNull UserHandle user, @NonNull @CallbackExecutor Executor executor,
@NonNull Consumer<Boolean> callback) {
try {
mPermissionManager.grantDefaultPermissionsToEnabledCarrierApps(packageNames,
user.getIdentifier());
executor.execute(() -> callback.accept(true));
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
private List<SplitPermissionInfo> splitPermissionInfoListToNonParcelableList(
List<SplitPermissionInfoParcelable> parcelableList) {
final int size = parcelableList.size();
@@ -416,4 +438,4 @@ public final class PermissionManager {
e.rethrowFromSystemServer();
}
}
}
}

View File

@@ -124,8 +124,8 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ApplicationPackageManager;
import android.app.AppOpsManager;
import android.app.ApplicationPackageManager;
import android.app.BroadcastOptions;
import android.app.IActivityManager;
import android.app.ResourcesManager;
@@ -20211,8 +20211,8 @@ public class PackageManagerService extends IPackageManager.Stub
// Disable any carrier apps. We do this very early in boot to prevent the apps from being
// disabled after already being started.
CarrierAppUtils.disableCarrierAppsUntilPrivileged(mContext.getOpPackageName(), this,
mPermissionManagerService, UserHandle.USER_SYSTEM, mContext);
CarrierAppUtils.disableCarrierAppsUntilPrivileged(
mContext.getOpPackageName(), UserHandle.USER_SYSTEM, mContext);
disableSkuSpecificApps();

View File

@@ -20,12 +20,10 @@ import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.RemoteException;
import android.os.UserHandle;
import android.permission.IPermissionManager;
import android.permission.PermissionManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.ArrayMap;
@@ -77,7 +75,6 @@ public final class CarrierAppUtils {
* privileged apps may have changed.
*/
public static synchronized void disableCarrierAppsUntilPrivileged(String callingPackage,
IPackageManager packageManager, IPermissionManager permissionManager,
TelephonyManager telephonyManager, int userId, Context context) {
if (DEBUG) {
Log.d(TAG, "disableCarrierAppsUntilPrivileged");
@@ -88,14 +85,14 @@ public final class CarrierAppUtils {
ArrayMap<String, List<String>> systemCarrierAssociatedAppsDisabledUntilUsed =
config.getDisabledUntilUsedPreinstalledCarrierAssociatedApps();
ContentResolver contentResolver = getContentResolverForUser(context, userId);
disableCarrierAppsUntilPrivileged(callingPackage, packageManager, permissionManager,
telephonyManager, contentResolver, userId, systemCarrierAppsDisabledUntilUsed,
systemCarrierAssociatedAppsDisabledUntilUsed);
disableCarrierAppsUntilPrivileged(callingPackage, telephonyManager, contentResolver,
userId, systemCarrierAppsDisabledUntilUsed,
systemCarrierAssociatedAppsDisabledUntilUsed, context);
}
/**
* Like {@link #disableCarrierAppsUntilPrivileged(String, IPackageManager, TelephonyManager,
* ContentResolver, int)}, but assumes that no carrier apps have carrier privileges.
* Like {@link #disableCarrierAppsUntilPrivileged(String, TelephonyManager, int, Context)},
* but assumes that no carrier apps have carrier privileges.
*
* This prevents a potential race condition on first boot - since the app's default state is
* enabled, we will initially disable it when the telephony stack is first initialized as it has
@@ -105,8 +102,7 @@ public final class CarrierAppUtils {
* Manager can kill it, and this can lead to crashes as the app is in an unexpected state.
*/
public static synchronized void disableCarrierAppsUntilPrivileged(String callingPackage,
IPackageManager packageManager, IPermissionManager permissionManager, int userId,
Context context) {
int userId, Context context) {
if (DEBUG) {
Log.d(TAG, "disableCarrierAppsUntilPrivileged");
}
@@ -114,13 +110,12 @@ public final class CarrierAppUtils {
ArraySet<String> systemCarrierAppsDisabledUntilUsed =
config.getDisabledUntilUsedPreinstalledCarrierApps();
ArrayMap<String, List<String>> systemCarrierAssociatedAppsDisabledUntilUsed =
config.getDisabledUntilUsedPreinstalledCarrierAssociatedApps();
ContentResolver contentResolver = getContentResolverForUser(context, userId);
disableCarrierAppsUntilPrivileged(callingPackage, packageManager, permissionManager,
null /* telephonyManager */, contentResolver, userId,
systemCarrierAppsDisabledUntilUsed, systemCarrierAssociatedAppsDisabledUntilUsed);
disableCarrierAppsUntilPrivileged(callingPackage, null /* telephonyManager */,
contentResolver, userId, systemCarrierAppsDisabledUntilUsed,
systemCarrierAssociatedAppsDisabledUntilUsed, context);
}
private static ContentResolver getContentResolverForUser(Context context, int userId) {
@@ -136,21 +131,21 @@ public final class CarrierAppUtils {
// Must be public b/c framework unit tests can't access package-private methods.
@VisibleForTesting
public static void disableCarrierAppsUntilPrivileged(String callingPackage,
IPackageManager packageManager, IPermissionManager permissionManager,
@Nullable TelephonyManager telephonyManager,
ContentResolver contentResolver, int userId,
ArraySet<String> systemCarrierAppsDisabledUntilUsed,
ArrayMap<String, List<String>> systemCarrierAssociatedAppsDisabledUntilUsed) {
@Nullable TelephonyManager telephonyManager, ContentResolver contentResolver,
int userId, ArraySet<String> systemCarrierAppsDisabledUntilUsed,
ArrayMap<String, List<String>> systemCarrierAssociatedAppsDisabledUntilUsed,
Context context) {
PackageManager packageManager = context.getPackageManager();
PermissionManager permissionManager =
(PermissionManager) context.getSystemService(Context.PERMISSION_SERVICE);
List<ApplicationInfo> candidates = getDefaultNotUpdatedCarrierAppCandidatesHelper(
packageManager, userId, systemCarrierAppsDisabledUntilUsed);
userId, systemCarrierAppsDisabledUntilUsed, context);
if (candidates == null || candidates.isEmpty()) {
return;
}
Map<String, List<ApplicationInfo>> associatedApps = getDefaultCarrierAssociatedAppsHelper(
packageManager,
userId,
systemCarrierAssociatedAppsDisabledUntilUsed);
userId, systemCarrierAssociatedAppsDisabledUntilUsed, context);
List<String> enabledCarrierPackages = new ArrayList<>();
boolean hasRunOnce = Settings.Secure.getInt(contentResolver,
@@ -167,19 +162,18 @@ public final class CarrierAppUtils {
&& !ArrayUtils.contains(restrictedCarrierApps, packageName);
// add hiddenUntilInstalled flag for carrier apps and associated apps
packageManager.setSystemAppHiddenUntilInstalled(packageName, true);
packageManager.setSystemAppState(
packageName, PackageManager.SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN);
List<ApplicationInfo> associatedAppList = associatedApps.get(packageName);
if (associatedAppList != null) {
for (ApplicationInfo associatedApp : associatedAppList) {
packageManager.setSystemAppHiddenUntilInstalled(
associatedApp.packageName,
true
);
packageManager.setSystemAppState(associatedApp.packageName,
PackageManager.SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN);
}
}
int enabledSetting = packageManager.getApplicationEnabledSetting(packageName,
userId);
int enabledSetting = context.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager().getApplicationEnabledSetting(packageName);
if (hasPrivileges) {
// Only update enabled state for the app on /system. Once it has been
// updated we shouldn't touch it.
@@ -190,24 +184,25 @@ public final class CarrierAppUtils {
|| (ai.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
Log.i(TAG, "Update state(" + packageName + "): ENABLED for user "
+ userId);
packageManager.setSystemAppInstallState(
packageName,
true /*installed*/,
userId);
packageManager.setApplicationEnabledSetting(
packageName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP,
userId,
callingPackage);
context.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.setSystemAppState(
packageName, PackageManager.SYSTEM_APP_STATE_INSTALLED);
context.createPackageContextAsUser(callingPackage, 0, UserHandle.of(userId))
.getPackageManager()
.setApplicationEnabledSetting(
packageName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
// Also enable any associated apps for this carrier app.
if (associatedAppList != null) {
for (ApplicationInfo associatedApp : associatedAppList) {
int associatedAppEnabledSetting =
packageManager.getApplicationEnabledSetting(
associatedApp.packageName, userId);
int associatedAppEnabledSetting = context
.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.getApplicationEnabledSetting(associatedApp.packageName);
if (associatedAppEnabledSetting
== PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|| associatedAppEnabledSetting
@@ -216,16 +211,17 @@ public final class CarrierAppUtils {
& ApplicationInfo.FLAG_INSTALLED) == 0) {
Log.i(TAG, "Update associated state(" + associatedApp.packageName
+ "): ENABLED for user " + userId);
packageManager.setSystemAppInstallState(
associatedApp.packageName,
true /*installed*/,
userId);
packageManager.setApplicationEnabledSetting(
associatedApp.packageName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP,
userId,
callingPackage);
context.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.setSystemAppState(associatedApp.packageName,
PackageManager.SYSTEM_APP_STATE_INSTALLED);
context.createPackageContextAsUser(
callingPackage, 0, UserHandle.of(userId))
.getPackageManager()
.setApplicationEnabledSetting(
associatedApp.packageName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
}
}
@@ -240,10 +236,10 @@ public final class CarrierAppUtils {
&& (ai.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
Log.i(TAG, "Update state(" + packageName
+ "): DISABLED_UNTIL_USED for user " + userId);
packageManager.setSystemAppInstallState(
packageName,
false /*installed*/,
userId);
context.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.setSystemAppState(
packageName, PackageManager.SYSTEM_APP_STATE_UNINSTALLED);
}
// Also disable any associated apps for this carrier app if this is the first
@@ -252,9 +248,10 @@ public final class CarrierAppUtils {
if (!hasRunOnce) {
if (associatedAppList != null) {
for (ApplicationInfo associatedApp : associatedAppList) {
int associatedAppEnabledSetting =
packageManager.getApplicationEnabledSetting(
associatedApp.packageName, userId);
int associatedAppEnabledSetting = context
.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.getApplicationEnabledSetting(associatedApp.packageName);
if (associatedAppEnabledSetting
== PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
&& (associatedApp.flags
@@ -262,10 +259,10 @@ public final class CarrierAppUtils {
Log.i(TAG,
"Update associated state(" + associatedApp.packageName
+ "): DISABLED_UNTIL_USED for user " + userId);
packageManager.setSystemAppInstallState(
associatedApp.packageName,
false /*installed*/,
userId);
context.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.setSystemAppState(associatedApp.packageName,
PackageManager.SYSTEM_APP_STATE_UNINSTALLED);
}
}
}
@@ -283,9 +280,10 @@ public final class CarrierAppUtils {
// apps.
String[] packageNames = new String[enabledCarrierPackages.size()];
enabledCarrierPackages.toArray(packageNames);
permissionManager.grantDefaultPermissionsToEnabledCarrierApps(packageNames, userId);
permissionManager.grantDefaultPermissionsToEnabledCarrierApps(packageNames,
UserHandle.of(userId), Runnable::run, isSuccess -> { });
}
} catch (RemoteException e) {
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Could not reach PackageManager", e);
}
}
@@ -294,13 +292,13 @@ public final class CarrierAppUtils {
* Returns the list of "default" carrier apps.
*
* This is the subset of apps returned by
* {@link #getDefaultCarrierAppCandidates(IPackageManager, int)} which currently have carrier
* {@link #getDefaultCarrierAppCandidates(int, Context)} which currently have carrier
* privileges per the SIM(s) inserted in the device.
*/
public static List<ApplicationInfo> getDefaultCarrierApps(IPackageManager packageManager,
TelephonyManager telephonyManager, int userId) {
public static List<ApplicationInfo> getDefaultCarrierApps(
TelephonyManager telephonyManager, int userId, Context context) {
// Get all system apps from the default list.
List<ApplicationInfo> candidates = getDefaultCarrierAppCandidates(packageManager, userId);
List<ApplicationInfo> candidates = getDefaultCarrierAppCandidates(userId, context);
if (candidates == null || candidates.isEmpty()) {
return null;
}
@@ -326,25 +324,23 @@ public final class CarrierAppUtils {
* Returns the list of "default" carrier app candidates.
*
* These are the apps subject to the hiding/showing logic in
* {@link CarrierAppUtils#disableCarrierAppsUntilPrivileged(String, IPackageManager,
* TelephonyManager, ContentResolver, int)}, as well as the apps which should have default
* {@link CarrierAppUtils#disableCarrierAppsUntilPrivileged(String, TelephonyManager, int,
* Context)}, as well as the apps which should have default
* permissions granted, when a matching SIM is inserted.
*
* Whether or not the app is actually considered a default app depends on whether the app has
* carrier privileges as determined by the SIMs in the device.
*/
public static List<ApplicationInfo> getDefaultCarrierAppCandidates(
IPackageManager packageManager, int userId) {
int userId, Context context) {
ArraySet<String> systemCarrierAppsDisabledUntilUsed =
SystemConfig.getInstance().getDisabledUntilUsedPreinstalledCarrierApps();
return getDefaultCarrierAppCandidatesHelper(packageManager, userId,
systemCarrierAppsDisabledUntilUsed);
return getDefaultCarrierAppCandidatesHelper(userId, systemCarrierAppsDisabledUntilUsed,
context);
}
private static List<ApplicationInfo> getDefaultCarrierAppCandidatesHelper(
IPackageManager packageManager,
int userId,
ArraySet<String> systemCarrierAppsDisabledUntilUsed) {
int userId, ArraySet<String> systemCarrierAppsDisabledUntilUsed, Context context) {
if (systemCarrierAppsDisabledUntilUsed == null) {
return null;
}
@@ -358,7 +354,7 @@ public final class CarrierAppUtils {
for (int i = 0; i < size; i++) {
String packageName = systemCarrierAppsDisabledUntilUsed.valueAt(i);
ApplicationInfo ai =
getApplicationInfoIfSystemApp(packageManager, userId, packageName);
getApplicationInfoIfSystemApp(userId, packageName, context);
if (ai != null) {
apps.add(ai);
}
@@ -367,9 +363,7 @@ public final class CarrierAppUtils {
}
private static List<ApplicationInfo> getDefaultNotUpdatedCarrierAppCandidatesHelper(
IPackageManager packageManager,
int userId,
ArraySet<String> systemCarrierAppsDisabledUntilUsed) {
int userId, ArraySet<String> systemCarrierAppsDisabledUntilUsed, Context context) {
if (systemCarrierAppsDisabledUntilUsed == null) {
return null;
}
@@ -383,7 +377,7 @@ public final class CarrierAppUtils {
for (int i = 0; i < size; i++) {
String packageName = systemCarrierAppsDisabledUntilUsed.valueAt(i);
ApplicationInfo ai =
getApplicationInfoIfNotUpdatedSystemApp(packageManager, userId, packageName);
getApplicationInfoIfNotUpdatedSystemApp(userId, packageName, context);
if (ai != null) {
apps.add(ai);
}
@@ -392,9 +386,8 @@ public final class CarrierAppUtils {
}
private static Map<String, List<ApplicationInfo>> getDefaultCarrierAssociatedAppsHelper(
IPackageManager packageManager,
int userId,
ArrayMap<String, List<String>> systemCarrierAssociatedAppsDisabledUntilUsed) {
int userId, ArrayMap<String, List<String>> systemCarrierAssociatedAppsDisabledUntilUsed,
Context context) {
int size = systemCarrierAssociatedAppsDisabledUntilUsed.size();
Map<String, List<ApplicationInfo>> associatedApps = new ArrayMap<>(size);
for (int i = 0; i < size; i++) {
@@ -404,7 +397,7 @@ public final class CarrierAppUtils {
for (int j = 0; j < associatedAppPackages.size(); j++) {
ApplicationInfo ai =
getApplicationInfoIfNotUpdatedSystemApp(
packageManager, userId, associatedAppPackages.get(j));
userId, associatedAppPackages.get(j), context);
// Only update enabled state for the app on /system. Once it has been updated we
// shouldn't touch it.
if (ai != null) {
@@ -422,19 +415,19 @@ public final class CarrierAppUtils {
@Nullable
private static ApplicationInfo getApplicationInfoIfNotUpdatedSystemApp(
IPackageManager packageManager,
int userId,
String packageName) {
int userId, String packageName, Context context) {
try {
ApplicationInfo ai = packageManager.getApplicationInfo(packageName,
PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
| PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS
| PackageManager.MATCH_SYSTEM_ONLY
| PackageManager.MATCH_FACTORY_ONLY, userId);
ApplicationInfo ai = context.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
| PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS
| PackageManager.MATCH_SYSTEM_ONLY
| PackageManager.MATCH_FACTORY_ONLY);
if (ai != null) {
return ai;
}
} catch (RemoteException e) {
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Could not reach PackageManager", e);
}
return null;
@@ -442,18 +435,18 @@ public final class CarrierAppUtils {
@Nullable
private static ApplicationInfo getApplicationInfoIfSystemApp(
IPackageManager packageManager,
int userId,
String packageName) {
int userId, String packageName, Context context) {
try {
ApplicationInfo ai = packageManager.getApplicationInfo(packageName,
PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
| PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS
| PackageManager.MATCH_SYSTEM_ONLY, userId);
ApplicationInfo ai = context.createContextAsUser(UserHandle.of(userId), 0)
.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
| PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS
| PackageManager.MATCH_SYSTEM_ONLY);
if (ai != null) {
return ai;
}
} catch (RemoteException e) {
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Could not reach PackageManager", e);
}
return null;