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 */
16package com.android.managedprovisioning.preprovisioning;
17
18import static android.app.admin.DevicePolicyManager.ACTION_START_ENCRYPTION;
19
20import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.PROVISIONING_ENCRYPT_DEVICE_ACTIVITY_TIME_MS;
21
22import android.content.Intent;
23import android.os.Bundle;
24import android.view.View;
25import android.widget.Button;
26import android.widget.TextView;
27
28import com.android.managedprovisioning.R;
29import com.android.managedprovisioning.common.ProvisionLogger;
30import com.android.managedprovisioning.common.SetupGlifLayoutActivity;
31import com.android.managedprovisioning.model.CustomizationParams;
32import 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 */
40public class EncryptDeviceActivity extends SetupGlifLayoutActivity {
41    private ProvisioningParams mParams;
42
43    protected EncryptionController getEncryptionController() {
44        return EncryptionController.getInstance(this);
45    }
46
47    @Override
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
82    protected int getMetricsCategory() {
83        return PROVISIONING_ENCRYPT_DEVICE_ACTIVITY_TIME_MS;
84    }
85
86    private void initializeUi(int headerRes, int titleRes, int mainTextRes) {
87        CustomizationParams customizationParams =
88                CustomizationParams.createInstance(mParams, this, mUtils);
89        initializeLayoutParams(R.layout.encrypt_device, headerRes, customizationParams.mainColor,
90                customizationParams.statusBarColor);
91        setTitle(titleRes);
92        ((TextView) findViewById(R.id.encrypt_main_text)).setText(mainTextRes);
93    }
94}