OSDN Git Service

am 57c88834: (-s ours) am 9fe36302: (-s ours) am 9cb97c44: Merge "DO NOT MERGE Fix...
[android-x86/packages-apps-Settings.git] / src / com / android / settings / CryptKeeperConfirm.java
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_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                         Log.e("CryptKeeper", "Failed to find the mount service");
66                         finish();
67                         return;
68                     }
69
70                     IMountService mountService = IMountService.Stub.asInterface(service);
71                     try {
72                         Bundle args = getIntent().getExtras();
73                         mountService.encryptStorage(args.getString("password"));
74                     } catch (Exception e) {
75                         Log.e("CryptKeeper", "Error while encrypting...", e);
76                     }
77                 }
78             }, 700);
79         }
80     }
81
82     private View mContentView;
83     private Button mFinalButton;
84     private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() {
85
86         public void onClick(View v) {
87             if (Utils.isMonkeyRunning()) {
88                 return;
89             }
90
91             Intent intent = new Intent(getActivity(), Blank.class);
92             intent.putExtras(getArguments());
93
94             startActivity(intent);
95         }
96     };
97
98     private void establishFinalConfirmationState() {
99         mFinalButton = (Button) mContentView.findViewById(R.id.execute_encrypt);
100         mFinalButton.setOnClickListener(mFinalClickListener);
101     }
102
103     @Override
104     public View onCreateView(LayoutInflater inflater, ViewGroup container,
105             Bundle savedInstanceState) {
106         mContentView = inflater.inflate(R.layout.crypt_keeper_confirm, null);
107         establishFinalConfirmationState();
108         return mContentView;
109     }
110 }