Home | History | Annotate | Download | only in settings
      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 
     17 package com.android.settings;
     18 
     19 import android.app.Activity;
     20 import android.app.Fragment;
     21 import android.app.StatusBarManager;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.os.Handler;
     26 import android.os.IBinder;
     27 import android.os.ServiceManager;
     28 import android.os.storage.IMountService;
     29 import android.util.Log;
     30 import android.view.LayoutInflater;
     31 import android.view.View;
     32 import android.view.ViewGroup;
     33 import android.widget.Button;
     34 
     35 public 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_HOME
     56                     | StatusBarManager.DISABLE_RECENT
     57                     | StatusBarManager.DISABLE_BACK);
     58 
     59             // Post a delayed message in 700 milliseconds to enable encryption.
     60             // NOTE: The animation on this activity is set for 500 milliseconds
     61             // I am giving it a little extra time to complete.
     62             mHandler.postDelayed(new Runnable() {
     63                 public void run() {
     64                     IBinder service = ServiceManager.getService("mount");
     65                     if (service == null) {
     66                         Log.e("CryptKeeper", "Failed to find the mount service");
     67                         finish();
     68                         return;
     69                     }
     70 
     71                     IMountService mountService = IMountService.Stub.asInterface(service);
     72                     try {
     73                         Bundle args = getIntent().getExtras();
     74                         mountService.encryptStorage(args.getString("password"));
     75                     } catch (Exception e) {
     76                         Log.e("CryptKeeper", "Error while encrypting...", e);
     77                     }
     78                 }
     79             }, 700);
     80         }
     81     }
     82 
     83     private View mContentView;
     84     private Button mFinalButton;
     85     private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() {
     86 
     87         public void onClick(View v) {
     88             if (Utils.isMonkeyRunning()) {
     89                 return;
     90             }
     91 
     92             Intent intent = new Intent(getActivity(), Blank.class);
     93             intent.putExtras(getArguments());
     94 
     95             startActivity(intent);
     96         }
     97     };
     98 
     99     private void establishFinalConfirmationState() {
    100         mFinalButton = (Button) mContentView.findViewById(R.id.execute_encrypt);
    101         mFinalButton.setOnClickListener(mFinalClickListener);
    102     }
    103 
    104     @Override
    105     public View onCreateView(LayoutInflater inflater, ViewGroup container,
    106             Bundle savedInstanceState) {
    107         mContentView = inflater.inflate(R.layout.crypt_keeper_confirm, null);
    108         establishFinalConfirmationState();
    109         return mContentView;
    110     }
    111 }
    112