• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.PackageInfo;
23 import android.content.pm.PackageManager.NameNotFoundException;
24 import android.content.pm.ResolveInfo;
25 import android.graphics.Bitmap;
26 import android.util.Log;
27 
28 import com.android.launcher3.compat.LauncherActivityInfoCompat;
29 import com.android.launcher3.compat.UserManagerCompat;
30 import com.android.launcher3.compat.UserHandleCompat;
31 
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.HashMap;
35 
36 /**
37  * Represents an app in AllAppsView.
38  */
39 public class AppInfo extends ItemInfo {
40     private static final String TAG = "Launcher3.AppInfo";
41 
42     /**
43      * The intent used to start the application.
44      */
45     Intent intent;
46 
47     /**
48      * A bitmap version of the application icon.
49      */
50     Bitmap iconBitmap;
51 
52     /**
53      * The time at which the app was first installed.
54      */
55     long firstInstallTime;
56 
57     ComponentName componentName;
58 
59     static final int DOWNLOADED_FLAG = 1;
60     static final int UPDATED_SYSTEM_APP_FLAG = 2;
61 
62     int flags = 0;
63 
AppInfo()64     AppInfo() {
65         itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
66     }
67 
getIntent()68     public Intent getIntent() {
69         return intent;
70     }
71 
getRestoredIntent()72     protected Intent getRestoredIntent() {
73         return null;
74     }
75 
76     /**
77      * Must not hold the Context.
78      */
AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user, IconCache iconCache, HashMap<Object, CharSequence> labelCache)79     public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
80             IconCache iconCache, HashMap<Object, CharSequence> labelCache) {
81         this.componentName = info.getComponentName();
82         this.container = ItemInfo.NO_ID;
83 
84         flags = initFlags(info);
85         firstInstallTime = info.getFirstInstallTime();
86         iconCache.getTitleAndIcon(this, info, labelCache);
87         intent = new Intent(Intent.ACTION_MAIN);
88         intent.addCategory(Intent.CATEGORY_LAUNCHER);
89         intent.setComponent(info.getComponentName());
90         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
91         long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
92         intent.putExtra(EXTRA_PROFILE, serialNumber);
93         this.user = user;
94     }
95 
initFlags(LauncherActivityInfoCompat info)96     private static int initFlags(LauncherActivityInfoCompat info) {
97         int appFlags = info.getApplicationInfo().flags;
98         int flags = 0;
99         if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
100             flags |= DOWNLOADED_FLAG;
101 
102             if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
103                 flags |= UPDATED_SYSTEM_APP_FLAG;
104             }
105         }
106         return flags;
107     }
108 
AppInfo(AppInfo info)109     public AppInfo(AppInfo info) {
110         super(info);
111         componentName = info.componentName;
112         title = info.title.toString();
113         intent = new Intent(info.intent);
114         flags = info.flags;
115         firstInstallTime = info.firstInstallTime;
116         iconBitmap = info.iconBitmap;
117     }
118 
119     @Override
toString()120     public String toString() {
121         return "ApplicationInfo(title=" + title.toString() + " id=" + this.id
122                 + " type=" + this.itemType + " container=" + this.container
123                 + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
124                 + " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos)
125                 + " user=" + user + ")";
126     }
127 
dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list)128     public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) {
129         Log.d(tag, label + " size=" + list.size());
130         for (AppInfo info: list) {
131             Log.d(tag, "   title=\"" + info.title + "\" iconBitmap="
132                     + info.iconBitmap + " firstInstallTime="
133                     + info.firstInstallTime);
134         }
135     }
136 
makeShortcut()137     public ShortcutInfo makeShortcut() {
138         return new ShortcutInfo(this);
139     }
140 }
141