OSDN Git Service

Show warnings when skipping Wi-Fi connection
authorRussell Brenner <russellbrenner@google.com>
Thu, 27 Sep 2012 18:37:54 +0000 (11:37 -0700)
committerThe Android Automerger <android-build@android.com>
Fri, 28 Sep 2012 21:23:23 +0000 (14:23 -0700)
If user skips over Wi-Fi, warn about possible carrier data charges or
inability to receive updates, depending on whether or not phone
service is available.

Note to translators: Some strings are being moved here from setup
wizard. They're tagged with their msgid's so as not to trigger
retranslation.

Bug: 7211786
Change-Id: Idec7863377bd453d1808b26ee3da75f8310b32e0

res/layout/setup_preference.xml
res/values/strings.xml
src/com/android/settings/wifi/WifiSettings.java

index 30b3373..c2f6989 100644 (file)
@@ -30,7 +30,7 @@
         android:gravity="bottom">
 
         <LinearLayout
-            android:id="@+id/button_bar"
+            android:id="@+id/title_bar"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_alignBottom="@id/title"
@@ -62,7 +62,7 @@
         <View
             android:id="@+id/top_divider"
             style="@style/TopDivider"
-            android:layout_below="@id/button_bar" />
+            android:layout_below="@id/title_bar" />
 
     </RelativeLayout>
 
                 android:layout_margin="5dip"
                 android:text="@string/wifi_setup_back" />
 
+            <Button
+                android:id="@+id/custom_button"
+                android:layout_width="150dip"
+                android:layout_height="wrap_content"
+                android:layout_alignParentEnd="true"
+                android:layout_margin="5dip"
+                android:text="@string/wifi_setup_skip" />
+
             <LinearLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                     android:layout_width="150dip"
                     android:layout_height="wrap_content"
                     android:layout_margin="5dip"
-                    android:text="@string/wifi_setup_next" />
-            </LinearLayout>
+                    android:text="@string/wifi_setup_next"
+                    android:visibility="gone" />
+                </LinearLayout>
         </RelativeLayout>
     </LinearLayout>
 </view>
\ No newline at end of file
index 106d507..8084a07 100644 (file)
     <string name="wifi_failed_save_message">Failed to save network</string>
     <!-- Button label to dismiss the dialog -->
     <string name="wifi_cancel">Cancel</string>
+    <!-- Button for skipping a step after having been warned of a potential concern [CHAR LIMIT=30] -->
+    <string name="wifi_skip_anyway" msgid="5205612884736051138">Skip anyway</string>
+    <!-- Button for going to the previous screen or step [CHAR LIMIT=20] -->
+    <string name="wifi_dont_skip">Don\'t skip</string>
+
+    <!-- Text warning about skipping Wi-Fi with a mobile connect (tablet) [CHAR LIMIT=NONE]-->
+    <string name="wifi_skipped_message" product="tablet" msgid="6518433975501257341">WARNING: You may incur extra carrier data charges.\n\nTablet setup can require significant network activity.</string>
+    <!-- Text warning about skipping Wi-Fi with a mobile connect (phone) [CHAR LIMIT=NONE]-->
+    <string name="wifi_skipped_message" product="default" msgid="4376150150678208848">WARNING: You may incur extra carrier data charges.\n\nPhone setup can require significant network activity.</string>
+    <!-- Text warning about skipping Wi-Fi without a mobile connect (tablet) [CHAR LIMIT=NONE] -->
+    <string name="wifi_and_mobile_skipped_message" product="tablet" msgid="5647058314212144925">WARNING: The tablet won\'t be able to verify that your software is up to date.</string>
+    <!-- Text warning about skipping Wi-Fi without a mobile connect (phone) [CHAR LIMIT=NONE] -->
+    <string name="wifi_and_mobile_skipped_message" product="default" msgid="1288483646141987070">WARNING: The phone won\'t be able to verify that your software is up to date.</string>
+    <!-- Text alerting that Wi-Fi couldn't connect (tablet) [CHAR LIMIT=NONE] -->
+    <string name="wifi_connect_failed_message" product="tablet" msgid="2006689630582761529">The tablet was unable to connect to this Wi-Fi network.</string>
+    <!-- Text alerting that Wi-Fi couldn't connect (phone) [CHAR LIMIT=NONE] -->
+    <string name="wifi_connect_failed_message" product="default" msgid="8220901976514642385">The phone was unable to connect to this Wi-Fi network.</string>
 
     <!-- Wi-Fi Advanced Settings --> <skip />
     <!-- Wi-Fi settings screen, advanced, settings section.  This is a header shown above advanced wifi settings. -->
     <!-- Hint text for network prefix length -->
     <string name="wifi_network_prefix_length_hint" translatable="false">24</string>
 
-
     <!-- Wi-Fi p2p / Wi-Fi Direct settings -->
     <!-- Used in the 1st-level settings screen to launch Wi-fi Direct settings [CHAR LIMIT=25] -->
     <string name="wifi_p2p_settings_title">Wi-Fi Direct</string>
