summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorBen Komalo <benkomalo@google.com>2011-07-21 15:04:27 -0700
committerBen Komalo <benkomalo@google.com>2011-08-16 14:39:23 -0700
commitc1615f66f7dbe5a76aefca862d96e0b5a6e123ff (patch)
tree5235d2f2f744be411f382d916b2a2ec9456b6658 /src/com/android
parent8a306cbc86ff63074d0c53593f1eb89fb8478a05 (diff)
downloadandroid_packages_apps_CertInstaller-c1615f66f7dbe5a76aefca862d96e0b5a6e123ff.tar.gz
android_packages_apps_CertInstaller-c1615f66f7dbe5a76aefca862d96e0b5a6e123ff.tar.bz2
android_packages_apps_CertInstaller-c1615f66f7dbe5a76aefca862d96e0b5a6e123ff.zip
Handle VIEW intents for cert installer
Bug: 4556536 Change-Id: I1d3b8e4b80415e2df9dfe334f0d9e195ab0e19ff
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/certinstaller/CertInstallerMain.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/com/android/certinstaller/CertInstallerMain.java b/src/com/android/certinstaller/CertInstallerMain.java
index 86be52a..02bcc66 100644
--- a/src/com/android/certinstaller/CertInstallerMain.java
+++ b/src/com/android/certinstaller/CertInstallerMain.java
@@ -17,13 +17,21 @@
package com.android.certinstaller;
import android.content.Intent;
+import android.net.Uri;
import android.os.Bundle;
import android.security.Credentials;
+import android.security.KeyChain;
+import android.util.Log;
import android.widget.Toast;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
+import libcore.io.IoUtils;
+
/**
* The main class for installing certificates to the system keystore. It reacts
* to the public {@link Credentials#INSTALL_ACTION} intent.
@@ -79,10 +87,50 @@ public class CertInstallerMain extends CertFile implements Runnable {
startActivityForResult(newIntent, REQUEST_INSTALL_CODE);
return;
}
+ } else if (Intent.ACTION_VIEW.equals(action)) {
+ Uri data = intent.getData();
+ String type = intent.getType();
+ if ((data != null) && (type != null)) {
+ byte[] payload = null;
+ InputStream is = null;
+ try {
+ is = getContentResolver().openInputStream(data);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int read = 0;
+ while ((read = is.read(buffer)) > 0) {
+ out.write(buffer, 0, read);
+ }
+ out.flush();
+ payload = out.toByteArray();
+ } catch (IOException ignored) {
+ // Not much we can do - it will be logged below as an error.
+ } finally {
+ IoUtils.closeQuietly(is);
+ }
+ if (payload == null) {
+ Log.e("CertInstaller", "Unable to read stream for for certificate");
+ } else {
+ installByType(type, payload);
+ }
+ }
}
finish();
}
+ private void installByType(String type, byte[] value) {
+ Intent intent = new Intent(this, CertInstaller.class);
+ if ("application/x-pkcs12".equals(type)) {
+ intent.putExtra(KeyChain.EXTRA_PKCS12, value);
+ } else if ("application/x-x509-ca-cert".equals(type)
+ || "application/x-x509-user-cert".equals(type)) {
+ intent.putExtra(KeyChain.EXTRA_CERTIFICATE, value);
+ } else {
+ throw new AssertionError("Unknown type: " + type);
+ }
+ startActivityForResult(intent, REQUEST_INSTALL_CODE);
+ }
+
@Override
protected void onInstallationDone(boolean success) {
super.onInstallationDone(success);