Search in sources :

Example 1 with DevicePolicyManagerInternal

use of android.app.admin.DevicePolicyManagerInternal in project android_frameworks_base by ResurrectionRemix.

the class NetworkStatsAccess method checkAccessLevel.

/** Returns the {@link NetworkStatsAccess.Level} for the given caller. */
@NetworkStatsAccess.Level
public static int checkAccessLevel(Context context, int callingUid, String callingPackage) {
    final DevicePolicyManagerInternal dpmi = LocalServices.getService(DevicePolicyManagerInternal.class);
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    boolean hasCarrierPrivileges = tm != null && tm.checkCarrierPrivilegesForPackage(callingPackage) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
    boolean isDeviceOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
    if (hasCarrierPrivileges || isDeviceOwner || UserHandle.getAppId(callingUid) == android.os.Process.SYSTEM_UID) {
        // all apps on the device.
        return NetworkStatsAccess.Level.DEVICE;
    }
    boolean hasAppOpsPermission = hasAppOpsPermission(context, callingUid, callingPackage);
    if (hasAppOpsPermission || context.checkCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY) == PackageManager.PERMISSION_GRANTED) {
        return NetworkStatsAccess.Level.DEVICESUMMARY;
    }
    boolean isProfileOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
    if (isProfileOwner) {
        // permission can access data usage for all apps in this user/profile.
        return NetworkStatsAccess.Level.USER;
    }
    // Everyone else gets default access (only to their own UID).
    return NetworkStatsAccess.Level.DEFAULT;
}
Also used : DevicePolicyManagerInternal(android.app.admin.DevicePolicyManagerInternal) TelephonyManager(android.telephony.TelephonyManager)

Example 2 with DevicePolicyManagerInternal

use of android.app.admin.DevicePolicyManagerInternal in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsAccess method checkAccessLevel.

/** Returns the {@link NetworkStatsAccess.Level} for the given caller. */
@NetworkStatsAccess.Level
public static int checkAccessLevel(Context context, int callingUid, String callingPackage) {
    final DevicePolicyManagerInternal dpmi = LocalServices.getService(DevicePolicyManagerInternal.class);
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    boolean hasCarrierPrivileges = tm != null && tm.checkCarrierPrivilegesForPackage(callingPackage) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
    boolean isDeviceOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
    if (hasCarrierPrivileges || isDeviceOwner || UserHandle.getAppId(callingUid) == android.os.Process.SYSTEM_UID) {
        // all apps on the device.
        return NetworkStatsAccess.Level.DEVICE;
    }
    boolean hasAppOpsPermission = hasAppOpsPermission(context, callingUid, callingPackage);
    if (hasAppOpsPermission || context.checkCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY) == PackageManager.PERMISSION_GRANTED) {
        return NetworkStatsAccess.Level.DEVICESUMMARY;
    }
    boolean isProfileOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
    if (isProfileOwner) {
        // permission can access data usage for all apps in this user/profile.
        return NetworkStatsAccess.Level.USER;
    }
    // Everyone else gets default access (only to their own UID).
    return NetworkStatsAccess.Level.DEFAULT;
}
Also used : DevicePolicyManagerInternal(android.app.admin.DevicePolicyManagerInternal) TelephonyManager(android.telephony.TelephonyManager)

Example 3 with DevicePolicyManagerInternal

use of android.app.admin.DevicePolicyManagerInternal in project android_frameworks_base by DirtyUnicorns.

the class ActivityStartInterceptor method interceptSuspendPackageIfNeed.

private boolean interceptSuspendPackageIfNeed() {
    // Do not intercept if the admin did not suspend the package
    if (mAInfo == null || mAInfo.applicationInfo == null || (mAInfo.applicationInfo.flags & FLAG_SUSPENDED) == 0) {
        return false;
    }
    DevicePolicyManagerInternal devicePolicyManager = LocalServices.getService(DevicePolicyManagerInternal.class);
    if (devicePolicyManager == null) {
        return false;
    }
    mIntent = devicePolicyManager.createPackageSuspendedDialogIntent(mAInfo.packageName, mUserId);
    mCallingPid = mRealCallingPid;
    mCallingUid = mRealCallingUid;
    mResolvedType = null;
    final UserInfo parent = mUserManager.getProfileParent(mUserId);
    if (parent != null) {
        mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id);
    } else {
        mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId);
    }
    mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null);
    return true;
}
Also used : DevicePolicyManagerInternal(android.app.admin.DevicePolicyManagerInternal) UserInfo(android.content.pm.UserInfo)

