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