Java 类android.content.pm.PermissionInfo 实例源码

项目:BlackList    文件:Permissions.java   
/**
 * Returns information string about permission
 **/
@Nullable
private static String getPermissionInfo(@NonNull Context context, @NonNull String permission) {
    context = context.getApplicationContext();
    PackageManager pm = context.getPackageManager();
    PermissionInfo info = null;
    try {
        info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException ex) {
        Log.w(TAG, ex);
    }

    if (info != null) {
        CharSequence label = info.loadLabel(pm);
        if (label == null) {
            label = info.nonLocalizedLabel;
        }
        return label.toString();
    }

    return null;
}
项目:mobile-store    文件:AppSecurityPermissions.java   
private boolean isDisplayablePermission(PermissionInfo pInfo, int existingReqFlags) {
    final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    final boolean isNormal = base == PermissionInfo.PROTECTION_NORMAL;
    final boolean isDangerous = base == PermissionInfo.PROTECTION_DANGEROUS
            || ((pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_PRE23) != 0);

    // Dangerous and normal permissions are always shown to the user
    // this is matches the permission list in AppDetails2
    if (isNormal || isDangerous) {
        return true;
    }

    final boolean isDevelopment = (pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0;
    final boolean wasGranted = (existingReqFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;

    // Development permissions are only shown to the user if they are already
    // granted to the app -- if we are installing an app and they are not
    // already granted, they will not be granted as part of the install.
    return isDevelopment && wasGranted;
}
项目:letv    文件:IApkManagerImpl.java   
public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException {
    waitForReadyInner();
    try {
        enforcePluginFileExists();
        if (shouldNotBlockOtherInfo()) {
            for (PluginPackageParser pluginPackageParser : this.mPluginCache.values()) {
                for (PermissionInfo permissionInfo : pluginPackageParser.getPermissions()) {
                    if (TextUtils.equals(permissionInfo.name, name)) {
                        return permissionInfo;
                    }
                }
            }
        }
        List<String> pkgs = this.mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid());
        for (PluginPackageParser pluginPackageParser2 : this.mPluginCache.values()) {
            for (PermissionInfo permissionInfo2 : pluginPackageParser2.getPermissions()) {
                if (TextUtils.equals(permissionInfo2.name, name) && pkgs.contains(permissionInfo2.packageName)) {
                    return permissionInfo2;
                }
            }
        }
    } catch (Exception e) {
        handleException(e);
    }
    return null;
}
项目:disclosure-android-app    文件:PermissionExplanationDialogPresenter.java   
private void initUi() {
  view.showPermissionStatus(permissionWasGrantedForApp(), permissionCanBeRevoked());

  if (permissionWasGrantedForApp()) {

    if (PermissionInfo.PROTECTION_NORMAL == permission.protectionLevel()) {
      view.showHint(stringProvider.getString(R.string.permission_status_normal));
    }

    if (PermissionInfo.PROTECTION_DANGEROUS == permission.protectionLevel()) {
      if (permissionCanBeRevoked()) {
        view.showHint(stringProvider.getString(R.string.permission_status_revokable));
      } else {
        view.showHint(stringProvider.getString(R.string.permission_status_no_runtime_permissions, Build.VERSION.RELEASE));
      }
    }
  } else {
    view.showHint(stringProvider.getString(R.string.permission_status_no_usage, app.label()));
  }
}
项目:DroidPlugin    文件:IPackageManagerHookHandle.java   
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
      /*public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException;*/
    if (args != null) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String packageName = (String) args[index0];
            int flags = (Integer) args[index1];
            PermissionInfo permissionInfo = PluginManager.getInstance().getPermissionInfo(packageName, flags);
            if (permissionInfo != null) {
                setFakedResult(permissionInfo);
                return true;
            }
        }
    }

    return super.beforeInvoke(receiver, method, args);
}
项目:DroidPlugin    文件:IPackageManagerHookHandle.java   
@Override
protected void afterInvoke(Object receiver, Method method, Object[] args, Object invokeResult) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
    /*public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException;*/
    if (args != null && invokeResult instanceof List) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String group = (String) args[index0];
            int flags = (Integer) args[index1];
            List<PermissionInfo> infos = PluginManager.getInstance().queryPermissionsByGroup(group, flags);
            if (infos != null && infos.size() > 0) {
                List old = (List) invokeResult;
                old.addAll(infos);
            }
        }
    }
    super.afterInvoke(receiver, method, args, invokeResult);
}
项目:FirebasePost    文件:PermissionsHelper.java   
/**
 * use for get {@link PermissionInfo} of all @param required
 *
 * @param context
 * @param required
 * @return
 */
