Search in sources :

Example 36 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MonitoringCertInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedStates) {
    super.onCreate(savedStates);
    mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
    DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class);
    final int numberOfCertificates = getIntent().getIntExtra(Settings.EXTRA_NUMBER_OF_CERTIFICATES, 1);
    final int titleId = RestrictedLockUtils.getProfileOrDeviceOwner(this, mUserId) != null ? // Check certificate
    R.plurals.ssl_ca_cert_settings_button : // Trust or remove certificate
    R.plurals.ssl_ca_cert_dialog_title;
    final CharSequence title = getResources().getQuantityText(titleId, numberOfCertificates);
    setTitle(title);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(title);
    builder.setCancelable(true);
    builder.setPositiveButton(getResources().getQuantityText(R.plurals.ssl_ca_cert_settings_button, numberOfCertificates), this);
    builder.setNeutralButton(R.string.cancel, null);
    builder.setOnDismissListener(this);
    if (dpm.getProfileOwnerAsUser(mUserId) != null) {
        builder.setMessage(getResources().getQuantityString(R.plurals.ssl_ca_cert_info_message, numberOfCertificates, dpm.getProfileOwnerNameAsUser(mUserId)));
    } else if (dpm.getDeviceOwnerComponentOnCallingUser() != null) {
        builder.setMessage(getResources().getQuantityString(R.plurals.ssl_ca_cert_info_message_device_owner, numberOfCertificates, dpm.getDeviceOwnerNameOnAnyUser()));
    } else {
        // Consumer case.  Show scary warning.
        builder.setIcon(android.R.drawable.stat_notify_error);
        builder.setMessage(R.string.ssl_ca_cert_warning_message);
    }
    builder.show();
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) AlertDialog(android.app.AlertDialog)

Example 37 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WirelessSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
    }
    log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
    mContext = getActivity();
    mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mPm = getPackageManager();
    mUm = (UserManager) getSystemService(Context.USER_SERVICE);
    addPreferencesFromResource(R.xml.wireless_settings);
    final boolean isAdmin = mUm.isAdminUser();
    final Activity activity = getActivity();
    mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
    SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
    RestrictedPreference androidBeam = (RestrictedPreference) findPreference(KEY_ANDROID_BEAM_SETTINGS);
    PreferenceScreen nfcPayment = (PreferenceScreen) findPreference(KEY_NFC_PAYMENT_SETTINGS);
    PreferenceCategory nfcCategory = (PreferenceCategory) findPreference(KEY_NFC_CATEGORY_SETTINGS);
    mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
    mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam, nfcPayment);
    mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
    String toggleable = Settings.Global.getString(activity.getContentResolver(), Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
    //enable/disable wimax depending on the value in config.xml
    final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(com.android.internal.R.bool.config_wimaxEnabled);
    if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        PreferenceScreen root = getPreferenceScreen();
        Preference ps = findPreference(KEY_WIMAX_SETTINGS);
        if (ps != null)
            root.removePreference(ps);
    } else {
        if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX) && isWimaxEnabled) {
            Preference ps = findPreference(KEY_WIMAX_SETTINGS);
            ps.setDependency(KEY_TOGGLE_AIRPLANE);
        }
    }
    // Manually set dependencies for Wifi when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
        findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // TODO: http://b/23693383
    if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
        removePreference(KEY_VPN_SETTINGS);
    }
    // Manually set dependencies for Bluetooth when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
    // No bluetooth-dependent items in the list. Code kept in case one is added later.
    }
    // Manually set dependencies for NFC when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
        findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_NFC_PAYMENT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // Remove NFC if not available
    mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
    if (mNfcAdapter == null) {
        getPreferenceScreen().removePreference(nfcCategory);
        mNfcEnabler = null;
    } else if (!mPm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
        // Only show if we have the HCE feature
        nfcCategory.removePreference(nfcPayment);
    }
    // if it's a wifi-only device, or for MSIM devices
    if (!isAdmin || Utils.isWifiOnly(getActivity()) || Utils.showSimCardTile(getActivity()) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        removePreference(KEY_MOBILE_NETWORK_SETTINGS);
        removePreference(KEY_MANAGE_MOBILE_PLAN);
    }
    // Remove Mobile Network Settings and Manage Mobile Plan
    // if config_show_mobile_plan sets false.
    final boolean isMobilePlanEnabled = this.getResources().getBoolean(R.bool.config_show_mobile_plan);
    if (!isMobilePlanEnabled) {
        Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
        if (pref != null) {
            removePreference(KEY_MANAGE_MOBILE_PLAN);
        }
    }
    // Remove Airplane Mode settings if it's a stationary device such as a TV.
    if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
        removePreference(KEY_TOGGLE_AIRPLANE);
    }
    // Enable Proxy selector settings if allowed.
    Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
    final DevicePolicyManager mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    // proxy UI disabled until we have better app support
    getPreferenceScreen().removePreference(mGlobalProxy);
    mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
    // Disable Tethering if it's not allowed or if it's a wifi-only device
    final ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
    if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
        getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
    } else if (!adminDisallowedTetherConfig) {
        Preference p = findPreference(KEY_TETHER_SETTINGS);
        p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
        // Grey out if provisioning is not available.
        p.setEnabled(!TetherSettings.isProvisioningNeededButUnavailable(getActivity()));
    }
    // Remove network reset if not allowed
    if (RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
        removePreference(KEY_NETWORK_RESET);
    }
    // Enable link to CMAS app settings depending on the value in config.xml.
    boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(com.android.internal.R.bool.config_cellBroadcastAppLinks);
    try {
        if (isCellBroadcastAppLinkEnabled) {
            if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
                // CMAS app disabled
                isCellBroadcastAppLinkEnabled = false;
            }
        }
    } catch (IllegalArgumentException ignored) {
        // CMAS app not installed
        isCellBroadcastAppLinkEnabled = false;
    }
    if (!mUm.isAdminUser() || !isCellBroadcastAppLinkEnabled || RestrictedLockUtils.hasBaseUserRestriction(mContext, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserHandle.myUserId())) {
        removePreference(KEY_CELL_BROADCAST_SETTINGS);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(android.support.v14.preference.SwitchPreference) NfcEnabler(com.android.settings.nfc.NfcEnabler) ConnectivityManager(android.net.ConnectivityManager) Activity(android.app.Activity) RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 38 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SuggestionsChecks method isFingerprintEnabled.

private boolean isFingerprintEnabled() {
    DevicePolicyManager dpManager = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    final int dpmFlags = dpManager.getKeyguardDisabledFeatures(null, /* admin */
    mContext.getUserId());
    return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) == 0;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager)

