ConvertToFbe.java revision 5a638a6ad159dd489de3da1089327f71e2138911
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.app.Activity;
19import android.content.Intent;
20import android.content.res.Resources;
21import android.os.Bundle;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.Button;
26
27import com.android.internal.logging.MetricsProto;
28import com.android.internal.logging.MetricsProto.MetricsEvent;
29import com.android.settings.ChooseLockSettingsHelper;
30import com.android.settings.R;
31import com.android.settings.SettingsActivity;
32import com.android.settings.SettingsPreferenceFragment;
33
34/* Class to prompt for conversion of userdata to file based encryption
35 */
36public class ConvertToFbe extends SettingsPreferenceFragment {
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 View onCreateView(LayoutInflater inflater, ViewGroup container,
50                Bundle savedInstanceState) {
51        View rootView = inflater.inflate(R.layout.convert_fbe, null);
52
53        final Button button = (Button) rootView.findViewById(R.id.button_convert_fbe);
54        button.setOnClickListener(new View.OnClickListener() {
55            public void onClick(View v) {
56                if(!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
57                    convert();
58                }
59            }
60        });
61
62        return rootView;
63    }
64
65    @Override
66    public void onActivityResult(int requestCode, int resultCode, Intent data) {
67        super.onActivityResult(requestCode, resultCode, data);
68
69        if (requestCode != KEYGUARD_REQUEST) {
70            return;
71        }
72
73        // If the user entered a valid keyguard credential, start the conversion
74        // process
75        if (resultCode == Activity.RESULT_OK) {
76            convert();
77        }
78    }
79
80    private void convert() {
81        SettingsActivity sa = (SettingsActivity) getActivity();
82        sa.startPreferencePanel(ConfirmConvertToFbe.class.getName(), null,
83                                R.string.convert_to_file_encryption, null, null, 0);
84    }
85
86    @Override
87    protected int getMetricsCategory() {
88        return MetricsEvent.CONVERT_FBE;
89    }
90}
91