Example usage for android.os UserManager DISALLOW_MODIFY_ACCOUNTS

List of usage examples for android.os UserManager DISALLOW_MODIFY_ACCOUNTS

Introduction

In this page you can find the example usage for android.os UserManager DISALLOW_MODIFY_ACCOUNTS.

Prototype

String DISALLOW_MODIFY_ACCOUNTS

To view the source code for android.os UserManager DISALLOW_MODIFY_ACCOUNTS.

Click Source Link

Document

Specifies if a user is disallowed from adding and removing accounts, unless they are android.accounts.AccountManager#addAccountExplicitly programmatically added by Authenticator.

Usage

From source file:Main.java

@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);
}

From source file:Main.java

public static boolean isUnableToModifyAccounts(Context context) {
    UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    Bundle restrictions = um.getUserRestrictions();
    return restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false);
}

From source file:com.afwsamples.testdpc.AddAccountActivity.java

private void disableUserRestrictions() {
    if (BuildCompat.isAtLeastN()) {
        // DPC is allowed to bypass DISALLOW_MODIFY_ACCOUNTS on N or above.
        Log.v(TAG, "skip disabling user restriction on N or above");
        return;/*from   ww w.  ja v a 2s . c o m*/
    }
    Log.v(TAG, "disabling user restrictions");
    mDisallowModifyAccounts = mUserManager.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS);
    mDevicePolicyManager.clearUserRestriction(mAdminComponentName, UserManager.DISALLOW_MODIFY_ACCOUNTS);
}

From source file:com.afwsamples.testdpc.AddAccountActivity.java

private void restoreUserRestrictions() {
    if (BuildCompat.isAtLeastN()) {
        // DPC is allowed to bypass DISALLOW_MODIFY_ACCOUNTS on N or above.
        Log.v(TAG, "skip restoring user restrictions on N or above");
        return;/*from w  ww  .  j av a 2 s  .  c  om*/
    }
    Log.v(TAG, "restoring user restrictions");
    if (mDisallowModifyAccounts) {
        mDevicePolicyManager.addUserRestriction(mAdminComponentName, UserManager.DISALLOW_MODIFY_ACCOUNTS);
    }
}

From source file:com.android.settings.Settings.java

