use of android.app.AppOpsManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DevelopmentSettings method writeMockLocation.
private void writeMockLocation() {
AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
// Disable the app op of the previous mock location app if such.
List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
if (packageOps != null) {
// Should be one but in case we are in a bad state due to use of command line tools.
for (PackageOps packageOp : packageOps) {
if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
String oldMockLocationApp = packageOp.getPackageName();
try {
ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, oldMockLocationApp, AppOpsManager.MODE_ERRORED);
} catch (NameNotFoundException e) {
/* ignore */
}
}
}
}
// Enable the app op of the new mock location app if such.
if (!TextUtils.isEmpty(mMockLocationApp)) {
try {
ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, mMockLocationApp, AppOpsManager.MODE_ALLOWED);
} catch (NameNotFoundException e) {
/* ignore */
}
}
}
use of android.app.AppOpsManager in project android_frameworks_base by DirtyUnicorns.
the class NetworkStatsAccess method hasAppOpsPermission.
private static boolean hasAppOpsPermission(Context context, int callingUid, String callingPackage) {
if (callingPackage != null) {
AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
final int mode = appOps.checkOp(AppOpsManager.OP_GET_USAGE_STATS, callingUid, callingPackage);
if (mode == AppOpsManager.MODE_DEFAULT) {
// The default behavior here is to check if PackageManager has given the app
// permission.
final int permissionCheck = context.checkCallingPermission(Manifest.permission.PACKAGE_USAGE_STATS);
return permissionCheck == PackageManager.PERMISSION_GRANTED;
}
return (mode == AppOpsManager.MODE_ALLOWED);
}
return false;
}
use of android.app.AppOpsManager in project android_frameworks_base by DirtyUnicorns.
the class Vpn method setPackageAuthorization.
/**
* Set whether a package has the ability to launch VPNs without user intervention.
*/
public boolean setPackageAuthorization(String packageName, boolean authorized) {
// Check if the caller is authorized.
enforceControlPermissionOrInternalCaller();
int uid = getAppUid(packageName, mUserHandle);
if (uid == -1 || VpnConfig.LEGACY_VPN.equals(packageName)) {
// Authorization for nonexistent packages (or fake ones) can't be updated.
return false;
}
long token = Binder.clearCallingIdentity();
try {
AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
appOps.setMode(AppOpsManager.OP_ACTIVATE_VPN, uid, packageName, authorized ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
return true;
} catch (Exception e) {
Log.wtf(TAG, "Failed to set app ops for package " + packageName + ", uid " + uid, e);
} finally {
Binder.restoreCallingIdentity(token);
}
return false;
}
use of android.app.AppOpsManager in project android_frameworks_base by DirtyUnicorns.
the class MountService method mkdirs.
@Override
public int mkdirs(String callingPkg, String appPath) {
final int userId = UserHandle.getUserId(Binder.getCallingUid());
final UserEnvironment userEnv = new UserEnvironment(userId);
// Validate that reported package name belongs to caller
final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
appOps.checkPackage(Binder.getCallingUid(), callingPkg);
File appFile = null;
try {
appFile = new File(appPath).getCanonicalFile();
} catch (IOException e) {
Slog.e(TAG, "Failed to resolve " + appPath + ": " + e);
return -1;
}
// belong to the calling package.
if (FileUtils.contains(userEnv.buildExternalStorageAppDataDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppObbDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppMediaDirs(callingPkg), appFile)) {
appPath = appFile.getAbsolutePath();
if (!appPath.endsWith("/")) {
appPath = appPath + "/";
}
try {
mConnector.execute("volume", "mkdirs", appPath);
return 0;
} catch (NativeDaemonConnectorException e) {
return e.getCode();
}
}
throw new SecurityException("Invalid mkdirs path: " + appFile);
}
use of android.app.AppOpsManager in project android_frameworks_base by AOSPA.
the class MountService method mkdirs.
@Override
public int mkdirs(String callingPkg, String appPath) {
final int userId = UserHandle.getUserId(Binder.getCallingUid());
final UserEnvironment userEnv = new UserEnvironment(userId);
// Validate that reported package name belongs to caller
final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
appOps.checkPackage(Binder.getCallingUid(), callingPkg);
File appFile = null;
try {
appFile = new File(appPath).getCanonicalFile();
} catch (IOException e) {
Slog.e(TAG, "Failed to resolve " + appPath + ": " + e);
return -1;
}
// belong to the calling package.
if (FileUtils.contains(userEnv.buildExternalStorageAppDataDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppObbDirs(callingPkg), appFile) || FileUtils.contains(userEnv.buildExternalStorageAppMediaDirs(callingPkg), appFile)) {
appPath = appFile.getAbsolutePath();
if (!appPath.endsWith("/")) {
appPath = appPath + "/";
}
try {
mConnector.execute("volume", "mkdirs", appPath);
return 0;
} catch (NativeDaemonConnectorException e) {
return e.getCode();
}
}
throw new SecurityException("Invalid mkdirs path: " + appFile);
}
Aggregations