Home | History | Annotate | Download | only in managedprovisioning
      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 com.android.internal.widget.LockPatternUtils;
     19 
     20 import android.app.Activity;
     21 import android.app.admin.DevicePolicyManager;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.os.ServiceManager;
     26 import android.os.storage.IMountService;
     27 import android.os.RemoteException;
     28 import android.view.View;
     29 import android.widget.Button;
     30 
     31 /**
     32  * Activity to ask for permission to activate full-filesystem encryption.
     33  *
     34  * Pressing 'settings' will launch settings to prompt the user to encrypt
     35  * the device.
     36  */
     37 public class EncryptDeviceActivity extends Activity {
     38     protected static final String EXTRA_RESUME = "com.android.managedprovisioning.RESUME";
     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 
     44     private Button mCancelButton;
     45     private Button mEncryptButton;
     46 
     47     @Override
     48     public void onCreate(Bundle savedInstanceState) {
     49         super.onCreate(savedInstanceState);
     50 
     51         final View contentView = getLayoutInflater().inflate(R.layout.encrypt_device, null);
     52         mEncryptButton = (Button) contentView.findViewById(R.id.accept_button);
     53         mCancelButton = (Button) contentView.findViewById(R.id.cancel_button);
     54         setContentView(contentView);
     55         mEncryptButton.setOnClickListener(new View.OnClickListener() {
     56             @Override
     57             public void onClick(View v) {
     58                 final Bundle resumeInfo = getIntent().getBundleExtra(EXTRA_RESUME);
     59                 BootReminder.setProvisioningReminder(EncryptDeviceActivity.this, resumeInfo);
     60                 // Use settings so user confirms password/pattern and its passed
     61                 // to encryption tool.
     62                 Intent intent = new Intent();
     63                 intent.setAction(DevicePolicyManager.ACTION_START_ENCRYPTION);
     64                 startActivity(intent);
     65             }
     66         });
     67 
     68         mCancelButton.setOnClickListener(new View.OnClickListener() {
     69             @Override
     70             public void onClick(View v) {
     71                 finish();
     72             }
     73         });
     74     }
     75 
     76     public static boolean isDeviceEncrypted() {
     77         IMountService mountService = IMountService.Stub.asInterface(
     78                 ServiceManager.getService("mount"));
     79 
     80         try {
     81             return (mountService.getEncryptionState() == IMountService.ENCRYPTION_STATE_OK);
     82         } catch (RemoteException e) {
     83             return false;
     84         }
     85     }
     86 }
     87