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

Commit b71239a4 authored by Fang Yunong's avatar Fang Yunong Committed by Linux Build Service Account
Browse files

Settings: N poring combine

Settings: tethering & portable hotspot help
merge b721eb5ad037d41cc95883d01d24f8aa26646e49

Settings: Move all carrier specific requirements to extension and these function
merge 05059c4938cd30e23fdaf91cbb02b0f65e0f3971

Settings: add USB tethering to USB connection type
merge 05c5422586495ff49126e2d91a250abe7fd0ee9a

Change-Id: I4ef17691f1aed44a47f38ca950fe6300d1687dcd
CRs-Fixed: 1039263
parent e388d09d
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -48,4 +48,24 @@

    <bool name="config_video_call_datausage_enable">false</bool>

    <!-- carrier tethering default ssid and password begin -->
    <bool name="use_empty_password_default">false</bool>
    <bool name="hotspot_default_ssid_with_imei_enable">false</bool>
    <!-- carrier tethering default ssid and password end -->

    <!-- show tethering help begin -->
    <bool name="tethering_show_help_for_first_using">false</bool>
    <bool name="tethering_show_help_menu">false</bool>
    <!-- show tethering help end -->
    <!-- Config voice over lte in wireless settings begin -->
    <bool name="config_voice_over_lte_enabled">false</bool>
    <!-- Config voice over lte in wireless settings end -->
    <!-- carrier tethering account check begin -->
    <bool name="edit_hotspot_timeout_enable">false</bool>
    <bool name="hotspot_accout_check_enable">false</bool>
    <string name="hotspot_accout_check_server_url"></string>
    <string name="hotspot_accout_up_sell_url"></string>

    <bool name="config_regional_usb_tethering_quick_start_enable">false</bool>
    <bool name="config_regional_hotspot_tether_help_enable">false</bool>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -6873,6 +6873,8 @@
         for this device should be used for. Choices are usb_use_charging_only,
         usb_use_file_transfer, use_use_photo_transfer, and usb_use_MIDI -->
    <string name="usb_use">Use USB to</string>
    <string name="usb_tethering_title">USB tethering</string>
    <string name="usb_tethering_desc">Use device for USB tethering</string>
    <!-- Settings item title for background check prefs [CHAR LIMIT=35] -->
    <string name="background_check_pref">Background check</string>
@@ -7556,4 +7558,6 @@
    <string name="network_operator_display_title">Show Network Operator</string>
    <string name="keywords_network_name_display">network name displayed</string>
    <string name="network_name_displayed_summary">Show network name on status bar</string>
    <string name="tethering_help_dialog_title">Help</string>
    <string name="tethering_help_dialog_text"><b>USB tethering</b> \n You can tether your Android device to your computer with a USB cable, to share your device\'s Internet connection with your computer. \n\n1.USB tethering works with Windows Vista, Windows 7, Windows 8, Windows 8.1 and Linux. \n\n2.If your device has an SD card or USB storage, you can\'t mount it on your computer when USB tethered. \n\n <b>Portable Wi-Fi hotspot</b> \n You can turn your Android device into a portable Wi-Fi hotspot, to share your Android device\'s Internet connection with one or more computers or other devices. \n\n1.When your device is serving as a Wi-Fi hotspot, you can\'t use your device\'s applications to access the Internet via its Wi-Fi connection (but of course you remain connected to the Internet via your mobile data network). \n\n2.You configure the hotspot with the Wi-Fi hotspot settings.</string>
</resources>

res/xml/tether_prefs.xml

100755 → 100644
+4 −0
Original line number Diff line number Diff line
@@ -45,4 +45,8 @@
            android:summary="@string/tether_settings_disabled_on_data_saver"
            android:selectable="false"
            settings:allowDividerAbove="true" />
    <PreferenceScreen
        android:key="tethering_help"
        android:title="@string/tethering_help_button_text" >
    </PreferenceScreen>
