use of android.app.AppOpsManager in project android_frameworks_base by ResurrectionRemix.
the class TelephonyManager method setDataEnabled.
/** @hide */
@SystemApi
public void setDataEnabled(int subId, boolean enable) {
try {
Log.d(TAG, "setDataEnabled: enabled=" + enable);
AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
if (enable) {
if (appOps.noteOp(AppOpsManager.OP_DATA_CONNECT_CHANGE) != AppOpsManager.MODE_ALLOWED) {
Log.w(TAG, "Permission denied by user.");
return;
}
}
ITelephony telephony = getITelephony();
if (telephony != null)
telephony.setDataEnabled(subId, enable);
} catch (RemoteException e) {
Log.e(TAG, "Error calling setDataEnabled", e);
}
}
use of android.app.AppOpsManager in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class VrManagerService method updateOverlayStateLocked.
private void updateOverlayStateLocked(String exemptedPackage, int newUserId, int oldUserId) {
AppOpsManager appOpsManager = getContext().getSystemService(AppOpsManager.class);
// If user changed drop restrictions for the old user.
if (oldUserId != newUserId) {
appOpsManager.setUserRestrictionForUser(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, false, mOverlayToken, null, oldUserId);
}
if (!mVrModeEnabled) {
return;
}
// Apply the restrictions for the current user based on vr state
String[] exemptions = (exemptedPackage == null) ? new String[0] : new String[] { exemptedPackage };
appOpsManager.setUserRestrictionForUser(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, true, mOverlayToken, exemptions, newUserId);
}
use of android.app.AppOpsManager in project android_frameworks_base by ResurrectionRemix.
the class RecentLocationApps method getAppList.
/**
* Fills a list of applications which queried location recently within specified time.
*/
public List<Request> getAppList() {
// Retrieve a location usage list from AppOps
AppOpsManager aoManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(LOCATION_OPS);
final int appOpsCount = appOps != null ? appOps.size() : 0;
// Process the AppOps list and generate a preference list.
ArrayList<Request> requests = new ArrayList<>(appOpsCount);
final long now = System.currentTimeMillis();
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final List<UserHandle> profiles = um.getUserProfiles();
for (int i = 0; i < appOpsCount; ++i) {
AppOpsManager.PackageOps ops = appOps.get(i);
// Don't show the Android System in the list - it's not actionable for the user.
// Also don't show apps belonging to background users except managed users.
String packageName = ops.getPackageName();
int uid = ops.getUid();
int userId = UserHandle.getUserId(uid);
boolean isAndroidOs = (uid == Process.SYSTEM_UID) && ANDROID_SYSTEM_PACKAGE_NAME.equals(packageName);
if (isAndroidOs || !profiles.contains(new UserHandle(userId))) {
continue;
}
Request request = getRequestFromOps(now, ops);
if (request != null) {
requests.add(request);
}
}
return requests;
}
use of android.app.AppOpsManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WriteSettingsDetails method getSummary.
public static CharSequence getSummary(Context context, String pkg) {
// first check if pkg is a system pkg
boolean isSystem = false;
PackageManager packageManager = context.getPackageManager();
try {
ApplicationInfo appInfo = packageManager.getApplicationInfo(pkg, 0);
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
isSystem = true;
}
} catch (PackageManager.NameNotFoundException e) {
// pkg doesn't even exist?
Log.w(LOG_TAG, "Package " + pkg + " not found", e);
return context.getString(R.string.write_settings_off);
}
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
List<AppOpsManager.PackageOps> packageOps = appOpsManager.getPackagesForOps(APP_OPS_OP_CODE);
if (packageOps == null) {
return context.getString(R.string.write_settings_off);
}
int uid = isSystem ? 0 : -1;
for (AppOpsManager.PackageOps packageOp : packageOps) {
if (pkg.equals(packageOp.getPackageName())) {
uid = packageOp.getUid();
break;
}
}
if (uid == -1) {
return context.getString(R.string.write_settings_off);
}
int mode = appOpsManager.noteOpNoThrow(AppOpsManager.OP_WRITE_SETTINGS, uid, pkg);
return context.getString((mode == AppOpsManager.MODE_ALLOWED) ? R.string.write_settings_on : R.string.write_settings_off);
}
Aggregations