get Permissions For Package
/*
* Copyright 2010, Mojodroid
*
* 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 com.mojodroid.permissionwatchdog;
import java.util.ArrayList;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
class Utils
{
private final static String TAG = "WatchdogUtils";
public static final Iterable<PermissionInfo> getPermissionsForPackage(PackageManager pm, String packageName)
{
ArrayList<PermissionInfo> retval = new ArrayList<PermissionInfo>();
try
{
PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
if (packageInfo.requestedPermissions != null)
{
for (String permName : packageInfo.requestedPermissions)
{
try
{
retval.add(pm.getPermissionInfo(permName, PackageManager.GET_META_DATA));
}
catch (NameNotFoundException e)
{
// Not an official android permission... no big deal
}
}
}
}
catch (NameNotFoundException e)
{
Log.e(TAG, "That's odd package: " + packageName + " should be here but isn't");
}
return retval;
}
public static final boolean getFlaggedDangerous(SharedPreferences prefs, PermissionInfo permInfo)
{
// User wants to override defaults
if (prefs.getBoolean("Prefs.PREFS_MANUAL_DANGER", false))
return prefs.getBoolean(permInfo.name, (permInfo.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS));
else
return (permInfo.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS);
}
}
Related examples in the same category