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

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

Settings: porting N code

1. Change all default language strings contains "WLAN" to "Wi-Fi".
2. Add overlay config to show Alert Dialog and cancel button
3. shows dialog when open wifi while WIFI_Tethering open
4. Display summary "Share your device's mobile data connection via USB
or a Mobile HotSpot" under Tethering & Mobile HotSpot

Change-Id: Ie8533970472222ed837272d976723c049e0e948b
CRs-Fixed: 1039259
parent b71239a4
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (c) 2016, The Linux Foundation. All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:
        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above
          copyright notice, this list of conditions and the following
          disclaimer in the documentation and/or other materials provided
          with the distribution.
        * Neither the name of The Linux Foundation nor the names of its
          contributors may be used to endorse or promote products derived
          from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
    WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
    ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
    IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/check"
    android:text="@string/dialog_not_show_again"
    >
</CheckBox>
+6 −0
Original line number Diff line number Diff line
@@ -68,4 +68,10 @@

    <bool name="config_regional_usb_tethering_quick_start_enable">false</bool>
    <bool name="config_regional_hotspot_tether_help_enable">false</bool>
    <!-- Config to enable/disable the USB line-->
    <bool name="config_usb_line_enable">false</bool>
    <bool name="config_show_dialog_open_wifi_when_tethering_open">false</bool>
    <bool name="config_regional_account_check_dialog_enable">false</bool>
    <!-- Tethering & Mobile HotSpots display summary on Tmoblie -->
    <bool name="config_tethering_settings_display_summary_Tmobile">false</bool>
</resources>
+15 −1
Original line number Diff line number Diff line
@@ -25,6 +25,15 @@
    <!-- Strings for Dialog deny button -->
    <string name="deny">Deny</string>
    <string name="wifiap_settings_desc">WLAN wifiap can share this phone\u2019s data Internet connection with other PC/mobile devices via WLAN.</string>
    <string name="wifiap_settings_indication">After the WLAN wifiap is turned on, other PC/mobile devices can connect to it and start using the internet by following steps:</string>
    <string name="wifiap_settings_indication_step1">1. Turn on WLAN on PC/Mobile device.</string>
    <string name="wifiap_settings_indication_step2">2. Find \u201c<xliff:g id="ssid_name">%s</xliff:g>\u201d in the list of WLAN networks.</string>
    <string name="wifiap_title">WLAN hotspot</string>
    <string name="wifiap_configure_ap_text">Set up WLAN wifiap</string>
    <string name="wifiap_configure_subtext"><xliff:g id="network_ssid">%1$s</xliff:g><xliff:g id="network_security">%2$s</xliff:g> portable WLAN wifiap</string>
    <string name="wifiap_turn_on_hint">To use WLAN wifiap, turn it on.</string>
    <!-- Strings for Dialog close button [CHAR LIMIT=20] -->
    <string name="dlg_close">Close</string>
    <!-- Strings for Dialog switch button [CHAR LIMIT=20] -->
@@ -7560,4 +7569,9 @@
    <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>
    <string name="turn_on_wifi_dialog_title">Turn on wifi</string>
    <string name="turn_on_wifi_dialog_text">Wi-Fi is turned off when Mobile HotSpot is active. To turn on Wi-Fi, please turn off Mobile HotSpot.</string>
    <string name="dialog_not_show_again">Do not show again</string>
    <string name="tethering_settings_summary">Share your device\'s mobile data connection via USB or a Mobile HotSpot</string>
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -363,6 +363,12 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
            Preference p = findPreference(KEY_TETHER_SETTINGS);
            p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));

            if (this.getResources().getBoolean(
                    R.bool.config_tethering_settings_display_summary_Tmobile)){
                RestrictedPreference rp = (RestrictedPreference) p;
                rp.useAdminDisabledSummary(false);
                p.setSummary(R.string.tethering_settings_summary);
            }
            // Grey out if provisioning is not available.
            p.setEnabled(!TetherSettings
                    .isProvisioningNeededButUnavailable(getActivity()));