Example 39 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CryptKeeperSettings method addEncryptionInfoToPreference.

private void addEncryptionInfoToPreference(Preference preference, int type, String password) {
    Activity activity = getActivity();
    DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm.getDoNotAskCredentialsOnBoot()) {
        preference.getExtras().putInt(TYPE, StorageManager.CRYPT_TYPE_DEFAULT);
        preference.getExtras().putString(PASSWORD, "");
    } else {
        preference.getExtras().putInt(TYPE, type);
        preference.getExtras().putString(PASSWORD, password);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) Activity(android.app.Activity)

Example 40 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TimeoutListPreference method removeUnusableTimeouts.

public void removeUnusableTimeouts(long maxTimeout, EnforcedAdmin admin) {
    final DevicePolicyManager dpm = (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return;
    }
    if (admin == null && mAdmin == null && !isDisabledByAdmin()) {
        return;
    }
    if (admin == null) {
        maxTimeout = Long.MAX_VALUE;
    }
    ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
    ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
    for (int i = 0; i < mInitialValues.length; ++i) {
        long timeout = Long.parseLong(mInitialValues[i].toString());
        if (timeout <= maxTimeout) {
            revisedEntries.add(mInitialEntries[i]);
            revisedValues.add(mInitialValues[i]);
        }
    }
    // by admin, otherwise remove the padlock in case it was set earlier.
    if (revisedValues.size() == 0) {
        setDisabledByAdmin(admin);
        return;
    } else {
        setDisabledByAdmin(null);
    }
    if (revisedEntries.size() != getEntries().length) {
        final int userPreference = Integer.parseInt(getValue());
        setEntries(revisedEntries.toArray(new CharSequence[0]));
        setEntryValues(revisedValues.toArray(new CharSequence[0]));
        mAdmin = admin;
        if (userPreference <= maxTimeout) {
            setValue(String.valueOf(userPreference));
        } else if (revisedValues.size() > 0 && Long.parseLong(revisedValues.get(revisedValues.size() - 1).toString()) == maxTimeout) {
            // If the last one happens to be the same as the max timeout, select that
            setValue(String.valueOf(maxTimeout));
        } else {
        // There will be no highlighted selection since nothing in the list matches
        // maxTimeout. The user can still select anything less than maxTimeout.
        // TODO: maybe append maxTimeout to the list and mark selected.
        }
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ArrayList(java.util.ArrayList)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)159 ComponentName (android.content.ComponentName)45 UserManager (android.os.UserManager)29 UserInfo (android.content.pm.UserInfo)25 RemoteException (android.os.RemoteException)24 LockPatternUtils (com.android.internal.widget.LockPatternUtils)19 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)14 PersistableBundle (android.os.PersistableBundle)8 PendingIntent (android.app.PendingIntent)6 IBinder (android.os.IBinder)6 UserHandle (android.os.UserHandle)6 IPackageManager (android.content.pm.IPackageManager)5 Uri (android.net.Uri)5 VrManagerInternal (com.android.server.vr.VrManagerInternal)5 ResolveInfo (android.content.pm.ResolveInfo)4 Point (android.graphics.Point)4 Binder (android.os.Binder)4 KeyStore (android.security.KeyStore)4 ArraySet (android.util.ArraySet)4