Commits

Irfan Sheriff  committed f3a0201

Update enterprise API usage

Also, remove the unnecessary keystore lock/unlock checks since these
are now controlled at lockscreen

Change-Id: If65c4029d4cf2b8377fbc3512c9f691572125995

  • Participants
  • Parent commits 1ef6a10

Comments (0)

Files changed (2)

File src/com/android/settings/wifi/WifiConfigController.java

  */
 public class WifiConfigController implements TextWatcher,
         View.OnClickListener, AdapterView.OnItemSelectedListener {
-    private static final String KEYSTORE_SPACE = WifiConfiguration.KEYSTORE_URI;
-
-    private static final String PHASE2_PREFIX = "auth=";
-
     private final WifiConfigUiBase mConfigUi;
     private final View mView;
     private final AccessPoint mAccessPoint;
     private int mAccessPointSecurity;
     private TextView mPasswordView;
 
+    private String unspecifiedCert = "unspecified";
+
     private Spinner mSecuritySpinner;
     private Spinner mEapMethodSpinner;
     private Spinner mEapCaCertSpinner;
 
     private final Handler mTextViewChangedHandler;
 
-    static boolean requireKeyStore(WifiConfiguration config) {
-        if (config == null) {
-            return false;
-        }
-        if (!TextUtils.isEmpty(config.key_id.value())) {
-            return true;
-        }
-        String values[] = { config.ca_cert.value(), config.client_cert.value() };
-        for (String value : values) {
-            if (value != null && value.startsWith(KEYSTORE_SPACE)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     public WifiConfigController(
             WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) {
         mConfigUi = parent;
         final Context context = mConfigUi.getContext();
         final Resources resources = context.getResources();
 
+        unspecifiedCert = context.getString(R.string.wifi_unspecified);
         mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
         mIpSettingsSpinner.setOnItemSelectedListener(this);
         mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
             case AccessPoint.SECURITY_EAP:
                 config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
                 config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
-                config.eap.setValue((String) mEapMethodSpinner.getSelectedItem());
-
-                config.phase2.setValue((mPhase2Spinner.getSelectedItemPosition() == 0) ? "" :
-                        PHASE2_PREFIX + mPhase2Spinner.getSelectedItem());
-                config.ca_cert.setValue((mEapCaCertSpinner.getSelectedItemPosition() == 0) ? "" :
-                        KEYSTORE_SPACE + Credentials.CA_CERTIFICATE +
-                        (String) mEapCaCertSpinner.getSelectedItem());
-                config.client_cert.setValue((mEapUserCertSpinner.getSelectedItemPosition() == 0) ?
-                        "" : KEYSTORE_SPACE + Credentials.USER_CERTIFICATE +
-                        (String) mEapUserCertSpinner.getSelectedItem());
-                final boolean isEmptyKeyId = (mEapUserCertSpinner.getSelectedItemPosition() == 0);
-                config.key_id.setValue(isEmptyKeyId ? "" : Credentials.USER_PRIVATE_KEY +
-                        (String) mEapUserCertSpinner.getSelectedItem());
-                config.engine.setValue(isEmptyKeyId ? WifiConfiguration.ENGINE_DISABLE :
-                        WifiConfiguration.ENGINE_ENABLE);
-                config.engine_id.setValue(isEmptyKeyId ? "" : WifiConfiguration.KEYSTORE_ENGINE_ID);
-                config.identity.setValue((mEapIdentityView.length() == 0) ? "" :
-                        mEapIdentityView.getText().toString());
-                config.anonymous_identity.setValue((mEapAnonymousView.length() == 0) ? "" :
+                config.enterpriseConfig.setEapMethod(mEapMethodSpinner.getSelectedItemPosition());
+                config.enterpriseConfig.setPhase2Method(mPhase2Spinner.getSelectedItemPosition());
+                String caCert = (String) mEapCaCertSpinner.getSelectedItem();
+                if (caCert.equals(unspecifiedCert)) caCert = "";
+                String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
+                if (clientCert.equals(unspecifiedCert)) clientCert = "";
+                config.enterpriseConfig.setCaCertificate(caCert);
+                config.enterpriseConfig.setClientCertificate(clientCert);
+                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
+                config.enterpriseConfig.setAnonymousIdentity(
                         mEapAnonymousView.getText().toString());
-                if (mPasswordView.length() != 0) {
-                    config.password.setValue(mPasswordView.getText().toString());
-                }
+                config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
                 break;
 
             default:
 
             if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
                 WifiConfiguration config = mAccessPoint.getConfig();
-                setSelection(mEapMethodSpinner, config.eap.value());
-
-                final String phase2Method = config.phase2.value();
-                if (phase2Method != null && phase2Method.startsWith(PHASE2_PREFIX)) {
-                    setSelection(mPhase2Spinner, phase2Method.substring(PHASE2_PREFIX.length()));
-                } else {
-                    setSelection(mPhase2Spinner, phase2Method);
-                }
+                mEapMethodSpinner.setSelection(config.enterpriseConfig.getEapMethod());
+                mPhase2Spinner.setSelection(config.enterpriseConfig.getPhase2Method());
 
-                setCertificate(mEapCaCertSpinner, KEYSTORE_SPACE + Credentials.CA_CERTIFICATE,
-                        config.ca_cert.value());
-                setCertificate(mEapUserCertSpinner, Credentials.USER_PRIVATE_KEY,
-                        config.key_id.value());
-                mEapIdentityView.setText(config.identity.value());
-                mEapAnonymousView.setText(config.anonymous_identity.value());
+                setSelection(mEapCaCertSpinner, config.enterpriseConfig.getCaCertificate());
+                setSelection(mEapUserCertSpinner, config.enterpriseConfig.getClientCertificate());
+                mEapIdentityView.setText(config.enterpriseConfig.getIdentity());
+                mEapAnonymousView.setText(config.enterpriseConfig.getAnonymousIdentity());
             }
         }
 
 
     private void loadCertificates(Spinner spinner, String prefix) {
         final Context context = mConfigUi.getContext();
-        final String unspecified = context.getString(R.string.wifi_unspecified);
 
         String[] certs = KeyStore.getInstance().saw(prefix);
         if (certs == null || certs.length == 0) {
-            certs = new String[] {unspecified};
+            certs = new String[] {unspecifiedCert};
         } else {
             final String[] array = new String[certs.length + 1];
-            array[0] = unspecified;
+            array[0] = unspecifiedCert;
             System.arraycopy(certs, 0, array, 1, certs.length);
             certs = array;
         }
         spinner.setAdapter(adapter);
     }
 
-    private void setCertificate(Spinner spinner, String prefix, String cert) {
-        if (cert != null && cert.startsWith(prefix)) {
-            setSelection(spinner, cert.substring(prefix.length()));
-        }
-    }
-
     private void setSelection(Spinner spinner, String value) {
         if (value != null) {
             @SuppressWarnings("unchecked")

File src/com/android/settings/wifi/WifiSettings.java

 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;
 
     private AtomicBoolean mConnected = new AtomicBoolean(false);
 
-    private int mKeyStoreNetworkId = INVALID_NETWORK_ID;
-
     private WifiDialog mDialog;
 
     private TextView mEmptyView;
         }
 
         getActivity().registerReceiver(mReceiver, mFilter);
-        if (mKeyStoreNetworkId != INVALID_NETWORK_ID && KeyStore.getInstance().isUnlocked()) {
-            mWifiManager.connect(mKeyStoreNetworkId, mConnectListener);
-        }
-        mKeyStoreNetworkId = INVALID_NETWORK_ID;
-
         updateAccessPoints();
     }
 
         switch (item.getItemId()) {
             case MENU_ID_CONNECT: {
                 if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
-                    if (!requireKeyStore(mSelectedAccessPoint.getConfig())) {
-                        mWifiManager.connect(mSelectedAccessPoint.networkId,
-                                mConnectListener);
-                    }
+                    mWifiManager.connect(mSelectedAccessPoint.networkId,
+                            mConnectListener);
                 } else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
                     /** Bypass dialog for unsecured networks */
                     mSelectedAccessPoint.generateOpenNetworkConfig();
                && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN;
    }
 
-    private boolean requireKeyStore(WifiConfiguration config) {
-        if (WifiConfigController.requireKeyStore(config) && !KeyStore.getInstance().isUnlocked()) {
-            mKeyStoreNetworkId = config.networkId;
-            Credentials.getInstance().unlock(getActivity());
-            return true;
-        }
-        return false;
-    }
-
     /**
      * Shows the latest access points available with supplimental information like
      * the strength of network and the security for it.
 
         if (config == null) {
             if (mSelectedAccessPoint != null
-                    && !requireKeyStore(mSelectedAccessPoint.getConfig())
                     && mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
                 mWifiManager.connect(mSelectedAccessPoint.networkId,
                         mConnectListener);
                 mWifiManager.save(config, mSaveListener);
             }
         } else {
-            if (configController.isEdit() || requireKeyStore(config)) {
+            if (configController.isEdit()) {
                 mWifiManager.save(config, mSaveListener);
             } else {
                 mWifiManager.connect(config, mConnectListener);