1 /*
2  * Copyright (C) 2021 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.providers.media.photopicker.util;
18 
19 import android.annotation.SuppressLint;
20 import android.content.pm.UserProperties;
21 import android.util.Log;
22 
23 import androidx.appcompat.app.AppCompatActivity;
24 
25 import com.android.modules.utils.build.SdkLevel;
26 import com.android.providers.media.ConfigStore;
27 import com.android.providers.media.photopicker.data.UserManagerState;
28 import com.android.providers.media.photopicker.data.model.UserId;
29 
30 public class RecentsPreviewUtil {
31     private static final String TAG = "PhotoPickerRecentsPreviewUtil";
32 
33     /**
34      * Show blank screen in Recents if profile with SHOW_IN_QUIET_MODE_HIDDEN property is on
35      * (e.g. Private profile). This prevents leaking existence of the profile after the activity
36      * is moved to Recents and the profile was switched to the quiet mode.
37      */
38     @SuppressLint("NewApi")
updateRecentsVisibilitySetting(ConfigStore configStore, UserManagerState state, AppCompatActivity activity)39     public static void updateRecentsVisibilitySetting(ConfigStore configStore,
40             UserManagerState state, AppCompatActivity activity) {
41         if (!(SdkLevel.isAtLeastV() && configStore.isPrivateSpaceInPhotoPickerEnabled())) return;
42         if (state == null) {
43             Log.e(TAG, "Can't update Recents screenshot setting, user manager state is null");
44             return;
45         }
46         for (UserId userId : state.getAllUserProfileIds()) {
47             if (state.getShowInQuietMode(userId) == UserProperties.SHOW_IN_QUIET_MODE_HIDDEN
48                     && !state.isProfileOff(userId)) {
49                 activity.setRecentsScreenshotEnabled(false);
50                 return;
51             }
52         }
53         activity.setRecentsScreenshotEnabled(true);
54     }
55 }
56