• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.CustomizationParams;
31 import com.android.managedprovisioning.model.ProvisioningParams;
32 
33 import com.google.android.setupdesign.GlifLayout;
34 
35 /**
36  * Activity to ask for permission to activate full-filesystem encryption.
37  *
38  * Pressing 'settings' will launch settings to prompt the user to encrypt
39  * the device.
40  */
41 public class EncryptDeviceActivity extends SetupGlifLayoutActivity {
42     private ProvisioningParams mParams;
43 
44     @Override
onCreate(Bundle savedInstanceState)45     protected void onCreate(Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47 
48         mParams = getIntent().getParcelableExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS);
49         if (mParams == null) {
50             ProvisionLogger.loge("Missing params in EncryptDeviceActivity activity");
51             getTransitionHelper().finishActivity(this);
52             return;
53         }
54 
55         if (getUtils().isProfileOwnerAction(mParams.provisioningAction)) {
56             initializeUi(R.string.setup_work_profile,
57                     R.string.setup_profile_encryption,
58                     R.string.encrypt_device_text_for_profile_owner_setup);
59         } else if (getUtils().isDeviceOwnerAction(mParams.provisioningAction)) {
60             initializeUi(R.string.setup_work_device,
61                     R.string.setup_device_encryption,
62                     R.string.encrypt_device_text_for_device_owner_setup);
63         } else {
64             ProvisionLogger.loge("Unknown provisioning action: " + mParams.provisioningAction);
65             getTransitionHelper().finishActivity(this);
66         }
67     }
68 
69     @Override
getMetricsCategory()70     protected int getMetricsCategory() {
71         return PROVISIONING_ENCRYPT_DEVICE_ACTIVITY_TIME_MS;
72     }
73 
initializeUi(int headerRes, int titleRes, int mainTextRes)74     private void initializeUi(int headerRes, int titleRes, int mainTextRes) {
75         CustomizationParams customizationParams =
76                 CustomizationParams.createInstance(mParams, this, mUtils);
77         initializeLayoutParams(R.layout.encrypt_device, headerRes, customizationParams);
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 }