Example 4 with DevicePolicyManagerInternal

use of android.app.admin.DevicePolicyManagerInternal in project android_frameworks_base by AOSPA.

the class NetworkStatsAccess method checkAccessLevel.

/** Returns the {@link NetworkStatsAccess.Level} for the given caller. */
@NetworkStatsAccess.Level
public static int checkAccessLevel(Context context, int callingUid, String callingPackage) {
    final DevicePolicyManagerInternal dpmi = LocalServices.getService(DevicePolicyManagerInternal.class);
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    boolean hasCarrierPrivileges = tm != null && tm.checkCarrierPrivilegesForPackage(callingPackage) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
    boolean isDeviceOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
    if (hasCarrierPrivileges || isDeviceOwner || UserHandle.getAppId(callingUid) == android.os.Process.SYSTEM_UID) {
        // all apps on the device.
        return NetworkStatsAccess.Level.DEVICE;
    }
    boolean hasAppOpsPermission = hasAppOpsPermission(context, callingUid, callingPackage);
    if (hasAppOpsPermission || context.checkCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY) == PackageManager.PERMISSION_GRANTED) {
        return NetworkStatsAccess.Level.DEVICESUMMARY;
    }
    boolean isProfileOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
    if (isProfileOwner) {
        // permission can access data usage for all apps in this user/profile.
        return NetworkStatsAccess.Level.USER;
    }
    // Everyone else gets default access (only to their own UID).
    return NetworkStatsAccess.Level.DEFAULT;
}
Also used : DevicePolicyManagerInternal(android.app.admin.DevicePolicyManagerInternal) TelephonyManager(android.telephony.TelephonyManager)

Example 5 with DevicePolicyManagerInternal

use of android.app.admin.DevicePolicyManagerInternal in project platform_frameworks_base by android.

the class NetworkStatsAccess method checkAccessLevel.

/** Returns the {@link NetworkStatsAccess.Level} for the given caller. */
@NetworkStatsAccess.Level
public static int checkAccessLevel(Context context, int callingUid, String callingPackage) {
    final DevicePolicyManagerInternal dpmi = LocalServices.getService(DevicePolicyManagerInternal.class);
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    boolean hasCarrierPrivileges = tm != null && tm.checkCarrierPrivilegesForPackage(callingPackage) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
    boolean isDeviceOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
    if (hasCarrierPrivileges || isDeviceOwner || UserHandle.getAppId(callingUid) == android.os.Process.SYSTEM_UID) {
        // all apps on the device.
        return NetworkStatsAccess.Level.DEVICE;
    }
    boolean hasAppOpsPermission = hasAppOpsPermission(context, callingUid, callingPackage);
    if (hasAppOpsPermission || context.checkCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY) == PackageManager.PERMISSION_GRANTED) {
        return NetworkStatsAccess.Level.DEVICESUMMARY;
    }
    boolean isProfileOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
    if (isProfileOwner) {
        // permission can access data usage for all apps in this user/profile.
        return NetworkStatsAccess.Level.USER;
    }
    // Everyone else gets default access (only to their own UID).
    return NetworkStatsAccess.Level.DEFAULT;
}
Also used : DevicePolicyManagerInternal(android.app.admin.DevicePolicyManagerInternal) TelephonyManager(android.telephony.TelephonyManager)

Aggregations

DevicePolicyManagerInternal (android.app.admin.DevicePolicyManagerInternal)10 UserInfo (android.content.pm.UserInfo)5 TelephonyManager (android.telephony.TelephonyManager)5