Fixed a Settings crash.
+ 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
This commit is contained in:
@@ -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);
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user