Update CertInstaller message to include app name.
Bug: 159324357
Test: local with CtsVerifier
Change-Id: I5a0103bcd652908080148e5dd3752aa453b6369c
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c80a628..7cf78ce 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -60,10 +60,15 @@
<!-- Title of dialog to select the certificate usage when installing a certificate outside Settings -->
<string name="select_certificate_usage_title">Choose a certificate type</string>
- <!-- Title of dialog to redirect user when installing a CA certificate outside Settings -->
- <string name="redirect_ca_certificate_title">Can\'t install CA certificates</string>
- <!-- Message of dialog to redirect user when installing a CA certificate outside Settings -->
- <string name="redirect_ca_certificate_message">CA certificates can put your privacy at risk and must be installed in Settings</string>
+ <!-- Title of dialog that lets the user know that they must install CA certificates
+ in Settings. -->
+ <string name="redirect_ca_certificate_title">Install CA certificates in Settings</string>
+ <!-- Message of dialog that lets the user know that they must install CA certificates in
+ Settings. The placeholder is the name of the app that was trying to install the CA
+ certificate. -->
+ <string name="redirect_ca_certificate_with_app_info_message">This certificate from
+ <xliff:g id="requesting_app" example="Some App">%1$s</xliff:g> must be installed in
+ Settings. Only install CA certificates from organizations you trust.</string>
<!-- Button of dialog to redirect user when installing a CA certificate outside Settings -->
<string name="redirect_ca_certificate_close_button">Close</string>
<!-- Title of dialog to inform user that certificate selected is invalid -->
diff --git a/src/com/android/certinstaller/CertInstaller.java b/src/com/android/certinstaller/CertInstaller.java
index 4302965..3a6b7b3 100644
--- a/src/com/android/certinstaller/CertInstaller.java
+++ b/src/com/android/certinstaller/CertInstaller.java
@@ -25,6 +25,8 @@
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.security.Credentials;
@@ -345,10 +347,31 @@
}
}
+ public CharSequence getCallingAppLabel() {
+ final String callingPkg = mCredentials.getReferrer();
+ if (callingPkg == null) {
+ Log.e(TAG, "Cannot get calling calling AppPackage");
+ return null;
+ }
+
+ final PackageManager pm = getPackageManager();
+ final ApplicationInfo appInfo;
+ try {
+ appInfo = pm.getApplicationInfo(callingPkg, PackageManager.MATCH_DISABLED_COMPONENTS);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Unable to find info for package: " + callingPkg);
+ return null;
+ }
+
+ return appInfo.loadLabel(pm);
+ }
+
private Dialog createRedirectCaCertificateDialog() {
+ final String message = getString(
+ R.string.redirect_ca_certificate_with_app_info_message, getCallingAppLabel());
Dialog d = new AlertDialog.Builder(this)
.setTitle(R.string.redirect_ca_certificate_title)
- .setMessage(R.string.redirect_ca_certificate_message)
+ .setMessage(message)
.setPositiveButton(R.string.redirect_ca_certificate_close_button,
(dialog, id) -> toastErrorAndFinish(R.string.cert_not_saved))
.create();
diff --git a/src/com/android/certinstaller/CredentialHelper.java b/src/com/android/certinstaller/CredentialHelper.java
index 4350d04..a1e9314 100644
--- a/src/com/android/certinstaller/CredentialHelper.java
+++ b/src/com/android/certinstaller/CredentialHelper.java
@@ -471,4 +471,8 @@
return true;
}
}
+
+ public String getReferrer() {
+ return mReferrer;
+ }
}