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.launcher3.appprediction;
18 
19 import static com.android.quickstep.InstantAppResolverImpl.COMPONENT_CLASS_MARKER;
20 
21 import com.android.launcher3.allapps.AllAppsStore;
22 import com.android.launcher3.model.data.AppInfo;
23 import com.android.launcher3.model.data.ItemInfoWithIcon;
24 import com.android.launcher3.util.ComponentKey;
25 
26 public class ComponentKeyMapper {
27 
28     protected final ComponentKey componentKey;
29     private final DynamicItemCache mCache;
30 
ComponentKeyMapper(ComponentKey key, DynamicItemCache cache)31     public ComponentKeyMapper(ComponentKey key, DynamicItemCache cache) {
32         componentKey = key;
33         mCache = cache;
34     }
35 
getPackage()36     public String getPackage() {
37         return componentKey.componentName.getPackageName();
38     }
39 
getComponentClass()40     public String getComponentClass() {
41         return componentKey.componentName.getClassName();
42     }
43 
getComponentKey()44     public ComponentKey getComponentKey() {
45         return componentKey;
46     }
47 
48     @Override
toString()49     public String toString() {
50         return componentKey.toString();
51     }
52 
getApp(AllAppsStore store)53     public ItemInfoWithIcon getApp(AllAppsStore store) {
54         AppInfo item = store.getApp(componentKey);
55         if (item != null) {
56             return item;
57         } else if (getComponentClass().equals(COMPONENT_CLASS_MARKER)) {
58             return mCache.getInstantApp(componentKey.componentName.getPackageName());
59         } else {
60             return mCache.getShortcutInfo(componentKey);
61         }
62     }
63 }
64