Merge "Refactor PackageParser (11/n)"
This commit is contained in:
@@ -723,6 +723,7 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable {
|
||||
|
||||
@Override
|
||||
public ParsingPackageImpl addImplicitPermission(String permission) {
|
||||
addUsesPermission(new ParsedUsesPermission(permission, 0 /*usesPermissionFlags*/));
|
||||
this.implicitPermissions = CollectionUtils.add(this.implicitPermissions,
|
||||
TextUtils.safeIntern(permission));
|
||||
return this;
|
||||
|
||||
@@ -74,6 +74,7 @@ import android.content.pm.parsing.result.ParseInput;
|
||||
import android.content.pm.parsing.result.ParseInput.DeferredError;
|
||||
import android.content.pm.parsing.result.ParseResult;
|
||||
import android.content.pm.parsing.result.ParseTypeImpl;
|
||||
import android.content.pm.permission.CompatibilityPermissionInfo;
|
||||
import android.content.pm.split.DefaultSplitAssetLoader;
|
||||
import android.content.pm.split.SplitAssetDependencyLoader;
|
||||
import android.content.pm.split.SplitAssetLoader;
|
||||
@@ -904,7 +905,7 @@ public class ParsingPackageUtils {
|
||||
);
|
||||
}
|
||||
|
||||
convertNewPermissions(pkg);
|
||||
convertCompatPermissions(pkg);
|
||||
|
||||
convertSplitPermissions(pkg);
|
||||
|
||||
@@ -2790,31 +2791,16 @@ public class ParsingPackageUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void convertNewPermissions(ParsingPackage pkg) {
|
||||
final int NP = PackageParser.NEW_PERMISSIONS.length;
|
||||
StringBuilder newPermsMsg = null;
|
||||
for (int ip = 0; ip < NP; ip++) {
|
||||
final PackageParser.NewPermissionInfo npi
|
||||
= PackageParser.NEW_PERMISSIONS[ip];
|
||||
if (pkg.getTargetSdkVersion() >= npi.sdkVersion) {
|
||||
private static void convertCompatPermissions(ParsingPackage pkg) {
|
||||
for (int i = 0, size = CompatibilityPermissionInfo.COMPAT_PERMS.length; i < size; i++) {
|
||||
final CompatibilityPermissionInfo info = CompatibilityPermissionInfo.COMPAT_PERMS[i];
|
||||
if (pkg.getTargetSdkVersion() >= info.sdkVersion) {
|
||||
break;
|
||||
}
|
||||
if (!pkg.getRequestedPermissions().contains(npi.name)) {
|
||||
if (newPermsMsg == null) {
|
||||
newPermsMsg = new StringBuilder(128);
|
||||
newPermsMsg.append(pkg.getPackageName());
|
||||
newPermsMsg.append(": compat added ");
|
||||
} else {
|
||||
newPermsMsg.append(' ');
|
||||
}
|
||||
newPermsMsg.append(npi.name);
|
||||
pkg.addUsesPermission(new ParsedUsesPermission(npi.name, 0))
|
||||
.addImplicitPermission(npi.name);
|
||||
if (!pkg.getRequestedPermissions().contains(info.name)) {
|
||||
pkg.addImplicitPermission(info.name);
|
||||
}
|
||||
}
|
||||
if (newPermsMsg != null) {
|
||||
Slog.i(TAG, newPermsMsg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void convertSplitPermissions(ParsingPackage pkg) {
|
||||
@@ -2830,8 +2816,7 @@ public class ParsingPackageUtils {
|
||||
for (int in = 0; in < newPerms.size(); in++) {
|
||||
final String perm = newPerms.get(in);
|
||||
if (!requestedPermissions.contains(perm)) {
|
||||
pkg.addUsesPermission(new ParsedUsesPermission(perm, 0))
|
||||
.addImplicitPermission(perm);
|
||||
pkg.addImplicitPermission(perm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm.permission;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.parsing.component.ParsedUsesPermission;
|
||||
|
||||
/**
|
||||
* Implements compatibility support for permissions, and old applications
|
||||
* will be automatically granted it.
|
||||
*
|
||||
* Compatibility permissions are permissions that are automatically granted to
|
||||
* packages that target an SDK prior to when the permission was introduced.
|
||||
* Sometimes the platform makes breaking behaviour changes and hides the legacy
|
||||
* behaviour behind a permission. In these instances, we ensure applications
|
||||
* targeting older platform versions are implicitly granted the correct set of
|
||||
* permissions.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class CompatibilityPermissionInfo extends ParsedUsesPermission {
|
||||
|
||||
public final int sdkVersion;
|
||||
|
||||
/**
|
||||
* List of new permissions that have been added since 1.0.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final CompatibilityPermissionInfo[] COMPAT_PERMS =
|
||||
new CompatibilityPermissionInfo[]{
|
||||
new CompatibilityPermissionInfo(Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
android.os.Build.VERSION_CODES.DONUT, 0 /*usesPermissionFlags*/),
|
||||
new CompatibilityPermissionInfo(Manifest.permission.READ_PHONE_STATE,
|
||||
android.os.Build.VERSION_CODES.DONUT, 0 /*usesPermissionFlags*/)
|
||||
};
|
||||
|
||||
private CompatibilityPermissionInfo(String name, int sdkVersion,
|
||||
@UsesPermissionFlags int usesPermissionFlags) {
|
||||
super(name, usesPermissionFlags);
|
||||
this.sdkVersion = sdkVersion;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user