</PreferenceScreen>
+119 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
@@ -27,10 +28,15 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@@ -38,6 +44,8 @@ import android.os.UserManager;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.logging.MetricsProto.MetricsEvent;
@@ -66,7 +74,18 @@ public class TetherSettings extends RestrictedSettingsFragment
    private static final String ENABLE_WIFI_AP_EXT = "enable_wifi_ap_ext";
    private static final String ENABLE_BLUETOOTH_TETHERING = "enable_bluetooth_tethering";
    private static final String TETHER_CHOICE = "TETHER_TYPE";
    private static final String TETHERING_HELP = "tethering_help";
    private static final String DATA_SAVER_FOOTER = "disabled_on_data_saver";
    private static final String ACTION_EXTRA = "choice";
    private static final String ACTION_EXTRA_VALUE = "value";
    private static final String SHAREPREFERENCE_DEFAULT_WIFI = "def_wifiap_set";
    private static final String SHAREPREFERENCE_FIFE_NAME = "MY_PERFS";
    private static final String ACTION_HOTSPOT_CONFIGURE = "Hotspot_PreConfigure";
    private static final String ACTION_HOTSPOT_POST_CONFIGURE = "Hotspot_PostConfigure";
    private static final String CONFIGURE_RESULT = "PreConfigure_result";
    private static final String ACTION_HOTSPOT_CONFIGURE_RRSPONSE =
            "Hotspot_PreConfigure_Response";


    private static final int DIALOG_AP_SETTINGS = 1;

@@ -76,6 +95,7 @@ public class TetherSettings extends RestrictedSettingsFragment

    private WifiApEnabler mWifiApEnabler;
    private Preference mEnableWifiAp;
    private PreferenceScreen mTetherHelp;

    private SwitchPreference mBluetoothTether;

@@ -109,12 +129,15 @@ public class TetherSettings extends RestrictedSettingsFragment

    private boolean mBluetoothEnableForTether;

    /* One of INVALID, WIFI_TETHERING, USB_TETHERING or BLUETOOTH_TETHERING */
    private int mTetherChoice = -1;

    /* Stores the package name and the class name of the provisioning app */
    private String[] mProvisionApp;
    private static final int PROVISION_REQUEST = 0;

    private boolean mUnavailable;

    private BroadcastReceiver mConfigureReceiver;
    private DataSaverBackend mDataSaverBackend;
    private boolean mDataSaverEnabled;
    private Preference mDataSaverFooter;
@@ -132,6 +155,9 @@ public class TetherSettings extends RestrictedSettingsFragment
    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());
@@ -156,6 +182,7 @@ public class TetherSettings extends RestrictedSettingsFragment

        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);
@@ -175,6 +202,13 @@ public class TetherSettings extends RestrictedSettingsFragment
            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);

@@ -378,6 +412,7 @@ public class TetherSettings extends RestrictedSettingsFragment
        }

        updateState();
        registerConfigureReceiver(getActivity());
    }

    @Override
@@ -394,6 +429,7 @@ public class TetherSettings extends RestrictedSettingsFragment
            mEnableWifiAp.setOnPreferenceChangeListener(null);
            mWifiApEnabler.pause();
        }
        unRegisterConfigureReceiver();
    }

    private void updateState() {
@@ -574,6 +610,14 @@ public class TetherSettings extends RestrictedSettingsFragment
            }
        } else if (preference == mCreateNetwork) {
            showDialog(DIALOG_AP_SETTINGS);
        } else if (getResources().getBoolean(
                R.bool.config_regional_hotspot_tether_help_enable)
                && preference == mTetherHelp) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setTitle(R.string.tethering_help_dialog_title);
            alert.setMessage(R.string.tethering_help_dialog_text);
            alert.setPositiveButton(R.string.okay, null);
            alert.show();
        }

        return super.onPreferenceTreeClick(preference);
