Java Code Examples for android.os.UserManager#hasUserRestriction()
The following examples show how to use
android.os.UserManager#hasUserRestriction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Decide if volume is mountable per device policies. */ private boolean isMountDisallowed(VolumeInfo vol) { UserManager userManager = mContext.getSystemService(UserManager.class); boolean isUsbRestricted = false; if (vol.disk != null && vol.disk.isUsb()) { isUsbRestricted = userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER, Binder.getCallingUserHandle()); } boolean isTypeRestricted = false; if (vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_PRIVATE) { isTypeRestricted = userManager .hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, Binder.getCallingUserHandle()); } return isUsbRestricted || isTypeRestricted; }
Example 2
Source File: WallpaperManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public boolean isSetWallpaperAllowed(String callingPackage) { final PackageManager pm = mContext.getPackageManager(); String[] uidPackages = pm.getPackagesForUid(Binder.getCallingUid()); boolean uidMatchPackage = Arrays.asList(uidPackages).contains(callingPackage); if (!uidMatchPackage) { return false; // callingPackage was faked. } final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) { return true; } final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); return !um.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER); }
Example 3
Source File: ShutdownThread.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Request a reboot into safe mode. Must be called from a Looper thread in which its UI * is shown. * * @param context Context used to display the shutdown progress dialog. This must be a context * suitable for displaying UI (aka Themable). * @param confirm true if user confirmation is needed before shutting down. */ public static void rebootSafeMode(final Context context, boolean confirm) { UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); if (um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { return; } mReboot = true; mRebootSafeMode = true; mRebootHasProgressBar = false; mReason = null; shutdownInner(context, confirm); }
Example 4
Source File: PowerAction.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean onLongPress() { UserManager um = mContext.getSystemService(UserManager.class); if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { mWindowManagerFuncs.rebootSafeMode(true); return true; } return false; }
Example 5
Source File: RestartAction.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean onLongPress() { UserManager um = mContext.getSystemService(UserManager.class); if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { mWindowManagerFuncs.rebootSafeMode(true); return true; } return false; }
Example 6
Source File: CallLog.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public static boolean shouldHaveSharedCallLogEntries(Context context, UserManager userManager, int userId) { if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, UserHandle.of(userId))) { return false; } final UserInfo userInfo = userManager.getUserInfo(userId); return userInfo != null && !userInfo.isManagedProfile(); }
Example 7
Source File: AccountManagementFragment.java From delion with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private boolean canAddAccounts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return true; UserManager userManager = (UserManager) getActivity() .getSystemService(Context.USER_SERVICE); return !userManager.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS); }
Example 8
Source File: AccountManagementFragment.java From AndroidChromium with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private boolean canAddAccounts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return true; UserManager userManager = (UserManager) getActivity() .getSystemService(Context.USER_SERVICE); return !userManager.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS); }
Example 9
Source File: SettingsHelper.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
private void setGpsLocation(String value) { UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) { return; } final String GPS = LocationManager.GPS_PROVIDER; boolean enabled = GPS.equals(value) || value.startsWith(GPS + ",") || value.endsWith("," + GPS) || value.contains("," + GPS + ","); Settings.Secure.setLocationProviderEnabled( mContext.getContentResolver(), GPS, enabled); }
Example 10
Source File: SettingsHelper.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
private void setGpsLocation(String value) { UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) { return; } final String GPS = LocationManager.GPS_PROVIDER; boolean enabled = GPS.equals(value) || value.startsWith(GPS + ",") || value.endsWith("," + GPS) || value.contains("," + GPS + ","); Settings.Secure.setLocationProviderEnabled( mContext.getContentResolver(), GPS, enabled); }
Example 11
Source File: InstallNonMarketAppsDeprecationTest.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
@Before public void setUp() { mUm = (UserManager) getContext().getSystemService(Context.USER_SERVICE); mHasUserRestriction = mUm.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES); mSystemSetUserRestriction = mUm.getUserRestrictionSource( UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, Process.myUserHandle()) == UserManager.RESTRICTION_SOURCE_SYSTEM; mUsersAddedByTest = new ArrayList<>(); }
Example 12
Source File: DevicePolicies.java From island with Apache License 2.0 | 5 votes |
public void addUserRestrictionIfNeeded(final Context context, final String key) { if (Users.isProfile() && UserManager.DISALLOW_SET_WALLPAPER.equals(key)) return; // Immutable if (SDK_INT >= N) { if (! mDevicePolicyManager.getUserRestrictions(sCachedComponent).containsKey(key)) mDevicePolicyManager.addUserRestriction(sCachedComponent, key); } else { final UserManager um = (UserManager) context.getSystemService(USER_SERVICE); if (um == null || ! um.hasUserRestriction(key)) mDevicePolicyManager.addUserRestriction(sCachedComponent, key); } }
Example 13
Source File: DevicePolicies.java From island with Apache License 2.0 | 5 votes |
public void clearUserRestrictionsIfNeeded(final Context context, final String... keys) { Bundle restrictions = null; for (final String key : keys) { if (Users.isProfile() && UserManager.DISALLOW_SET_WALLPAPER.equals(key)) return; // Immutable if (SDK_INT >= N) { if (restrictions == null) restrictions = mDevicePolicyManager.getUserRestrictions(sCachedComponent); if (restrictions.containsKey(key)) mDevicePolicyManager.clearUserRestriction(sCachedComponent, key); } else { final UserManager um = (UserManager) context.getSystemService(USER_SERVICE); if (um == null || um.hasUserRestriction(key)) mDevicePolicyManager.clearUserRestriction(sCachedComponent, key); } } }
Example 14
Source File: AccountManagementFragment.java From 365browser with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private boolean canAddAccounts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return true; UserManager userManager = (UserManager) getActivity() .getSystemService(Context.USER_SERVICE); return !userManager.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS); }
Example 15
Source File: DeviceAdminReceiver.java From android-testdpc with Apache License 2.0 | 4 votes |
private static void updatePasswordConstraintNotification(Context context) { final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService( Context.DEVICE_POLICY_SERVICE); final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); if (!dpm.isProfileOwnerApp(context.getPackageName()) && !dpm.isDeviceOwnerApp(context.getPackageName())) { // Only try to update the notification if we are a profile or device owner. return; } final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final ArrayList<CharSequence> problems = new ArrayList<>(); if (!dpm.isActivePasswordSufficient()) { problems.add(context.getText(R.string.password_not_compliant_title)); } if (um.hasUserRestriction(UserManager.DISALLOW_UNIFIED_PASSWORD) && Util.isManagedProfileOwner(context) && isUsingUnifiedPassword(context)) { problems.add(context.getText(R.string.separate_challenge_required_title)); } if (!problems.isEmpty()) { final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); style.setBigContentTitle( context.getText(R.string.set_new_password_notification_content)); for (final CharSequence problem : problems) { style.addLine(problem); } final NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context); warn.setOngoing(true) .setSmallIcon(R.drawable.ic_launcher) .setStyle(style) .setContentIntent(PendingIntent.getActivity(context, /*requestCode*/ -1, new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD), /*flags*/ 0)); nm.notify(CHANGE_PASSWORD_NOTIFICATION_ID, warn.getNotification()); } else { nm.cancel(CHANGE_PASSWORD_NOTIFICATION_ID); } }