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

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

Fix:first use USB-Tethering have no notifcation dialog

Rootcase:
Haven't this funcional code.

Solution:
Supplement codes.

Change-Id: Ia35ad1f46578a2daf69cb17a74beffd436e62e1f
CRs-Fixed: 1064551
parent 3f63f667
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -7590,6 +7590,12 @@
    <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>
    <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_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>
</resources>
+46 −7
Original line number Diff line number Diff line
@@ -88,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_FIRST_LAUNCH_USE_TETHERING = "FirstLaunchUSBTethering";
    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";
@@ -95,7 +96,6 @@ public class TetherSettings extends RestrictedSettingsFragment
    private static final String ACTION_HOTSPOT_CONFIGURE_RRSPONSE =
            "Hotspot_PreConfigure_Response";


    private static final int DIALOG_AP_SETTINGS = 1;

    private static final String TAG = "TetheringSettings";
@@ -140,6 +140,7 @@ public class TetherSettings extends RestrictedSettingsFragment

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

    /* Stores the package name and the class name of the provisioning app */
    private String[] mProvisionApp;
@@ -712,11 +713,12 @@ public class TetherSettings extends RestrictedSettingsFragment
    public boolean onPreferenceTreeClick(Preference preference) {
        if (preference == mUsbTether) {
            if (mUsbTether.isChecked() && mUsbEnable) {
            //get the wifi status
                //save the current wifi status for restore
                mIsWifiEnabled = mWifiStatusManager.isWifiEnabled();
            IntentFilter filter = new IntentFilter();
            filter.addAction(UsbManager.ACTION_USB_STATE);
            getActivity().registerReceiver(mTetherChangeReceiver, filter);

                if (isFirstUseUSBTethering(getActivity())) {
                    showFirstUseUSBTetheringDialog(getActivity());
                }
                startTethering(TETHERING_USB);
            } else {
                mCm.stopTethering(TETHERING_USB);
@@ -789,6 +791,43 @@ public class TetherSettings extends RestrictedSettingsFragment
        return isFirstUse;
    }

    private boolean isFirstUseUSBTethering(final Context ctx) {
        SharedPreferences sharedPereference = ctx.getSharedPreferences(
                SHAREPREFERENCE_FIFE_NAME, Activity.MODE_PRIVATE);
        boolean isNeed = sharedPereference.getBoolean(KEY_FIRST_LAUNCH_USE_TETHERING, true);
        if(isNeed) {
            Editor editor = sharedPereference.edit();
            editor.putBoolean(KEY_FIRST_LAUNCH_USE_TETHERING, false);
            editor.apply();
        }
        return isNeed;
    }

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

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

    private void checkDefaultValue(Context ctx) {
        boolean def_ssid = ctx.getResources().getBoolean(
                R.bool.hotspot_default_ssid_with_imei_enable);