CryptKeeperConfirm.java revision 13d62049f7c96c47356f23eaee7f0997612fdf9f
1/* 2 * Copyright (C) 2011 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 17package com.android.settings; 18 19import android.app.Activity; 20import android.app.Fragment; 21import android.app.StatusBarManager; 22import android.content.Context; 23import android.content.Intent; 24import android.os.Bundle; 25import android.os.Handler; 26import android.os.IBinder; 27import android.os.ServiceManager; 28import android.os.storage.IMountService; 29import android.util.Log; 30import android.view.LayoutInflater; 31import android.view.View; 32import android.view.ViewGroup; 33import android.widget.Button; 34 35public class CryptKeeperConfirm extends Fragment { 36 37 public static class Blank extends Activity { 38 private Handler mHandler = new Handler(); 39 40 @Override 41 public void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 44 setContentView(R.layout.crypt_keeper_blank); 45 46 if (Utils.isMonkeyRunning()) { 47 finish(); 48 } 49 50 StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); 51 sbm.disable(StatusBarManager.DISABLE_EXPAND 52 | StatusBarManager.DISABLE_NOTIFICATION_ICONS 53 | StatusBarManager.DISABLE_NOTIFICATION_ALERTS 54 | StatusBarManager.DISABLE_SYSTEM_INFO 55 | StatusBarManager.DISABLE_NAVIGATION 56 | StatusBarManager.DISABLE_BACK); 57 58 // Post a delayed message in 700 milliseconds to enable encryption. 59 // NOTE: The animation on this activity is set for 500 milliseconds 60 // I am giving it a little extra time to complete. 61 mHandler.postDelayed(new Runnable() { 62 public void run() { 63 IBinder service = ServiceManager.getService("mount"); 64 if (service == null) { 65 return; 66 } 67 68 IMountService mountService = IMountService.Stub.asInterface(service); 69 try { 70 Bundle args = getIntent().getExtras(); 71 Log.d("CryptKeeper", "### password = " + args.getString("password")); 72 mountService.encryptStorage(args.getString("password")); 73 } catch (Exception e) { 74 Log.e("CryptKeeper", "Error while encrypting...", e); 75 } 76 } 77 }, 700); 78 } 79 } 80 81 private View mContentView; 82 private Button mFinalButton; 83 private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { 84 85 public void onClick(View v) { 86 if (Utils.isMonkeyRunning()) { 87 return; 88 } 89 90 Intent intent = new Intent(getActivity(), Blank.class); 91 intent.putExtras(getArguments()); 92 93 startActivity(intent); 94 } 95 }; 96 97 private void establishFinalConfirmationState() { 98 mFinalButton = (Button) mContentView.findViewById(R.id.execute_encrypt); 99 mFinalButton.setOnClickListener(mFinalClickListener); 100 } 101 102 @Override 103 public View onCreateView(LayoutInflater inflater, ViewGroup container, 104 Bundle savedInstanceState) { 105 mContentView = inflater.inflate(R.layout.crypt_keeper_confirm, null); 106 establishFinalConfirmationState(); 107 return mContentView; 108 } 109} 110