Search in sources :

Example 1 with DataSaverBackend

use of com.android.settings.datausage.DataSaverBackend in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TetherSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (icicle != null) {
        mTetherChoice = icicle.getInt(TETHER_CHOICE);
    }
    addPreferencesFromResource(R.xml.tether_prefs);
    mDataSaverBackend = new DataSaverBackend(getContext());
    mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
    mDataSaverFooter = findPreference(DATA_SAVER_FOOTER);
    setIfOnlyAvailableForAdmins(true);
    if (isUiRestricted()) {
        mUnavailable = true;
        setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
        return;
    }
    final Activity activity = getActivity();
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener, BluetoothProfile.PAN);
    }
    mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY);
    boolean enableWifiApSettingsExt = getResources().getBoolean(R.bool.show_wifi_hotspot_settings);
    boolean isWifiApEnabled = getResources().getBoolean(R.bool.hide_wifi_hotspot);
    checkDefaultValue(getActivity());
    if (enableWifiApSettingsExt) {
        mEnableWifiAp = (HotspotPreference) findPreference(ENABLE_WIFI_AP_EXT);
        getPreferenceScreen().removePreference(findPreference(ENABLE_WIFI_AP));
        getPreferenceScreen().removePreference(mCreateNetwork);
        Intent intent = new Intent();
        intent.setAction("com.qti.ap.settings");
        intent.setPackage("com.qualcomm.qti.extsettings");
        mEnableWifiAp.setIntent(intent);
    } else {
        mEnableWifiAp = (SwitchPreference) findPreference(ENABLE_WIFI_AP);
        getPreferenceScreen().removePreference(findPreference(ENABLE_WIFI_AP_EXT));
    }
    if (isWifiApEnabled) {
        getPreferenceScreen().removePreference(mEnableWifiAp);
        getPreferenceScreen().removePreference(mCreateNetwork);
    }
    if (getResources().getBoolean(R.bool.config_regional_hotspot_tether_help_enable)) {
        mTetherHelp = (PreferenceScreen) findPreference(TETHERING_HELP);
    } else {
        getPreferenceScreen().removePreference(findPreference(TETHERING_HELP));
    }
    mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
    mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
    mHotspotInactivityTimeout = (ListPreference) findPreference(HOTSPOT_TIMEOUT);
    mDataSaverBackend.addListener(this);
    mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    mUsbRegexs = mCm.getTetherableUsbRegexs();
    mWifiRegexs = mCm.getTetherableWifiRegexs();
    mBluetoothRegexs = mCm.getTetherableBluetoothRegexs();
    final boolean usbAvailable = mUsbRegexs.length != 0;
    final boolean wifiAvailable = mWifiRegexs.length != 0;
    final boolean bluetoothAvailable = mBluetoothRegexs.length != 0;
    if (!usbAvailable || Utils.isMonkeyRunning()) {
        getPreferenceScreen().removePreference(mUsbTether);
    }
    if (wifiAvailable && !Utils.isMonkeyRunning()) {
        mWifiApEnabler = new WifiApEnabler(activity, mDataSaverBackend, mEnableWifiAp);
        initWifiTethering();
    } else {
        getPreferenceScreen().removePreference(mEnableWifiAp);
        getPreferenceScreen().removePreference(mCreateNetwork);
    }
    if (!bluetoothAvailable) {
        getPreferenceScreen().removePreference(mBluetoothTether);
    } else {
        BluetoothPan pan = mBluetoothPan.get();
        if (pan != null && pan.isTetheringOn()) {
            mBluetoothTether.setChecked(true);
        } else {
            mBluetoothTether.setChecked(false);
        }
    }
    mHotspotInactivityTimeout.setOnPreferenceChangeListener(this);
    // Set initial state based on Data Saver mode.
    onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
}
Also used : DataSaverBackend(com.android.settings.datausage.DataSaverBackend) PreferenceScreen(android.support.v7.preference.PreferenceScreen) WifiApEnabler(com.android.settings.wifi.WifiApEnabler) Activity(android.app.Activity) Intent(android.content.Intent) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothPan(android.bluetooth.BluetoothPan)

Aggregations

Activity (android.app.Activity)1 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 BluetoothPan (android.bluetooth.BluetoothPan)1 Intent (android.content.Intent)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 DataSaverBackend (com.android.settings.datausage.DataSaverBackend)1 WifiApEnabler (com.android.settings.wifi.WifiApEnabler)1