OSDN Git Service

Fixed a Settings crash.
authorPauloftheWest <paulofthewest@google.com>
Fri, 26 Sep 2014 23:05:44 +0000 (16:05 -0700)
committerPauloftheWest <paulofthewest@google.com>
Mon, 29 Sep 2014 21:58:27 +0000 (14:58 -0700)
+ When in Settings->More... we will no longer provide a tethering option
if tethering requires provisioning, but the provisioning app is invalid.

Bug: 17671381
Change-Id: I48a8178865a7ffddec714c1f6ee6f18d34801b60

src/com/android/settings/TetherSettings.java
src/com/android/settings/WirelessSettings.java

index 45d8dee..c611772 100644 (file)
@@ -30,6 +30,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.PackageManager;
 import android.content.res.AssetManager;
 import android.hardware.usb.UsbManager;
 import android.net.ConnectivityManager;
@@ -471,16 +472,37 @@ public class TetherSettings extends SettingsPreferenceFragment
         return false;
     }
 
-    boolean isProvisioningNeeded() {
-        if (SystemProperties.getBoolean("net.tethering.noprovisioning", false)) {
+    public static boolean isProvisioningNeededButUnavailable(Context context) {
+        String[] provisionApp = context.getResources().getStringArray(
+                com.android.internal.R.array.config_mobile_hotspot_provision_app);
+        return (isProvisioningNeeded(provisionApp)
+                && !isIntentAvailable(context, provisionApp));
+    }
+
+    private static boolean isIntentAvailable(Context context, String[] provisionApp) {
+        if (provisionApp.length <  2) {
+            throw new IllegalArgumentException("provisionApp length should at least be 2");
+        }
+        final PackageManager packageManager = context.getPackageManager();
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.setClassName(provisionApp[0], provisionApp[1]);
+
+        return (packageManager.queryIntentActivities(intent,
+                PackageManager.MATCH_DEFAULT_ONLY).size() > 0);
+    }
+
+
+    private static boolean isProvisioningNeeded(String[] provisionApp) {
+        if (SystemProperties.getBoolean("net.tethering.noprovisioning", false)
+                || provisionApp == null) {
             return false;
         }
-        return mProvisionApp.length == 2;
+        return (provisionApp.length == 2);
     }
 
     private void startProvisioningIfNecessary(int choice) {
         mTetherChoice = choice;
-        if (isProvisioningNeeded()) {
+        if (isProvisioningNeeded(mProvisionApp)) {
             Intent intent = new Intent(Intent.ACTION_MAIN);
             intent.setClassName(mProvisionApp[0], mProvisionApp[1]);
             intent.putExtra(TETHER_CHOICE, mTetherChoice);
index ab7e28b..9cb3d72 100644 (file)
@@ -367,6 +367,10 @@ public class WirelessSettings extends SettingsPreferenceFragment
         } else {
             Preference p = findPreference(KEY_TETHER_SETTINGS);
             p.setTitle(Utils.getTetheringLabel(cm));
+
+            // Grey out if provisioning is not available.
+            p.setEnabled(!TetherSettings
+                    .isProvisioningNeededButUnavailable(getActivity()));
         }
 
         // Enable link to CMAS app settings depending on the value in config.xml.