Search in sources :

Example 1 with NfcEnabler

use of com.android.settings.nfc.NfcEnabler 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)

Aggregations

Activity (android.app.Activity)1 DevicePolicyManager (android.app.admin.DevicePolicyManager)1 ConnectivityManager (android.net.ConnectivityManager)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 Preference (android.support.v7.preference.Preference)1 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 NfcEnabler (com.android.settings.nfc.NfcEnabler)1 RestrictedPreference (com.android.settingslib.RestrictedPreference)1