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