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 26 import com.android.managedprovisioning.R; 27 import com.android.managedprovisioning.common.ProvisionLogger; 28 import com.android.managedprovisioning.common.SetupGlifLayoutActivity; 29 import com.android.managedprovisioning.common.Utils; 30 import com.android.managedprovisioning.model.ProvisioningParams; 31 32 import com.google.android.setupdesign.GlifLayout; 33 import com.google.android.setupdesign.util.DeviceHelper; 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 43 @Override onCreate(Bundle savedInstanceState)44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 47 mParams = getIntent().getParcelableExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS); 48 if (mParams == null) { 49 ProvisionLogger.loge("Missing params in EncryptDeviceActivity activity"); 50 getTransitionHelper().finishActivity(this); 51 return; 52 } 53 54 CharSequence deviceName = DeviceHelper.getDeviceName(getApplicationContext()); 55 if (getUtils().isProfileOwnerAction(mParams.provisioningAction)) { 56 initializeUi( 57 R.string.setup_work_profile, 58 getString(R.string.setup_profile_encryption), 59 getString(R.string.encrypt_device_text_for_profile_owner_setup, deviceName)); 60 } else if (getUtils().isDeviceOwnerAction(mParams.provisioningAction)) { 61 initializeUi( 62 R.string.setup_work_device, 63 getString(R.string.setup_device_encryption, deviceName), 64 getString(R.string.encrypt_device_text_for_device_owner_setup, deviceName)); 65 } else { 66 ProvisionLogger.loge("Unknown provisioning action: " + mParams.provisioningAction); 67 getTransitionHelper().finishActivity(this); 68 } 69 } 70 71 @Override getMetricsCategory()72 protected int getMetricsCategory() { 73 return PROVISIONING_ENCRYPT_DEVICE_ACTIVITY_TIME_MS; 74 } 75 initializeUi(int headerRes, String titleRes, String mainTextRes)76 private void initializeUi(int headerRes, String titleRes, String mainTextRes) { 77 initializeLayoutParams(R.layout.encrypt_device, headerRes); 78 setTitle(titleRes); 79 GlifLayout layout = findViewById(R.id.setup_wizard_layout); 80 layout.setDescriptionText(mainTextRes); 81 Utils.addEncryptButton(layout, (View view) -> { 82 getEncryptionController().setEncryptionReminder(mParams); 83 // Use settings so user confirms password/pattern and its passed 84 // to encryption tool. 85 getTransitionHelper().startActivityWithTransition( 86 EncryptDeviceActivity.this, new Intent(ACTION_START_ENCRYPTION)); 87 }); 88 } 89 } 90