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