Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33b0a66a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'hotspot_summary'

* changes:
  Display current vpn for Vpn preference summary text
  Display carrier network name as celluar setting summary.
  Add hotspot summary text
parents 85de8ad1 0ef0d500
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2941,6 +2941,12 @@
    <string name="tether_settings_title_usb_bluetooth">Tethering</string>
    <!-- Tethering controls, item title to go into the tethering settings when USB, Bluetooth and Wifi tethering are available [CHAR LIMIT=25]-->
    <string name="tether_settings_title_all">Hotspot &amp; Tethering</string>
    <!-- Tethering setting summary when both Wi-Fi hotspot and tether are turned on [CHAR LIMIT=NONE]-->
    <string name="tether_settings_summary_hotspot_on_tether_on">Hotspot on, tethering</string>
    <!-- Tethering setting summary when Wi-Fi hotspot is on and tether is off [CHAR LIMIT=NONE]-->
    <string name="tether_settings_summary_hotspot_on_tether_off">Hotspot on</string>
    <!-- Tethering setting summary when Wi-Fi hotspot is off and tether is on [CHAR LIMIT=NONE]-->
    <string name="tether_settings_summary_hotspot_off_tether_on">Tethering</string>
    <!-- Tethering controls, footer note displayed when tethering is disabled because Data Saver mode is on [CHAR LIMIT=none]-->
    <string name="tether_settings_disabled_on_data_saver">"Can\u2019t tether or use portable hotspots while Data Saver is on"</string>
+2 −1
Original line number Diff line number Diff line
@@ -253,7 +253,8 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
                    new NfcPreferenceController(context).updateNonIndexableKeys(result);
                    new MobilePlanPreferenceController(context, null /* MobilePlanClickHandler */)
                            .updateNonIndexableKeys(result);
                    new MobileNetworkPreferenceController(context).updateNonIndexableKeys(result);
                    new MobileNetworkPreferenceController(context)
                            .updateNonIndexableKeys(result);

                    // Remove Airplane Mode settings if it's a stationary device such as a TV.
                    new AirplaneModePreferenceController(context, null /* fragment */)
+47 −1
Original line number Diff line number Diff line
@@ -17,25 +17,39 @@ package com.android.settings.network;

import android.content.Context;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;

import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.LifecycleObserver;
import com.android.settings.core.lifecycle.events.OnPause;
import com.android.settings.core.lifecycle.events.OnResume;

import static android.os.UserHandle.myUserId;
import static android.os.UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS;
import static com.android.settingslib.RestrictedLockUtils.hasBaseUserRestriction;

public class MobileNetworkPreferenceController extends PreferenceController {
public class MobileNetworkPreferenceController extends PreferenceController implements
        LifecycleObserver, OnResume, OnPause {

    private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";

    private final UserManager mUserManager;
    private final boolean mIsSecondaryUser;
    private final TelephonyManager mTelephonyManager;
    private Preference mPreference;
    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    PhoneStateListener mPhoneStateListener;

    public MobileNetworkPreferenceController(Context context) {
        super(context);
        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        mIsSecondaryUser = !mUserManager.isAdminUser();
    }

@@ -46,8 +60,40 @@ public class MobileNetworkPreferenceController extends PreferenceController {
                && !hasBaseUserRestriction(mContext, DISALLOW_CONFIG_MOBILE_NETWORKS, myUserId());
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        if (isAvailable()) {
            mPreference = screen.findPreference(getPreferenceKey());
        }
    }

    @Override
    public String getPreferenceKey() {
        return KEY_MOBILE_NETWORK_SETTINGS;
    }

    @Override
    public void onResume() {
        if (isAvailable()) {
            if (mPhoneStateListener == null) {
                mPhoneStateListener = new PhoneStateListener() {
                    @Override
                    public void onServiceStateChanged(ServiceState serviceState) {
                        if (mPreference != null) {
                            mPreference.setSummary(mTelephonyManager.getNetworkOperatorName());
                        }
                    }
                };
            }
            mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
        }
    }

    @Override
    public void onPause() {
        if (mPhoneStateListener != null) {
            mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
        }
    }
}
+8 −2
Original line number Diff line number Diff line
@@ -81,16 +81,22 @@ public class NetworkDashboardFragment extends DashboardFragment implements
                new MobilePlanPreferenceController(context, this);
        final WifiMasterSwitchPreferenceController wifiPreferenceController =
                new WifiMasterSwitchPreferenceController(context, mMetricsFeatureProvider);
        final MobileNetworkPreferenceController mobileNetworkPreferenceController =
                new MobileNetworkPreferenceController(context);
        final VpnPreferenceController vpnPreferenceController =
                new VpnPreferenceController(context);
        final Lifecycle lifecycle = getLifecycle();
        lifecycle.addObserver(airplaneModePreferenceController);
        lifecycle.addObserver(mobilePlanPreferenceController);
        lifecycle.addObserver(wifiPreferenceController);
        lifecycle.addObserver(mobileNetworkPreferenceController);
        lifecycle.addObserver(vpnPreferenceController);

