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

Commit 29aab7a2 authored by PauloftheWest's avatar PauloftheWest
Browse files

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
parent 5c664d8e
Loading
Loading
Loading
Loading
+26 −4
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.AssetManager;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
@@ -471,16 +472,37 @@ public class TetherSettings extends SettingsPreferenceFragment
        return false;
        return false;
    }
    }


    boolean isProvisioningNeeded() {
    public static boolean isProvisioningNeededButUnavailable(Context context) {
        if (SystemProperties.getBoolean("net.tethering.noprovisioning", false)) {
        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 false;
        }
        }
        return mProvisionApp.length == 2;
        return (provisionApp.length == 2);
    }
    }


    private void startProvisioningIfNecessary(int choice) {
    private void startProvisioningIfNecessary(int choice) {
        mTetherChoice = choice;
        mTetherChoice = choice;
        if (isProvisioningNeeded()) {
        if (isProvisioningNeeded(mProvisionApp)) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(mProvisionApp[0], mProvisionApp[1]);
            intent.setClassName(mProvisionApp[0], mProvisionApp[1]);
            intent.putExtra(TETHER_CHOICE, mTetherChoice);
            intent.putExtra(TETHER_CHOICE, mTetherChoice);
+4 −0
Original line number Original line Diff line number Diff line
@@ -367,6 +367,10 @@ public class WirelessSettings extends SettingsPreferenceFragment
        } else {
        } else {
            Preference p = findPreference(KEY_TETHER_SETTINGS);
            Preference p = findPreference(KEY_TETHER_SETTINGS);
            p.setTitle(Utils.getTetheringLabel(cm));
            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.
        // Enable link to CMAS app settings depending on the value in config.xml.