summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2009-10-24 16:27:51 +0800
committerHung-ying Tyan <tyanh@google.com>2009-10-26 12:14:55 +0800
commitd674440a49f278793aa2a2bb01c231f8cea7f8c0 (patch)
tree107f9cf9d1ffd2c0e2ed7be0324abc115594e1fd
parent7b4cee910e1e755d2f0468a5f79aaa97e926a3a9 (diff)
downloadandroid_packages_apps_CertInstaller-d674440a49f278793aa2a2bb01c231f8cea7f8c0.tar.gz
android_packages_apps_CertInstaller-d674440a49f278793aa2a2bb01c231f8cea7f8c0.tar.bz2
android_packages_apps_CertInstaller-d674440a49f278793aa2a2bb01c231f8cea7f8c0.zip
Handling missing sd card in certinstaller.
http://b/issue?id=2211438
-rw-r--r--res/values-es-rUS/strings.xml1
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/com/android/certinstaller/CertFile.java10
-rw-r--r--src/com/android/certinstaller/CertFileList.java20
-rw-r--r--src/com/android/certinstaller/CertInstallerMain.java19
-rw-r--r--src/com/android/certinstaller/Util.java5
6 files changed, 42 insertions, 16 deletions
diff --git a/res/values-es-rUS/strings.xml b/res/values-es-rUS/strings.xml
index 43f7935..c239ff6 100644
--- a/res/values-es-rUS/strings.xml
+++ b/res/values-es-rUS/strings.xml
@@ -42,5 +42,4 @@
<string name="cert_too_large_error" msgid="8806716564341320607">"Se ha producido un error en la instalación. El tamaño del certificado es demasiado grande."</string>
<string name="cert_missing_error" msgid="4220080091005628628">"Se ha producido un error en la instalación. No se puede ubicar el archivo del certificado."</string>
<string name="cert_read_error" msgid="9120813657318906215">"Se ha producido un error en la instalación. No se puede leer el archivo del certificado."</string>
- <string name="no_pkcs12_found" msgid="6491877089871006521">"No se ha encontrado el archivo .p12 en la tarjeta SD."</string>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5ea6043..e95b05a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -60,5 +60,6 @@
<!-- toast message -->
<string name="cert_read_error">Installation failed. Cannot read the certificate file.</string>
- <string name="no_pkcs12_found">No .p12 file found in the SD card.</string>
+ <string name="no_cert_file_found">No certificate file found in the SD card.</string>
+ <string name="sdcard_not_present">SD card is not present.</string>
</resources>
diff --git a/src/com/android/certinstaller/CertFile.java b/src/com/android/certinstaller/CertFile.java
index ccc44b7..baeca8e 100644
--- a/src/com/android/certinstaller/CertFile.java
+++ b/src/com/android/certinstaller/CertFile.java
@@ -71,10 +71,9 @@ public class CertFile extends PreferenceActivity implements FileFilter {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_INSTALL_CODE) {
- boolean success = (resultCode == RESULT_OK);
- if (success) Util.deleteFile(mCertFile);
+ onInstallationDone((resultCode == RESULT_OK)
+ && Util.deleteFile(mCertFile));
mCertFile = null;
- onInstallationDone(success);
} else {
Log.w(TAG, "unknown request code: " + requestCode);
}
@@ -151,6 +150,11 @@ public class CertFile extends PreferenceActivity implements FileFilter {
return (path.endsWith(PKCS12_EXT) || path.endsWith(CERT_EXT));
}
+ protected boolean isSdCardPresent() {
+ return Environment.getExternalStorageState().equals(
+ Environment.MEDIA_MOUNTED);
+ }
+
private void install(String fileName, byte[] value) {
Intent intent = new Intent(this, CertInstaller.class);
intent.putExtra(CredentialHelper.CERT_NAME_KEY, fileName);
diff --git a/src/com/android/certinstaller/CertFileList.java b/src/com/android/certinstaller/CertFileList.java
index 3d6a180..bd7767f 100644
--- a/src/com/android/certinstaller/CertFileList.java
+++ b/src/com/android/certinstaller/CertFileList.java
@@ -58,8 +58,16 @@ public class CertFileList extends CertFile
}
@Override
- protected void onInstallationDone(boolean success) {
- if (!success) setAllFilesEnabled(true);
+ protected void onInstallationDone(boolean fileDeleted) {
+ if (!fileDeleted) {
+ if (isSdCardPresent()) {
+ setAllFilesEnabled(true);
+ } else {
+ Toast.makeText(this, R.string.sdcard_not_present,
+ Toast.LENGTH_SHORT).show();
+ finish();
+ }
+ }
}
@Override
@@ -90,14 +98,20 @@ public class CertFileList extends CertFile
if (isFinishing()) {
Log.d(TAG, "finishing, exit createFileList()");
return;
+ } else if (!isSdCardPresent()) {
+ Toast.makeText(this, R.string.sdcard_not_present,
+ Toast.LENGTH_SHORT).show();
+ finish();
+ return;
}
+
try {
PreferenceScreen root = getPreferenceScreen();
root.removeAll();
List<File> allFiles = getAllCertFiles();
if (allFiles.isEmpty()) {
- Toast.makeText(this, R.string.no_pkcs12_found,
+ Toast.makeText(this, R.string.no_cert_file_found,
Toast.LENGTH_SHORT).show();
} else {
int prefixEnd = Environment.getExternalStorageDirectory()
diff --git a/src/com/android/certinstaller/CertInstallerMain.java b/src/com/android/certinstaller/CertInstallerMain.java
index 17d1a09..a24843a 100644
--- a/src/com/android/certinstaller/CertInstallerMain.java
+++ b/src/com/android/certinstaller/CertInstallerMain.java
@@ -52,15 +52,20 @@ public class CertInstallerMain extends CertFile implements Runnable {
Bundle bundle = intent.getExtras();
if ((bundle == null) || bundle.isEmpty()) {
- List<File> allFiles = getAllCertFiles();
- if (allFiles.isEmpty()) {
- Toast.makeText(this, R.string.no_pkcs12_found,
+ if (!isSdCardPresent()) {
+ Toast.makeText(this, R.string.sdcard_not_present,
Toast.LENGTH_SHORT).show();
- } else if (allFiles.size() == 1) {
- installFromFile(allFiles.get(0));
- return;
} else {
- startActivity(new Intent(this, CertFileList.class));
+ List<File> allFiles = getAllCertFiles();
+ if (allFiles.isEmpty()) {
+ Toast.makeText(this, R.string.no_cert_file_found,
+ Toast.LENGTH_SHORT).show();
+ } else if (allFiles.size() == 1) {
+ installFromFile(allFiles.get(0));
+ return;
+ } else {
+ startActivity(new Intent(this, CertFileList.class));
+ }
}
} else {
Intent newIntent = new Intent(this, CertInstaller.class);
diff --git a/src/com/android/certinstaller/Util.java b/src/com/android/certinstaller/Util.java
index 0db177c..61b4a19 100644
--- a/src/com/android/certinstaller/Util.java
+++ b/src/com/android/certinstaller/Util.java
@@ -90,9 +90,12 @@ class Util {
}
}
- static void deleteFile(File file) {
+ static boolean deleteFile(File file) {
if ((file != null) && !file.delete()) {
Log.w(TAG, "cannot delete cert: " + file);
+ return false;
+ } else {
+ return true;
}
}