• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.intentresolver;
18 
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.ArgumentMatchers.anyInt;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23 
24 import android.content.res.Resources;
25 import android.database.Cursor;
26 import android.os.UserHandle;
27 
28 import com.android.intentresolver.chooser.TargetInfo;
29 import com.android.intentresolver.emptystate.CrossProfileIntentsChecker;
30 import com.android.intentresolver.shortcuts.ShortcutLoader;
31 
32 import kotlin.jvm.functions.Function2;
33 
34 import java.util.function.Consumer;
35 import java.util.function.Function;
36 
37 /**
38  * Singleton providing overrides to be applied by any {@code IChooserWrapper} used in testing.
39  * We cannot directly mock the activity created since instrumentation creates it, so instead we use
40  * this singleton to modify behavior.
41  */
42 public class ChooserActivityOverrideData {
43     private static ChooserActivityOverrideData sInstance = null;
44 
getInstance()45     public static ChooserActivityOverrideData getInstance() {
46         if (sInstance == null) {
47             sInstance = new ChooserActivityOverrideData();
48         }
49         return sInstance;
50     }
51     public Function<TargetInfo, Boolean> onSafelyStartInternalCallback;
52     public Function2<UserHandle, Consumer<ShortcutLoader.Result>, ShortcutLoader>
53             shortcutLoaderFactory = (userHandle, callback) -> null;
54     public ChooserListController resolverListController;
55     public ChooserListController workResolverListController;
56     public Boolean isVoiceInteraction;
57     public Cursor resolverCursor;
58     public boolean resolverForceException;
59     public Resources resources;
60     public boolean hasCrossProfileIntents;
61     public boolean isQuietModeEnabled;
62     public UserHandle personalUserHandle;
63     public CrossProfileIntentsChecker mCrossProfileIntentsChecker;
64 
reset()65     public void reset() {
66         onSafelyStartInternalCallback = null;
67         isVoiceInteraction = null;
68         resolverCursor = null;
69         resolverForceException = false;
70         resolverListController = mock(ChooserListController.class);
71         workResolverListController = mock(ChooserListController.class);
72         resources = null;
73         hasCrossProfileIntents = true;
74         isQuietModeEnabled = false;
75         personalUserHandle = null;
76         shortcutLoaderFactory = ((userHandle, resultConsumer) -> null);
77         mCrossProfileIntentsChecker = mock(CrossProfileIntentsChecker.class);
78         when(mCrossProfileIntentsChecker.hasCrossProfileIntents(any(), anyInt(), anyInt()))
79                 .thenAnswer(invocation -> hasCrossProfileIntents);
80     }
81 
ChooserActivityOverrideData()82     private ChooserActivityOverrideData() {}
83 }
84 
85