        final List<PreferenceController> controllers = new ArrayList<>();
        controllers.add(airplaneModePreferenceController);
        controllers.add(new MobileNetworkPreferenceController(context));
        controllers.add(mobileNetworkPreferenceController);
        controllers.add(new TetherPreferenceController(context));
        controllers.add(new VpnPreferenceController(context));
        controllers.add(vpnPreferenceController);
        controllers.add(new ProxyPreferenceController(context));
        controllers.add(mobilePlanPreferenceController);
        controllers.add(wifiPreferenceController);
+103 −4
Original line number Diff line number Diff line
@@ -15,17 +15,23 @@
 */
package com.android.settings.network;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.TetherSettings;
import com.android.settings.core.PreferenceController;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;
import static com.android.settingslib.RestrictedLockUtils.checkIfRestrictionEnforced;
@@ -36,28 +42,60 @@ public class TetherPreferenceController extends PreferenceController {
    private static final String KEY_TETHER_SETTINGS = "tether_settings";

    private final boolean mAdminDisallowedTetherConfig;
    private final AtomicReference<BluetoothPan> mBluetoothPan;
    private final ConnectivityManager mConnectivityManager;
    private final BluetoothAdapter mBluetoothAdapter;
    private final UserManager mUserManager;

    private final BluetoothProfile.ServiceListener mBtProfileServiceListener =
            new android.bluetooth.BluetoothProfile.ServiceListener() {
                public void onServiceConnected(int profile, BluetoothProfile proxy) {
                    mBluetoothPan.set((BluetoothPan) proxy);
                    updateSummary();
                }

                public void onServiceDisconnected(int profile) {
                    mBluetoothPan.set(null);
                }
            };

    private Preference mPreference;

    @VisibleForTesting(otherwise = VisibleForTesting.NONE)
    TetherPreferenceController() {
        super(null);
        mAdminDisallowedTetherConfig = false;
        mBluetoothPan = null;
        mConnectivityManager = null;
        mBluetoothAdapter = null;
        mUserManager = null;
    }

    public TetherPreferenceController(Context context) {
        super(context);
        mBluetoothPan = new AtomicReference<>();
        mAdminDisallowedTetherConfig = checkIfRestrictionEnforced(
                context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
        mConnectivityManager =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter != null) {
            mBluetoothAdapter.getProfileProxy(context, mBtProfileServiceListener,
                    BluetoothProfile.PAN);
        }
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        final Preference preference = screen.findPreference(KEY_TETHER_SETTINGS);
        if (preference != null && !mAdminDisallowedTetherConfig) {
            preference.setTitle(
        mPreference = screen.findPreference(KEY_TETHER_SETTINGS);
        if (mPreference != null && !mAdminDisallowedTetherConfig) {
            mPreference.setTitle(
                    com.android.settingslib.Utils.getTetheringLabel(mConnectivityManager));

            // Grey out if provisioning is not available.
            preference.setEnabled(!TetherSettings.isProvisioningNeededButUnavailable(mContext));
            mPreference.setEnabled(!TetherSettings.isProvisioningNeededButUnavailable(mContext));
        }
    }

@@ -70,6 +108,11 @@ public class TetherPreferenceController extends PreferenceController {
        return !isBlocked;
    }

    @Override
    public void updateState(Preference preference) {
        updateSummary();
    }

    @Override
    public void updateNonIndexableKeys(List<String> keys) {
        if (!mUserManager.isAdminUser() || !mConnectivityManager.isTetheringSupported()) {
@@ -81,4 +124,60 @@ public class TetherPreferenceController extends PreferenceController {
    public String getPreferenceKey() {
        return KEY_TETHER_SETTINGS;
    }

    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    void updateSummary() {
        if (mPreference == null) {
            // Preference is not ready yet.
            return;
        }
        String[] allTethered = mConnectivityManager.getTetheredIfaces();
        String[] wifiTetherRegex = mConnectivityManager.getTetherableWifiRegexs();
        String[] bluetoothRegex = mConnectivityManager.getTetherableBluetoothRegexs();

        boolean hotSpotOn = false;
        boolean tetherOn = false;
        if (allTethered != null) {
            if (wifiTetherRegex != null) {
                for (String tethered : allTethered) {
                    for (String regex : wifiTetherRegex) {
                        if (tethered.matches(regex)) {
                            hotSpotOn = true;
                            break;
                        }
                    }
                }
            }
            if (allTethered.length > 1) {
                // We have more than 1 tethered connection
                tetherOn = true;
            } else if (allTethered.length == 1) {
                // We have more than 1 tethered, it's either wifiTether (hotspot), or other type of
                // tether.
                tetherOn = !hotSpotOn;
            } else {
                // No tethered connection.
                tetherOn = false;
            }
        }
        if (!tetherOn
                && bluetoothRegex != null && bluetoothRegex.length > 0
                && mBluetoothAdapter != null
                && mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
            // Check bluetooth state. It's not included in mConnectivityManager.getTetheredIfaces.
            final BluetoothPan pan = mBluetoothPan.get();
            tetherOn = pan != null && pan.isTetheringOn();
        }
        if (!hotSpotOn && !tetherOn) {
            // Both off
            mPreference.setSummary(R.string.switch_off_text);
        } else if (hotSpotOn && tetherOn) {
            // Both on
            mPreference.setSummary(R.string.tether_settings_summary_hotspot_on_tether_on);
        } else if (hotSpotOn) {
            mPreference.setSummary(R.string.tether_settings_summary_hotspot_on_tether_off);
        } else {
            mPreference.setSummary(R.string.tether_settings_summary_hotspot_off_tether_on);
        }
    }
}
Loading