@@ -608,6 +652,80 @@ public class TetherSettings extends RestrictedSettingsFragment
        return R.string.help_url_tether;
    }

    private void checkDefaultValue(Context ctx) {
        boolean def_ssid = ctx.getResources().getBoolean(
                R.bool.hotspot_default_ssid_with_imei_enable);
        boolean clear_pwd = ctx.getResources().getBoolean( R.bool.use_empty_password_default);
        if (def_ssid || clear_pwd) {
            SharedPreferences sharedPreferences = ctx.getSharedPreferences(
                    SHAREPREFERENCE_FIFE_NAME,Activity.MODE_PRIVATE);
            boolean hasSetDefaultValue = sharedPreferences.getBoolean(
                    SHAREPREFERENCE_DEFAULT_WIFI, false);
            if ((!hasSetDefaultValue) && (setDefaultValue(ctx , def_ssid , clear_pwd))) {
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putBoolean(SHAREPREFERENCE_DEFAULT_WIFI,true);
                editor.commit();
            }
        }
    }

    private boolean setDefaultValue(Context ctx, boolean default_ssid, boolean clear_password) {
        WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
        if (wifiManager == null) {
            return false;
        }
        WifiConfiguration wifiAPConfig = wifiManager.getWifiApConfiguration();
        if (wifiAPConfig == null) {
            return false;
        }
        if (default_ssid) {
            TelephonyManager tm = (TelephonyManager) ctx.getSystemService(
                    Context.TELEPHONY_SERVICE);
            String deviceId = tm.getDeviceId();
            String lastFourDigits = "";
            if ((deviceId != null) && (deviceId.length() > 3)) {
                lastFourDigits =  deviceId.substring(deviceId.length()-4);
            }
            wifiAPConfig.SSID = Build.MODEL;
            if ((!TextUtils.isEmpty(lastFourDigits)) && (wifiAPConfig.SSID != null)
                    && (wifiAPConfig.SSID.indexOf(lastFourDigits) < 0)) {
                 wifiAPConfig.SSID += " " + lastFourDigits;
            }
        }
        if (clear_password) {
            wifiAPConfig.preSharedKey = "";
        }
        wifiManager.setWifiApConfiguration(wifiAPConfig);
        return true;
    }

    private void unRegisterConfigureReceiver() {
        if (mConfigureReceiver != null) {
            getActivity().unregisterReceiver(mConfigureReceiver);
            mConfigureReceiver = null;
        }
    }

    private void registerConfigureReceiver(Context ctx) {
        IntentFilter filter = new IntentFilter(ACTION_HOTSPOT_CONFIGURE_RRSPONSE);
        if (mConfigureReceiver == null) {
            mConfigureReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (action.equals(ACTION_HOTSPOT_CONFIGURE_RRSPONSE)) {
                        boolean result = intent.getBooleanExtra(CONFIGURE_RESULT,true);
                        if (result) {
                            startTethering(mTetherChoice);
                        } else {
                            mWifiApEnabler.setChecked(false);
                        }
                    }
                }
            };
        }
        ctx.registerReceiver(mConfigureReceiver, filter);
    }
    private BluetoothProfile.ServiceListener mProfileServiceListener =
            new BluetoothProfile.ServiceListener() {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
+18 −1
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.hardware.usb.UsbPortStatus;
import android.os.UserHandle;
import android.os.UserManager;

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

public class UsbBackend {

@@ -32,11 +34,12 @@ public class UsbBackend {
    public static final int MODE_POWER_SINK   = 0x00;
    public static final int MODE_POWER_SOURCE = 0x01;

    private static final int MODE_DATA_MASK  = 0x03 << 1;
    private static final int MODE_DATA_MASK  = 0x07 << 1;
    public static final int MODE_DATA_NONE   = 0x00 << 1;
    public static final int MODE_DATA_MTP    = 0x01 << 1;
    public static final int MODE_DATA_PTP    = 0x02 << 1;
    public static final int MODE_DATA_MIDI   = 0x03 << 1;
    public static final int MODE_DATA_TETHERING   = 0x04 << 1;

    private final boolean mRestricted;
    private final boolean mRestrictedBySystem;
@@ -48,8 +51,11 @@ public class UsbBackend {
    private UsbPortStatus mPortStatus;

    private boolean mIsUnlocked;
    private boolean mTetheringEnabled;
    private Context mContext;

    public UsbBackend(Context context) {
        mContext = context;
        Intent intent = context.registerReceiver(null,
                new IntentFilter(UsbManager.ACTION_USB_STATE));
        mIsUnlocked = intent == null ?
@@ -58,6 +64,8 @@ public class UsbBackend {
        mUserManager = UserManager.get(context);
        mUsbManager = context.getSystemService(UsbManager.class);

        mTetheringEnabled = context.getResources().getBoolean(
                R.bool.config_regional_usb_tethering_quick_start_enable);
        mRestricted = mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);
        mRestrictedBySystem = mUserManager.hasBaseUserRestriction(
                UserManager.DISALLOW_USB_FILE_TRANSFER, UserHandle.of(UserHandle.myUserId()));
@@ -87,6 +95,10 @@ public class UsbBackend {
    }

    public int getUsbDataMode() {
        if (mTetheringEnabled
                && mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_RNDIS)) {
            return MODE_DATA_TETHERING;
        }
        if (!mIsUnlocked) {
            if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_CHARGING)) {
                //Take this as charging mode
@@ -120,6 +132,11 @@ public class UsbBackend {
                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MIDI);
                mUsbManager.setUsbDataUnlocked(true);
                break;
            case MODE_DATA_TETHERING:
                Intent intent = new Intent();
                intent.setClass(mContext, TetherSettings.class);
                mContext.startActivity(intent);
                break;
            default:
                //default mode is "charging"
                mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_CHARGING);
Loading