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.internal.app;
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.internal.app.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, ResolverListCommunicator resolverListCommunicator, UserHandle initialIntentsUserHandle)35     public ResolverWrapperAdapter(Context context,
36             List<Intent> payloadIntents,
37             Intent[] initialIntents,
38             List<ResolveInfo> rList, boolean filterLastUsed,
39             ResolverListController resolverListController,
40             ResolverListCommunicator resolverListCommunicator,
41             UserHandle initialIntentsUserHandle) {
42         super(context, payloadIntents, initialIntents, rList, filterLastUsed,
43                 resolverListController, resolverListCommunicator, false, initialIntentsUserHandle);
44     }
45 
getLabelIdlingResource()46     public CountingIdlingResource getLabelIdlingResource() {
47         return mLabelIdlingResource;
48     }
49 
50     @Override
createLoadLabelTask(DisplayResolveInfo info)51     protected LoadLabelTask createLoadLabelTask(DisplayResolveInfo info) {
52         return new LoadLabelWrapperTask(info);
53     }
54 
55     class LoadLabelWrapperTask extends LoadLabelTask {
56 
LoadLabelWrapperTask(DisplayResolveInfo dri)57         protected LoadLabelWrapperTask(DisplayResolveInfo dri) {
58             super(dri);
59         }
60 
61         @Override
onPreExecute()62         protected void onPreExecute() {
63             mLabelIdlingResource.increment();
64         }
65 
66         @Override
onPostExecute(CharSequence[] result)67         protected void onPostExecute(CharSequence[] result) {
68             super.onPostExecute(result);
69             mLabelIdlingResource.decrement();
70         }
71     }
72 }
73