1 /* 2 * Copyright 2014, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.managedprovisioning.preprovisioning; 17 18 import static android.app.admin.DevicePolicyManager.ACTION_START_ENCRYPTION; 19 20 import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.PROVISIONING_ENCRYPT_DEVICE_ACTIVITY_TIME_MS; 21 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.view.View; 25 import android.widget.Button; 26 import android.widget.TextView; 27 28 import com.android.managedprovisioning.R; 29 import com.android.managedprovisioning.common.ProvisionLogger; 30 import com.android.managedprovisioning.common.SetupGlifLayoutActivity; 31 import com.android.managedprovisioning.model.CustomizationParams; 32 import com.android.managedprovisioning.model.ProvisioningParams; 33 34 /** 35 * Activity to ask for permission to activate full-filesystem encryption. 36 * 37 * Pressing 'settings' will launch settings to prompt the user to encrypt 38 * the device. 39 */ 40 public class EncryptDeviceActivity extends SetupGlifLayoutActivity { 41 private ProvisioningParams mParams; 42 getEncryptionController()43 protected EncryptionController getEncryptionController() { 44 return EncryptionController.getInstance(this); 45 } 46 47 @Override onCreate(Bundle savedInstanceState)48 protected void onCreate(Bundle savedInstanceState) { 49 super.onCreate(savedInstanceState); 50 51 mParams = getIntent().getParcelableExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS); 52 if (mParams == null) { 53 ProvisionLogger.loge("Missing params in EncryptDeviceActivity activity"); 54 finish(); 55 return; 56 } 57 58 if (getUtils().isProfileOwnerAction(mParams.provisioningAction)) { 59 initializeUi(R.string.setup_work_profile, 60 R.string.setup_profile_encryption, 61 R.string.encrypt_device_text_for_profile_owner_setup); 62 } else if (getUtils().isDeviceOwnerAction(mParams.provisioningAction)) { 63 initializeUi(R.string.setup_work_device, 64 R.string.setup_device_encryption, 65 R.string.encrypt_device_text_for_device_owner_setup); 66 } else { 67 ProvisionLogger.loge("Unknown provisioning action: " + mParams.provisioningAction); 68 finish(); 69 return; 70 } 71 72 Button encryptButton = (Button) findViewById(R.id.encrypt_button); 73 encryptButton.setOnClickListener((View v) -> { 74 getEncryptionController().setEncryptionReminder(mParams); 75 // Use settings so user confirms password/pattern and its passed 76 // to encryption tool. 77 startActivity(new Intent(ACTION_START_ENCRYPTION)); 78 }); 79 } 80 81 @Override getMetricsCategory()82 protected int getMetricsCategory() { 83 return PROVISIONING_ENCRYPT_DEVICE_ACTIVITY_TIME_MS; 84 } 85 initializeUi(int headerRes, int titleRes, int mainTextRes)86 private void initializeUi(int headerRes, int titleRes, int mainTextRes) { 87 initializeLayoutParams(R.layout.encrypt_device, headerRes, false, 88 CustomizationParams.createInstance(mParams, this, mUtils).statusBarColor); 89 setTitle(titleRes); 90 ((TextView) findViewById(R.id.encrypt_main_text)).setText(mainTextRes); 91 } 92 }