1 /* 2 * Copyright (C) 2023 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 17 package com.android.settings.privatespace; 18 19 import static com.android.settings.privatespace.PrivateSpaceMaintainer.HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL; 20 import static com.android.settings.privatespace.PrivateSpaceMaintainer.HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL; 21 22 import android.app.AlertDialog; 23 import android.content.Context; 24 import android.content.DialogInterface; 25 26 import com.android.settings.R; 27 import com.android.settings.core.TogglePreferenceController; 28 29 /** 30 * Toggle Preference Controller responsible for managing the visibility of private space entry point 31 * in the "All Apps" section. This includes: 32 * 33 * <p>Toggling the entry point's visibility (hiding/unhiding) 34 * 35 * <p>Displaying a dialog to inform the user that the entry point will be hidden when private space 36 * is locked (if the hide option is enabled) 37 */ 38 public class HidePrivateSpaceController extends TogglePreferenceController { 39 private final PrivateSpaceMaintainer mPrivateSpaceMaintainer; 40 HidePrivateSpaceController(Context context, String key)41 public HidePrivateSpaceController(Context context, String key) { 42 super(context, key); 43 mPrivateSpaceMaintainer = PrivateSpaceMaintainer.getInstance(context); 44 } 45 46 @Override 47 @AvailabilityStatus getAvailabilityStatus()48 public int getAvailabilityStatus() { 49 return android.os.Flags.allowPrivateProfile() 50 && android.multiuser.Flags.enablePrivateSpaceFeatures() 51 ? AVAILABLE 52 : UNSUPPORTED_ON_DEVICE; 53 } 54 55 @Override isChecked()56 public boolean isChecked() { 57 return mPrivateSpaceMaintainer.getHidePrivateSpaceEntryPointSetting() 58 != HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL; 59 } 60 61 @Override setChecked(boolean isChecked)62 public boolean setChecked(boolean isChecked) { 63 mPrivateSpaceMaintainer.setHidePrivateSpaceEntryPointSetting( 64 isChecked ? HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL 65 : HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL); 66 if (isChecked) { 67 showAlertDialog(); 68 } 69 return true; 70 } 71 72 @Override getSliceHighlightMenuRes()73 public int getSliceHighlightMenuRes() { 74 return 0; 75 } 76 showAlertDialog()77 private void showAlertDialog() { 78 new AlertDialog.Builder(mContext) 79 .setTitle(R.string.private_space_hide_dialog_title) 80 .setMessage(R.string.private_space_hide_dialog_message) 81 .setPositiveButton( 82 R.string.private_space_hide_dialog_button, 83 (DialogInterface dialog, int which) -> { 84 dialog.dismiss(); 85 }) 86 .show(); 87 } 88 } 89