Search in sources :

Example 1 with AppOpsManager

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);
    }
}
Also used : AppOpsManager(android.app.AppOpsManager) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony) SystemApi(android.annotation.SystemApi)

Example 2 with AppOpsManager

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;
}
Also used : AppOpsManager(android.app.AppOpsManager)

Example 3 with AppOpsManager

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);
}
Also used : AppOpsManager(android.app.AppOpsManager)

Example 4 with AppOpsManager

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;
}
Also used : ArrayList(java.util.ArrayList) AppOpsManager(android.app.AppOpsManager) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle)

Example 5 with AppOpsManager

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);
}
Also used : AppOpsManager(android.app.AppOpsManager) PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

AppOpsManager (android.app.AppOpsManager)101 ApplicationInfo (android.content.pm.ApplicationInfo)28 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)27 PackageManager (android.content.pm.PackageManager)18 PackageOps (android.app.AppOpsManager.PackageOps)14 ArrayList (java.util.ArrayList)14 UserHandle (android.os.UserHandle)13 IOException (java.io.IOException)10 Context (android.content.Context)9 PackageInfo (android.content.pm.PackageInfo)9 Method (java.lang.reflect.Method)9 TargetApi (android.annotation.TargetApi)8 HashMap (java.util.HashMap)8 RemoteException (android.os.RemoteException)7 ActivityManager (android.app.ActivityManager)6 Intent (android.content.Intent)6 ResolveInfo (android.content.pm.ResolveInfo)6 UserManager (android.os.UserManager)6 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)6 Field (java.lang.reflect.Field)6