index 92e622d..61093e6 100644 (file)
@@ -20,6 +20,8 @@ import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
 
 import android.app.ActionBar;
 import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
 import android.app.Dialog;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -45,6 +47,7 @@ import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
 import android.security.Credentials;
 import android.security.KeyStore;
+import android.telephony.TelephonyManager;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.ContextMenu;
@@ -58,6 +61,7 @@ import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.AdapterView.AdapterContextMenuInfo;
+import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.PopupMenu;
 import android.widget.PopupMenu.OnMenuItemClickListener;
@@ -101,6 +105,8 @@ public class WifiSettings extends SettingsPreferenceFragment
     private static final int WIFI_DIALOG_ID = 1;
     private static final int WPS_PBC_DIALOG_ID = 2;
     private static final int WPS_PIN_DIALOG_ID = 3;
+    private static final int WIFI_SKIPPED_DIALOG_ID = 4;
+    private static final int WIFI_AND_MOBILE_SKIPPED_DIALOG_ID = 5;
 
     // Combo scans can take 5-6s to complete - set to 10s.
     private static final int WIFI_RESCAN_INTERVAL_MS = 10 * 1000;
@@ -143,6 +149,9 @@ public class WifiSettings extends SettingsPreferenceFragment
     // this boolean extra specifies whether to auto finish when connection is established
     private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
 
+    // this boolean extra shows a custom button that we can control
+    protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button";
+
     // this boolean extra is set if we are being invoked by the Setup Wizard
     private static final String EXTRA_IS_FIRST_RUN = "firstRun";
 
@@ -228,6 +237,27 @@ public class WifiSettings extends SettingsPreferenceFragment
                     }
                 });
             }
+
+            if (getActivity().getIntent().getBooleanExtra(EXTRA_SHOW_CUSTOM_BUTTON, false)) {
+                view.findViewById(R.id.button_bar).setVisibility(View.VISIBLE);
+                view.findViewById(R.id.back_button).setVisibility(View.INVISIBLE);
+                view.findViewById(R.id.skip_button).setVisibility(View.INVISIBLE);
+                view.findViewById(R.id.next_button).setVisibility(View.INVISIBLE);
+
+                Button customButton = (Button) view.findViewById(R.id.custom_button);
+                customButton.setVisibility(View.VISIBLE);
+                customButton.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        if (isPhone() && !hasSimProblem()) {
+                            showDialog(WIFI_SKIPPED_DIALOG_ID);
+                        } else {
+                            showDialog(WIFI_AND_MOBILE_SKIPPED_DIALOG_ID);
+                        }
+                    }
+                });
+            }
+
             return view;
         } else {
             return super.onCreateView(inflater, container, savedInstanceState);
@@ -598,10 +628,69 @@ public class WifiSettings extends SettingsPreferenceFragment
                 return new WpsDialog(getActivity(), WpsInfo.PBC);
             case WPS_PIN_DIALOG_ID:
                 return new WpsDialog(getActivity(), WpsInfo.DISPLAY);
+            case WIFI_SKIPPED_DIALOG_ID:
+                return new AlertDialog.Builder(getActivity())
+                            .setMessage(R.string.wifi_skipped_message)
+                            .setCancelable(false)
+                            .setNegativeButton(R.string.wifi_skip_anyway,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                    getActivity().setResult(Activity.RESULT_CANCELED);
+                                    getActivity().finish();
+                                }
+                            })
+                            .setPositiveButton(R.string.wifi_dont_skip,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                }
+                            })
+                            .create();
+            case WIFI_AND_MOBILE_SKIPPED_DIALOG_ID:
+                return new AlertDialog.Builder(getActivity())
+                            .setMessage(R.string.wifi_and_mobile_skipped_message)
+                            .setCancelable(false)
+                            .setNegativeButton(R.string.wifi_skip_anyway,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                    getActivity().setResult(Activity.RESULT_CANCELED);
+                                    getActivity().finish();
+                                }
+                            })
+                            .setPositiveButton(R.string.wifi_dont_skip,
+                                    new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int id) {
+                                }
+                            })
+                            .create();
+
         }
         return super.onCreateDialog(dialogId);
     }
 
+    private boolean isPhone() {
+        final TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(
+                Context.TELEPHONY_SERVICE);
+        return telephonyManager != null
+                && telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
+    }
+
+    /**
+    * Return true if there's any SIM related impediment to connectivity.
+    * Treats Unknown as OK. (Only returns true if we're sure of a SIM problem.)
+    */
+   protected boolean hasSimProblem() {
+       final TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(
+               Context.TELEPHONY_SERVICE);
+       return telephonyManager != null
+               && telephonyManager.getCurrentPhoneType() == TelephonyManager.PHONE_TYPE_GSM
+               && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY
+               && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN;
+   }
+
     private boolean requireKeyStore(WifiConfiguration config) {
         if (WifiConfigController.requireKeyStore(config) &&
                 KeyStore.getInstance().state() != KeyStore.State.UNLOCKED) {