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