• 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.graphics.Bitmap;
23 import android.util.Log;
24 
25 import com.android.launcher3.compat.LauncherActivityInfoCompat;
26 import com.android.launcher3.compat.UserHandleCompat;
27 import com.android.launcher3.compat.UserManagerCompat;
28 import com.android.launcher3.util.ComponentKey;
29 import com.android.launcher3.util.PackageManagerHelper;
30 
31 import java.util.ArrayList;
32 
33 /**
34  * Represents an app in AllAppsView.
35  */
36 public class AppInfo extends ItemInfo {
37 
38     /**
39      * The intent used to start the application.
40      */
41     public Intent intent;
42 
43     /**
44      * A bitmap version of the application icon.
45      */
46     public Bitmap iconBitmap;
47 
48     /**
49      * Indicates whether we're using a low res icon
50      */
51     boolean usingLowResIcon;
52 
53     public ComponentName componentName;
54 
55     static final int DOWNLOADED_FLAG = 1;
56     static final int UPDATED_SYSTEM_APP_FLAG = 2;
57 
58     int flags = 0;
59 
60     /**
61      * {@see ShortcutInfo#isDisabled}
62      */
63     int isDisabled = ShortcutInfo.DEFAULT;
64 
AppInfo()65     public AppInfo() {
66         itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
67     }
68 
69     @Override
getIntent()70     public Intent getIntent() {
71         return intent;
72     }
73 
getRestoredIntent()74     protected Intent getRestoredIntent() {
75         return null;
76     }
77 
78     /**
79      * Must not hold the Context.
80      */
AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user, IconCache iconCache)81     public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
82             IconCache iconCache) {
83         this(context, info, user, iconCache,
84                 UserManagerCompat.getInstance(context).isQuietModeEnabled(user));
85     }
86 
AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user, IconCache iconCache, boolean quietModeEnabled)87     public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
88             IconCache iconCache, boolean quietModeEnabled) {
89         this.componentName = info.getComponentName();
90         this.container = ItemInfo.NO_ID;
91         flags = initFlags(info);
92         if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) {
93             isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
94         }
95         if (quietModeEnabled) {
96             isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
97         }
98 
99         iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
100         intent = makeLaunchIntent(context, info, user);
101         this.user = user;
102     }
103 
initFlags(LauncherActivityInfoCompat info)104     public static int initFlags(LauncherActivityInfoCompat info) {
105         int appFlags = info.getApplicationInfo().flags;
106         int flags = 0;
107         if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
108             flags |= DOWNLOADED_FLAG;
109 
110             if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
111                 flags |= UPDATED_SYSTEM_APP_FLAG;
112             }
113         }
114         return flags;
115     }
116 
AppInfo(AppInfo info)117     public AppInfo(AppInfo info) {
118         super(info);
119         componentName = info.componentName;
120         title = Utilities.trim(info.title);
121         intent = new Intent(info.intent);
122         flags = info.flags;
123         isDisabled = info.isDisabled;
124         iconBitmap = info.iconBitmap;
125     }
126 
127     @Override
dumpProperties()128     protected String dumpProperties() {
129         return super.dumpProperties() + " componentName=" + componentName;
130     }
131 
132     /**
133      * Helper method used for debugging.
134      */
dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list)135     public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) {
136         Log.d(tag, label + " size=" + list.size());
137         for (AppInfo info: list) {
138             Log.d(tag, "   title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
139                     + " componentName=" + info.componentName.getPackageName());
140         }
141     }
142 
makeShortcut()143     public ShortcutInfo makeShortcut() {
144         return new ShortcutInfo(this);
145     }
146 
toComponentKey()147     public ComponentKey toComponentKey() {
148         return new ComponentKey(componentName, user);
149     }
150 
makeLaunchIntent(Context context, LauncherActivityInfoCompat info, UserHandleCompat user)151     public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info,
152             UserHandleCompat user) {
153         long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
154         return new Intent(Intent.ACTION_MAIN)
155             .addCategory(Intent.CATEGORY_LAUNCHER)
156             .setComponent(info.getComponentName())
157             .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
158             .putExtra(EXTRA_PROFILE, serialNumber);
159     }
160 
161     @Override
isDisabled()162     public boolean isDisabled() {
163         return isDisabled != 0;
164     }
165 }
166