Example usage for android.app.admin DevicePolicyManager installCaCert

List of usage examples for android.app.admin DevicePolicyManager installCaCert

Introduction

In this page you can find the example usage for android.app.admin DevicePolicyManager installCaCert.

Prototype

public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) 

Source Link

Document

Installs the given certificate as a user CA.

Usage

From source file:com.afwsamples.testdpc.common.Util.java

/**
 * @return If the certificate was successfully installed.
 */// w w  w  . j  a  v a  2 s.  c  o  m
public static boolean installCaCertificate(InputStream certificateInputStream, DevicePolicyManager dpm,
        ComponentName admin) {
    try {
        if (certificateInputStream != null) {
            ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
            int len = 0;
            while ((len = certificateInputStream.read(buffer)) > 0) {
                byteBuffer.write(buffer, 0, len);
            }
            return dpm.installCaCert(admin, byteBuffer.toByteArray());
        }
    } catch (IOException e) {
        Log.e(TAG, "installCaCertificate: ", e);
    }
    return false;
}