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;
|
2017-01-05 15:22:41 -08:00
|
|
|
import android.content.pm.LauncherActivityInfo;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.UserHandle;
|
2009-11-17 17:32:16 -08:00
|
|
|
|
2015-02-18 16:46:50 -08:00
|
|
|
import com.android.launcher3.compat.UserManagerCompat;
|
2015-06-16 11:36:19 -07:00
|
|
|
import com.android.launcher3.util.ComponentKey;
|
2016-04-06 16:18:20 -07:00
|
|
|
import com.android.launcher3.util.PackageManagerHelper;
|
2014-04-30 03:02:21 +01: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
|
|
|
*/
|
2016-12-15 17:40:07 -08:00
|
|
|
public class AppInfo extends ItemInfoWithIcon {
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The intent used to start the application.
|
|
|
|
|
*/
|
2015-05-22 11:12:27 -07:00
|
|
|
public Intent intent;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2015-04-08 19:01:34 -07:00
|
|
|
public ComponentName componentName;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2016-01-21 19:50:02 +00:00
|
|
|
/**
|
|
|
|
|
* {@see ShortcutInfo#isDisabled}
|
|
|
|
|
*/
|
2017-02-17 12:16:13 -08:00
|
|
|
public int isDisabled = ShortcutInfo.DEFAULT;
|
2016-01-21 19:50:02 +00:00
|
|
|
|
2016-09-08 20:31:38 -07:00
|
|
|
public AppInfo() {
|
2017-03-14 14:02:00 -07:00
|
|
|
itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2016-05-31 15:01:35 -07:00
|
|
|
@Override
|
2014-03-17 09:34:39 -07:00
|
|
|
public Intent getIntent() {
|
2013-07-24 15:33:46 -07:00
|
|
|
return intent;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
*/
|
2017-01-05 15:22:41 -08:00
|
|
|
public AppInfo(Context context, LauncherActivityInfo info, UserHandle user) {
|
2017-03-21 15:12:01 -07:00
|
|
|
this(info, user, UserManagerCompat.getInstance(context).isQuietModeEnabled(user));
|
2016-11-09 10:43:58 -08:00
|
|
|
}
|
|
|
|
|
|
2017-03-21 15:12:01 -07:00
|
|
|
public AppInfo(LauncherActivityInfo info, UserHandle user, boolean quietModeEnabled) {
|
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;
|
2016-11-09 10:43:58 -08:00
|
|
|
this.user = user;
|
2016-04-06 16:18:20 -07:00
|
|
|
if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) {
|
2016-01-21 19:50:02 +00:00
|
|
|
isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
|
|
|
|
|
}
|
2016-01-22 17:48:29 +00:00
|
|
|
if (quietModeEnabled) {
|
|
|
|
|
isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-21 15:12:01 -07:00
|
|
|
intent = makeLaunchIntent(info);
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2011-07-11 17:44:15 -07:00
|
|
|
|
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;
|
2015-05-08 17:00:10 -07:00
|
|
|
title = Utilities.trim(info.title);
|
2009-03-03 19:32:27 -08:00
|
|
|
intent = new Intent(info.intent);
|
2016-01-21 19:50:02 +00:00
|
|
|
isDisabled = info.isDisabled;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-09-01 10:55:20 -07:00
|
|
|
protected String dumpProperties() {
|
|
|
|
|
return super.dumpProperties() + " componentName=" + componentName;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2009-08-17 11:03:03 -04: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
|
|
|
|
2015-06-16 11:36:19 -07:00
|
|
|
public ComponentKey toComponentKey() {
|
|
|
|
|
return new ComponentKey(componentName, user);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-21 15:12:01 -07:00
|
|
|
public static Intent makeLaunchIntent(LauncherActivityInfo info) {
|
2014-11-10 18:05:31 -08:00
|
|
|
return new Intent(Intent.ACTION_MAIN)
|
|
|
|
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
|
|
|
.setComponent(info.getComponentName())
|
2017-03-21 15:12:01 -07:00
|
|
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
2014-11-10 18:05:31 -08:00
|
|
|
}
|
2016-01-21 19:50:02 +00:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isDisabled() {
|
|
|
|
|
return isDisabled != 0;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|