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

Commit bcc5e2aa authored by Yue Liang's avatar Yue Liang
Browse files

HotSpot learning after initialize activated

When user activated hotspot as initialize,
will pop-up for learning, customer chooses YES
option, then show learning.

Change-Id: Ie8cf5080c637e342c17e9bc5a06814cc73ce9fdd
CRs-Fixed: 1070422
parent 05dcf726
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -92,4 +92,5 @@
    <bool name="config_regional_security_show_password_enable">false</bool>
    <!-- Config to show bluetooth menu-->
    <bool name="config_hide_bluetooth_menu">false</bool>
    <bool name="config_hotspot_need_show_activated_dialog">false</bool>
</resources>
+7 −2
Original line number Diff line number Diff line
@@ -7594,7 +7594,7 @@
    <string name="tethering_no_sim_alert_title">No SIM Card</string>
    <string name="tethering_no_sim_card_text">Please install SIM card in order to share your data connection with other devices using Mobile HotSpot or USB tethering for Internet access.</string>
    <string name="tether_settings_launch_title">Mobile HotSpot</string>
    <string name="wifi_tether_first_use_message">Set up Mobile HotSpot at the First Use</string>
    <string name="wifi_tether_first_use_message">Set up Wi-Fi hotspot at the First Use</string>
    <string name="lte_data_and_voice_calling_enabled">LTE data and Voice Calling (IMS/VoLTE) service enabled </string>
    <string name="lte_data_service_enabled">LTE data service enabled </string>
    <string name="turn_off_wifi_dialog_title">Turn off Wi-Fi</string>
@@ -7603,10 +7603,13 @@
    <string name="show_battery_percentage">Show battery percentage</string>
    <string name="show_battery_percentage_summary">Show battery level percentage inside the status bar</string>
    <string name="learn_usb_dialog_title">First Time Notification Use</string>
    <string name="learn_usb_dialog_title">USB tethering is activated</string>
    <string name="learn_usb_dialog_text">Would you like to learn more about USB Tethering on your phone?</string>
    <string name="mobile_tether_help_dialog_title">Mobile HotSpot Help</string>
    <string name="mobile_usb_help_dialog_text">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, and Linux, the USB drivers for tethering may be needed.\n\n2. If your device has an SD card or USB storage, you can\'t mount it on your computer when USB tethered</string>
    <string name="mobile_hotspot_help_dialog_title">Mobile HotSpot Help</string>
    <string name="mobile_hotspot_help_dialog_text">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 not 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="wifiap_mobile_hotspot_help">Status</string>
    <string name="dialog_font_warining_title">Information</string>
@@ -7630,4 +7633,6 @@
    <string name="qtifeedback_package">com.qti.smq.qualcommFeedback</string>
    <string name="qtifeedback_activity">com.qti.smq.ui.QtiFeedbackActivity</string>
    <string name="learn_hotspot_dialog_title">Wi-Fi tethering is activated</string>
    <string name="learn_hotspot_dialog_text">Would you like to learn more about wifi Tethering on your phone?</string>
