Merge "Add annotations and finals to PermissionInfo"
This commit is contained in:
committed by
Android (Google) Code Review
commit
a3e79d624c
@@ -11842,12 +11842,12 @@ package android.content.pm {
|
||||
}
|
||||
|
||||
public class PermissionInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
|
||||
ctor public PermissionInfo();
|
||||
ctor public PermissionInfo(android.content.pm.PermissionInfo);
|
||||
ctor @Deprecated public PermissionInfo();
|
||||
ctor @Deprecated public PermissionInfo(@NonNull android.content.pm.PermissionInfo);
|
||||
method public int describeContents();
|
||||
method public int getProtection();
|
||||
method public int getProtectionFlags();
|
||||
method public CharSequence loadDescription(android.content.pm.PackageManager);
|
||||
method @Nullable public CharSequence loadDescription(@NonNull android.content.pm.PackageManager);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.PermissionInfo> CREATOR;
|
||||
field public static final int FLAG_COSTS_MONEY = 1; // 0x1
|
||||
field public static final int FLAG_INSTALLED = 1073741824; // 0x40000000
|
||||
@@ -11868,10 +11868,10 @@ package android.content.pm {
|
||||
field public static final int PROTECTION_NORMAL = 0; // 0x0
|
||||
field public static final int PROTECTION_SIGNATURE = 2; // 0x2
|
||||
field @Deprecated public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3; // 0x3
|
||||
field public int descriptionRes;
|
||||
field @StringRes public int descriptionRes;
|
||||
field public int flags;
|
||||
field public String group;
|
||||
field public CharSequence nonLocalizedDescription;
|
||||
field @Nullable public String group;
|
||||
field @Nullable public CharSequence nonLocalizedDescription;
|
||||
field @Deprecated public int protectionLevel;
|
||||
}
|
||||
|
||||
|
||||
@@ -1722,8 +1722,8 @@ package android.content.pm {
|
||||
field public static final int PROTECTION_FLAG_OEM = 16384; // 0x4000
|
||||
field public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 65536; // 0x10000
|
||||
field public static final int PROTECTION_FLAG_WELLBEING = 131072; // 0x20000
|
||||
field public String backgroundPermission;
|
||||
field public int requestRes;
|
||||
field @Nullable public final String backgroundPermission;
|
||||
field @StringRes public int requestRes;
|
||||
}
|
||||
|
||||
public class ResolveInfo implements android.os.Parcelable {
|
||||
|
||||
@@ -669,7 +669,7 @@ package android.content.pm {
|
||||
field public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 65536; // 0x10000
|
||||
field public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 32768; // 0x8000
|
||||
field public static final int PROTECTION_FLAG_WELLBEING = 131072; // 0x20000
|
||||
field public String backgroundPermission;
|
||||
field @Nullable public final String backgroundPermission;
|
||||
}
|
||||
|
||||
public final class ShortcutInfo implements android.os.Parcelable {
|
||||
|
||||
@@ -3319,7 +3319,20 @@ public class PackageParser {
|
||||
TypedArray sa = res.obtainAttributes(parser,
|
||||
com.android.internal.R.styleable.AndroidManifestPermission);
|
||||
|
||||
Permission perm = new Permission(owner);
|
||||
String backgroundPermission = null;
|
||||
if (sa.hasValue(
|
||||
com.android.internal.R.styleable.AndroidManifestPermission_backgroundPermission)) {
|
||||
if ("android".equals(owner.packageName)) {
|
||||
backgroundPermission = sa.getNonResourceString(
|
||||
com.android.internal.R.styleable
|
||||
.AndroidManifestPermission_backgroundPermission);
|
||||
} else {
|
||||
Slog.w(TAG, owner.packageName + " defines a background permission. Only the "
|
||||
+ "'android' package can do that.");
|
||||
}
|
||||
}
|
||||
|
||||
Permission perm = new Permission(owner, backgroundPermission);
|
||||
if (!parsePackageItemInfo(owner, perm.info, outError,
|
||||
"<permission>", sa, true /*nameRequired*/,
|
||||
com.android.internal.R.styleable.AndroidManifestPermission_name,
|
||||
@@ -3348,19 +3361,6 @@ public class PackageParser {
|
||||
perm.info.requestRes = sa.getResourceId(
|
||||
com.android.internal.R.styleable.AndroidManifestPermission_request, 0);
|
||||
|
||||
if (sa.hasValue(
|
||||
com.android.internal.R.styleable.AndroidManifestPermission_backgroundPermission)) {
|
||||
if ("android".equals(owner.packageName)) {
|
||||
perm.info.backgroundPermission = sa.getNonResourceString(
|
||||
com.android.internal.R.styleable
|
||||
.AndroidManifestPermission_backgroundPermission);
|
||||
} else {
|
||||
Slog.w(TAG, owner.packageName + " defines permission '" + perm.info.name
|
||||
+ "' with a background permission. Only the 'android' package can do "
|
||||
+ "that.");
|
||||
}
|
||||
}
|
||||
|
||||
perm.info.protectionLevel = sa.getInt(
|
||||
com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
|
||||
PermissionInfo.PROTECTION_NORMAL);
|
||||
@@ -3403,7 +3403,7 @@ public class PackageParser {
|
||||
private boolean parsePermissionTree(Package owner, Resources res,
|
||||
XmlResourceParser parser, String[] outError)
|
||||
throws XmlPullParserException, IOException {
|
||||
Permission perm = new Permission(owner);
|
||||
Permission perm = new Permission(owner, (String) null);
|
||||
|
||||
TypedArray sa = res.obtainAttributes(parser,
|
||||
com.android.internal.R.styleable.AndroidManifestPermissionTree);
|
||||
@@ -7613,9 +7613,12 @@ public class PackageParser {
|
||||
@UnsupportedAppUsage
|
||||
public PermissionGroup group;
|
||||
|
||||
public Permission(Package _owner) {
|
||||
super(_owner);
|
||||
info = new PermissionInfo();
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public Permission(Package owner, @Nullable String backgroundPermission) {
|
||||
super(owner);
|
||||
info = new PermissionInfo(backgroundPermission);
|
||||
}
|
||||
|
||||
@UnsupportedAppUsage
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
package android.content.pm;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
@@ -300,7 +303,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
* The group this permission is a part of, as per
|
||||
* {@link android.R.attr#permissionGroup}.
|
||||
*/
|
||||
public String group;
|
||||
public @Nullable String group;
|
||||
|
||||
/**
|
||||
* Flag for {@link #flags}, corresponding to <code>costsMoney</code>
|
||||
@@ -322,18 +325,27 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
*/
|
||||
public static final int FLAG_INSTALLED = 1<<30;
|
||||
|
||||
/** @hide */
|
||||
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
|
||||
FLAG_COSTS_MONEY,
|
||||
FLAG_INSTALLED,
|
||||
FLAG_REMOVED
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Flags {}
|
||||
|
||||
/**
|
||||
* Additional flags about this permission as given by
|
||||
* {@link android.R.attr#permissionFlags}.
|
||||
*/
|
||||
public int flags;
|
||||
public @Flags int flags;
|
||||
|
||||
/**
|
||||
* A string resource identifier (in the package's resources) of this
|
||||
* permission's description. From the "description" attribute or,
|
||||
* if not set, 0.
|
||||
*/
|
||||
public int descriptionRes;
|
||||
public @StringRes int descriptionRes;
|
||||
|
||||
/**
|
||||
* A string resource identifier (in the package's resources) used to request the permissions.
|
||||
@@ -342,7 +354,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public int requestRes;
|
||||
public @StringRes int requestRes;
|
||||
|
||||
/**
|
||||
* Some permissions only grant access while the app is in foreground. Some of these permissions
|
||||
@@ -357,7 +369,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public String backgroundPermission;
|
||||
public final @Nullable String backgroundPermission;
|
||||
|
||||
/**
|
||||
* The description string provided in the AndroidManifest file, if any. You
|
||||
@@ -365,7 +377,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
* is in a resource. You probably want
|
||||
* {@link PermissionInfo#loadDescription} instead.
|
||||
*/
|
||||
public CharSequence nonLocalizedDescription;
|
||||
public @Nullable CharSequence nonLocalizedDescription;
|
||||
|
||||
/** @hide */
|
||||
public static int fixProtectionLevel(int level) {
|
||||
@@ -383,7 +395,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
|
||||
/** @hide */
|
||||
@UnsupportedAppUsage
|
||||
public static String protectionToString(int level) {
|
||||
public static @NonNull String protectionToString(int level) {
|
||||
String protLevel = "????";
|
||||
switch (level & PROTECTION_MASK_BASE) {
|
||||
case PermissionInfo.PROTECTION_DANGEROUS:
|
||||
@@ -456,10 +468,26 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
return protLevel;
|
||||
}
|
||||
|
||||
public PermissionInfo() {
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public PermissionInfo(@Nullable String backgroundPermission) {
|
||||
this.backgroundPermission = backgroundPermission;
|
||||
}
|
||||
|
||||
public PermissionInfo(PermissionInfo orig) {
|
||||
/**
|
||||
* @deprecated Should only be created by the system.
|
||||
*/
|
||||
@Deprecated
|
||||
public PermissionInfo() {
|
||||
this((String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Should only be created by the system.
|
||||
*/
|
||||
@Deprecated
|
||||
public PermissionInfo(@NonNull PermissionInfo orig) {
|
||||
super(orig);
|
||||
protectionLevel = orig.protectionLevel;
|
||||
flags = orig.flags;
|
||||
@@ -481,7 +509,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
* @return Returns a CharSequence containing the permission's description.
|
||||
* If there is no description, null is returned.
|
||||
*/
|
||||
public CharSequence loadDescription(PackageManager pm) {
|
||||
public @Nullable CharSequence loadDescription(@NonNull PackageManager pm) {
|
||||
if (nonLocalizedDescription != null) {
|
||||
return nonLocalizedDescription;
|
||||
}
|
||||
@@ -551,7 +579,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
|
||||
return (protectionLevel & PermissionInfo.PROTECTION_FLAG_APPOP) != 0;
|
||||
}
|
||||
|
||||
public static final @android.annotation.NonNull Creator<PermissionInfo> CREATOR =
|
||||
public static final @NonNull Creator<PermissionInfo> CREATOR =
|
||||
new Creator<PermissionInfo>() {
|
||||
@Override
|
||||
public PermissionInfo createFromParcel(Parcel source) {
|
||||
|
||||
@@ -455,7 +455,7 @@ public class PackageParserTest {
|
||||
pkg.splitPrivateFlags = new int[] { 100 };
|
||||
pkg.applicationInfo = new ApplicationInfo();
|
||||
|
||||
pkg.permissions.add(new PackageParser.Permission(pkg));
|
||||
pkg.permissions.add(new PackageParser.Permission(pkg, (String) null));
|
||||
pkg.permissionGroups.add(new PackageParser.PermissionGroup(pkg, ID_NULL, ID_NULL, ID_NULL));
|
||||
|
||||
final PackageParser.ParseComponentArgs dummy = new PackageParser.ParseComponentArgs(
|
||||
|
||||
Reference in New Issue
Block a user