Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 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; |
| 17 | |
Rubin Xu | 44cdbdf | 2014-11-28 15:19:14 +0000 | [diff] [blame] | 18 | import com.android.setupwizard.navigationbar.SetupWizardNavBar; |
| 19 | import com.android.setupwizard.navigationbar.SetupWizardNavBar.NavigationBarListener; |
Kenny Guy | a878152 | 2014-05-30 16:15:01 +0100 | [diff] [blame] | 20 | |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 21 | import android.app.Activity; |
Kenny Guy | a878152 | 2014-05-30 16:15:01 +0100 | [diff] [blame] | 22 | import android.app.admin.DevicePolicyManager; |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 23 | import android.content.Intent; |
Jessica Hummel | e3146e9 | 2014-05-21 15:09:21 +0100 | [diff] [blame] | 24 | import android.os.Bundle; |
| 25 | import android.os.ServiceManager; |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 26 | import android.os.storage.IMountService; |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 27 | import android.os.RemoteException; |
Jessica Hummel | e3146e9 | 2014-05-21 15:09:21 +0100 | [diff] [blame] | 28 | import android.view.View; |
Sander Alewijnse | a36dd99 | 2015-01-15 16:41:43 +0000 | [diff] [blame] | 29 | import android.widget.TextView; |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Activity to ask for permission to activate full-filesystem encryption. |
| 33 | * |
Kenny Guy | a0e00a5 | 2014-07-15 18:39:22 +0100 | [diff] [blame] | 34 | * Pressing 'settings' will launch settings to prompt the user to encrypt |
| 35 | * the device. |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 36 | */ |
Rubin Xu | 44cdbdf | 2014-11-28 15:19:14 +0000 | [diff] [blame] | 37 | public class EncryptDeviceActivity extends Activity implements NavigationBarListener { |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 38 | protected static final String EXTRA_RESUME = "com.android.managedprovisioning.RESUME"; |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 39 | 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 Alewijnse | a36dd99 | 2015-01-15 16:41:43 +0000 | [diff] [blame] | 44 | private Bundle mResumeInfo; |
| 45 | private String mResumeTarget; |
| 46 | |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 47 | @Override |
| 48 | public void onCreate(Bundle savedInstanceState) { |
| 49 | super.onCreate(savedInstanceState); |
| 50 | |
Sander Alewijnse | a36dd99 | 2015-01-15 16:41:43 +0000 | [diff] [blame] | 51 | mResumeInfo = getIntent().getBundleExtra(EXTRA_RESUME); |
| 52 | mResumeTarget = mResumeInfo.getString(EXTRA_RESUME_TARGET); |
| 53 | |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 54 | final View contentView = getLayoutInflater().inflate(R.layout.encrypt_device, null); |
Robin Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 55 | setContentView(contentView); |
Sander Alewijnse | a36dd99 | 2015-01-15 16:41:43 +0000 | [diff] [blame] | 56 | |
| 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 Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 72 | } |
| 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 Xu | 44cdbdf | 2014-11-28 15:19:14 +0000 | [diff] [blame] | 84 | |
| 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 Alewijnse | a36dd99 | 2015-01-15 16:41:43 +0000 | [diff] [blame] | 97 | BootReminder.setProvisioningReminder(EncryptDeviceActivity.this, mResumeInfo); |
Rubin Xu | 44cdbdf | 2014-11-28 15:19:14 +0000 | [diff] [blame] | 98 | // 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 Lee | 3ab2b57 | 2014-05-06 18:39:07 +0100 | [diff] [blame] | 104 | } |