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 */ 16 package com.android.settings.applications; 17 18 import android.app.Activity; 19 import android.content.Intent; 20 import android.content.res.Resources; 21 import android.os.Bundle; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.widget.Button; 26 27 import com.android.internal.logging.MetricsProto; 28 import com.android.internal.logging.MetricsProto.MetricsEvent; 29 import com.android.settings.ChooseLockSettingsHelper; 30 import com.android.settings.R; 31 import com.android.settings.SettingsActivity; 32 import com.android.settings.SettingsPreferenceFragment; 33 34 /* Class to prompt for conversion of userdata to file based encryption 35 */ 36 public 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 runKeyguardConfirmation(int request)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 onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)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 onActivityResult(int requestCode, int resultCode, Intent data)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 convert()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 getMetricsCategory()87 protected int getMetricsCategory() { 88 return MetricsEvent.CONVERT_FBE; 89 } 90 } 91