@@ -1708,7 +1708,7 @@ public boolean getStorageEncryption(ComponentName admin) {
17081708 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
17091709 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
17101710 *
1711- * @return current status of encryption. The value will be one of
1711+ * @return current status of encryption. The value will be one of
17121712 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
17131713 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
17141714 */
@@ -1729,15 +1729,18 @@ public int getStorageEncryptionStatus(int userHandle) {
17291729 }
17301730
17311731 /**
1732- * Installs the given certificate as a User CA.
1732+ * Installs the given certificate as a user CA.
1733+ *
1734+ * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1735+ * @param certBuffer encoded form of the certificate to install.
17331736 *
17341737 * @return false if the certBuffer cannot be parsed or installation is
1735- * interrupted, otherwise true
1738+ * interrupted, true otherwise.
17361739 */
1737- public boolean installCaCert (ComponentName who , byte [] certBuffer ) {
1740+ public boolean installCaCert (ComponentName admin , byte [] certBuffer ) {
17381741 if (mService != null ) {
17391742 try {
1740- return mService .installCaCert (who , certBuffer );
1743+ return mService .installCaCert (admin , certBuffer );
17411744 } catch (RemoteException e ) {
17421745 Log .w (TAG , "Failed talking with device policy service" , e );
17431746 }
@@ -1746,13 +1749,16 @@ public boolean installCaCert(ComponentName who, byte[] certBuffer) {
17461749 }
17471750
17481751 /**
1749- * Uninstalls the given certificate from the list of User CAs, if present.
1752+ * Uninstalls the given certificate from trusted user CAs, if present.
1753+ *
1754+ * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1755+ * @param certBuffer encoded form of the certificate to remove.
17501756 */
1751- public void uninstallCaCert (ComponentName who , byte [] certBuffer ) {
1757+ public void uninstallCaCert (ComponentName admin , byte [] certBuffer ) {
17521758 if (mService != null ) {
17531759 try {
17541760 final String alias = getCaCertAlias (certBuffer );
1755- mService .uninstallCaCert (who , alias );
1761+ mService .uninstallCaCert (admin , alias );
17561762 } catch (CertificateException e ) {
17571763 Log .w (TAG , "Unable to parse certificate" , e );
17581764 } catch (RemoteException e ) {
@@ -1762,16 +1768,47 @@ public void uninstallCaCert(ComponentName who, byte[] certBuffer) {
17621768 }
17631769
17641770 /**
1765- * Returns whether there are any user-installed CA certificates.
1771+ * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1772+ * If a user has installed any certificates by other means than device policy these will be
1773+ * included too.
1774+ *
1775+ * @return a List of byte[] arrays, each encoding one user CA certificate.
17661776 */
1767- public boolean hasAnyCaCertsInstalled () {
1768- TrustedCertificateStore certStore = new TrustedCertificateStore ();
1769- Set <String > aliases = certStore .userAliases ();
1770- return aliases != null && !aliases .isEmpty ();
1777+ public List <byte []> getInstalledCaCerts () {
1778+ final TrustedCertificateStore certStore = new TrustedCertificateStore ();
1779+ List <byte []> certs = new ArrayList <byte []>();
1780+ for (String alias : certStore .userAliases ()) {
1781+ try {
1782+ certs .add (certStore .getCertificate (alias ).getEncoded ());
1783+ } catch (CertificateException ce ) {
1784+ Log .w (TAG , "Could not encode certificate: " + alias , ce );
1785+ }
1786+ }
1787+ return certs ;
17711788 }
17721789
17731790 /**
1774- * Returns whether this certificate has been installed as a User CA.
1791+ * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1792+ * means other than device policy will also be removed, except for system CA certificates.
1793+ *
1794+ * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1795+ */
1796+ public void uninstallAllUserCaCerts (ComponentName admin ) {
1797+ if (mService != null ) {
1798+ for (String alias : new TrustedCertificateStore ().userAliases ()) {
1799+ try {
1800+ mService .uninstallCaCert (admin , alias );
1801+ } catch (RemoteException re ) {
1802+ Log .w (TAG , "Failed talking with device policy service" , re );
1803+ }
1804+ }
1805+ }
1806+ }
1807+
1808+ /**
1809+ * Returns whether this certificate is installed as a trusted CA.
1810+ *
1811+ * @param certBuffer encoded form of the certificate to look up.
17751812 */
17761813 public boolean hasCaCertInstalled (byte [] certBuffer ) {
17771814 try {
0 commit comments