private void updateHeaderList(List<Header> target) {
    final boolean showDev = mDevelopmentPreferences.getBoolean(DevelopmentSettings.PREF_SHOW,
            android.os.Build.TYPE.equals("eng"));
    int i = 0;/*from  w  w w .j  av a2  s  .com*/
    boolean IsSupVoice = Settings.this.getResources()
            .getBoolean(com.android.internal.R.bool.config_voice_capable);
    final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
    mHeaderIndexMap.clear();
    while (i < target.size()) {
        Header header = target.get(i);
        // Ids are integers, so downcasting
        int id = (int) header.id;
        if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
            Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
        } else if (id == R.id.wifi_settings) {
            // Remove WiFi Settings if WiFi service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
                target.remove(i);
            }
        } else if (id == R.id.bluetooth_settings) {
            // Remove Bluetooth Settings if Bluetooth service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
                target.remove(i);
            }
        } else if (id == R.id.data_usage_settings) {
            // Remove data usage when kernel module not enabled
            final INetworkManagementService netManager = INetworkManagementService.Stub
                    .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
            try {
                /* SPRDADD to delete the data usage item of settings @{ */
                boolean support_cmcc = SystemProperties.get("ro.operator").equals("cmcc");
                if (!netManager.isBandwidthControlEnabled() || support_cmcc) {
                    target.remove(i);
                }
            } catch (RemoteException e) {
                // ignored
            }
        } else if (id == R.id.battery_settings) {
            // Remove battery settings when battery is not available. (e.g. TV)

            if (!mBatteryPresent) {
                target.remove(i);
            }
            /* @} */
        } else if (id == R.id.account_settings) {
            int headerIndex = i + 1;
            i = insertAccountsHeaders(target, headerIndex);
            // SPRD: clear viewCache
            ListAdapter listAdapter = getListAdapter();
            if (listAdapter instanceof HeaderAdapter) {
                // add for tab style
                ((HeaderAdapter) listAdapter).flushViewCache();
            }
        } else if (id == R.id.home_settings) {
            if (!updateHomeSettingHeaders(header)) {
                target.remove(i);
            }
        } else if (id == R.id.user_settings) {
            if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
                target.remove(i);
            }
        } else if (id == R.id.nfc_payment_settings) {
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
                target.remove(i);
            } else {
                // Only show if NFC is on and we have the HCE feature
                NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
                if (!adapter.isEnabled() || !getPackageManager()
                        .hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
                    target.remove(i);
                }
            }
        } else if (id == R.id.development_settings) {
            if (!showDev) {
                target.remove(i);
            }
        } else if (id == R.id.account_add) {
            if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
                target.remove(i);
            }
        }

        /* SPRD: modified for cucc feature @{ */
        else if (id == R.id.network_preference_settings) {
            //if (!("cucc".equals(WifiManager.SUPPORT_VERSION))) {
            if (!CU_SUPPORT) { //modify for CUCC support  2013-11-22
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add AudioProfile  @{ */
        else if (id == R.id.sound_settings && IsSupVoice) {
            target.remove(header);
        } else if (id == R.id.audio_profiles && !IsSupVoice) {
            target.remove(header);
        }
        /* @} */
        /* SPRD: for multi-sim @{ */
        else if (id == R.id.dual_sim_settings) {
            if (!TelephonyManager.isMultiSim() || (!mVoiceCapable)) {
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add for uui style 335009 @{ */
        else if (id == R.id.uninstall_settings) {
            if (!UNIVERSEUI_SUPPORT) {
                target.remove(header);
            }
        }
        /* @} */
        /* smart_wake {@*/
        else if (id == R.id.smart_wake) {
            if (!SMART_WAKE) {
                target.remove(header);
            }
        }
        /* @} */
        /*lyx 20150320 power_saving */
        else if (id == R.id.power_saving) {
            if (!FeatureOption.PRJ_FEATURE_POWER_SAVING) {
                target.remove(header);
            }
        }
        /* @} */
        if (i < target.size() && target.get(i) == header && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
                && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
            target.remove(i);
        }

        // Increment if the current one wasn't removed by the Utils code.
        if (i < target.size() && target.get(i) == header) {
            // Hold on to the first header, when we need to reset to the top-level
            if (mFirstHeader == null
                    && HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
                mFirstHeader = header;
            }
            mHeaderIndexMap.put(id, i);
            i++;
        }
    }
}

From source file:com.android.settings.HWSettings.java

public void updateHeaderList(List<Header> target) {
    final boolean showDev = mDevelopmentPreferences.getBoolean(DevelopmentSettings.PREF_SHOW,
            android.os.Build.TYPE.equals("eng"));
    int i = 0;/*w w w.  j av  a2s .co  m*/
    boolean IsSupVoice = this.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
    final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
    mHeaderIndexMap.clear();
    while (i < target.size()) {
        Header header = target.get(i);
        // Ids are integers, so downcasting
        int id = (int) header.id;
        if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
            Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
        } else if (id == R.id.wifi_settings) {
            // Remove WiFi Settings if WiFi service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
                target.remove(i);
            }
        } else if (id == R.id.bluetooth_settings) {
            // Remove Bluetooth Settings if Bluetooth service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
                target.remove(i);
            }
        } else if (id == R.id.data_usage_settings) {
            // Remove data usage when kernel module not enabled
            final INetworkManagementService netManager = INetworkManagementService.Stub
                    .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
            try {
                /* SPRDADD to delete the data usage item of settings @{ */
                boolean support_cmcc = SystemProperties.get("ro.operator").equals("cmcc");
                if (!netManager.isBandwidthControlEnabled() || support_cmcc) {
                    target.remove(i);
                }
            } catch (RemoteException e) {
                // ignored
            }
        } else if (id == R.id.battery_settings) {
            // Remove battery settings when battery is not available. (e.g. TV)

            if (!mBatteryPresent) {
                target.remove(i);
            }
            /* @} */
        } else if (id == R.id.account_settings) {
            int headerIndex = i + 1;
            i = insertAccountsHeaders(target, headerIndex);
            // SPRD: clear viewCache
            ListAdapter listAdapter = getListAdapter();
            if (listAdapter instanceof HeaderAdapter) {
                // add for tab style
                ((HeaderAdapter) listAdapter).flushViewCache();
            }
        } else if (id == R.id.home_settings) {
            if (!updateHomeSettingHeaders(header)) {
                target.remove(i);
            }
        } else if (id == R.id.user_settings) {
            if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
                target.remove(i);
            }
        } else if (id == R.id.nfc_payment_settings) {
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
                target.remove(i);
            } else {
                // Only show if NFC is on and we have the HCE feature
                NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
                if (!adapter.isEnabled() || !getPackageManager()
                        .hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
                    target.remove(i);
                }
            }
        } else if (id == R.id.development_settings) {
            if (!showDev) {
                target.remove(i);
            }
        } else if (id == R.id.account_add) {
            if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
                target.remove(i);
            }
        }

        /* SPRD: modified for cucc feature @{ */
        else if (id == R.id.network_preference_settings) {
            //if (!("cucc".equals(WifiManager.SUPPORT_VERSION))) {
            if (!CU_SUPPORT) { //modify for CUCC support  2013-11-22
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add AudioProfile  @{ */
        else if (id == R.id.sound_settings && IsSupVoice) {
            target.remove(header);
        } else if (id == R.id.audio_profiles && !IsSupVoice) {
            target.remove(header);
        }
        /* @} */
        /* SPRD: for multi-sim @{ */
        else if (id == R.id.dual_sim_settings) {
            if (!TelephonyManager.isMultiSim() || (!mVoiceCapable)) {
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add for uui style 335009 @{ */
        else if (id == R.id.uninstall_settings) {
            target.remove(header);
        }
        /* @} */
        /*
        else if (id == R.id.mobile_network_settings_hw){
              header.intent.putExtra(MobileSimChoose.PACKAGE_NAME,
               "com.android.phone");
              header.intent.putExtra(MobileSimChoose.CLASS_NAME,
               "com.android.phone.MobileNetworkSettings");
        }
        */
        if (i < target.size() && target.get(i) == header && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
                && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
            target.remove(i);
        }

        // Increment if the current one wasn't removed by the Utils code.
        if (i < target.size() && target.get(i) == header) {
            // Hold on to the first header, when we need to reset to the top-level
            if (mFirstHeader == null
                    && HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
                mFirstHeader = header;
            }
            mHeaderIndexMap.put(id, i);
            i++;
        }
    }
}