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

Commit 3a973d60 authored by Fang Yunong's avatar Fang Yunong Committed by Gerrit - the friendly Code Review server
Browse files

Fix HotSpot bug:

1.HotSpot enabling hasn't pop up dialog to notify Wifi enabled.

2.In MPCS mode desktop existing Tethering HotSpot icon.

3.If wifi just enabled but hasn't connected, no need to notify
when open hotspot.

Change-Id: If92af84aba0edcd747572138f5315ac712bcaa2f
CRs-Fixed: 1039259
parent b0c3b951
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -491,7 +491,6 @@
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.VOICE_LAUNCH" />
                <category android:name="com.android.settings.SHORTCUT" />
            </intent-filter>
            <intent-filter android:priority="1">
                <action android:name="com.android.settings.action.SETTINGS" />
+2 −0
Original line number Diff line number Diff line
@@ -101,4 +101,6 @@
    <bool name="config_hidesupl_enable">false</bool>
    <!-- Whether to hide mms apn-->
    <bool name="config_hide_mms_enable">false</bool>
    <!-- show pop up notification for turn off wifi begin -->
    <bool name="hotspot_show_turn_off_wifi_dialog">false</bool>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -7588,4 +7588,6 @@
    <string name="wifi_tether_first_use_message">Set up Mobile 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>
    <string name="turn_off_wifi_dialog_text">Wi-Fi is turned off when Mobile HotSpot is active. To turn on Wi-Fi, please turn off Mobile HotSpot.</string>
</resources>
+48 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
@@ -64,6 +65,10 @@ import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
import static android.net.ConnectivityManager.TETHERING_USB;
import static android.net.ConnectivityManager.TETHERING_WIFI;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;

/*
 * Displays preferences for Tethering.
 */
@@ -83,6 +88,7 @@ public class TetherSettings extends RestrictedSettingsFragment
    private static final String SHAREPREFERENCE_DEFAULT_WIFI = "def_wifiap_set";
    private static final String SHAREPREFERENCE_FIFE_NAME = "MY_PERFS";
    private static final String KEY_FIRST_LAUNCH_HOTSPOT = "FirstLaunchHotspotTethering";
    private static final String KEY_TURN_OFF_WIFI_SHOW_AGAIN = "TurnOffWifiShowAgain";
    private static final String ACTION_HOTSPOT_PRE_CONFIGURE = "Hotspot_PreConfigure";
    private static final String ACTION_HOTSPOT_POST_CONFIGURE = "Hotspot_PostConfigure";
    private static final String CONFIGURE_RESULT = "PreConfigure_result";
@@ -601,6 +607,9 @@ public class TetherSettings extends RestrictedSettingsFragment
                getPrefContext().startActivity(intent);
                ((HotspotPreference)preference).setChecked(false);
                return false;
            } else if(checkWifiConnectivityState(getActivity())) {
                showTurnOffWifiDialog(getActivity());
                startTethering(TETHERING_WIFI);
            } else {
                startTethering(TETHERING_WIFI);
            }
@@ -610,6 +619,45 @@ public class TetherSettings extends RestrictedSettingsFragment
        return false;
    }

    private boolean checkWifiConnectivityState(Context ctx) {
        if(mCm == null) {
            ConnectivityManager mCm = (ConnectivityManager) ctx.
                    getSystemService(Context.CONNECTIVITY_SERVICE);
        }
        NetworkInfo info = mCm == null ? null : mCm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        return (info != null && info.isConnected());
    }

    private void showTurnOffWifiDialog(final Context ctx) {
        LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        View showAgainView = inflater.inflate(R.layout.not_show_again, null);
        CheckBox notShowAgainCheckbox = (CheckBox)showAgainView.findViewById(R.id.check);
        final SharedPreferences sharedpreferences = ctx.getSharedPreferences(
                SHAREPREFERENCE_FIFE_NAME, Context.MODE_PRIVATE);
        boolean showAgain = sharedpreferences.getBoolean(KEY_TURN_OFF_WIFI_SHOW_AGAIN, true);
        if (!showAgain) {
            return;
        } else {
            AlertDialog.Builder alert = new AlertDialog.Builder(ctx)
                    .setTitle(ctx.getResources().getString(R.string.turn_off_wifi_dialog_title))
                    .setMessage(ctx.getResources().getString(R.string.turn_off_wifi_dialog_text))
                    .setView(showAgainView)
                    .setPositiveButton(ctx.getResources().
                        getString(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,
                            !notShowAgainCheckbox.isChecked());
                    editor.commit();
                }
            });
            alert.setCancelable(false);
            alert.show();
        }
    }

    public static boolean isProvisioningNeededButUnavailable(Context context) {
        return (TetherUtil.isProvisioningNeeded(context)
                && !isIntentAvailable(context));