• 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.uiflows;
17 
18 import android.app.admin.DevicePolicyManager;
19 import android.content.Intent;
20 import android.os.Bundle;
21 import android.view.View;
22 import android.widget.Button;
23 import android.widget.TextView;
24 
25 import com.android.managedprovisioning.BootReminder;
26 import com.android.managedprovisioning.ProvisionLogger;
27 import com.android.managedprovisioning.R;
28 import com.android.managedprovisioning.SetupLayoutActivity;
29 import com.android.managedprovisioning.model.ProvisioningParams;
30 import com.android.managedprovisioning.parser.MessageParser;
31 
32 /**
33  * Activity to ask for permission to activate full-filesystem encryption.
34  *
35  * Pressing 'settings' will launch settings to prompt the user to encrypt
36  * the device.
37  */
38 public class EncryptDeviceActivity extends SetupLayoutActivity {
39     private ProvisioningParams mParams;
40 
41     @Override
onCreate(Bundle savedInstanceState)42     public void onCreate(Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44 
45         mParams = (ProvisioningParams) getIntent().getParcelableExtra(
46                 ProvisioningParams.EXTRA_PROVISIONING_PARAMS);
47         if (mParams == null) {
48             ProvisionLogger.loge("Missing params in EncryptDeviceActivity activity");
49             finish();
50         }
51 
52         if (mUtils.isProfileOwnerAction(mParams.provisioningAction)) {
53             initializeUi(R.string.setup_work_profile,
54                     R.string.setup_profile_encryption,
55                     R.string.encrypt_device_text_for_profile_owner_setup);
56         } else if (mUtils.isDeviceOwnerAction(mParams.provisioningAction)) {
57             initializeUi(R.string.setup_work_device,
58                     R.string.setup_device_encryption,
59                     R.string.encrypt_device_text_for_device_owner_setup);
60         } else {
61             ProvisionLogger.loge("Unknown provisioning action: " + mParams.provisioningAction);
62             finish();
63         }
64 
65         Button encryptButton = (Button) findViewById(R.id.encrypt_button);
66         encryptButton.setOnClickListener(new View.OnClickListener() {
67                 @Override
68                 public void onClick(View v) {
69                     EncryptionController.getInstance(EncryptDeviceActivity.this)
70                             .setEncryptionReminder(mParams);
71                     // Use settings so user confirms password/pattern and its passed
72                     // to encryption tool.
73                     Intent intent = new Intent();
74                     intent.setAction(DevicePolicyManager.ACTION_START_ENCRYPTION);
75                     startActivity(intent);
76                 }
77             });
78     }
79 
initializeUi(int headerRes, int titleRes, int mainTextRes)80     private void initializeUi(int headerRes, int titleRes, int mainTextRes) {
81         initializeLayoutParams(R.layout.encrypt_device, headerRes, false);
82         setTitle(titleRes);
83         ((TextView) findViewById(R.id.encrypt_main_text)).setText(mainTextRes);
84         maybeSetLogoAndMainColor(mParams.mainColor);
85     }
86 }
87