• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 android.content.Context;
20 import android.content.Intent;
21 import android.content.pm.ResolveInfo;
22 import android.os.UserHandle;
23 
24 import androidx.test.espresso.idling.CountingIdlingResource;
25 
26 import com.android.intentresolver.chooser.DisplayResolveInfo;
27 
28 import java.util.List;
29 
30 public class ResolverWrapperAdapter extends ResolverListAdapter {
31 
32     private CountingIdlingResource mLabelIdlingResource =
33             new CountingIdlingResource("LoadLabelTask");
34 
ResolverWrapperAdapter( Context context, List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList, boolean filterLastUsed, ResolverListController resolverListController, UserHandle userHandle, Intent targetIntent, ResolverListCommunicator resolverListCommunicator)35     public ResolverWrapperAdapter(
36             Context context,
37             List<Intent> payloadIntents,
38             Intent[] initialIntents,
39             List<ResolveInfo> rList,
40             boolean filterLastUsed,
41             ResolverListController resolverListController,
42             UserHandle userHandle,
43             Intent targetIntent,
44             ResolverListCommunicator resolverListCommunicator) {
45         super(
46                 context,
47                 payloadIntents,
48                 initialIntents,
49                 rList,
50                 filterLastUsed,
51                 resolverListController,
52                 userHandle,
53                 targetIntent,
54                 resolverListCommunicator,
55                 false);
56     }
57 
getLabelIdlingResource()58     public CountingIdlingResource getLabelIdlingResource() {
59         return mLabelIdlingResource;
60     }
61 
62     @Override
createLoadLabelTask(DisplayResolveInfo info)63     protected LoadLabelTask createLoadLabelTask(DisplayResolveInfo info) {
64         return new LoadLabelWrapperTask(info);
65     }
66 
67     class LoadLabelWrapperTask extends LoadLabelTask {
68 
LoadLabelWrapperTask(DisplayResolveInfo dri)69         protected LoadLabelWrapperTask(DisplayResolveInfo dri) {
70             super(dri);
71         }
72 
73         @Override
onPreExecute()74         protected void onPreExecute() {
75             mLabelIdlingResource.increment();
76         }
77 
78         @Override
onPostExecute(CharSequence[] result)79         protected void onPostExecute(CharSequence[] result) {
80             super.onPostExecute(result);
81             mLabelIdlingResource.decrement();
82         }
83     }
84 }
85