Merge "Create recents protectionLevel"
This commit is contained in:
committed by
Android (Google) Code Review
commit
9aee235f28
@@ -2280,6 +2280,7 @@ package android.content.pm {
|
||||
field public static final int PROTECTION_FLAG_DOCUMENTER = 262144; // 0x40000
|
||||
field public static final int PROTECTION_FLAG_INCIDENT_REPORT_APPROVER = 1048576; // 0x100000
|
||||
field public static final int PROTECTION_FLAG_OEM = 16384; // 0x4000
|
||||
field public static final int PROTECTION_FLAG_RECENTS = 33554432; // 0x2000000
|
||||
field public static final int PROTECTION_FLAG_RETAIL_DEMO = 16777216; // 0x1000000
|
||||
field public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 65536; // 0x10000
|
||||
field public static final int PROTECTION_FLAG_WELLBEING = 131072; // 0x20000
|
||||
|
||||
@@ -251,6 +251,16 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
@SystemApi
|
||||
public static final int PROTECTION_FLAG_RETAIL_DEMO = 0x1000000;
|
||||
|
||||
/**
|
||||
* Additional flag for {@link #protectionLevel}, corresponding
|
||||
* to the <code>recents</code> value of
|
||||
* {@link android.R.attr#protectionLevel}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public static final int PROTECTION_FLAG_RECENTS = 0x2000000;
|
||||
|
||||
/** @hide */
|
||||
@IntDef(flag = true, prefix = { "PROTECTION_FLAG_" }, value = {
|
||||
PROTECTION_FLAG_PRIVILEGED,
|
||||
@@ -274,6 +284,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
PROTECTION_FLAG_APP_PREDICTOR,
|
||||
PROTECTION_FLAG_COMPANION,
|
||||
PROTECTION_FLAG_RETAIL_DEMO,
|
||||
PROTECTION_FLAG_RECENTS,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ProtectionFlags {}
|
||||
@@ -532,6 +543,9 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
if ((level & PermissionInfo.PROTECTION_FLAG_RETAIL_DEMO) != 0) {
|
||||
protLevel.append("|retailDemo");
|
||||
}
|
||||
if ((level & PermissionInfo.PROTECTION_FLAG_RECENTS) != 0) {
|
||||
protLevel.append("|recents");
|
||||
}
|
||||
return protLevel.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -303,6 +303,9 @@
|
||||
<!-- Additional flag from base permission type: this permission will be granted to the
|
||||
retail demo app, as defined by the OEM. -->
|
||||
<flag name="retailDemo" value="0x1000000" />
|
||||
<!-- Additional flag from base permission type: this permission will be granted to the
|
||||
recents app. -->
|
||||
<flag name="recents" value="0x2000000" />
|
||||
</attr>
|
||||
|
||||
<!-- Flags indicating more context for a permission group. -->
|
||||
|
||||
@@ -77,6 +77,7 @@ public abstract class PackageManagerInternal {
|
||||
PACKAGE_WIFI,
|
||||
PACKAGE_COMPANION,
|
||||
PACKAGE_RETAIL_DEMO,
|
||||
PACKAGE_RECENTS,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface KnownPackage {}
|
||||
@@ -97,9 +98,10 @@ public abstract class PackageManagerInternal {
|
||||
public static final int PACKAGE_WIFI = 13;
|
||||
public static final int PACKAGE_COMPANION = 14;
|
||||
public static final int PACKAGE_RETAIL_DEMO = 15;
|
||||
public static final int PACKAGE_RECENTS = 16;
|
||||
// Integer value of the last known package ID. Increases as new ID is added to KnownPackage.
|
||||
// Please note the numbers should be continuous.
|
||||
public static final int LAST_KNOWN_PACKAGE = PACKAGE_RETAIL_DEMO;
|
||||
public static final int LAST_KNOWN_PACKAGE = PACKAGE_RECENTS;
|
||||
|
||||
@IntDef(flag = true, prefix = "RESOLVE_", value = {
|
||||
RESOLVE_NON_BROWSER_ONLY,
|
||||
@@ -1060,6 +1062,8 @@ public abstract class PackageManagerInternal {
|
||||
return "Retail Demo";
|
||||
case PACKAGE_OVERLAY_CONFIG_SIGNATURE:
|
||||
return "Overlay Config Signature";
|
||||
case PACKAGE_RECENTS:
|
||||
return "Recents";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ import android.annotation.AppIdInt;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.annotation.WorkerThread;
|
||||
import android.app.ActivityManager;
|
||||
@@ -1203,6 +1204,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
public ViewCompiler viewCompiler;
|
||||
public @Nullable String wellbeingPackage;
|
||||
public @Nullable String retailDemoPackage;
|
||||
public @Nullable String recentsPackage;
|
||||
public ComponentName resolveComponentName;
|
||||
public ArrayMap<String, AndroidPackage> packages;
|
||||
public boolean enableFreeCacheV2;
|
||||
@@ -1737,6 +1739,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
final @Nullable String mSharedSystemSharedLibraryPackageName;
|
||||
final @Nullable String mRetailDemoPackage;
|
||||
final @Nullable String mOverlayConfigSignaturePackage;
|
||||
final @Nullable String mRecentsPackage;
|
||||
|
||||
private final PackageUsage mPackageUsage = new PackageUsage();
|
||||
private final CompilerStats mCompilerStats = new CompilerStats();
|
||||
@@ -2980,6 +2983,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
mSystemTextClassifierPackageName = testParams.systemTextClassifierPackage;
|
||||
mWellbeingPackage = testParams.wellbeingPackage;
|
||||
mRetailDemoPackage = testParams.retailDemoPackage;
|
||||
mRecentsPackage = testParams.recentsPackage;
|
||||
mDocumenterPackage = testParams.documenterPackage;
|
||||
mConfiguratorPackage = testParams.configuratorPackage;
|
||||
mAppPredictionServicePackage = testParams.appPredictionServicePackage;
|
||||
@@ -3564,6 +3568,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
mIncidentReportApproverPackage = getIncidentReportApproverPackageName();
|
||||
mRetailDemoPackage = getRetailDemoPackageName();
|
||||
mOverlayConfigSignaturePackage = getOverlayConfigSignaturePackageName();
|
||||
mRecentsPackage = getRecentsPackageName();
|
||||
|
||||
// Now that we know all of the shared libraries, update all clients to have
|
||||
// the correct library paths.
|
||||
@@ -21329,15 +21334,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
|
||||
@Override
|
||||
public @Nullable String getAttentionServicePackageName() {
|
||||
final String flattenedComponentName =
|
||||
mContext.getString(R.string.config_defaultAttentionService);
|
||||
if (flattenedComponentName != null) {
|
||||
ComponentName componentName = ComponentName.unflattenFromString(flattenedComponentName);
|
||||
if (componentName != null && componentName.getPackageName() != null) {
|
||||
return ensureSystemPackageName(componentName.getPackageName());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return ensureSystemPackageName(
|
||||
getPackageFromComponentString(R.string.config_defaultAttentionService));
|
||||
}
|
||||
|
||||
private @Nullable String getDocumenterPackageName() {
|
||||
@@ -21372,17 +21370,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
|
||||
@Override
|
||||
public String getAppPredictionServicePackageName() {
|
||||
String flattenedAppPredictionServiceComponentName =
|
||||
mContext.getString(R.string.config_defaultAppPredictionService);
|
||||
if (flattenedAppPredictionServiceComponentName == null) {
|
||||
return null;
|
||||
}
|
||||
ComponentName appPredictionServiceComponentName =
|
||||
ComponentName.unflattenFromString(flattenedAppPredictionServiceComponentName);
|
||||
if (appPredictionServiceComponentName == null) {
|
||||
return null;
|
||||
}
|
||||
return ensureSystemPackageName(appPredictionServiceComponentName.getPackageName());
|
||||
return ensureSystemPackageName(
|
||||
getPackageFromComponentString(R.string.config_defaultAppPredictionService));
|
||||
}
|
||||
|
||||
private @NonNull String[] dropNonSystemPackages(@NonNull String[] pkgNames) {
|
||||
@@ -21399,19 +21388,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
|
||||
@Override
|
||||
public String getSystemCaptionsServicePackageName() {
|
||||
String flattenedSystemCaptionsServiceComponentName =
|
||||
mContext.getString(R.string.config_defaultSystemCaptionsService);
|
||||
|
||||
if (TextUtils.isEmpty(flattenedSystemCaptionsServiceComponentName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ComponentName systemCaptionsServiceComponentName =
|
||||
ComponentName.unflattenFromString(flattenedSystemCaptionsServiceComponentName);
|
||||
if (systemCaptionsServiceComponentName == null) {
|
||||
return null;
|
||||
}
|
||||
return ensureSystemPackageName(systemCaptionsServiceComponentName.getPackageName());
|
||||
return ensureSystemPackageName(
|
||||
getPackageFromComponentString(R.string.config_defaultSystemCaptionsService));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -21429,19 +21407,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
|
||||
@Override
|
||||
public String getContentCaptureServicePackageName() {
|
||||
final String flattenedContentCaptureService =
|
||||
mContext.getString(R.string.config_defaultContentCaptureService);
|
||||
|
||||
if (TextUtils.isEmpty(flattenedContentCaptureService)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ComponentName contentCaptureServiceComponentName =
|
||||
ComponentName.unflattenFromString(flattenedContentCaptureService);
|
||||
if (contentCaptureServiceComponentName == null) {
|
||||
return null;
|
||||
}
|
||||
return ensureSystemPackageName(contentCaptureServiceComponentName.getPackageName());
|
||||
return ensureSystemPackageName(
|
||||
getPackageFromComponentString(R.string.config_defaultContentCaptureService));
|
||||
}
|
||||
|
||||
public String getOverlayConfigSignaturePackageName() {
|
||||
@@ -21484,6 +21451,26 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getRecentsPackageName() {
|
||||
return ensureSystemPackageName(
|
||||
getPackageFromComponentString(R.string.config_recentsComponentName));
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getPackageFromComponentString(@StringRes int stringResId) {
|
||||
final String componentString = mContext.getString(stringResId);
|
||||
if (TextUtils.isEmpty(componentString)) {
|
||||
return null;
|
||||
}
|
||||
final ComponentName component = ComponentName.unflattenFromString(componentString);
|
||||
if (component == null) {
|
||||
return null;
|
||||
}
|
||||
return component.getPackageName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String ensureSystemPackageName(@Nullable String packageName) {
|
||||
if (packageName == null) {
|
||||
@@ -25092,6 +25079,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
: new String[] {mRetailDemoPackage};
|
||||
case PackageManagerInternal.PACKAGE_OVERLAY_CONFIG_SIGNATURE:
|
||||
return filterOnlySystemPackages(getOverlayConfigSignaturePackageName());
|
||||
case PackageManagerInternal.PACKAGE_RECENTS:
|
||||
return filterOnlySystemPackages(mRecentsPackage);
|
||||
default:
|
||||
return ArrayUtils.emptyArray(String.class);
|
||||
}
|
||||
|
||||
@@ -331,6 +331,10 @@ public final class Permission {
|
||||
return (mPermissionInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_RETAIL_DEMO) != 0;
|
||||
}
|
||||
|
||||
public boolean isRecents() {
|
||||
return (mPermissionInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_RECENTS) != 0;
|
||||
}
|
||||
|
||||
public void transfer(@NonNull String oldPackageName, @NonNull String newPackageName) {
|
||||
if (!oldPackageName.equals(mPermissionInfo.packageName)) {
|
||||
return;
|
||||
|
||||
@@ -3616,6 +3616,13 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
||||
// Special permission granted only to the OEM specified retail demo app
|
||||
allowed = true;
|
||||
}
|
||||
if (!allowed && bp.isRecents()
|
||||
&& ArrayUtils.contains(mPackageManagerInt.getKnownPackageNames(
|
||||
PackageManagerInternal.PACKAGE_RECENTS, UserHandle.USER_SYSTEM),
|
||||
pkg.getPackageName())) {
|
||||
// Special permission for the recents app.
|
||||
allowed = true;
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user