文章目录
- 开发平台基本信息
- 问题描述
- 解决方法
开发平台基本信息
芯片: SDM450
版本: Android 9.0
kernel: msm-4.9
问题描述
设备在进行入网认证的时候,实验室要求应用在使用特殊权限的时候,需要告知用户,要用户授权才能使用相应的权限;Android需要申请的危险权限,是以组的形势申请的,比如说,拨打电话、读取通话记录、写入通话记录都是属于电话权限分组;而在入网认证的时候,实验室要求这些权限组要拆分为单独的权限,每个权限就是独立的,不再是以组的形势。
解决方法
diff --git a/packages/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/AppPermissionsFragment.java b/packages/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/AppPermissionsFragment.java
old mode 100644
new mode 100755
index 05e46fd..f6e9233
--- a/packages/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/AppPermissionsFragment.java
+++ b/packages/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/AppPermissionsFragment.java
@@ -24,12 +24,17 @@ import android.app.AlertDialog;import android.app.Fragment;import android.content.Context;import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;import android.content.Intent;import android.content.pm.ApplicationInfo;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PermissionInfo;import android.graphics.drawable.Drawable;
+import android.Manifest;import android.net.Uri;
+import android.widget.Switch;import android.os.Bundle;import android.preference.Preference;import android.preference.Preference.OnPreferenceChangeListener;
@@ -43,7 +48,9 @@ import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;
-import android.widget.Switch;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;import android.widget.Toast;import com.android.packageinstaller.R;
@@ -73,6 +80,7 @@ public final class AppPermissionsFragment extends SettingsWithHeaderprivate PreferenceScreen mExtraScreen;private boolean mHasConfirmedRevoke;
+ String mPackageName;public static AppPermissionsFragment newInstance(String packageName) {return setPackageName(new AppPermissionsFragment(), packageName);
@@ -95,9 +103,9 @@ public final class AppPermissionsFragment extends SettingsWithHeaderab.setDisplayHomeAsUpEnabled(true);}- String packageName = getArguments().getString(Intent.EXTRA_PACKAGE_NAME);
+ mPackageName = getArguments().getString(Intent.EXTRA_PACKAGE_NAME);Activity activity = getActivity();
- PackageInfo packageInfo = getPackageInfo(activity, packageName);
+ PackageInfo packageInfo = getPackageInfo(activity, mPackageName);if (packageInfo == null) {Toast.makeText(activity, R.string.app_not_found_dlg_title, Toast.LENGTH_LONG).show();activity.finish();
@@ -255,6 +263,7 @@ public final class AppPermissionsFragment extends SettingsWithHeader}}preference.setPersistent(false);
+ preference.setChecked(group.areRuntimePermissionsGranted());if (isPlatform) {screen.addPreference(preference);
@@ -264,6 +273,33 @@ public final class AppPermissionsFragment extends SettingsWithHeader}mExtraScreen.addPreference(preference);}
+ // if (AppPermissionGroup.isStrictOpEnable() && isPlatform) {
+ try {
+ if (!group.getName().equals(Manifest.permission_group.STORAGE)) {
+ PackageManager pm = context.getPackageManager();
+ for (Permission permission : group.getPermissions()) {
+ PermissionInfo perm = pm.getPermissionInfo(permission.getName(), 0);
+ final String[] filterPermissions = new String[]{permission.getName()};
+ // if (perm.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS) {
+ SwitchPreference preference_permission = new SwitchPreference(context);
+ preference_permission.setOnPreferenceChangeListener(this);
+ preference_permission.setKey(permission.getName());
+ preference_permission.setTitle(perm.loadLabel(pm));
+ preference_permission.setPersistent(false);
+ preference_permission.setEnabled(true);
+ AppPermissionGroup permissionGroup = getPermisssionGroup(perm.group);
+ preference_permission.setChecked(
+ permissionGroup.areRuntimePermissionsGranted(filterPermissions));
+ screen.addPreference(preference_permission);
+ // } else if (perm.protectionLevel == PermissionInfo.PROTECTION_NORMAL) {
+ // continue;
+ // }
+ }
+ }
+ } catch (NameNotFoundException e) {
+ Log.e(LOG_TAG, "Problem getting package info for " + mPackageName, e);
+ }
+ //}}if (mExtraScreen != null) {
@@ -289,12 +325,79 @@ public final class AppPermissionsFragment extends SettingsWithHeadersetLoading(false /* loading */, true /* animate */);}+ private AppPermissionGroup getPermisssionGroup(String group) {
+ for (AppPermissionGroup mGroup : mAppPermissions.getPermissionGroups()) {
+ if (group.equals(mGroup.getName())) {
+ return mGroup;
+ }
+ }
+ return null;
+ }
+
+ private void updateEveryPermissionPreference(AppPermissionGroup group) {
+ if (group.getName().equals(Manifest.permission_group.STORAGE)) return;
+ PackageManager pm = getContext().getPackageManager();
+ PreferenceScreen screen = getPreferenceScreen();
+ for (Permission permission : group.getPermissions()) {
+ Preference permission_preference
+ = screen.findPreference((CharSequence) permission.getName());
+ try {
+ PermissionInfo permInfo = pm.getPermissionInfo(permission.getName(), 0);
+ AppPermissionGroup permissionGroup = getPermisssionGroup(permInfo.group);
+ final String[] filterPermissions = new String[]{permission.getName()};
+ ((SwitchPreference) permission_preference).setChecked(
+ permissionGroup.areRuntimePermissionsGranted(filterPermissions));
+ } catch (NameNotFoundException e) {
+ Log.e(LOG_TAG, "Failed to update permission_preference", e);
+ }
+ }
+ }
+@Overridepublic boolean onPreferenceChange(final Preference preference, Object newValue) {
- String groupName = preference.getKey();
- final AppPermissionGroup group = mAppPermissions.getPermissionGroup(groupName);
+ String key = preference.getKey();
+ final String[] filterPermissions = new String[]{key};
+ final AppPermissionGroup group = mAppPermissions.getPermissionGroup(key);
+ PackageManager pm = getContext().getPackageManager();if (group == null) {
+ //if (AppPermissionGroup.isStrictOpEnable()) {
+ try {
+ PermissionInfo permInfo = pm.getPermissionInfo(key, 0);
+ final AppPermissionGroup title_group
+ = mAppPermissions.getPermissionGroup(permInfo.group);
+ final boolean grantedByDefault = title_group.hasGrantedByDefaultPermission();
+ PreferenceScreen screen = getPreferenceScreen();
+ Preference group_preference = screen.findPreference((CharSequence) permInfo.group);
+ AppPermissionGroup permissionGroup = getPermisssionGroup(permInfo.group);
+ if (newValue == Boolean.TRUE) {
+ ((SwitchPreference)preference).setChecked(true);
+ title_group.grantRuntimePermissions(false, filterPermissions);
+ ((SwitchPreference) group_preference).setChecked(
+ permissionGroup.areRuntimePermissionsGranted());
+ } else {
+ //When the permission is off, the application maybe will crash, so need to
+ //add a warning dialog when the user revoke the permission.
+ new AlertDialog.Builder(getContext())
+ .setMessage(grantedByDefault ? R.string.system_warning
+ : R.string.old_sdk_deny_warning)
+ .setNegativeButton(R.string.cancel, null)
+ .setPositiveButton(R.string.grant_dialog_button_deny_anyway,
+ new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ ((SwitchPreference) preference).setChecked(false);
+ title_group.revokeRuntimePermissions(false, filterPermissions);
+ ((SwitchPreference) group_preference).setChecked(
+ permissionGroup.areRuntimePermissionsGranted());
+ }
+ })
+ .show();
+ }
+ } catch (NameNotFoundException e) {
+ Log.e(LOG_TAG, "Problem getting package info for ", e);
+ }
+ // }return false;}