</resources>
+15 −20
Original line number Diff line number Diff line
@@ -157,7 +157,6 @@ public class TetherSettings extends RestrictedSettingsFragment
    private boolean mUsbEnable = false;
    private WifiManager mWifiStatusManager;
    private boolean mIsWifiEnabled = false;
    private boolean mHaveWifiApConfig = false;

    @Override
    protected int getMetricsCategory() {
@@ -283,24 +282,6 @@ public class TetherSettings extends RestrictedSettingsFragment
                Context.WIFI_SERVICE);
    }

    @Override
    public void onResume() {
        super.onResume();
        if(mWifiManager != null) {
            WifiConfiguration config = mWifiManager.getWifiApConfiguration();
            boolean isNotNoneSecurity = config.getAuthType() > WifiConfiguration.KeyMgmt.NONE;
            // WifiConfiguration.KeyMgmt be used to management schemes,
            // WifiConfiguration.preSharedKey for use with WPA-PSK, it's password,
            // if preSharedKey is empty, the WifiConfiguration need to set password.
            if(isNotNoneSecurity) {
                mHaveWifiApConfig = config.preSharedKey != null &&
                    !config.preSharedKey.isEmpty();
            } else {
                mHaveWifiApConfig = true;
            }
        }
    }

    @Override
    public void onDestroy() {
        mDataSaverBackend.remListener(this);
@@ -628,6 +609,20 @@ public class TetherSettings extends RestrictedSettingsFragment
                == TelephonyManager.SIM_STATE_READY);
    }

    private boolean checkWifiApConfig() {
        WifiConfiguration config = mWifiManager.getWifiApConfiguration();
        boolean isNotNoneSecurity = config.getAuthType() > WifiConfiguration.KeyMgmt.NONE;
        // WifiConfiguration.KeyMgmt be used to management schemes,
        // WifiConfiguration.preSharedKey for use with WPA-PSK, it's password,
        // if preSharedKey is empty, the WifiConfiguration need to set password.
        if(isNotNoneSecurity) {
            return config.preSharedKey != null &&
                !config.preSharedKey.isEmpty();
        } else {
            return true;
        }
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object value) {
        boolean enable = (Boolean) value;
@@ -638,7 +633,7 @@ public class TetherSettings extends RestrictedSettingsFragment
                ((HotspotPreference)preference).setChecked(false);
                return false;
            } else if(enableWifiApSettingsExt &&
                (isNeedShowHelp(getPrefContext()) || !mHaveWifiApConfig)) {
                (isNeedShowHelp(getPrefContext()) || !checkWifiApConfig())) {
                Intent intent = new Intent();
                intent.setAction(ACTION_HOTSPOT_PRE_CONFIGURE);
                intent.setPackage("com.qualcomm.qti.extsettings");
+57 −2
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@

package com.android.settings.wifi;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
@@ -28,10 +32,12 @@ import android.os.UserHandle;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import com.android.settings.HotspotPreference;
import com.android.settings.TetherSettings;
import com.android.settings.R;
import com.android.settings.datausage.DataSaverBackend;
import com.android.settingslib.TetherUtil;

import android.app.AlertDialog;
import android.app.Dialog;
import java.util.ArrayList;

public class WifiApEnabler {
@@ -48,6 +54,8 @@ public class WifiApEnabler {
    private boolean mEnabling = false;
    private static final String ACTION_HOTSPOT_POST_CONFIGURE = "Hotspot_PostConfigure";
    private static final String ACTION_EXTRA = "choice";
    private static final String KEY_FIRST_HOTSPOT_ACTIVATED = "FirstHotspotActivated";
    private static final String MY_PREF_FILE = "MY_PERFS";
    public static final int TETHERING_WIFI = 0;

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -164,6 +172,52 @@ public class WifiApEnabler {
        }
    }

    private void showWifiTetheringLearning(final Context ctx) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setTitle(ctx.getResources().getString(R.string.mobile_hotspot_help_dialog_title));
        builder.setMessage(ctx.getResources().getString(R.string.mobile_hotspot_help_dialog_text));
        builder.setPositiveButton(ctx.getResources().getString(R.string.yes), null);
        builder.setCancelable(false);
        builder.show();
    }


    private void showWifiTetheringActivatedDialog(final Context ctx) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setTitle(ctx.getResources().getString(R.string.learn_hotspot_dialog_title));
        builder.setMessage(ctx.getResources().getString(R.string.learn_hotspot_dialog_text));
        builder.setPositiveButton(ctx.getResources().getString(R.string.yes),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        showWifiTetheringLearning(ctx);
                    }
                });
        builder.setNegativeButton(ctx.getResources().getString(R.string.skip_label), null);
        builder.setCancelable(false);
        builder.show();
    }

    private boolean isNeedShowActivated (final Context ctx) {
        SharedPreferences sharedPreferences = ctx.getSharedPreferences(
                MY_PREF_FILE, Activity.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();
        boolean isFirstUse = sharedPreferences.getBoolean(KEY_FIRST_HOTSPOT_ACTIVATED,true);
        if (isFirstUse) {
            editor = sharedPreferences.edit();
            editor.putBoolean(KEY_FIRST_HOTSPOT_ACTIVATED, false);
            editor.commit();
        }
        return isFirstUse;
    }

    private void showActivatedDialog(final Context ctx) {
        if (ctx.getResources().getBoolean(R.bool.config_hotspot_need_show_activated_dialog)
                && isNeedShowActivated(ctx)) {
            showWifiTetheringActivatedDialog(ctx);
        }
    }

    private void handleWifiApStateChanged(int state, int reason) {
        boolean enableWifiApSettingsExt = mContext.getResources().getBoolean(
                R.bool.show_wifi_hotspot_settings);
@@ -183,6 +237,7 @@ public class WifiApEnabler {
                    hSwitch.setChecked(true);
                    /* Doesnt need the airplane check */
                    hSwitch.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
                    showActivatedDialog(mContext);
                    break;
                case WifiManager.WIFI_AP_STATE_DISABLING:
                    hSwitch.setSummary(R.string.wifi_tether_stopping);