blob: be46a6e282999918f4696ef0ec6ec4a0366024d6 [file] [log] [blame]
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.cts.verifier.managedprovisioning;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
/**
* A helper activity that executes commands sent from CtsVerifier in the primary user to the managed
* profile in COMP mode.
*
* Note: We have to use a dummy activity because cross-profile intents only work for activities.
*/
public class CompHelperActivity extends Activity {
public static final String TAG = "CompHelperActivity";
// Set always-on VPN.
public static final String ACTION_SET_ALWAYS_ON_VPN
= "com.android.cts.verifier.managedprovisioning.COMP_SET_ALWAYS_ON_VPN";
// Install trusted CA cert.
public static final String ACTION_INSTALL_CA_CERT
= "com.android.cts.verifier.managedprovisioning.COMP_INSTALL_CA_CERT";
// Set the number of login failures after which the managed profile is wiped.
public static final String ACTION_SET_MAXIMUM_PASSWORD_ATTEMPTS
= "com.android.cts.verifier.managedprovisioning.COMP_SET_MAXIMUM_PASSWORD_ATTEMPTS";
/*
* The CA cert below is the content of cacert.pem as generated by:
*
* openssl req -new -x509 -days 3650 -extensions v3_ca -keyout cakey.pem -out cacert.pem
*/
private static final String TEST_CA =
"-----BEGIN CERTIFICATE-----\n" +
"MIIDXTCCAkWgAwIBAgIJAK9Tl/F9V8kSMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n" +
"BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n" +
"aWRnaXRzIFB0eSBMdGQwHhcNMTUwMzA2MTczMjEx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6rbP0\n" +
"wQ==\n" +
"-----END CERTIFICATE-----";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ComponentName admin = CompDeviceAdminTestReceiver.getReceiverComponentName();
final DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(
Context.DEVICE_POLICY_SERVICE);
final String action = getIntent().getAction();
if (ACTION_SET_ALWAYS_ON_VPN.equals(action)) {
try {
dpm.setAlwaysOnVpnPackage(admin, getPackageName(), false /* lockdownEnabled */);
} catch (Exception e) {
Log.e(TAG, "Unable to set always-on VPN", e);
}
} else if (ACTION_INSTALL_CA_CERT.equals(action)) {
dpm.installCaCert(admin, TEST_CA.getBytes());
} else if (ACTION_SET_MAXIMUM_PASSWORD_ATTEMPTS.equals(action)) {
dpm.setMaximumFailedPasswordsForWipe(admin, 100);
}
finish();
}
}