2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
2014-04-30 03:02:21 +01:00
|
|
|
import android.content.Context;
|
2009-03-03 19:32:27 -08:00
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.graphics.Bitmap;
|
2009-11-17 17:32:16 -08:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
import com.android.launcher3.compat.LauncherActivityInfoCompat;
|
|
|
|
|
import com.android.launcher3.compat.UserHandleCompat;
|
2015-02-18 16:46:50 -08:00
|
|
|
import com.android.launcher3.compat.UserManagerCompat;
|
2014-04-30 03:02:21 +01:00
|
|
|
|
2010-07-29 13:59:29 -07:00
|
|
|
import java.util.ArrayList;
|
2014-04-21 19:36:14 -07:00
|
|
|
import java.util.Arrays;
|
2010-07-29 13:59:29 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
2010-02-08 13:44:00 -08:00
|
|
|
* Represents an app in AllAppsView.
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2014-03-04 17:16:11 -08:00
|
|
|
public class AppInfo extends ItemInfo {
|
2013-09-04 00:45:37 +02:00
|
|
|
private static final String TAG = "Launcher3.AppInfo";
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The intent used to start the application.
|
|
|
|
|
*/
|
|
|
|
|
Intent intent;
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* A bitmap version of the application icon.
|
|
|
|
|
*/
|
|
|
|
|
Bitmap iconBitmap;
|
|
|
|
|
|
2011-01-21 15:38:02 -08:00
|
|
|
/**
|
|
|
|
|
* The time at which the app was first installed.
|
|
|
|
|
*/
|
|
|
|
|
long firstInstallTime;
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
ComponentName componentName;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2011-02-28 15:16:42 -08:00
|
|
|
static final int DOWNLOADED_FLAG = 1;
|
|
|
|
|
static final int UPDATED_SYSTEM_APP_FLAG = 2;
|
|
|
|
|
|
2010-07-29 13:59:29 -07:00
|
|
|
int flags = 0;
|
2010-02-08 13:44:00 -08:00
|
|
|
|
2013-09-04 00:45:37 +02:00
|
|
|
AppInfo() {
|
2010-02-08 13:44:00 -08:00
|
|
|
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2014-03-17 09:34:39 -07:00
|
|
|
public Intent getIntent() {
|
2013-07-24 15:33:46 -07:00
|
|
|
return intent;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-27 14:17:08 -05:00
|
|
|
protected Intent getRestoredIntent() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
2010-02-08 13:44:00 -08:00
|
|
|
* Must not hold the Context.
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2014-04-30 03:02:21 +01:00
|
|
|
public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
|
2015-02-18 16:46:50 -08:00
|
|
|
IconCache iconCache) {
|
2014-04-30 03:02:21 +01:00
|
|
|
this.componentName = info.getComponentName();
|
2010-02-08 13:44:00 -08:00
|
|
|
this.container = ItemInfo.NO_ID;
|
2010-07-29 13:59:29 -07:00
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
flags = initFlags(info);
|
|
|
|
|
firstInstallTime = info.getFirstInstallTime();
|
2015-02-18 16:46:50 -08:00
|
|
|
iconCache.getTitleAndIcon(this, info);
|
2014-11-10 18:05:31 -08:00
|
|
|
intent = makeLaunchIntent(context, info, user);
|
2014-04-30 03:02:21 +01:00
|
|
|
this.user = user;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2011-07-11 17:44:15 -07:00
|
|
|
|
2014-11-10 18:05:31 -08:00
|
|
|
public static int initFlags(LauncherActivityInfoCompat info) {
|
2014-06-30 12:30:31 +01:00
|
|
|
int appFlags = info.getApplicationInfo().flags;
|
2013-07-08 18:03:46 -07:00
|
|
|
int flags = 0;
|
|
|
|
|
if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
|
|
|
|
|
flags |= DOWNLOADED_FLAG;
|
|
|
|
|
|
|
|
|
|
if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
|
|
|
|
|
flags |= UPDATED_SYSTEM_APP_FLAG;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 00:45:37 +02:00
|
|
|
public AppInfo(AppInfo info) {
|
2011-08-29 14:03:34 -07:00
|
|
|
super(info);
|
2010-02-08 13:44:00 -08:00
|
|
|
componentName = info.componentName;
|
2009-03-03 19:32:27 -08:00
|
|
|
title = info.title.toString();
|
|
|
|
|
intent = new Intent(info.intent);
|
2010-09-08 16:01:19 -07:00
|
|
|
flags = info.flags;
|
2011-01-21 15:38:02 -08:00
|
|
|
firstInstallTime = info.firstInstallTime;
|
2014-04-30 03:02:21 +01:00
|
|
|
iconBitmap = info.iconBitmap;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
2013-07-08 17:17:08 -07:00
|
|
|
return "ApplicationInfo(title=" + title.toString() + " id=" + this.id
|
|
|
|
|
+ " type=" + this.itemType + " container=" + this.container
|
|
|
|
|
+ " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY
|
2014-04-21 19:36:14 -07:00
|
|
|
+ " spanX=" + spanX + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos)
|
2014-04-30 03:02:21 +01:00
|
|
|
+ " user=" + user + ")";
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2009-08-17 11:03:03 -04:00
|
|
|
|
2013-09-04 00:45:37 +02:00
|
|
|
public static void dumpApplicationInfoList(String tag, String label, ArrayList<AppInfo> list) {
|
2009-11-17 17:32:16 -08:00
|
|
|
Log.d(tag, label + " size=" + list.size());
|
2013-09-04 00:45:37 +02:00
|
|
|
for (AppInfo info: list) {
|
2011-07-11 16:02:31 -07:00
|
|
|
Log.d(tag, " title=\"" + info.title + "\" iconBitmap="
|
|
|
|
|
+ info.iconBitmap + " firstInstallTime="
|
2011-01-21 15:38:02 -08:00
|
|
|
+ info.firstInstallTime);
|
2009-11-17 17:32:16 -08:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
|
|
|
|
|
public ShortcutInfo makeShortcut() {
|
2011-08-29 14:03:34 -07:00
|
|
|
return new ShortcutInfo(this);
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
2014-11-10 18:05:31 -08:00
|
|
|
|
|
|
|
|
public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info,
|
|
|
|
|
UserHandleCompat user) {
|
|
|
|
|
long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
|
|
|
|
|
return new Intent(Intent.ACTION_MAIN)
|
|
|
|
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
|
|
|
.setComponent(info.getComponentName())
|
|
|
|
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
|
|
|
|
|
.putExtra(EXTRA_PROFILE, serialNumber);
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|