blob: 745213803267bb030e7c6c1cb9db3673603faf00 [file] [log] [blame]
Robin Lee3ab2b572014-05-06 18:39:07 +01001/*
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;
17
Rubin Xu44cdbdf2014-11-28 15:19:14 +000018import com.android.setupwizard.navigationbar.SetupWizardNavBar;
19import com.android.setupwizard.navigationbar.SetupWizardNavBar.NavigationBarListener;
Kenny Guya8781522014-05-30 16:15:01 +010020
Robin Lee3ab2b572014-05-06 18:39:07 +010021import android.app.Activity;
Kenny Guya8781522014-05-30 16:15:01 +010022import android.app.admin.DevicePolicyManager;
Robin Lee3ab2b572014-05-06 18:39:07 +010023import android.content.Intent;
Jessica Hummele3146e92014-05-21 15:09:21 +010024import android.os.Bundle;
25import android.os.ServiceManager;
Robin Lee3ab2b572014-05-06 18:39:07 +010026import android.os.storage.IMountService;
Robin Lee3ab2b572014-05-06 18:39:07 +010027import android.os.RemoteException;
Jessica Hummele3146e92014-05-21 15:09:21 +010028import android.view.View;
Sander Alewijnsea36dd992015-01-15 16:41:43 +000029import android.widget.TextView;
Robin Lee3ab2b572014-05-06 18:39:07 +010030
31/**
32 * Activity to ask for permission to activate full-filesystem encryption.
33 *
Kenny Guya0e00a52014-07-15 18:39:22 +010034 * Pressing 'settings' will launch settings to prompt the user to encrypt
35 * the device.
Robin Lee3ab2b572014-05-06 18:39:07 +010036 */
Rubin Xu44cdbdf2014-11-28 15:19:14 +000037public class EncryptDeviceActivity extends Activity implements NavigationBarListener {
Robin Lee3ab2b572014-05-06 18:39:07 +010038 protected static final String EXTRA_RESUME = "com.android.managedprovisioning.RESUME";
Sander Alewijnse28bffd62014-06-05 10:54:26 +010039 protected static final String EXTRA_RESUME_TARGET =
40 "com.android.managedprovisioning.RESUME_TARGET";
41 protected static final String TARGET_PROFILE_OWNER = "profile_owner";
42 protected static final String TARGET_DEVICE_OWNER = "device_owner";
43
Sander Alewijnsea36dd992015-01-15 16:41:43 +000044 private Bundle mResumeInfo;
45 private String mResumeTarget;
46
Robin Lee3ab2b572014-05-06 18:39:07 +010047 @Override
48 public void onCreate(Bundle savedInstanceState) {
49 super.onCreate(savedInstanceState);
50
Sander Alewijnsea36dd992015-01-15 16:41:43 +000051 mResumeInfo = getIntent().getBundleExtra(EXTRA_RESUME);
52 mResumeTarget = mResumeInfo.getString(EXTRA_RESUME_TARGET);
53
Robin Lee3ab2b572014-05-06 18:39:07 +010054 final View contentView = getLayoutInflater().inflate(R.layout.encrypt_device, null);
Robin Lee3ab2b572014-05-06 18:39:07 +010055 setContentView(contentView);
Sander Alewijnsea36dd992015-01-15 16:41:43 +000056
57 TextView titleView = (TextView) findViewById(R.id.title);
58 TextView maintextView = (TextView) findViewById(R.id.encrypt_main_text);
59 if (TARGET_PROFILE_OWNER.equals(mResumeTarget)) {
60 if (titleView != null) titleView.setText(getString(R.string.setup_work_profile));
61 if (maintextView != null) {
62 maintextView.setText(
63 getString(R.string.encrypt_device_text_for_profile_owner_setup));
64 }
65 } else if (TARGET_DEVICE_OWNER.equals(mResumeTarget)) {
66 if (titleView != null) titleView.setText(getString(R.string.setup_work_device));
67 if (maintextView != null) {
68 maintextView.setText(
69 getString(R.string.encrypt_device_text_for_device_owner_setup));
70 }
71 }
Robin Lee3ab2b572014-05-06 18:39:07 +010072 }
73
74 public static boolean isDeviceEncrypted() {
75 IMountService mountService = IMountService.Stub.asInterface(
76 ServiceManager.getService("mount"));
77
78 try {
79 return (mountService.getEncryptionState() == IMountService.ENCRYPTION_STATE_OK);
80 } catch (RemoteException e) {
81 return false;
82 }
83 }
Rubin Xu44cdbdf2014-11-28 15:19:14 +000084
85 @Override
86 public void onNavigationBarCreated(SetupWizardNavBar bar) {
87 bar.getNextButton().setText(R.string.encrypt_device_launch_settings);
88 }
89
90 @Override
91 public void onNavigateBack() {
92 onBackPressed();
93 }
94
95 @Override
96 public void onNavigateNext() {
Sander Alewijnsea36dd992015-01-15 16:41:43 +000097 BootReminder.setProvisioningReminder(EncryptDeviceActivity.this, mResumeInfo);
Rubin Xu44cdbdf2014-11-28 15:19:14 +000098 // Use settings so user confirms password/pattern and its passed
99 // to encryption tool.
100 Intent intent = new Intent();
101 intent.setAction(DevicePolicyManager.ACTION_START_ENCRYPTION);
102 startActivity(intent);
103 }
Robin Lee3ab2b572014-05-06 18:39:07 +0100104}