private static List<PermissionInfo> getPermissions(Context context, List<String> required) {

    List<PermissionInfo> permissionInfoList = new ArrayList<>();

    PackageManager pm = context.getPackageManager();
    for (String permission : required) {
        PermissionInfo pinfo = null;
        try {
            pinfo = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            continue;
        }

        permissionInfoList.add(pinfo);
    }
    return permissionInfoList;
}
项目:DroidPluginLibrary    文件:IPackageManagerHookHandle.java   
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
      /*public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException;*/
    if (args != null) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String packageName = (String) args[index0];
            int flags = (Integer) args[index1];
            PermissionInfo permissionInfo = PluginManager.getInstance().getPermissionInfo(packageName, flags);
            if (permissionInfo != null) {
                setFakedResult(permissionInfo);
                return true;
            }
        }
    }

    return super.beforeInvoke(receiver, method, args);
}
项目:DroidPluginLibrary    文件:IPackageManagerHookHandle.java   
@Override
protected void afterInvoke(Object receiver, Method method, Object[] args, Object invokeResult) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
    /*public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException;*/
    if (args != null && invokeResult instanceof List) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String group = (String) args[index0];
            int flags = (Integer) args[index1];
            List<PermissionInfo> infos = PluginManager.getInstance().queryPermissionsByGroup(group, flags);
            if (infos != null && infos.size() > 0) {
                List old = (List) invokeResult;
                old.addAll(infos);
            }
        }
    }
    super.afterInvoke(receiver, method, args, invokeResult);
}
项目:AppOpsX    文件:Helper.java   
private static void joinOpEntryInfo(OpEntryInfo opEntryInfo,Context context){
  String groupS = FAKE_PERMS_GROUP.get(opEntryInfo.opName);

  try {
    if (groupS == null && opEntryInfo.opPermsName != null) {
      PermissionInfo permissionInfo = context.getPackageManager()
          .getPermissionInfo(opEntryInfo.opPermsName, PackageManager.GET_META_DATA);
      groupS = permissionInfo.group;
    }
  } catch (Exception e) {
    //ignore
  }

  PermGroupInfo permGroupInfo = null;
  if (groupS != null) {
    permGroupInfo = PERMS_GROUPS.get(groupS);
  }

  if (permGroupInfo == null) {
    permGroupInfo = OTHER_PERM_INFO;
  }

  opEntryInfo.icon = permGroupInfo.icon;
  opEntryInfo.groupName = permGroupInfo.group;

}
项目:pet    文件:IPackageManagerHookHandle.java   
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
      /*public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException;*/
    if (args != null) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String packageName = (String) args[index0];
            int flags = (Integer) args[index1];
            PermissionInfo permissionInfo = PluginManager.getInstance().getPermissionInfo(packageName, flags);
            if (permissionInfo != null) {
                setFakedResult(permissionInfo);
                return true;
            }
        }
    }

    return super.beforeInvoke(receiver, method, args);
}
项目:pet    文件:IPackageManagerHookHandle.java   
@Override
protected void afterInvoke(Object receiver, Method method, Object[] args, Object invokeResult) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
    /*public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException;*/
    if (args != null && invokeResult instanceof List) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String group = (String) args[index0];
            int flags = (Integer) args[index1];
            List<PermissionInfo> infos = PluginManager.getInstance().queryPermissionsByGroup(group, flags);
            if (infos != null && infos.size() > 0) {
                List old = (List) invokeResult;
                old.addAll(infos);
            }
        }
    }
    super.afterInvoke(receiver, method, args, invokeResult);
}
项目:under-the-hood    文件:PackageInfoAssembler.java   
/**
 * Returns page-entry for each defined permission in the app (the passed activity belongs to).
 * <p>
 * See {@link DefaultProperties#createSectionRuntimePermissions(Activity, List)} for more details
 *
 * @param context                  must not be null and must be instance of activity (needed for getting the state)
 * @param packageInfo              from {@link PackageManager#getPackageInfo(String, int)} requiring {@link PackageManager#GET_PERMISSIONS} flag
 * @param onlyDangerousPermissions only include permissions with flag PROTECTION_DANGEROUS (ie. have to be granted by the user)
 * @return list of page-entries
 */
