Clean <plurals> in CertificateMonitor
Bug: 199230228 Test: make Change-Id: I2b9ff69c1d14f134c94191a89a155b5a872dbc73
This commit is contained in:
@@ -463,10 +463,11 @@
|
||||
<!-- SSL CA cert notification --> <skip />
|
||||
<!-- Shows up when there is a user SSL CA Cert installed on the
|
||||
device. Indicates to the user that SSL traffic can be intercepted. [CHAR LIMIT=NONE] -->
|
||||
<plurals name="ssl_ca_cert_warning">
|
||||
<item quantity="one">Certificate authority installed</item>
|
||||
<item quantity="other">Certificate authorities installed</item>
|
||||
</plurals>
|
||||
<string name="ssl_ca_cert_warning">{count, plural,
|
||||
=1 {Certificate authority installed}
|
||||
other {Certificate authorities installed}
|
||||
}
|
||||
</string>
|
||||
<!-- Content text for a notification. The Title of the notification is "ssl_ca_cert_warning".
|
||||
This says that an unknown party is doing the monitoring. [CHAR LIMIT=100]-->
|
||||
<string name="ssl_ca_cert_noti_by_unknown">By an unknown third party</string>
|
||||
|
||||
@@ -1266,7 +1266,7 @@
|
||||
<java-symbol type="string" name="file_count" />
|
||||
<java-symbol type="string" name="matches_found" />
|
||||
<java-symbol type="plurals" name="pinpuk_attempts" />
|
||||
<java-symbol type="plurals" name="ssl_ca_cert_warning" />
|
||||
<java-symbol type="string" name="ssl_ca_cert_warning" />
|
||||
|
||||
<java-symbol type="array" name="carrier_properties" />
|
||||
<java-symbol type="array" name="config_sms_enabled_locking_shift_tables" />
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.provider.Settings;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyChain;
|
||||
import android.security.KeyChain.KeyChainConnection;
|
||||
import android.util.PluralsMessageFormatter;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
|
||||
@@ -46,7 +47,9 @@ import java.io.IOException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CertificateMonitor {
|
||||
protected static final int MONITORING_CERT_NOTIFICATION_ID = SystemMessage.NOTE_SSL_CERT_INFO;
|
||||
@@ -212,10 +215,15 @@ public class CertificateMonitor {
|
||||
dialogIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE,
|
||||
null, UserHandle.of(parentUserId));
|
||||
|
||||
Map<String, Object> arguments = new HashMap<>();
|
||||
arguments.put("count", pendingCertificateCount);
|
||||
|
||||
return new Notification.Builder(userContext, SystemNotificationChannels.SECURITY)
|
||||
.setSmallIcon(smallIconId)
|
||||
.setContentTitle(resources.getQuantityText(R.plurals.ssl_ca_cert_warning,
|
||||
pendingCertificateCount))
|
||||
.setContentTitle(PluralsMessageFormatter.format(
|
||||
resources,
|
||||
arguments,
|
||||
R.string.ssl_ca_cert_warning))
|
||||
.setContentText(contentText)
|
||||
.setContentIntent(notifyIntent)
|
||||
.setShowWhen(false)
|
||||
|
||||
@@ -273,6 +273,14 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
mIsAutomotive = mContext.getPackageManager()
|
||||
.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
|
||||
|
||||
final String TEST_STRING = "{count, plural,\n"
|
||||
+ " =1 {Test for exactly 1 cert out of 4}\n"
|
||||
+ " other {Test for exactly # certs out of 4}\n"
|
||||
+ "}";
|
||||
doReturn(TEST_STRING)
|
||||
.when(mContext.resources)
|
||||
.getString(R.string.ssl_ca_cert_warning);
|
||||
}
|
||||
|
||||
private TransferOwnershipMetadataManager getMockTransferMetadataManager() {
|
||||
@@ -1767,9 +1775,6 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
StringParceledListSlice oneCert = asSlice(new String[] {"1"});
|
||||
StringParceledListSlice fourCerts = asSlice(new String[] {"1", "2", "3", "4"});
|
||||
|
||||
final String TEST_STRING = "Test for exactly 2 certs out of 4";
|
||||
doReturn(TEST_STRING).when(mContext.resources).getQuantityText(anyInt(), eq(2));
|
||||
|
||||
// Given that we have exactly one certificate installed,
|
||||
when(getServices().keyChainConnection.getService().getUserCaAliases()).thenReturn(oneCert);
|
||||
// when that certificate is approved,
|
||||
@@ -1785,9 +1790,10 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
dpms.approveCaCert(fourCerts.getList().get(0), userId, true);
|
||||
dpms.approveCaCert(fourCerts.getList().get(1), userId, true);
|
||||
// a notification should be shown saying that there are two certificates left to approve.
|
||||
final String TEST_STRING_RESULT = "Test for exactly 2 certs out of 4";
|
||||
verify(getServices().notificationManager, timeout(1000))
|
||||
.notifyAsUser(anyString(), anyInt(), argThat(hasExtra(EXTRA_TITLE,
|
||||
TEST_STRING
|
||||
TEST_STRING_RESULT
|
||||
)), eq(user));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user