+60 −3
Original line number Diff line number Diff line
@@ -16,10 +16,15 @@

package com.android.settings.wifi;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.NetworkInfo;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
@@ -29,8 +34,11 @@ import android.os.Message;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.widget.CheckBox;
import android.widget.Switch;
import android.widget.Toast;
import android.view.LayoutInflater;
import android.view.View;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
@@ -42,10 +50,11 @@ import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.WirelessUtils;

import java.util.concurrent.atomic.AtomicBoolean;

import android.util.Log;
public class WifiEnabler implements SwitchBar.OnSwitchChangeListener  {
    private Context mContext;
    private SwitchBar mSwitchBar;
    private static CheckBox mNotShowAgainCheckbox;
    private boolean mListeningToOnSwitchChange = false;
    private AtomicBoolean mConnected = new AtomicBoolean(false);

@@ -75,6 +84,8 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {

    private static final String EVENT_DATA_IS_WIFI_ON = "is_wifi_on";
    private static final int EVENT_UPDATE_INDEX = 0;
    public static final String MY_PREF_FILE = "MY_PERFS";
    public static final String KEY_TURN_OFF_WIFI_SHOW_AGAIN = "TurnOffWifiShowAgain";

    private Handler mHandler = new Handler() {
        @Override
@@ -225,11 +236,57 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
        // Disable tethering if enabling Wifi
        if (!mWifiManager.getWifiStaSapConcurrency()) {
            if (mayDisableTethering(isChecked)) {
                if (mContext.getResources().getBoolean(
                        R.bool.config_show_dialog_open_wifi_when_tethering_open)) {
                    LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
                            Context.LAYOUT_INFLATER_SERVICE);
                    View showAgainView = inflater.inflate(R.layout.not_show_again, null);
                    mNotShowAgainCheckbox = (CheckBox)showAgainView.findViewById(R.id.check);
                    final SharedPreferences sharedpreferences = mContext.getSharedPreferences(
                            MY_PREF_FILE, Context.MODE_PRIVATE);
                    boolean showAgain = sharedpreferences.getBoolean(
                            KEY_TURN_OFF_WIFI_SHOW_AGAIN, true);

                    if (!showAgain) {
                        mWifiManager.setWifiApEnabled(null, false);
                        MetricsLogger.action(mContext,
                                isChecked ? MetricsEvent.ACTION_WIFI_ON :
                                MetricsEvent.ACTION_WIFI_OFF);
                        if (!mWifiManager.setWifiEnabled(isChecked)) {
                            // Error
                            mSwitchBar.setEnabled(true);
                            Toast.makeText(mContext, R.string.wifi_error,
                                   Toast.LENGTH_SHORT).show();
                        }
                        return;
                    }

                    AlertDialog.Builder alert = new AlertDialog.Builder(mContext)
                            .setTitle(R.string.turn_on_wifi_dialog_title)
                            .setMessage(R.string.turn_on_wifi_dialog_text)
                            .setView(showAgainView)
                            .setPositiveButton(R.string.okay,
                                    new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                 Editor editor = sharedpreferences.edit();
                                 editor.putBoolean(KEY_TURN_OFF_WIFI_SHOW_AGAIN,
                                          !mNotShowAgainCheckbox.isChecked());
                                 editor.commit();
                            }
                    });
                    alert.setCancelable(false);
                    alert.show();
                }
                mWifiManager.setWifiApEnabled(null, false);
                if (!mWifiManager.setWifiEnabled(isChecked)) {
                    // Error
                    mSwitchBar.setEnabled(true);
                    Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show();
                }
                return;
            }
        }
        MetricsLogger.action(mContext,
                isChecked ? MetricsEvent.ACTION_WIFI_ON : MetricsEvent.ACTION_WIFI_OFF);
        if (!mWifiManager.setWifiEnabled(isChecked)) {
            // Error
            mSwitchBar.setEnabled(true);