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;
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);