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 17package com.android.launcher2; 18 19import android.content.ComponentName; 20import android.content.Intent; 21import android.content.pm.LauncherActivityInfo; 22import android.content.pm.LauncherApps; 23import android.content.pm.PackageManager.NameNotFoundException; 24import android.content.pm.ResolveInfo; 25import android.graphics.Bitmap; 26import android.os.UserHandle; 27import android.util.Log; 28 29import java.util.ArrayList; 30import java.util.HashMap; 31 32/** 33 * Represents an app in AllAppsView. 34 */ 35class ApplicationInfo extends ItemInfo { 36 private static final String TAG = "Launcher2.ApplicationInfo"; 37 38 /** 39 * The intent used to start the application. 40 */ 41 Intent intent; 42 43 /** 44 * A bitmap version of the application icon. 45 */ 46 Bitmap iconBitmap; 47 48 /** 49 * The time at which the app was first installed. 50 */ 51 long firstInstallTime; 52 53 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 ApplicationInfo() { 61 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; 62 } 63 64 /** 65 * Must not hold the Context. 66 */ 67 public ApplicationInfo(LauncherActivityInfo info, UserHandle user, IconCache iconCache, 68 HashMap<Object, CharSequence> labelCache) { 69 70 this.componentName = info.getComponentName(); 71 this.container = ItemInfo.NO_ID; 72 this.setActivity(componentName, 73 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 74 75 int appFlags = info.getApplicationInfo().flags; 76 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { 77 flags |= DOWNLOADED_FLAG; 78 } 79 if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { 80 flags |= UPDATED_SYSTEM_APP_FLAG; 81 } 82 firstInstallTime = info.getFirstInstallTime(); 83 iconCache.getTitleAndIcon(this, info, labelCache); 84 intent = new Intent(Intent.ACTION_MAIN); 85 intent.addCategory(Intent.CATEGORY_LAUNCHER); 86 intent.setComponent(info.getComponentName()); 87 intent.putExtra(EXTRA_PROFILE, user); 88 updateUser(intent); 89 } 90 91 public ApplicationInfo(ApplicationInfo info) { 92 super(info); 93 componentName = info.componentName; 94 title = info.title.toString(); 95 intent = new Intent(info.intent); 96 flags = info.flags; 97 firstInstallTime = info.firstInstallTime; 98 } 99 100 /** 101 * Creates the application intent based on a component name and various launch flags. 102 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}. 103 * 104 * @param className the class name of the component representing the intent 105 * @param launchFlags the launch flags 106 */ 107 final void setActivity(ComponentName className, int launchFlags) { 108 intent = new Intent(Intent.ACTION_MAIN); 109 intent.addCategory(Intent.CATEGORY_LAUNCHER); 110 intent.setComponent(className); 111 intent.setFlags(launchFlags); 112 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; 113 } 114 115 @Override 116 public String toString() { 117 return "ApplicationInfo(title=" + title.toString() + " P=" + user + ")"; 118 } 119 120 public static void dumpApplicationInfoList(String tag, String label, 121 ArrayList<ApplicationInfo> list) { 122 Log.d(tag, label + " size=" + list.size()); 123 for (ApplicationInfo info: list) { 124 Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" 125 + info.iconBitmap + " firstInstallTime=" 126 + info.firstInstallTime); 127 } 128 } 129 130 public ShortcutInfo makeShortcut() { 131 return new ShortcutInfo(this); 132 } 133} 134