summaryrefslogtreecommitdiffstats
path: root/src/com/android/certinstaller/CertInstallerMain.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/certinstaller/CertInstallerMain.java')
-rw-r--r--src/com/android/certinstaller/CertInstallerMain.java97
1 files changed, 62 insertions, 35 deletions
diff --git a/src/com/android/certinstaller/CertInstallerMain.java b/src/com/android/certinstaller/CertInstallerMain.java
index e184ae6..f95bb84 100644
--- a/src/com/android/certinstaller/CertInstallerMain.java
+++ b/src/com/android/certinstaller/CertInstallerMain.java
@@ -28,11 +28,14 @@ import android.security.KeyChain;
import android.util.Log;
import android.widget.Toast;
-import libcore.io.IoUtils;
-import libcore.io.Streams;
-
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import libcore.io.IoUtils;
+import libcore.io.Streams;
/**
* The main class for installing certificates to the system keystore. It reacts
@@ -46,19 +49,28 @@ public class CertInstallerMain extends PreferenceActivity {
private static final String INSTALL_CERT_AS_USER_CLASS = ".InstallCertAsUser";
- private static final String[] ACCEPT_MIME_TYPES = {
- "application/x-pkcs12",
- "application/x-x509-ca-cert",
- "application/x-x509-user-cert",
- "application/x-x509-server-cert",
- "application/x-pem-file",
- "application/pkix-cert"
- };
+ public static final String WIFI_CONFIG = "wifi-config";
+ public static final String WIFI_CONFIG_DATA = "wifi-config-data";
+ public static final String WIFI_CONFIG_FILE = "wifi-config-file";
+
+ private static Map<String,String> MIME_MAPPINGS = new HashMap<>();
+
+ static {
+ MIME_MAPPINGS.put("application/x-x509-ca-cert", KeyChain.EXTRA_CERTIFICATE);
+ MIME_MAPPINGS.put("application/x-x509-user-cert", KeyChain.EXTRA_CERTIFICATE);
+ MIME_MAPPINGS.put("application/x-x509-server-cert", KeyChain.EXTRA_CERTIFICATE);
+ MIME_MAPPINGS.put("application/x-pem-file", KeyChain.EXTRA_CERTIFICATE);
+ MIME_MAPPINGS.put("application/pkix-cert", KeyChain.EXTRA_CERTIFICATE);
+ MIME_MAPPINGS.put("application/x-pkcs12", KeyChain.EXTRA_PKCS12);
+ MIME_MAPPINGS.put("application/x-wifi-config", WIFI_CONFIG);
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ Log.d("WFII", "Created!");
+
setResult(RESULT_CANCELED);
UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
@@ -96,7 +108,7 @@ public class CertInstallerMain extends PreferenceActivity {
|| bundle.containsKey(Credentials.EXTRA_INSTALL_AS_UID)))) {
final Intent openIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
openIntent.setType("*/*");
- openIntent.putExtra(Intent.EXTRA_MIME_TYPES, ACCEPT_MIME_TYPES);
+ openIntent.putExtra(Intent.EXTRA_MIME_TYPES, MIME_MAPPINGS.keySet().toArray());
openIntent.putExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, true);
startActivityForResult(openIntent, REQUEST_OPEN_DOCUMENT);
} else {
@@ -114,38 +126,53 @@ public class CertInstallerMain extends PreferenceActivity {
mimeType = getContentResolver().getType(uri);
}
- InputStream in = null;
- try {
- in = getContentResolver().openInputStream(uri);
-
- final byte[] raw = Streams.readFully(in);
- startInstallActivity(mimeType, raw);
+ String target = MIME_MAPPINGS.get(mimeType);
+ if (target == null) {
+ throw new IllegalArgumentException("Unknown MIME type: " + mimeType);
+ }
- } catch (IOException e) {
- Log.e(TAG, "Failed to read certificate: " + e);
- Toast.makeText(this, R.string.cert_read_error, Toast.LENGTH_LONG).show();
- } finally {
- IoUtils.closeQuietly(in);
+ if (WIFI_CONFIG.equals(target)) {
+ startWifiInstallActivity(mimeType, uri);
+ }
+ else {
+ InputStream in = null;
+ try {
+ in = getContentResolver().openInputStream(uri);
+
+ final byte[] raw = Streams.readFully(in);
+ startInstallActivity(target, raw);
+
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to read certificate: " + e);
+ Toast.makeText(this, R.string.cert_read_error, Toast.LENGTH_LONG).show();
+ } finally {
+ IoUtils.closeQuietly(in);
+ }
}
}
- private void startInstallActivity(String mimeType, byte[] value) {
+ private void startInstallActivity(String target, byte[] value) {
Intent intent = new Intent(this, CertInstaller.class);
- if ("application/x-pkcs12".equals(mimeType)) {
- intent.putExtra(KeyChain.EXTRA_PKCS12, value);
- } else if ("application/x-x509-ca-cert".equals(mimeType)
- || "application/x-x509-user-cert".equals(mimeType)
- || "application/x-x509-server-cert".equals(mimeType)
- || "application/x-pem-file".equals(mimeType)
- || "application/pkix-cert".equals(mimeType)) {
- intent.putExtra(KeyChain.EXTRA_CERTIFICATE, value);
- } else {
- throw new IllegalArgumentException("Unknown MIME type: " + mimeType);
- }
+ intent.putExtra(target, value);
startActivityForResult(intent, REQUEST_INSTALL);
}
+ private void startWifiInstallActivity(String mimeType, Uri uri) {
+ Intent intent = new Intent(this, WiFiInstaller.class);
+ try (BufferedInputStream in =
+ new BufferedInputStream(getContentResolver().openInputStream(uri))) {
+ byte[] data = Streams.readFully(in);
+ intent.putExtra(WIFI_CONFIG_FILE, uri.toString());
+ intent.putExtra(WIFI_CONFIG_DATA, data);
+ intent.putExtra(WIFI_CONFIG, mimeType);
+ startActivityForResult(intent, REQUEST_INSTALL);
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to read wifi config: " + e);
+ Toast.makeText(this, R.string.cert_read_error, Toast.LENGTH_LONG).show();
+ }
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_OPEN_DOCUMENT) {