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.PrivateSpaceAuthenticationActivity.EXTRA_SHOW_PRIVATE_SPACE_UNLOCKED; 20 21 import android.app.settings.SettingsEnums; 22 import android.graphics.drawable.Drawable; 23 import android.os.Bundle; 24 import android.util.Log; 25 import android.widget.Toast; 26 27 import com.android.settings.R; 28 import com.android.settings.dashboard.DashboardFragment; 29 30 /** Fragment representing the Private Space dashboard in Settings. */ 31 public class PrivateSpaceDashboardFragment extends DashboardFragment { 32 private static final String TAG = "PSDashboardFragment"; 33 34 @Override onCreate(Bundle icicle)35 public void onCreate(Bundle icicle) { 36 if (android.os.Flags.allowPrivateProfile() 37 && android.multiuser.Flags.enablePrivateSpaceFeatures()) { 38 super.onCreate(icicle); 39 if (icicle == null 40 && getIntent().getBooleanExtra(EXTRA_SHOW_PRIVATE_SPACE_UNLOCKED, false)) { 41 Log.i(TAG, "Private space unlocked showing toast"); 42 Drawable drawable = 43 getContext().getDrawable(R.drawable.ic_private_space_unlock_icon); 44 Toast.makeCustomToastWithIcon( 45 getContext(), 46 null /* looper */, 47 getContext().getString(R.string.private_space_unlocked), 48 Toast.LENGTH_SHORT, 49 drawable) 50 .show(); 51 } 52 } 53 } 54 55 @Override onStart()56 public void onStart() { 57 super.onStart(); 58 if (PrivateSpaceMaintainer.getInstance(getContext()).isPrivateSpaceLocked()) { 59 // To make sure the task is removed if it is the last activity in that stack. 60 getActivity().finishAndRemoveTask(); 61 } 62 } 63 64 @Override getPreferenceScreenResId()65 protected int getPreferenceScreenResId() { 66 return R.xml.private_space_settings; 67 } 68 69 @Override getMetricsCategory()70 public int getMetricsCategory() { 71 return SettingsEnums.PRIVATE_SPACE_SETTINGS; 72 } 73 74 @Override getLogTag()75 protected String getLogTag() { 76 return TAG; 77 } 78 } 79