Java Code Examples for android.os.UserManager#getUserRestrictions()

The following examples show how to use android.os.UserManager#getUserRestrictions() . 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: TextClassifierImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@NonNull
private static List<LabeledIntent> createForPhone(Context context, String text) {
    final List<LabeledIntent> actions = new ArrayList<>();
    final UserManager userManager = context.getSystemService(UserManager.class);
    final Bundle userRestrictions = userManager != null
            ? userManager.getUserRestrictions() : new Bundle();
    if (!userRestrictions.getBoolean(UserManager.DISALLOW_OUTGOING_CALLS, false)) {
        actions.add(new LabeledIntent(
                context.getString(com.android.internal.R.string.dial),
                context.getString(com.android.internal.R.string.dial_desc),
                new Intent(Intent.ACTION_DIAL).setData(
                        Uri.parse(String.format("tel:%s", text))),
                LabeledIntent.DEFAULT_REQUEST_CODE));
    }
    actions.add(new LabeledIntent(
            context.getString(com.android.internal.R.string.add_contact),
            context.getString(com.android.internal.R.string.add_contact_desc),
            new Intent(Intent.ACTION_INSERT_OR_EDIT)
                    .setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE)
                    .putExtra(ContactsContract.Intents.Insert.PHONE, text),
            text.hashCode()));
    if (!userRestrictions.getBoolean(UserManager.DISALLOW_SMS, false)) {
        actions.add(new LabeledIntent(
                context.getString(com.android.internal.R.string.sms),
                context.getString(com.android.internal.R.string.sms_desc),
                new Intent(Intent.ACTION_SENDTO)
                        .setData(Uri.parse(String.format("smsto:%s", text))),
                LabeledIntent.DEFAULT_REQUEST_CODE));
    }
    return actions;
}
 
Example 2
Source File: UninstallDropTarget.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public static boolean supportsDrop(Context context, Object info) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    Bundle restrictions = userManager.getUserRestrictions();
    if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
            || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
        return false;
    }

    return getUninstallTarget(context, info) != null;
}
 
Example 3
Source File: FeatureUtilities.java    From delion with Apache License 2.0 5 votes vote down vote up
@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static boolean hasSyncPermissions(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return true;

    UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    Bundle userRestrictions = manager.getUserRestrictions();
    return !userRestrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false);
}
 
Example 4
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static boolean hasSyncPermissions(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return true;

    UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    Bundle userRestrictions = manager.getUserRestrictions();
    return !userRestrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false);
}
 
Example 5
Source File: UninstallDropTarget.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static boolean supportsDrop(Context context, Object info) {
    if (Utilities.ATLEAST_JB_MR2) {
        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        Bundle restrictions = userManager.getUserRestrictions();
        if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
                || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
            return false;
        }
    }

    Pair<ComponentName, Integer> componentInfo = getAppInfoFlags(info);
    return componentInfo != null && (componentInfo.second & AppInfo.DOWNLOADED_FLAG) != 0;
}
 
Example 6
Source File: LauncherClings.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/** Returns whether the clings are enabled or should be shown */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private boolean areClingsEnabled() {
    // disable clings when running in a test harness
    if(ActivityManager.isRunningInTestHarness()) return false;

    // Disable clings for accessibility when explore by touch is enabled
    final AccessibilityManager a11yManager = (AccessibilityManager) mLauncher.getSystemService(
            Launcher.ACCESSIBILITY_SERVICE);
    if (a11yManager.isTouchExplorationEnabled()) {
        return false;
    }

    // Restricted secondary users (child mode) will potentially have very few apps
    // seeded when they start up for the first time. Clings won't work well with that
    if (Utilities.ATLEAST_JB_MR2) {
        UserManager um = (UserManager) mLauncher.getSystemService(Context.USER_SERVICE);
        Bundle restrictions = um.getUserRestrictions();
        if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
            return false;
        }
    }
    if (Settings.Secure.getInt(mLauncher.getContentResolver(), SKIP_FIRST_USE_HINTS, 0)
            == 1) {
        return false;
    }
    return true;
}
 
Example 7
Source File: FeatureUtilities.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static boolean hasSyncPermissions(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return true;

    UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    Bundle userRestrictions = manager.getUserRestrictions();
    return !userRestrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false);
}
 
Example 8
Source File: LauncherClings.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/** Returns whether the clings are enabled or should be shown */
private boolean areClingsEnabled() {
    if (DISABLE_CLINGS) {
        return false;
    }

    // disable clings when running in a test harness
    if(ActivityManager.isRunningInTestHarness()) return false;

    // Disable clings for accessibility when explore by touch is enabled
    final AccessibilityManager a11yManager = (AccessibilityManager) mLauncher.getSystemService(
            Launcher.ACCESSIBILITY_SERVICE);
    if (a11yManager.isTouchExplorationEnabled()) {
        return false;
    }

    // Restricted secondary users (child mode) will potentially have very few apps
    // seeded when they start up for the first time. Clings won't work well with that
    boolean supportsLimitedUsers =
            android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
    Account[] accounts = AccountManager.get(mLauncher).getAccounts();
    if (supportsLimitedUsers && accounts.length == 0) {
        UserManager um = (UserManager) mLauncher.getSystemService(Context.USER_SERVICE);
        Bundle restrictions = um.getUserRestrictions();
        if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
            return false;
        }
    }
    if (Settings.Secure.getInt(mLauncher.getContentResolver(), SKIP_FIRST_USE_HINTS, 0)
            == 1) {
        return false;
    }
    return true;
}
 
Example 9
Source File: DeleteDropTarget.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
@Override
public void onDragStart(DragSource source, Object info, int dragAction) {
    boolean isVisible = true;
    boolean useUninstallLabel = !LauncherAppState.isDisableAllApps() &&
            isAllAppsApplication(source, info);
    boolean useDeleteLabel = !useUninstallLabel && source.supportsDeleteDropTarget();

    // If we are dragging an application from AppsCustomize, only show the control if we can
    // delete the app (it was downloaded), and rename the string to "uninstall" in such a case.
    // Hide the delete target if it is a widget from AppsCustomize.
    if (!willAcceptDrop(info) || isAllAppsWidget(source, info)) {
        isVisible = false;
    }
    if (useUninstallLabel) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            UserManager userManager = (UserManager)
                    getContext().getSystemService(Context.USER_SERVICE);
            Bundle restrictions = userManager.getUserRestrictions();
            if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
                    || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
                isVisible = false;
            }
        }
    }

    if (useUninstallLabel) {
        setCompoundDrawablesRelativeWithIntrinsicBounds(mUninstallDrawable, null, null, null);
    } else if (useDeleteLabel) {
        setCompoundDrawablesRelativeWithIntrinsicBounds(mRemoveDrawable, null, null, null);
    } else {
        isVisible = false;
    }
    mCurrentDrawable = (TransitionDrawable) getCurrentDrawable();

    mActive = isVisible;
    resetHoverColor();
    ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE);
    if (isVisible && getText().length() > 0) {
        setText(useUninstallLabel ? R.string.delete_target_uninstall_label
            : R.string.delete_target_label);
    }
}