use of android.app.AppOpsManager.PackageOps in project android_packages_apps_Settings by DirtyUnicorns.
the class AppStateAppOpsBridge method getPermissionInfo.
public PermissionState getPermissionInfo(String pkg, int uid) {
PermissionState permissionState = new PermissionState(pkg, new UserHandle(UserHandle.getUserId(uid)));
try {
permissionState.packageInfo = mIPackageManager.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS | PackageManager.MATCH_ANY_USER, permissionState.userHandle.getIdentifier());
if (permissionState.packageInfo != null) {
// Check static permission state (whatever that is declared in package manifest)
String[] requestedPermissions = permissionState.packageInfo.requestedPermissions;
int[] permissionFlags = permissionState.packageInfo.requestedPermissionsFlags;
if (requestedPermissions != null) {
for (int i = 0; i < requestedPermissions.length; i++) {
if (doesAnyPermissionMatch(requestedPermissions[i], mPermissions)) {
permissionState.permissionDeclared = true;
if ((permissionFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
permissionState.staticPermissionGranted = true;
break;
}
}
}
}
}
// Check app op state.
List<PackageOps> ops = mAppOpsManager.getOpsForPackage(uid, pkg, mAppOpsOpCodes);
if (ops != null && ops.size() > 0 && ops.get(0).getOps().size() > 0) {
permissionState.appOpMode = ops.get(0).getOps().get(0).getMode();
}
} catch (RemoteException e) {
Log.w(TAG, "PackageManager is dead. Can't get package info " + pkg, e);
}
return permissionState;
}
use of android.app.AppOpsManager.PackageOps in project android_packages_apps_Settings by DirtyUnicorns.
the class AppStateAppOpsBridge method loadAppOpsStates.
/*
* This method will set the appOpMode field of the associated PermissionState, which describes
* a particular package.
*/
private void loadAppOpsStates(SparseArray<ArrayMap<String, PermissionState>> entries) {
// Find out which packages have been granted permission from AppOps.
final List<AppOpsManager.PackageOps> packageOps = mAppOpsManager.getPackagesForOps(mAppOpsOpCodes);
final int packageOpsCount = packageOps != null ? packageOps.size() : 0;
for (int i = 0; i < packageOpsCount; i++) {
final AppOpsManager.PackageOps packageOp = packageOps.get(i);
final int userId = UserHandle.getUserId(packageOp.getUid());
if (!isThisUserAProfileOfCurrentUser(userId)) {
// This AppOp does not belong to any of this user's profiles.
continue;
}
final ArrayMap<String, PermissionState> entriesForProfile = entries.get(userId);
if (entriesForProfile == null) {
continue;
}
final PermissionState pe = entriesForProfile.get(packageOp.getPackageName());
if (pe == null) {
Log.w(TAG, "AppOp permission exists for package " + packageOp.getPackageName() + " of user " + userId + " but package doesn't exist or did not request " + mPermissions + " access");
continue;
}
if (packageOp.getOps().size() < 1) {
Log.w(TAG, "No AppOps permission exists for package " + packageOp.getPackageName());
continue;
}
pe.appOpMode = packageOp.getOps().get(0).getMode();
}
}
use of android.app.AppOpsManager.PackageOps in project platform_packages_apps_Settings by BlissRoms.
the class AppStateAppOpsBridge method getPermissionInfo.
public PermissionState getPermissionInfo(String pkg, int uid) {
PermissionState permissionState = new PermissionState(pkg, new UserHandle(UserHandle.getUserId(uid)));
try {
permissionState.packageInfo = mIPackageManager.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS | PackageManager.MATCH_ANY_USER, permissionState.userHandle.getIdentifier());
if (permissionState.packageInfo != null) {
// Check static permission state (whatever that is declared in package manifest)
String[] requestedPermissions = permissionState.packageInfo.requestedPermissions;
int[] permissionFlags = permissionState.packageInfo.requestedPermissionsFlags;
if (requestedPermissions != null) {
for (int i = 0; i < requestedPermissions.length; i++) {
if (doesAnyPermissionMatch(requestedPermissions[i], mPermissions)) {
permissionState.permissionDeclared = true;
if ((permissionFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
permissionState.staticPermissionGranted = true;
break;
}
}
}
}
}
// Check app op state.
List<PackageOps> ops = mAppOpsManager.getOpsForPackage(uid, pkg, mAppOpsOpCodes);
if (ops != null && ops.size() > 0 && ops.get(0).getOps().size() > 0) {
permissionState.appOpMode = ops.get(0).getOps().get(0).getMode();
}
} catch (RemoteException e) {
Log.w(TAG, "PackageManager is dead. Can't get package info " + pkg, e);
}
return permissionState;
}
use of android.app.AppOpsManager.PackageOps in project platform_packages_apps_Settings by BlissRoms.
the class DevelopmentSettings method updateMockLocation.
private void updateMockLocation() {
AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
if (packageOps != null) {
for (PackageOps packageOp : packageOps) {
if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
mMockLocationApp = packageOps.get(0).getPackageName();
break;
}
}
}
if (!TextUtils.isEmpty(mMockLocationApp)) {
String label = mMockLocationApp;
try {
ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
if (appLabel != null) {
label = appLabel.toString();
}
} catch (PackageManager.NameNotFoundException e) {
/* ignore */
}
mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
mHaveDebugSettings = true;
} else {
mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
}
}
use of android.app.AppOpsManager.PackageOps in project robolectric by robolectric.
the class ShadowAppOpsManagerTest method assertOps.
/**
* Assert that the results contain the expected op codes.
*/
private void assertOps(List<PackageOps> pkgOps, Integer... expectedOps) {
Set<Integer> actualOps = new HashSet<>();
for (PackageOps pkgOp : pkgOps) {
for (OpEntry entry : pkgOp.getOps()) {
actualOps.add(entry.getOp());
}
}
assertThat(actualOps).containsAtLeastElementsIn(expectedOps);
}
Aggregations