ConvertToFbe.java revision 4a01283309f737395a01f0fae68a369dc537a8da
1/*
2 * Copyright (C) 2015 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 */
16package com.android.settings.applications;
17
18import android.annotation.Nullable;
19import android.app.Activity;
20import android.content.Intent;
21import android.content.res.Resources;
22import android.os.Bundle;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.view.ViewGroup;
26import android.widget.Button;
27
28import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
29import com.android.settings.R;
30import com.android.settings.SettingsActivity;
31import com.android.settings.core.InstrumentedFragment;
32import com.android.settings.password.ChooseLockSettingsHelper;
33
34/* Class to prompt for conversion of userdata to file based encryption
35 */
36public class ConvertToFbe extends InstrumentedFragment {
37    static final String TAG = "ConvertToFBE";
38    static final String CONVERT_FBE_EXTRA = "ConvertFBE";
39    private static final int KEYGUARD_REQUEST = 55;
40
41    private boolean runKeyguardConfirmation(int request) {
42        Resources res = getActivity().getResources();
43        return new ChooseLockSettingsHelper(getActivity(), this)
44            .launchConfirmationActivity(request,
45                                        res.getText(R.string.convert_to_file_encryption));
46    }
47
48    @Override
49    public void onCreate(@Nullable Bundle savedInstanceState) {
50        super.onCreate(savedInstanceState);
51        getActivity().setTitle(R.string.convert_to_file_encryption);
52    }
53
54    @Override
55    public View onCreateView(LayoutInflater inflater, ViewGroup container,
56                Bundle savedInstanceState) {
57        View rootView = inflater.inflate(R.layout.convert_fbe, null);
58
59        final Button button = (Button) rootView.findViewById(R.id.button_convert_fbe);
60        button.setOnClickListener(new View.OnClickListener() {
61            public void onClick(View v) {
62                if(!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
63                    convert();
64                }
65            }
66        });
67
68        return rootView;
69    }
70
71    @Override
72    public void onActivityResult(int requestCode, int resultCode, Intent data) {
73        super.onActivityResult(requestCode, resultCode, data);
74
75        if (requestCode != KEYGUARD_REQUEST) {
76            return;
77        }
78
79        // If the user entered a valid keyguard credential, start the conversion
80        // process
81        if (resultCode == Activity.RESULT_OK) {
82            convert();
83        }
84    }
85
86    private void convert() {
87        SettingsActivity sa = (SettingsActivity) getActivity();
88        sa.startPreferencePanel(this, ConfirmConvertToFbe.class.getName(), null,
89                                R.string.convert_to_file_encryption, null, null, 0);
90    }
91
92    @Override
93    public int getMetricsCategory() {
94        return MetricsEvent.CONVERT_FBE;
95    }
96}
97