@SuppressLint("NewApi")
public static List<PageEntry<?>> createPmPermissionInfo(final @NonNull Context context, @NonNull PackageInfo packageInfo, boolean onlyDangerousPermissions) {

    if (!(context instanceof Activity)) {
        throw new IllegalArgumentException("context must be of type activity - needed for getting current permission state");
    }

    List<PageEntry<?>> entries = new ArrayList<>();
    if (packageInfo.requestedPermissions != null && packageInfo.requestedPermissions.length > 0) {
        List<String> permissionNames = new ArrayList<>();
        for (int i = 0; i < packageInfo.requestedPermissions.length; i++) {
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1
                    || !onlyDangerousPermissions
                    || packageInfo.requestedPermissionsFlags[i] == PermissionInfo.PROTECTION_DANGEROUS) {
                permissionNames.add(packageInfo.requestedPermissions[i]);
            }
        }
        Collections.sort(permissionNames);

        return DefaultProperties.createSectionRuntimePermissions(((Activity) context), permissionNames).removeHeader().asEntryList();
    }

    return entries;
}
项目:DynamicAppLoader    文件:IPackageManagerHookHandle.java   
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
      /*public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException;*/
    if (args != null) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String packageName = (String) args[index0];
            int flags = (Integer) args[index1];
            PermissionInfo permissionInfo = PluginManager.getInstance().getPermissionInfo(packageName, flags);
            if (permissionInfo != null) {
                setFakedResult(permissionInfo);
                return true;
            }
        }
    }

    return super.beforeInvoke(receiver, method, args);
}
项目:DynamicAppLoader    文件:IPackageManagerHookHandle.java   
@Override
protected void afterInvoke(Object receiver, Method method, Object[] args, Object invokeResult) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
    /*public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException;*/
    if (args != null && invokeResult instanceof List) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String group = (String) args[index0];
            int flags = (Integer) args[index1];
            List<PermissionInfo> infos = PluginManager.getInstance().queryPermissionsByGroup(group, flags);
            if (infos != null && infos.size() > 0) {
                List old = (List) invokeResult;
                old.addAll(infos);
            }
        }
    }
    super.afterInvoke(receiver, method, args, invokeResult);
}
项目:NewKam    文件:ApkHelper.java   
@Nullable public static List<PermissionsView> getAppPermissions(@NonNull Context context, String packageName) {
    try {
        List<PermissionsView> permissionsViews = new ArrayList<>();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
        for (String permission : info.requestedPermissions) {
            PermissionInfo permissionInfo = getPermissionInfo(context, permission);
            if (!InputHelper.isEmpty(permission) && permissionInfo != null &&
                    !InputHelper.isEmpty(permissionInfo.loadDescription(context.getPackageManager()))) {
                permissionsViews.add(PermissionsView.getInstance(permission));
            }
        }
        return permissionsViews;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:android_external_MicroGUiTools    文件:PermissionCheckGroup.java   
private void doPermissionCheck(Context context, ResultCollector collector, final String permission) {
    PackageManager pm = context.getPackageManager();
    try {
        PermissionInfo info = pm.getPermissionInfo(permission, 0);
        PermissionGroupInfo groupInfo = info.group != null ? pm.getPermissionGroupInfo(info.group, 0) : null;
        CharSequence permLabel = info.loadLabel(pm);
        CharSequence groupLabel = groupInfo != null ? groupInfo.loadLabel(pm) : permLabel;
        collector.addResult(context.getString(R.string.self_check_name_permission, permLabel),
                context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED ? Positive : Negative,
                context.getString(R.string.self_check_resolution_permission, groupLabel),
                new SelfCheckGroup.CheckResolver() {

                    @Override
                    public void tryResolve(Fragment fragment) {
                        fragment.requestPermissions(new String[]{permission}, 0);
                    }
                });
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, e);
    }
}
项目:fdroid    文件:AppSecurityPermissions.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private boolean isDisplayablePermission(PermissionInfo pInfo, int existingReqFlags) {
    final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    final boolean isNormal = base == PermissionInfo.PROTECTION_NORMAL;
    final boolean isDangerous = base == PermissionInfo.PROTECTION_DANGEROUS;

    // Dangerous and normal permissions are always shown to the user
    if (isNormal || isDangerous) {
        return true;
    }

    final boolean isDevelopment = (pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0;
    final boolean wasGranted = (existingReqFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;

    // Development permissions are only shown to the user if they are already
    // granted to the app -- if we are installing an app and they are not
    // already granted, they will not be granted as part of the install.
    return isDevelopment && wasGranted;
}
项目:DroidPluginLibrary    文件:IPackageManagerHookHandle.java   
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
      /*public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException;*/
    if (args != null) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String packageName = (String) args[index0];
            int flags = (Integer) args[index1];
            PermissionInfo permissionInfo = PluginManager.getInstance().getPermissionInfo(packageName, flags);
            if (permissionInfo != null) {
                setFakedResult(permissionInfo);
                return true;
            }
        }
    }

    return super.beforeInvoke(receiver, method, args);
}
项目:DroidPluginLibrary    文件:IPackageManagerHookHandle.java   
@Override
protected void afterInvoke(Object receiver, Method method, Object[] args, Object invokeResult) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
    /*public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException;*/
    if (args != null && invokeResult instanceof List) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String group = (String) args[index0];
            int flags = (Integer) args[index1];
            List<PermissionInfo> infos = PluginManager.getInstance().queryPermissionsByGroup(group, flags);
            if (infos != null && infos.size() > 0) {
                List old = (List) invokeResult;
                old.addAll(infos);
            }
        }
    }
    super.afterInvoke(receiver, method, args, invokeResult);
}
项目:FMTech    文件:PermissionsBucketer.java   
private static String getHumanReadablePermissionString(String paramString)
{
  try
  {
    PermissionInfo localPermissionInfo = FinskyApp.get().getPackageManager().getPermissionInfo(paramString, 0);
    if (localPermissionInfo != null)
    {
      CharSequence localCharSequence = localPermissionInfo.loadLabel(FinskyApp.get().getPackageManager());
      if (localCharSequence == null) {
        return null;
      }
      String str = localCharSequence.toString();
      return str;
    }
  }
  catch (PackageManager.NameNotFoundException localNameNotFoundException) {}
  return null;
}
项目:FMTech    文件:PermissionsBucketer.java   
private static boolean isDangerousPlatformDefinedPermission(String paramString)
{
  try
  {
    PermissionInfo localPermissionInfo = FinskyApp.get().getPackageManager().getPermissionInfo(paramString, 0);
    if (localPermissionInfo != null)
    {
      int i = localPermissionInfo.protectionLevel;
      if (i == 1) {
        return true;
      }
    }
  }
  catch (PackageManager.NameNotFoundException localNameNotFoundException) {}
  return false;
}
项目:allinone    文件:PermissionRecyclerItem.java   
@Override
public void bindData(View view, int position, PermissionInfo info) {
    Drawable drawable = info.loadIcon(getMContext().getPackageManager());
    mIcon.setImageDrawable(drawable);
    mTitle.setText(info.loadLabel(getMContext().getPackageManager()));
    mContent.setText(info.name);
    mProtectionLevel.setVisibility(View.VISIBLE);
    String protectionLevel = null;
    switch (info.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE) {
        case PermissionInfo.PROTECTION_NORMAL:
            protectionLevel = "normal";
            break;
        case PermissionInfo.PROTECTION_DANGEROUS:
            protectionLevel = "dangerous";
            break;
        case PermissionInfo.PROTECTION_SIGNATURE:
            protectionLevel = "signature";
            break;
        case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM:
            protectionLevel = "signature Or system";
            break;
    }
    mProtectionLevel.setText(protectionLevel);
}
项目:wheels    文件:IPackageManagerHookHandle.java   
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
      /*public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException;*/
    if (args != null) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String packageName = (String) args[index0];
            int flags = (Integer) args[index1];
            PermissionInfo permissionInfo = PluginManager.getInstance().getPermissionInfo(packageName, flags);
            if (permissionInfo != null) {
                setFakedResult(permissionInfo);
                return true;
            }
        }
    }

    return super.beforeInvoke(receiver, method, args);
}
项目:wheels    文件:IPackageManagerHookHandle.java   
@Override
protected void afterInvoke(Object receiver, Method method, Object[] args, Object invokeResult) throws Throwable {
    //API 2.3, 4.01_r1, 4.0.3_r1, 4.1.1_r1, 4.2_r1, 4.3_r1, 4.4_r1, 5.0.2_r1
    /*public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException;*/
    if (args != null && invokeResult instanceof List) {
        final int index0 = 0, index1 = 1;
        if (args.length > 1 && args[index0] instanceof String && args[index1] instanceof Integer) {
            String group = (String) args[index0];
            int flags = (Integer) args[index1];
            List<PermissionInfo> infos = PluginManager.getInstance().queryPermissionsByGroup(group, flags);
            if (infos != null && infos.size() > 0) {
                List old = (List) invokeResult;
                old.addAll(infos);
            }
        }
    }
    super.afterInvoke(receiver, method, args, invokeResult);
}
项目:SpotifyPopularSongs    文件:Utils.java   
/**
 * List all app permissions
 */
