• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.intentresolver.icons;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.pm.ResolveInfo;
22 import android.graphics.Bitmap;
23 import android.os.Trace;
24 import android.util.Log;
25 
26 import androidx.annotation.Nullable;
27 
28 import com.android.intentresolver.TargetPresentationGetter;
29 import com.android.intentresolver.chooser.DisplayResolveInfo;
30 
31 import java.util.function.Consumer;
32 
33 class LoadIconTask extends BaseLoadIconTask {
34     private static final String TAG = "IconTask";
35     protected final DisplayResolveInfo mDisplayResolveInfo;
36     private final ResolveInfo mResolveInfo;
37 
LoadIconTask( Context context, DisplayResolveInfo dri, TargetPresentationGetter.Factory presentationFactory, Consumer<Bitmap> callback)38     LoadIconTask(
39             Context context, DisplayResolveInfo dri,
40             TargetPresentationGetter.Factory presentationFactory,
41             Consumer<Bitmap> callback) {
42         super(context, presentationFactory, callback);
43         mDisplayResolveInfo = dri;
44         mResolveInfo = dri.getResolveInfo();
45     }
46 
47     @Override
48     @Nullable
doInBackground(Void... params)49     protected Bitmap doInBackground(Void... params) {
50         Trace.beginSection("app-icon");
51         try {
52             return loadIconForResolveInfo(mResolveInfo);
53         } catch (Exception e) {
54             ComponentName componentName = mDisplayResolveInfo.getResolvedComponentName();
55             Log.e(TAG, "Failed to load app icon for " + componentName, e);
56             return null;
57         } finally {
58             Trace.endSection();
59         }
60     }
61 
loadIconForResolveInfo(ResolveInfo ri)62     protected final Bitmap loadIconForResolveInfo(ResolveInfo ri) {
63         // Load icons based on userHandle from ResolveInfo. If in work profile/clone profile, icons
64         // should be badged.
65         return mPresentationFactory.makePresentationGetter(ri).getIconBitmap(ri.userHandle);
66     }
67 
68 }
69