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.documentsui; 18 19 import android.content.Intent; 20 import android.graphics.drawable.Drawable; 21 import android.os.Build; 22 import android.util.Log; 23 24 import androidx.annotation.RequiresApi; 25 26 import com.android.documentsui.base.UserId; 27 28 import java.util.ArrayList; 29 import java.util.HashMap; 30 import java.util.List; 31 import java.util.Map; 32 33 @RequiresApi(Build.VERSION_CODES.S) 34 public class TestUserManagerState implements UserManagerState { 35 36 private static final String TAG = "TestUserManagerState"; 37 public List<UserId> userIds = new ArrayList<>(); 38 public Map<UserId, String> userIdToLabelMap = new HashMap<>(); 39 public Map<UserId, Boolean> canFrowardToProfileIdMap = new HashMap<>(); 40 public Map<UserId, Drawable> userIdToBadgeMap = new HashMap<>(); 41 public String profileLabel = "Test"; 42 public Drawable profileBadge = null; 43 public Intent intent = new Intent(); 44 45 @Override getUserIds()46 public List<UserId> getUserIds() { 47 return userIds; 48 } 49 50 @Override getUserIdToLabelMap()51 public Map<UserId, String> getUserIdToLabelMap() { 52 return userIdToLabelMap; 53 } 54 55 @Override getUserIdToBadgeMap()56 public Map<UserId, Drawable> getUserIdToBadgeMap() { 57 return userIdToBadgeMap; 58 } 59 60 @Override getCanForwardToProfileIdMap(Intent intent)61 public Map<UserId, Boolean> getCanForwardToProfileIdMap(Intent intent) { 62 return canFrowardToProfileIdMap; 63 } 64 65 @Override onProfileActionStatusChange(String action, UserId userId)66 public void onProfileActionStatusChange(String action, UserId userId) { 67 if (Intent.ACTION_PROFILE_UNAVAILABLE.equals(action)) { 68 userIds.remove(userId); 69 return; 70 } else if (Intent.ACTION_PROFILE_AVAILABLE.equals(action)) { 71 if (!userIds.contains(userId)) { 72 userIds.add(userId); 73 } 74 if (!userIdToLabelMap.containsKey(userId)) { 75 userIdToLabelMap.put(userId, profileLabel); 76 } 77 if (!userIdToBadgeMap.containsKey(userId)) { 78 userIdToBadgeMap.put(userId, profileBadge); 79 } 80 if (!canFrowardToProfileIdMap.containsKey(userId)) { 81 canFrowardToProfileIdMap.put(userId, true); 82 } 83 } else { 84 Log.e(TAG, "Unexpected action received: " + action); 85 } 86 } 87 88 @Override setCurrentStateIntent(Intent intent)89 public void setCurrentStateIntent(Intent intent) { 90 } 91 92 @Override areHiddenInQuietModeProfilesPresent()93 public boolean areHiddenInQuietModeProfilesPresent() { 94 return false; 95 } 96 } 97