public static void printOutPermissions(Context context){
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
        if (info.requestedPermissions != null) {
            for (String p : info.requestedPermissions) {
                ILog.d(TAG, "Permission :" + p);
            }
        }

        if (info.permissions != null) {
            for (PermissionInfo permission : info.permissions) {
                ILog.d(TAG, "2 Permission :" + permission.toString());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:android_RuntimePermissionsCompat    文件:Permission.java   
@SuppressWarnings("deprecation")
public String protectionLevel() {
    switch (this.protectionLevel) {
        case PermissionInfo.PROTECTION_NORMAL:
            return "PROTECTION_NORMAL";
        case PermissionInfo.PROTECTION_DANGEROUS:
            return "PROTECTION_DANGEROUS";
        case PermissionInfo.PROTECTION_SIGNATURE:
            return "PROTECTION_SIGNATURE";
        case PermissionInfo.PROTECTION_SIGNATURE | PermissionInfo.PROTECTION_FLAG_PRIVILEGED:
            return "PROTECTION_PRIVILEGED";
        case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM:
            return "PROTECTION_SYSTEM";
        default:
            return "<UNKNOWN>";
    }
}
项目:android_RuntimePermissionsCompat    文件:RuntimePermissionsCompat.java   
public static boolean isRevocable(@NonNull final Context context, @NonNull final String permission) {
    if (Build.VERSION.SDK_INT < MARSHMALLOW) {
        return false;
    }

    final PackageManager packageManager = context.getPackageManager();
    if (packageManager == null) {
        return false;
    }
    try {
        final PermissionInfo permissionInfo = packageManager.getPermissionInfo(permission, 0);
        @SuppressLint("InlinedApi") // API-16+
        final int protectionLevel = (permissionInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE);
        return (protectionLevel != PermissionInfo.PROTECTION_NORMAL);
    }
    catch (final Exception e) {
        Log.e(TAG, e.getMessage(), e);
        return false;
    }
}
项目:IntentsLab    文件:MyPermissionInfoImpl.java   
/**
 * Fill this object with info obtained from {@link android.content.pm.PackageManager#getPermissionInfo(String, int)}
 */
void fillWithInfoFromPackageManager(PermissionInfo permissionInfo) {
    // If PackageManager haven't found permission this arg will be null
    if (permissionInfo == null) {
        // TODO: handle declared but missing permission
        return;
    }

    // Find defining package in mPackagesTryingDefine
    for (Iterator<MyPackageInfoImpl> iterator = mPackagesTryingDefine.iterator(); iterator.hasNext(); ) {
        MyPackageInfoImpl triedPackage = iterator.next();
        if (permissionInfo.packageName.equals(triedPackage.mPackageName)) {
            mOwnerPackage = triedPackage;
            iterator.remove();
        }
    }

    // Export data into fields
    mOwnerVerified = true;
    mSystemPermissionInfo = permissionInfo;
}
项目:DeviceControl    文件:AppSecurityPermissions.java   
private boolean isDisplayablePermission(PermissionInfo pInfo, int newReqFlags,
        int existingReqFlags) {
    final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    final boolean isNormal = (base == PermissionInfo.PROTECTION_NORMAL);
    final boolean isDangerous = (base == PermissionInfo.PROTECTION_DANGEROUS);
    // TODO: recheck
    //final boolean isRequired =
    //        ((newReqFlags & PackageInfo.REQUESTED_PERMISSION_REQUIRED) != 0);
    final boolean isDevelopment =
            ((pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0);
    final boolean wasGranted =
            ((existingReqFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0);
    final boolean isGranted =
            ((newReqFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0);

    // Dangerous and normal permissions are always shown to the user if the permission
    // is required, or it was previously granted
    if ((isNormal || isDangerous) && (/*isRequired || */wasGranted || isGranted)) {
        return true;
    }

    // Development permissions are only shown to the user if they are already
    // granted to the app -- if we are installing an app and they are not
    // already granted, they will not be granted as part of the install.
    return isDevelopment && wasGranted;
}
项目:fdroidclient    文件:AppSecurityPermissions.java   
private boolean isDisplayablePermission(PermissionInfo pInfo, int existingReqFlags) {
    final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    final boolean isNormal = base == PermissionInfo.PROTECTION_NORMAL;
    final boolean isDangerous = base == PermissionInfo.PROTECTION_DANGEROUS
            || ((pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_PRE23) != 0);

    // Dangerous and normal permissions are always shown to the user
    // this is matches the permission list in AppDetails2
    if (isNormal || isDangerous) {
        return true;
    }

    final boolean isDevelopment = (pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0;
    final boolean wasGranted = (existingReqFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;

    // Development permissions are only shown to the user if they are already
    // granted to the app -- if we are installing an app and they are not
    // already granted, they will not be granted as part of the install.
    return isDevelopment && wasGranted;
}
项目:AppOpsXposed    文件:OpsLabelHelper.java   
private static String getPermissionLabel(Context context, String permission, String defValue)
{
    try
    {
        final PackageManager pm = context.getPackageManager();
        final PermissionInfo pi = pm.getPermissionInfo(permission, 0);

        final CharSequence label = pi.loadLabel(pm);
        if(label != null && !label.toString().equals(permission))
            return label.toString();
    }
    catch(NameNotFoundException e)
    {
        // om nom nom
    }

    return defValue;
}
项目:permission-explorer    文件:PermissionCatalog.java   
public List<PermissionInfo> getAll() {
    if (allPerms == null) {
        allPerms = new ArrayList<PermissionInfo>();

        List<PermissionGroupInfo> permGroups = getAllGroups();
        permGroups.add(null);

        for (PermissionGroupInfo pgi : permGroups) {
            List<PermissionInfo> perms;
            try {
                perms = getByGroup(pgi == null ? null : pgi.name);
            } catch (NameNotFoundException e) {
                throw new AssertionError();
            }
            allPerms.addAll(perms);
        }
        Collections.sort(allPerms, PermissionComparator.getInstance());
    }

    return Collections.unmodifiableList(allPerms);
}
项目:permission-explorer    文件:PermissionCatalog.java   
public List<PermissionInfo> getByLevel(int level) {
    if (permsByLevel == null) {
        permsByLevel = new HashMap<Integer, List<PermissionInfo>>();

        for (PermissionInfo pi : getAll()) {
            if (!permsByLevel.containsKey(pi.protectionLevel))
                permsByLevel.put(pi.protectionLevel,
                        new ArrayList<PermissionInfo>());
            permsByLevel.get(pi.protectionLevel).add(pi);
        }

        for (List<PermissionInfo> perms : permsByLevel.values())
            Collections.sort(perms, PermissionComparator.getInstance());
    }

    return Collections.unmodifiableList(permsByLevel.get(level));
}
项目:permission-explorer    文件:PermissionCatalog.java   
public List<PermissionInfo> filter(List<PermissionInfo> list,
        Set<String> groups, Integer level, Integer relevance) {
    List<PermissionInfo> filteredList = new ArrayList<PermissionInfo>();
    for (PermissionInfo perm : list) {
        if (groups != null && !groups.contains(perm.group) || level != null
                && perm.protectionLevel < level)
            continue;

        if (relevance != null)
            if (relevance == RELEVANCE_COMMON
                    && !getCommonPermissionNames().contains(perm.name)
                    || relevance == RELEVANCE_SYSTEM
                    && !perm.packageName.equals(SYS_PACKAGE))
                continue;

        filteredList.add(perm);
    }
    return filteredList;
}
项目:permission-explorer    文件:PermissionListAdapter.java   
@Override
public boolean isFilterMatch(CharSequence constraint, PermissionInfo perm) {
    String[] prefixes = constraint.toString()
            .toLowerCase(Locale.getDefault()).split(" ");
    String[] words = PermissionUtils.getShortName(perm).split("_");

    for (String prefix : prefixes) {
        boolean hasPrefix = false;
        for (String word : words)
            if (word.toLowerCase(Locale.getDefault()).startsWith(prefix)) {
                hasPrefix = true;
                break;
            }
        if (!hasPrefix)
            return false;
    }
    return true;
}
项目:mobile-store    文件:AppSecurityPermissions.java   
private PermissionItemView getPermissionItemView(MyPermissionGroupInfo grp, MyPermissionInfo perm,
                                                 boolean first, CharSequence newPermPrefix) {
    PermissionItemView permView = (PermissionItemView) inflater.inflate(
            Build.VERSION.SDK_INT >= 17 &&
                    (perm.flags & PermissionInfo.FLAG_COSTS_MONEY) != 0
                    ? R.layout.app_permission_item_money : R.layout.app_permission_item,
            null);
    permView.setPermission(grp, perm, first, newPermPrefix);
    return permView;
}
项目:MiPushFramework    文件:FakeManifestUtils.java   
public static PackageInfo buildFakePackageInfo (PackageInfo info) {
    info.requestedPermissions = new String[]{Manifest.permission.VIBRATE,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.GET_TASKS,
            Manifest.permission.INTERNET,
            Manifest.permission.ACCESS_NETWORK_STATE,
            Manifest.permission.ACCESS_WIFI_STATE,
            info.packageName + ".permission.MIPUSH_RECEIVE"};
    PermissionInfo permissionInfo = new PermissionInfo();
    permissionInfo.protectionLevel = PermissionInfo.PROTECTION_SIGNATURE;
    permissionInfo.name = info.packageName + ".permission.MIPUSH_RECEIVE";
    info.permissions = new PermissionInfo[]{permissionInfo};
    return info;
}
项目:letv    文件:IApkManagerImpl.java   
public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException {
    waitForReadyInner();
    try {
        enforcePluginFileExists();
        List<PermissionInfo> list = new ArrayList();
        if (shouldNotBlockOtherInfo()) {
            for (PluginPackageParser pluginPackageParser : this.mPluginCache.values()) {
                for (PermissionInfo permissionInfo : pluginPackageParser.getPermissions()) {
                    if (TextUtils.equals(permissionInfo.group, group) && !list.contains(permissionInfo)) {
                        list.add(permissionInfo);
                    }
                }
            }
            return list;
        }
        List<String> pkgs = this.mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid());
        for (PluginPackageParser pluginPackageParser2 : this.mPluginCache.values()) {
            for (PermissionInfo permissionInfo2 : pluginPackageParser2.getPermissions()) {
                if (pkgs.contains(permissionInfo2.packageName) && TextUtils.equals(permissionInfo2.group, group) && !list.contains(permissionInfo2)) {
                    list.add(permissionInfo2);
                }
            }
        }
        return list;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
项目:letv    文件:ApkManager.java   
public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException {
    try {
        if (!(this.mApkManager == null || name == null)) {
            return this.mApkManager.getPermissionInfo(name, flags);
        }
    } catch (RemoteException e) {
        JLog.log("wuxinrong", "获取权限信息 失败 e=" + e.getMessage());
        throw e;
    } catch (Exception e2) {
        JLog.log("wuxinrong", "获取权限信息 失败 e=" + e2.getMessage());
    }
    return null;
}