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 18 import android.app.admin.DevicePolicyManager; 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.os.ServiceManager; 22 import android.os.storage.IMountService; 23 import android.os.RemoteException; 24 import android.view.View; 25 import android.widget.TextView; 26 27 /** 28 * Activity to ask for permission to activate full-filesystem encryption. 29 * 30 * Pressing 'settings' will launch settings to prompt the user to encrypt 31 * the device. 32 */ 33 public class EncryptDeviceActivity extends SetupLayoutActivity { 34 protected static final String EXTRA_RESUME = "com.android.managedprovisioning.RESUME"; 35 protected static final String EXTRA_RESUME_TARGET = 36 "com.android.managedprovisioning.RESUME_TARGET"; 37 protected static final String TARGET_PROFILE_OWNER = "profile_owner"; 38 protected static final String TARGET_DEVICE_OWNER = "device_owner"; 39 40 private Bundle mResumeInfo; 41 private String mResumeTarget; 42 43 @Override 44 public void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 47 mResumeInfo = getIntent().getBundleExtra(EXTRA_RESUME); 48 mResumeTarget = mResumeInfo.getString(EXTRA_RESUME_TARGET); 49 50 if (TARGET_PROFILE_OWNER.equals(mResumeTarget)) { 51 initializeLayoutParams(R.layout.encrypt_device, R.string.setup_work_profile, false); 52 setTitle(R.string.setup_profile_encryption); 53 ((TextView) findViewById(R.id.encrypt_main_text)).setText( 54 R.string.encrypt_device_text_for_profile_owner_setup); 55 } else if (TARGET_DEVICE_OWNER.equals(mResumeTarget)) { 56 initializeLayoutParams(R.layout.encrypt_device, R.string.setup_work_device, false); 57 setTitle(R.string.setup_device_encryption); 58 ((TextView) findViewById(R.id.encrypt_main_text)).setText( 59 R.string.encrypt_device_text_for_device_owner_setup); 60 } 61 configureNavigationButtons(R.string.encrypt_device_launch_settings, 62 View.VISIBLE, View.VISIBLE); 63 } 64 65 public static boolean isDeviceEncrypted() { 66 IMountService mountService = IMountService.Stub.asInterface( 67 ServiceManager.getService("mount")); 68 69 try { 70 return (mountService.getEncryptionState() == IMountService.ENCRYPTION_STATE_OK); 71 } catch (RemoteException e) { 72 return false; 73 } 74 } 75 76 @Override 77 public void onNavigateNext() { 78 BootReminder.setProvisioningReminder(EncryptDeviceActivity.this, mResumeInfo); 79 // Use settings so user confirms password/pattern and its passed 80 // to encryption tool. 81 Intent intent = new Intent(); 82 intent.setAction(DevicePolicyManager.ACTION_START_ENCRYPTION); 83 startActivity(intent); 84 } 85 }