use of android.app.AppOpsManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppOpsSummary method resetCounters.
private void resetCounters() {
final AppOpsManager appOps = (AppOpsManager) mActivity.getSystemService(Context.APP_OPS_SERVICE);
if (appOps == null) {
return;
}
appOps.resetCounters();
// reload content
resetAdapter();
}
use of android.app.AppOpsManager in project android_frameworks_base by ResurrectionRemix.
the class Settings method isCallingPackageAllowedToPerformAppOpsProtectedOperation.
/**
* Helper method to perform a general and comprehensive check of whether an operation that is
* protected by appops can be performed by a caller or not. e.g. OP_SYSTEM_ALERT_WINDOW and
* OP_WRITE_SETTINGS
* @hide
*/
public static boolean isCallingPackageAllowedToPerformAppOpsProtectedOperation(Context context, int uid, String callingPackage, boolean throwException, int appOpsOpCode, String[] permissions, boolean makeNote) {
if (callingPackage == null) {
return false;
}
AppOpsManager appOpsMgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
int mode = AppOpsManager.MODE_DEFAULT;
if (makeNote) {
mode = appOpsMgr.noteOpNoThrow(appOpsOpCode, uid, callingPackage);
} else {
mode = appOpsMgr.checkOpNoThrow(appOpsOpCode, uid, callingPackage);
}
switch(mode) {
case AppOpsManager.MODE_ALLOWED:
return true;
case AppOpsManager.MODE_DEFAULT:
// if it is granted during install time.
for (String permission : permissions) {
if (context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
// if either of the permissions are granted, we will allow it
return true;
}
}
default:
// this is for all other cases trickled down here...
if (!throwException) {
return false;
}
}
// prepare string to throw SecurityException
StringBuilder exceptionMessage = new StringBuilder();
exceptionMessage.append(callingPackage);
exceptionMessage.append(" was not granted ");
if (permissions.length > 1) {
exceptionMessage.append(" either of these permissions: ");
} else {
exceptionMessage.append(" this permission: ");
}
for (int i = 0; i < permissions.length; i++) {
exceptionMessage.append(permissions[i]);
exceptionMessage.append((i == permissions.length - 1) ? "." : ", ");
}
throw new SecurityException(exceptionMessage.toString());
}
use of android.app.AppOpsManager in project android_frameworks_base by DirtyUnicorns.
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 DrawOverlayDetails method getSummary.
public static CharSequence getSummary(Context context, String pkg) {
// first check if pkg is a system pkg
PackageManager packageManager = context.getPackageManager();
int uid = -1;
try {
ApplicationInfo appInfo = packageManager.getApplicationInfo(pkg, 0);
uid = appInfo.uid;
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
return context.getString(R.string.system_alert_window_on);
}
} catch (PackageManager.NameNotFoundException e) {
// pkg doesn't even exist?
Log.w(LOG_TAG, "Package " + pkg + " not found", e);
return context.getString(R.string.system_alert_window_off);
}
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
if (uid == -1) {
return context.getString(R.string.system_alert_window_off);
}
int mode = appOpsManager.noteOpNoThrow(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, uid, pkg);
return context.getString((mode == AppOpsManager.MODE_ALLOWED) ? R.string.system_alert_window_on : R.string.system_alert_window_off);
}
use of android.app.AppOpsManager in project android_frameworks_base by crdroidandroid.
the class BluetoothManagerService method enable.
public boolean enable(String packageName) throws RemoteException {
final int callingUid = Binder.getCallingUid();
final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
if (!callerSystem) {
if (!checkIfCallerIsForegroundUser()) {
Slog.w(TAG, "enable(): not allowed for non-active and non system user");
return false;
}
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
if (!isEnabled() && mPermissionReviewRequired && startConsentUiIfNeeded(packageName, callingUid, BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
return false;
}
}
if (DBG) {
Slog.d(TAG, "enable(" + packageName + "): mBluetooth =" + mBluetooth + " mBinding = " + mBinding + " mState = " + BluetoothAdapter.nameForState(mState));
}
AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
if (appOps.noteOp(AppOpsManager.OP_BLUETOOTH_CHANGE, callingUid, packageName) != AppOpsManager.MODE_ALLOWED)
return false;
synchronized (mReceiver) {
mQuietEnableExternal = false;
mEnableExternal = true;
// waive WRITE_SECURE_SETTINGS permission check
sendEnableMsg(false, packageName);
}
if (DBG)
Slog.d(TAG, "enable returning");
return true;
}
Aggregations