Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | package android.content.pm; |
| 17 | |
| 18 | import android.annotation.IntDef; |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Mehdi Alizadeh | 8887365 | 2019-02-04 14:16:46 -0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 22 | import android.annotation.TestApi; |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 23 | import android.annotation.UserIdInt; |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 24 | import android.app.Notification; |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 25 | import android.app.Person; |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 26 | import android.app.TaskStackBuilder; |
Artur Satayev | e23a0eb | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 27 | import android.compat.annotation.UnsupportedAppUsage; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 31 | import android.content.LocusId; |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 32 | import android.content.pm.LauncherApps.ShortcutQuery; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 34 | import android.content.res.Resources.NotFoundException; |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 35 | import android.graphics.Bitmap; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 36 | import android.graphics.drawable.Icon; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 37 | import android.os.Build; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 38 | import android.os.Bundle; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 39 | import android.os.Parcel; |
| 40 | import android.os.Parcelable; |
| 41 | import android.os.PersistableBundle; |
| 42 | import android.os.UserHandle; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 43 | import android.text.TextUtils; |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 44 | import android.util.ArraySet; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 45 | import android.util.Log; |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 46 | import android.view.contentcapture.ContentCaptureContext; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 47 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 48 | import com.android.internal.annotations.VisibleForTesting; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 49 | import com.android.internal.util.Preconditions; |
| 50 | |
| 51 | import java.lang.annotation.Retention; |
| 52 | import java.lang.annotation.RetentionPolicy; |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 53 | import java.util.List; |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 54 | import java.util.Objects; |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 55 | import java.util.Set; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 58 | * Represents a shortcut that can be published via {@link ShortcutManager}. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 59 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 60 | * @see ShortcutManager |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 61 | */ |
Jeff Sharkey | 70168dd | 2016-03-30 21:47:16 -0600 | [diff] [blame] | 62 | public final class ShortcutInfo implements Parcelable { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 63 | static final String TAG = "Shortcut"; |
| 64 | |
| 65 | private static final String RES_TYPE_STRING = "string"; |
| 66 | |
| 67 | private static final String ANDROID_PACKAGE_NAME = "android"; |
| 68 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 69 | private static final int IMPLICIT_RANK_MASK = 0x7fffffff; |
| 70 | |
| 71 | private static final int RANK_CHANGED_BIT = ~IMPLICIT_RANK_MASK; |
| 72 | |
| 73 | /** @hide */ |
| 74 | public static final int RANK_NOT_SET = Integer.MAX_VALUE; |
| 75 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 76 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 77 | public static final int FLAG_DYNAMIC = 1 << 0; |
| 78 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 79 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 80 | public static final int FLAG_PINNED = 1 << 1; |
| 81 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 82 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 83 | public static final int FLAG_HAS_ICON_RES = 1 << 2; |
| 84 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 85 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 86 | public static final int FLAG_HAS_ICON_FILE = 1 << 3; |
| 87 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 88 | /** @hide */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 89 | public static final int FLAG_KEY_FIELDS_ONLY = 1 << 4; |
| 90 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 91 | /** @hide */ |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 92 | public static final int FLAG_MANIFEST = 1 << 5; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 93 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 94 | /** @hide */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 95 | public static final int FLAG_DISABLED = 1 << 6; |
| 96 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 97 | /** @hide */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 98 | public static final int FLAG_STRINGS_RESOLVED = 1 << 7; |
| 99 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 100 | /** @hide */ |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 101 | public static final int FLAG_IMMUTABLE = 1 << 8; |
| 102 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 103 | /** @hide */ |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 104 | public static final int FLAG_ADAPTIVE_BITMAP = 1 << 9; |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 105 | |
| 106 | /** @hide */ |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 107 | public static final int FLAG_RETURNED_BY_SERVICE = 1 << 10; |
| 108 | |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 109 | /** @hide When this is set, the bitmap icon is waiting to be saved. */ |
| 110 | public static final int FLAG_ICON_FILE_PENDING_SAVE = 1 << 11; |
| 111 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 112 | /** |
| 113 | * "Shadow" shortcuts are the ones that are restored, but the owner package hasn't been |
| 114 | * installed yet. |
| 115 | * @hide |
| 116 | */ |
| 117 | public static final int FLAG_SHADOW = 1 << 12; |
| 118 | |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 119 | /** @hide */ |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 120 | public static final int FLAG_LONG_LIVED = 1 << 13; |
| 121 | |
| 122 | /** @hide */ |
Mehdi Alizadeh | 505fb76 | 2020-01-21 17:26:24 -0800 | [diff] [blame] | 123 | public static final int FLAG_CACHED = 1 << 14; |
| 124 | |
| 125 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 126 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 127 | FLAG_DYNAMIC, |
| 128 | FLAG_PINNED, |
| 129 | FLAG_HAS_ICON_RES, |
| 130 | FLAG_HAS_ICON_FILE, |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 131 | FLAG_KEY_FIELDS_ONLY, |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 132 | FLAG_MANIFEST, |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 133 | FLAG_DISABLED, |
| 134 | FLAG_STRINGS_RESOLVED, |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 135 | FLAG_IMMUTABLE, |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 136 | FLAG_ADAPTIVE_BITMAP, |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 137 | FLAG_RETURNED_BY_SERVICE, |
| 138 | FLAG_ICON_FILE_PENDING_SAVE, |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 139 | FLAG_SHADOW, |
| 140 | FLAG_LONG_LIVED, |
Mehdi Alizadeh | 505fb76 | 2020-01-21 17:26:24 -0800 | [diff] [blame] | 141 | FLAG_CACHED, |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 142 | }) |
| 143 | @Retention(RetentionPolicy.SOURCE) |
| 144 | public @interface ShortcutFlags {} |
| 145 | |
| 146 | // Cloning options. |
| 147 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 148 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 149 | private static final int CLONE_REMOVE_ICON = 1 << 0; |
| 150 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 151 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 152 | private static final int CLONE_REMOVE_INTENT = 1 << 1; |
| 153 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 154 | /** @hide */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 155 | public static final int CLONE_REMOVE_NON_KEY_INFO = 1 << 2; |
| 156 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 157 | /** @hide */ |
| 158 | public static final int CLONE_REMOVE_RES_NAMES = 1 << 3; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 159 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 160 | /** @hide */ |
Mehdi Alizadeh | c609602 | 2019-05-27 12:17:36 -0700 | [diff] [blame] | 161 | public static final int CLONE_REMOVE_PERSON = 1 << 4; |
| 162 | |
| 163 | /** @hide */ |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 164 | public static final int CLONE_REMOVE_FOR_CREATOR = CLONE_REMOVE_ICON | CLONE_REMOVE_RES_NAMES; |
| 165 | |
| 166 | /** @hide */ |
| 167 | public static final int CLONE_REMOVE_FOR_LAUNCHER = CLONE_REMOVE_ICON | CLONE_REMOVE_INTENT |
Mehdi Alizadeh | c609602 | 2019-05-27 12:17:36 -0700 | [diff] [blame] | 168 | | CLONE_REMOVE_RES_NAMES | CLONE_REMOVE_PERSON; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 169 | |
| 170 | /** @hide */ |
Makoto Onuki | a01f4f0 | 2016-12-15 15:58:41 -0800 | [diff] [blame] | 171 | public static final int CLONE_REMOVE_FOR_LAUNCHER_APPROVAL = CLONE_REMOVE_INTENT |
Mehdi Alizadeh | c609602 | 2019-05-27 12:17:36 -0700 | [diff] [blame] | 172 | | CLONE_REMOVE_RES_NAMES | CLONE_REMOVE_PERSON; |
| 173 | |
| 174 | /** @hide */ |
| 175 | public static final int CLONE_REMOVE_FOR_APP_PREDICTION = CLONE_REMOVE_ICON |
Makoto Onuki | a01f4f0 | 2016-12-15 15:58:41 -0800 | [diff] [blame] | 176 | | CLONE_REMOVE_RES_NAMES; |
| 177 | |
| 178 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 179 | @IntDef(flag = true, prefix = { "CLONE_" }, value = { |
| 180 | CLONE_REMOVE_ICON, |
| 181 | CLONE_REMOVE_INTENT, |
| 182 | CLONE_REMOVE_NON_KEY_INFO, |
| 183 | CLONE_REMOVE_RES_NAMES, |
Mehdi Alizadeh | c609602 | 2019-05-27 12:17:36 -0700 | [diff] [blame] | 184 | CLONE_REMOVE_PERSON, |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 185 | CLONE_REMOVE_FOR_CREATOR, |
Mehdi Alizadeh | c609602 | 2019-05-27 12:17:36 -0700 | [diff] [blame] | 186 | CLONE_REMOVE_FOR_LAUNCHER, |
| 187 | CLONE_REMOVE_FOR_LAUNCHER_APPROVAL, |
| 188 | CLONE_REMOVE_FOR_APP_PREDICTION |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 189 | }) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 190 | @Retention(RetentionPolicy.SOURCE) |
| 191 | public @interface CloneFlags {} |
| 192 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 193 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 194 | * Shortcut is not disabled. |
| 195 | */ |
| 196 | public static final int DISABLED_REASON_NOT_DISABLED = 0; |
| 197 | |
| 198 | /** |
| 199 | * Shortcut has been disabled by the publisher app with the |
| 200 | * {@link ShortcutManager#disableShortcuts(List)} API. |
| 201 | */ |
| 202 | public static final int DISABLED_REASON_BY_APP = 1; |
| 203 | |
| 204 | /** |
| 205 | * Shortcut has been disabled due to changes to the publisher app. (e.g. a manifest shortcut |
| 206 | * no longer exists.) |
| 207 | */ |
| 208 | public static final int DISABLED_REASON_APP_CHANGED = 2; |
| 209 | |
| 210 | /** |
Makoto Onuki | 5482a8e6 | 2018-01-09 10:31:08 -0800 | [diff] [blame] | 211 | * Shortcut is disabled for an unknown reason. |
| 212 | */ |
| 213 | public static final int DISABLED_REASON_UNKNOWN = 3; |
| 214 | |
| 215 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 216 | * A disabled reason that's equal to or bigger than this is due to backup and restore issue. |
| 217 | * A shortcut with such a reason wil be visible to the launcher, but not to the publisher. |
| 218 | * ({@link #isVisibleToPublisher()} will be false.) |
| 219 | */ |
| 220 | private static final int DISABLED_REASON_RESTORE_ISSUE_START = 100; |
| 221 | |
| 222 | /** |
| 223 | * Shortcut has been restored from the previous device, but the publisher app on the current |
| 224 | * device is of a lower version. The shortcut will not be usable until the app is upgraded to |
| 225 | * the same version or higher. |
| 226 | */ |
| 227 | public static final int DISABLED_REASON_VERSION_LOWER = 100; |
| 228 | |
| 229 | /** |
| 230 | * Shortcut has not been restored because the publisher app does not support backup and restore. |
| 231 | */ |
| 232 | public static final int DISABLED_REASON_BACKUP_NOT_SUPPORTED = 101; |
| 233 | |
| 234 | /** |
| 235 | * Shortcut has not been restored because the publisher app's signature has changed. |
| 236 | */ |
| 237 | public static final int DISABLED_REASON_SIGNATURE_MISMATCH = 102; |
| 238 | |
| 239 | /** |
| 240 | * Shortcut has not been restored for unknown reason. |
| 241 | */ |
| 242 | public static final int DISABLED_REASON_OTHER_RESTORE_ISSUE = 103; |
| 243 | |
| 244 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 245 | @IntDef(prefix = { "DISABLED_REASON_" }, value = { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 246 | DISABLED_REASON_NOT_DISABLED, |
| 247 | DISABLED_REASON_BY_APP, |
| 248 | DISABLED_REASON_APP_CHANGED, |
Makoto Onuki | 5482a8e6 | 2018-01-09 10:31:08 -0800 | [diff] [blame] | 249 | DISABLED_REASON_UNKNOWN, |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 250 | DISABLED_REASON_VERSION_LOWER, |
| 251 | DISABLED_REASON_BACKUP_NOT_SUPPORTED, |
| 252 | DISABLED_REASON_SIGNATURE_MISMATCH, |
| 253 | DISABLED_REASON_OTHER_RESTORE_ISSUE, |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 254 | }) |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 255 | @Retention(RetentionPolicy.SOURCE) |
| 256 | public @interface DisabledReason{} |
| 257 | |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 258 | /** |
| 259 | * Return a label for disabled reasons, which are *not* supposed to be shown to the user. |
| 260 | * @hide |
| 261 | */ |
| 262 | public static String getDisabledReasonDebugString(@DisabledReason int disabledReason) { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 263 | switch (disabledReason) { |
| 264 | case DISABLED_REASON_NOT_DISABLED: |
| 265 | return "[Not disabled]"; |
| 266 | case DISABLED_REASON_BY_APP: |
| 267 | return "[Disabled: by app]"; |
| 268 | case DISABLED_REASON_APP_CHANGED: |
| 269 | return "[Disabled: app changed]"; |
| 270 | case DISABLED_REASON_VERSION_LOWER: |
| 271 | return "[Disabled: lower version]"; |
| 272 | case DISABLED_REASON_BACKUP_NOT_SUPPORTED: |
| 273 | return "[Disabled: backup not supported]"; |
| 274 | case DISABLED_REASON_SIGNATURE_MISMATCH: |
| 275 | return "[Disabled: signature mismatch]"; |
| 276 | case DISABLED_REASON_OTHER_RESTORE_ISSUE: |
| 277 | return "[Disabled: unknown restore issue]"; |
| 278 | } |
| 279 | return "[Disabled: unknown reason:" + disabledReason + "]"; |
| 280 | } |
| 281 | |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 282 | /** |
| 283 | * Return a label for a disabled reason for shortcuts that are disabled due to a backup and |
| 284 | * restore issue. If the reason is not due to backup & restore, then it'll return null. |
| 285 | * |
| 286 | * This method returns localized, user-facing strings, which will be returned by |
| 287 | * {@link #getDisabledMessage()}. |
| 288 | * |
| 289 | * @hide |
| 290 | */ |
| 291 | public static String getDisabledReasonForRestoreIssue(Context context, |
| 292 | @DisabledReason int disabledReason) { |
| 293 | final Resources res = context.getResources(); |
| 294 | |
| 295 | switch (disabledReason) { |
| 296 | case DISABLED_REASON_VERSION_LOWER: |
| 297 | return res.getString( |
| 298 | com.android.internal.R.string.shortcut_restored_on_lower_version); |
| 299 | case DISABLED_REASON_BACKUP_NOT_SUPPORTED: |
| 300 | return res.getString( |
| 301 | com.android.internal.R.string.shortcut_restore_not_supported); |
| 302 | case DISABLED_REASON_SIGNATURE_MISMATCH: |
| 303 | return res.getString( |
| 304 | com.android.internal.R.string.shortcut_restore_signature_mismatch); |
| 305 | case DISABLED_REASON_OTHER_RESTORE_ISSUE: |
| 306 | return res.getString( |
| 307 | com.android.internal.R.string.shortcut_restore_unknown_issue); |
Makoto Onuki | 5482a8e6 | 2018-01-09 10:31:08 -0800 | [diff] [blame] | 308 | case DISABLED_REASON_UNKNOWN: |
| 309 | return res.getString( |
| 310 | com.android.internal.R.string.shortcut_disabled_reason_unknown); |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 311 | } |
| 312 | return null; |
| 313 | } |
| 314 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 315 | /** @hide */ |
| 316 | public static boolean isDisabledForRestoreIssue(@DisabledReason int disabledReason) { |
| 317 | return disabledReason >= DISABLED_REASON_RESTORE_ISSUE_START; |
| 318 | } |
| 319 | |
| 320 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 321 | * Shortcut category for messaging related actions, such as chat. |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 322 | */ |
| 323 | public static final String SHORTCUT_CATEGORY_CONVERSATION = "android.shortcut.conversation"; |
| 324 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 325 | private final String mId; |
| 326 | |
| 327 | @NonNull |
| 328 | private final String mPackageName; |
| 329 | |
| 330 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 331 | private ComponentName mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 332 | |
| 333 | @Nullable |
| 334 | private Icon mIcon; |
| 335 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 336 | private int mTitleResId; |
| 337 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 338 | private String mTitleResName; |
| 339 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 340 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 341 | private CharSequence mTitle; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 342 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 343 | private int mTextResId; |
| 344 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 345 | private String mTextResName; |
| 346 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 347 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 348 | private CharSequence mText; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 349 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 350 | private int mDisabledMessageResId; |
| 351 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 352 | private String mDisabledMessageResName; |
| 353 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 354 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 355 | private CharSequence mDisabledMessage; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 356 | |
| 357 | @Nullable |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 358 | private ArraySet<String> mCategories; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 359 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 360 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 361 | * Intents *with extras removed*. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 362 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 363 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 364 | private Intent[] mIntents; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 365 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 366 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 367 | * Extras for the intents. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 368 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 369 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 370 | private PersistableBundle[] mIntentPersistableExtrases; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 371 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 372 | @Nullable |
| 373 | private Person[] mPersons; |
| 374 | |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 375 | @Nullable |
| 376 | private LocusId mLocusId; |
| 377 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 378 | private int mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 379 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 380 | /** |
| 381 | * Internally used for auto-rank-adjustment. |
| 382 | * |
| 383 | * RANK_CHANGED_BIT is used to denote that the rank of a shortcut is changing. |
| 384 | * The rest of the bits are used to denote the order in which shortcuts are passed to |
| 385 | * APIs, which is used to preserve the argument order when ranks are tie. |
| 386 | */ |
| 387 | private int mImplicitRank; |
| 388 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 389 | @Nullable |
| 390 | private PersistableBundle mExtras; |
| 391 | |
| 392 | private long mLastChangedTimestamp; |
| 393 | |
| 394 | // Internal use only. |
| 395 | @ShortcutFlags |
| 396 | private int mFlags; |
| 397 | |
| 398 | // Internal use only. |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 399 | private int mIconResId; |
| 400 | |
| 401 | private String mIconResName; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 402 | |
| 403 | // Internal use only. |
| 404 | @Nullable |
| 405 | private String mBitmapPath; |
| 406 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 407 | private final int mUserId; |
| 408 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 409 | /** @hide */ |
| 410 | public static final int VERSION_CODE_UNKNOWN = -1; |
| 411 | |
| 412 | private int mDisabledReason; |
| 413 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 414 | private ShortcutInfo(Builder b) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 415 | mUserId = b.mContext.getUserId(); |
| 416 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 417 | mId = Preconditions.checkStringNotEmpty(b.mId, "Shortcut ID must be provided"); |
| 418 | |
| 419 | // Note we can't do other null checks here because SM.updateShortcuts() takes partial |
| 420 | // information. |
| 421 | mPackageName = b.mContext.getPackageName(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 422 | mActivity = b.mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 423 | mIcon = b.mIcon; |
| 424 | mTitle = b.mTitle; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 425 | mTitleResId = b.mTitleResId; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 426 | mText = b.mText; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 427 | mTextResId = b.mTextResId; |
| 428 | mDisabledMessage = b.mDisabledMessage; |
| 429 | mDisabledMessageResId = b.mDisabledMessageResId; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 430 | mCategories = cloneCategories(b.mCategories); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 431 | mIntents = cloneIntents(b.mIntents); |
| 432 | fixUpIntentExtras(); |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 433 | mPersons = clonePersons(b.mPersons); |
| 434 | if (b.mIsLongLived) { |
| 435 | setLongLived(); |
| 436 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 437 | mRank = b.mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 438 | mExtras = b.mExtras; |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 439 | mLocusId = b.mLocusId; |
| 440 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 441 | updateTimestamp(); |
| 442 | } |
| 443 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 444 | /** |
| 445 | * Extract extras from {@link #mIntents} and set them to {@link #mIntentPersistableExtrases} |
| 446 | * as {@link PersistableBundle}, and remove extras from the original intents. |
| 447 | */ |
| 448 | private void fixUpIntentExtras() { |
| 449 | if (mIntents == null) { |
| 450 | mIntentPersistableExtrases = null; |
| 451 | return; |
| 452 | } |
| 453 | mIntentPersistableExtrases = new PersistableBundle[mIntents.length]; |
| 454 | for (int i = 0; i < mIntents.length; i++) { |
| 455 | final Intent intent = mIntents[i]; |
| 456 | final Bundle extras = intent.getExtras(); |
| 457 | if (extras == null) { |
| 458 | mIntentPersistableExtrases[i] = null; |
| 459 | } else { |
| 460 | mIntentPersistableExtrases[i] = new PersistableBundle(extras); |
| 461 | intent.replaceExtras((Bundle) null); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | private static ArraySet<String> cloneCategories(Set<String> source) { |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 467 | if (source == null) { |
| 468 | return null; |
| 469 | } |
| 470 | final ArraySet<String> ret = new ArraySet<>(source.size()); |
| 471 | for (CharSequence s : source) { |
| 472 | if (!TextUtils.isEmpty(s)) { |
| 473 | ret.add(s.toString().intern()); |
| 474 | } |
| 475 | } |
| 476 | return ret; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 479 | private static Intent[] cloneIntents(Intent[] intents) { |
| 480 | if (intents == null) { |
| 481 | return null; |
| 482 | } |
| 483 | final Intent[] ret = new Intent[intents.length]; |
| 484 | for (int i = 0; i < ret.length; i++) { |
| 485 | if (intents[i] != null) { |
| 486 | ret[i] = new Intent(intents[i]); |
| 487 | } |
| 488 | } |
| 489 | return ret; |
| 490 | } |
| 491 | |
| 492 | private static PersistableBundle[] clonePersistableBundle(PersistableBundle[] bundle) { |
| 493 | if (bundle == null) { |
| 494 | return null; |
| 495 | } |
| 496 | final PersistableBundle[] ret = new PersistableBundle[bundle.length]; |
| 497 | for (int i = 0; i < ret.length; i++) { |
| 498 | if (bundle[i] != null) { |
| 499 | ret[i] = new PersistableBundle(bundle[i]); |
| 500 | } |
| 501 | } |
| 502 | return ret; |
| 503 | } |
| 504 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 505 | private static Person[] clonePersons(Person[] persons) { |
| 506 | if (persons == null) { |
| 507 | return null; |
| 508 | } |
| 509 | final Person[] ret = new Person[persons.length]; |
| 510 | for (int i = 0; i < ret.length; i++) { |
| 511 | if (persons[i] != null) { |
| 512 | // Don't need to keep the icon, remove it to save space |
| 513 | ret[i] = persons[i].toBuilder().setIcon(null).build(); |
| 514 | } |
| 515 | } |
| 516 | return ret; |
| 517 | } |
| 518 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 519 | /** |
| 520 | * Throws if any of the mandatory fields is not set. |
| 521 | * |
| 522 | * @hide |
| 523 | */ |
Makoto Onuki | 106ff7a | 2016-12-01 10:17:57 -0800 | [diff] [blame] | 524 | public void enforceMandatoryFields(boolean forPinned) { |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 525 | Preconditions.checkStringNotEmpty(mId, "Shortcut ID must be provided"); |
Makoto Onuki | 106ff7a | 2016-12-01 10:17:57 -0800 | [diff] [blame] | 526 | if (!forPinned) { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 527 | Objects.requireNonNull(mActivity, "Activity must be provided"); |
Makoto Onuki | 106ff7a | 2016-12-01 10:17:57 -0800 | [diff] [blame] | 528 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 529 | if (mTitle == null && mTitleResId == 0) { |
Makoto Onuki | a1d38b3 | 2016-06-10 15:32:26 -0700 | [diff] [blame] | 530 | throw new IllegalArgumentException("Short label must be provided"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 531 | } |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 532 | Objects.requireNonNull(mIntents, "Shortcut Intent must be provided"); |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 533 | Preconditions.checkArgument(mIntents.length > 0, "Shortcut Intent must be provided"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Copy constructor. |
| 538 | */ |
| 539 | private ShortcutInfo(ShortcutInfo source, @CloneFlags int cloneFlags) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 540 | mUserId = source.mUserId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 541 | mId = source.mId; |
| 542 | mPackageName = source.mPackageName; |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 543 | mActivity = source.mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 544 | mFlags = source.mFlags; |
| 545 | mLastChangedTimestamp = source.mLastChangedTimestamp; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 546 | mDisabledReason = source.mDisabledReason; |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 547 | mLocusId = source.mLocusId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 548 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 549 | // Just always keep it since it's cheep. |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 550 | mIconResId = source.mIconResId; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 551 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 552 | if ((cloneFlags & CLONE_REMOVE_NON_KEY_INFO) == 0) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 553 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 554 | if ((cloneFlags & CLONE_REMOVE_ICON) == 0) { |
| 555 | mIcon = source.mIcon; |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 556 | mBitmapPath = source.mBitmapPath; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | mTitle = source.mTitle; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 560 | mTitleResId = source.mTitleResId; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 561 | mText = source.mText; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 562 | mTextResId = source.mTextResId; |
| 563 | mDisabledMessage = source.mDisabledMessage; |
| 564 | mDisabledMessageResId = source.mDisabledMessageResId; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 565 | mCategories = cloneCategories(source.mCategories); |
Mehdi Alizadeh | c609602 | 2019-05-27 12:17:36 -0700 | [diff] [blame] | 566 | if ((cloneFlags & CLONE_REMOVE_PERSON) == 0) { |
| 567 | mPersons = clonePersons(source.mPersons); |
| 568 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 569 | if ((cloneFlags & CLONE_REMOVE_INTENT) == 0) { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 570 | mIntents = cloneIntents(source.mIntents); |
| 571 | mIntentPersistableExtrases = |
| 572 | clonePersistableBundle(source.mIntentPersistableExtrases); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 573 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 574 | mRank = source.mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 575 | mExtras = source.mExtras; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 576 | |
| 577 | if ((cloneFlags & CLONE_REMOVE_RES_NAMES) == 0) { |
| 578 | mTitleResName = source.mTitleResName; |
| 579 | mTextResName = source.mTextResName; |
| 580 | mDisabledMessageResName = source.mDisabledMessageResName; |
| 581 | mIconResName = source.mIconResName; |
| 582 | } |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 583 | } else { |
| 584 | // Set this bit. |
| 585 | mFlags |= FLAG_KEY_FIELDS_ONLY; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 589 | /** |
| 590 | * Load a string resource from the publisher app. |
| 591 | * |
| 592 | * @param resId resource ID |
| 593 | * @param defValue default value to be returned when the specified resource isn't found. |
| 594 | */ |
| 595 | private CharSequence getResourceString(Resources res, int resId, CharSequence defValue) { |
| 596 | try { |
| 597 | return res.getString(resId); |
| 598 | } catch (NotFoundException e) { |
| 599 | Log.e(TAG, "Resource for ID=" + resId + " not found in package " + mPackageName); |
| 600 | return defValue; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * Load the string resources for the text fields and set them to the actual value fields. |
| 606 | * This will set {@link #FLAG_STRINGS_RESOLVED}. |
| 607 | * |
| 608 | * @param res {@link Resources} for the publisher. Must have been loaded with |
| 609 | * {@link PackageManager#getResourcesForApplicationAsUser}. |
| 610 | * |
| 611 | * @hide |
| 612 | */ |
| 613 | public void resolveResourceStrings(@NonNull Resources res) { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 614 | mFlags |= FLAG_STRINGS_RESOLVED; |
| 615 | |
| 616 | if ((mTitleResId == 0) && (mTextResId == 0) && (mDisabledMessageResId == 0)) { |
| 617 | return; // Bail early. |
| 618 | } |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 619 | |
| 620 | if (mTitleResId != 0) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 621 | mTitle = getResourceString(res, mTitleResId, mTitle); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 622 | } |
| 623 | if (mTextResId != 0) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 624 | mText = getResourceString(res, mTextResId, mText); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 625 | } |
| 626 | if (mDisabledMessageResId != 0) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 627 | mDisabledMessage = getResourceString(res, mDisabledMessageResId, mDisabledMessage); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 631 | /** |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 632 | * Look up resource name for a given resource ID. |
| 633 | * |
| 634 | * @return a simple resource name (e.g. "text_1") when {@code withType} is false, or with the |
| 635 | * type (e.g. "string/text_1"). |
| 636 | * |
| 637 | * @hide |
| 638 | */ |
| 639 | @VisibleForTesting |
| 640 | public static String lookUpResourceName(@NonNull Resources res, int resId, boolean withType, |
| 641 | @NonNull String packageName) { |
| 642 | if (resId == 0) { |
| 643 | return null; |
| 644 | } |
| 645 | try { |
| 646 | final String fullName = res.getResourceName(resId); |
| 647 | |
| 648 | if (ANDROID_PACKAGE_NAME.equals(getResourcePackageName(fullName))) { |
| 649 | // If it's a framework resource, the value won't change, so just return the ID |
| 650 | // value as a string. |
| 651 | return String.valueOf(resId); |
| 652 | } |
| 653 | return withType ? getResourceTypeAndEntryName(fullName) |
| 654 | : getResourceEntryName(fullName); |
| 655 | } catch (NotFoundException e) { |
| 656 | Log.e(TAG, "Resource name for ID=" + resId + " not found in package " + packageName |
| 657 | + ". Resource IDs may change when the application is upgraded, and the system" |
| 658 | + " may not be able to find the correct resource."); |
| 659 | return null; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | /** |
| 664 | * Extract the package name from a fully-donated resource name. |
| 665 | * e.g. "com.android.app1:drawable/icon1" -> "com.android.app1" |
| 666 | * @hide |
| 667 | */ |
| 668 | @VisibleForTesting |
| 669 | public static String getResourcePackageName(@NonNull String fullResourceName) { |
| 670 | final int p1 = fullResourceName.indexOf(':'); |
| 671 | if (p1 < 0) { |
| 672 | return null; |
| 673 | } |
| 674 | return fullResourceName.substring(0, p1); |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Extract the type name from a fully-donated resource name. |
| 679 | * e.g. "com.android.app1:drawable/icon1" -> "drawable" |
| 680 | * @hide |
| 681 | */ |
| 682 | @VisibleForTesting |
| 683 | public static String getResourceTypeName(@NonNull String fullResourceName) { |
| 684 | final int p1 = fullResourceName.indexOf(':'); |
| 685 | if (p1 < 0) { |
| 686 | return null; |
| 687 | } |
| 688 | final int p2 = fullResourceName.indexOf('/', p1 + 1); |
| 689 | if (p2 < 0) { |
| 690 | return null; |
| 691 | } |
| 692 | return fullResourceName.substring(p1 + 1, p2); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Extract the type name + the entry name from a fully-donated resource name. |
| 697 | * e.g. "com.android.app1:drawable/icon1" -> "drawable/icon1" |
| 698 | * @hide |
| 699 | */ |
| 700 | @VisibleForTesting |
| 701 | public static String getResourceTypeAndEntryName(@NonNull String fullResourceName) { |
| 702 | final int p1 = fullResourceName.indexOf(':'); |
| 703 | if (p1 < 0) { |
| 704 | return null; |
| 705 | } |
| 706 | return fullResourceName.substring(p1 + 1); |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * Extract the entry name from a fully-donated resource name. |
| 711 | * e.g. "com.android.app1:drawable/icon1" -> "icon1" |
| 712 | * @hide |
| 713 | */ |
| 714 | @VisibleForTesting |
| 715 | public static String getResourceEntryName(@NonNull String fullResourceName) { |
| 716 | final int p1 = fullResourceName.indexOf('/'); |
| 717 | if (p1 < 0) { |
| 718 | return null; |
| 719 | } |
| 720 | return fullResourceName.substring(p1 + 1); |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * Return the resource ID for a given resource ID. |
| 725 | * |
| 726 | * Basically its' a wrapper over {@link Resources#getIdentifier(String, String, String)}, except |
| 727 | * if {@code resourceName} is an integer then it'll just return its value. (Which also the |
| 728 | * aforementioned method would do internally, but not documented, so doing here explicitly.) |
| 729 | * |
| 730 | * @param res {@link Resources} for the publisher. Must have been loaded with |
| 731 | * {@link PackageManager#getResourcesForApplicationAsUser}. |
| 732 | * |
| 733 | * @hide |
| 734 | */ |
| 735 | @VisibleForTesting |
| 736 | public static int lookUpResourceId(@NonNull Resources res, @Nullable String resourceName, |
| 737 | @Nullable String resourceType, String packageName) { |
| 738 | if (resourceName == null) { |
| 739 | return 0; |
| 740 | } |
| 741 | try { |
| 742 | try { |
| 743 | // It the name can be parsed as an integer, just use it. |
| 744 | return Integer.parseInt(resourceName); |
| 745 | } catch (NumberFormatException ignore) { |
| 746 | } |
| 747 | |
| 748 | return res.getIdentifier(resourceName, resourceType, packageName); |
| 749 | } catch (NotFoundException e) { |
| 750 | Log.e(TAG, "Resource ID for name=" + resourceName + " not found in package " |
| 751 | + packageName); |
| 752 | return 0; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Look up resource names from the resource IDs for the icon res and the text fields, and fill |
| 758 | * in the resource name fields. |
| 759 | * |
| 760 | * @param res {@link Resources} for the publisher. Must have been loaded with |
| 761 | * {@link PackageManager#getResourcesForApplicationAsUser}. |
| 762 | * |
| 763 | * @hide |
| 764 | */ |
| 765 | public void lookupAndFillInResourceNames(@NonNull Resources res) { |
| 766 | if ((mTitleResId == 0) && (mTextResId == 0) && (mDisabledMessageResId == 0) |
| 767 | && (mIconResId == 0)) { |
| 768 | return; // Bail early. |
| 769 | } |
| 770 | |
| 771 | // We don't need types for strings because their types are always "string". |
| 772 | mTitleResName = lookUpResourceName(res, mTitleResId, /*withType=*/ false, mPackageName); |
| 773 | mTextResName = lookUpResourceName(res, mTextResId, /*withType=*/ false, mPackageName); |
| 774 | mDisabledMessageResName = lookUpResourceName(res, mDisabledMessageResId, |
| 775 | /*withType=*/ false, mPackageName); |
| 776 | |
| 777 | // But icons have multiple possible types, so include the type. |
| 778 | mIconResName = lookUpResourceName(res, mIconResId, /*withType=*/ true, mPackageName); |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Look up resource IDs from the resource names for the icon res and the text fields, and fill |
| 783 | * in the resource ID fields. |
| 784 | * |
| 785 | * This is called when an app is updated. |
| 786 | * |
| 787 | * @hide |
| 788 | */ |
| 789 | public void lookupAndFillInResourceIds(@NonNull Resources res) { |
| 790 | if ((mTitleResName == null) && (mTextResName == null) && (mDisabledMessageResName == null) |
| 791 | && (mIconResName == null)) { |
| 792 | return; // Bail early. |
| 793 | } |
| 794 | |
| 795 | mTitleResId = lookUpResourceId(res, mTitleResName, RES_TYPE_STRING, mPackageName); |
| 796 | mTextResId = lookUpResourceId(res, mTextResName, RES_TYPE_STRING, mPackageName); |
| 797 | mDisabledMessageResId = lookUpResourceId(res, mDisabledMessageResName, RES_TYPE_STRING, |
| 798 | mPackageName); |
| 799 | |
| 800 | // mIconResName already contains the type, so the third argument is not needed. |
| 801 | mIconResId = lookUpResourceId(res, mIconResName, null, mPackageName); |
| 802 | } |
| 803 | |
| 804 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 805 | * Copy a {@link ShortcutInfo}, optionally removing fields. |
| 806 | * @hide |
| 807 | */ |
| 808 | public ShortcutInfo clone(@CloneFlags int cloneFlags) { |
| 809 | return new ShortcutInfo(this, cloneFlags); |
| 810 | } |
| 811 | |
| 812 | /** |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 813 | * @hide |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 814 | * |
| 815 | * @isUpdating set true if it's "update", as opposed to "replace". |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 816 | */ |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 817 | public void ensureUpdatableWith(ShortcutInfo source, boolean isUpdating) { |
| 818 | if (isUpdating) { |
| 819 | Preconditions.checkState(isVisibleToPublisher(), |
| 820 | "[Framework BUG] Invisible shortcuts can't be updated"); |
| 821 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 822 | Preconditions.checkState(mUserId == source.mUserId, "Owner User ID must match"); |
| 823 | Preconditions.checkState(mId.equals(source.mId), "ID must match"); |
| 824 | Preconditions.checkState(mPackageName.equals(source.mPackageName), |
| 825 | "Package name must match"); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 826 | |
| 827 | if (isVisibleToPublisher()) { |
| 828 | // Don't do this check for restore-blocked shortcuts. |
| 829 | Preconditions.checkState(!isImmutable(), "Target ShortcutInfo is immutable"); |
| 830 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 834 | * Copy non-null/zero fields from another {@link ShortcutInfo}. Only "public" information |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 835 | * will be overwritten. The timestamp will *not* be updated to be consistent with other |
| 836 | * setters (and also the clock is not injectable in this file). |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 837 | * |
| 838 | * - Flags will not change |
| 839 | * - mBitmapPath will not change |
| 840 | * - Current time will be set to timestamp |
| 841 | * |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 842 | * @throws IllegalStateException if source is not compatible. |
| 843 | * |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 844 | * @hide |
| 845 | */ |
| 846 | public void copyNonNullFieldsFrom(ShortcutInfo source) { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 847 | ensureUpdatableWith(source, /*isUpdating=*/ true); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 848 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 849 | if (source.mActivity != null) { |
| 850 | mActivity = source.mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | if (source.mIcon != null) { |
| 854 | mIcon = source.mIcon; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 855 | |
| 856 | mIconResId = 0; |
| 857 | mIconResName = null; |
| 858 | mBitmapPath = null; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 859 | } |
| 860 | if (source.mTitle != null) { |
| 861 | mTitle = source.mTitle; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 862 | mTitleResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 863 | mTitleResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 864 | } else if (source.mTitleResId != 0) { |
| 865 | mTitle = null; |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 866 | mTitleResId = source.mTitleResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 867 | mTitleResName = null; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 868 | } |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 869 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 870 | if (source.mText != null) { |
| 871 | mText = source.mText; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 872 | mTextResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 873 | mTextResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 874 | } else if (source.mTextResId != 0) { |
| 875 | mText = null; |
| 876 | mTextResId = source.mTextResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 877 | mTextResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 878 | } |
| 879 | if (source.mDisabledMessage != null) { |
| 880 | mDisabledMessage = source.mDisabledMessage; |
| 881 | mDisabledMessageResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 882 | mDisabledMessageResName = null; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 883 | } else if (source.mDisabledMessageResId != 0) { |
| 884 | mDisabledMessage = null; |
| 885 | mDisabledMessageResId = source.mDisabledMessageResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 886 | mDisabledMessageResName = null; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 887 | } |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 888 | if (source.mCategories != null) { |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 889 | mCategories = cloneCategories(source.mCategories); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 890 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 891 | if (source.mPersons != null) { |
| 892 | mPersons = clonePersons(source.mPersons); |
| 893 | } |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 894 | if (source.mIntents != null) { |
| 895 | mIntents = cloneIntents(source.mIntents); |
| 896 | mIntentPersistableExtrases = |
| 897 | clonePersistableBundle(source.mIntentPersistableExtrases); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 898 | } |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 899 | if (source.mRank != RANK_NOT_SET) { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 900 | mRank = source.mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 901 | } |
| 902 | if (source.mExtras != null) { |
| 903 | mExtras = source.mExtras; |
| 904 | } |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 905 | |
| 906 | if (source.mLocusId != null) { |
| 907 | mLocusId = source.mLocusId; |
| 908 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | /** |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 912 | * @hide |
| 913 | */ |
| 914 | public static Icon validateIcon(Icon icon) { |
| 915 | switch (icon.getType()) { |
| 916 | case Icon.TYPE_RESOURCE: |
| 917 | case Icon.TYPE_BITMAP: |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 918 | case Icon.TYPE_ADAPTIVE_BITMAP: |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 919 | break; // OK |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 920 | default: |
| 921 | throw getInvalidIconException(); |
| 922 | } |
| 923 | if (icon.hasTint()) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 924 | throw new IllegalArgumentException("Icons with tints are not supported"); |
| 925 | } |
| 926 | |
| 927 | return icon; |
| 928 | } |
| 929 | |
| 930 | /** @hide */ |
| 931 | public static IllegalArgumentException getInvalidIconException() { |
| 932 | return new IllegalArgumentException("Unsupported icon type:" |
Makoto Onuki | a97256b | 2016-07-15 13:23:54 -0700 | [diff] [blame] | 933 | +" only the bitmap and resource types are supported"); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 937 | * Builder class for {@link ShortcutInfo} objects. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 938 | * |
| 939 | * @see ShortcutManager |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 940 | */ |
| 941 | public static class Builder { |
| 942 | private final Context mContext; |
| 943 | |
| 944 | private String mId; |
| 945 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 946 | private ComponentName mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 947 | |
| 948 | private Icon mIcon; |
| 949 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 950 | private int mTitleResId; |
| 951 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 952 | private CharSequence mTitle; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 953 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 954 | private int mTextResId; |
| 955 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 956 | private CharSequence mText; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 957 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 958 | private int mDisabledMessageResId; |
| 959 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 960 | private CharSequence mDisabledMessage; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 961 | |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 962 | private Set<String> mCategories; |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 963 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 964 | private Intent[] mIntents; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 965 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 966 | private Person[] mPersons; |
| 967 | |
| 968 | private boolean mIsLongLived; |
| 969 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 970 | private int mRank = RANK_NOT_SET; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 971 | |
| 972 | private PersistableBundle mExtras; |
| 973 | |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 974 | private LocusId mLocusId; |
| 975 | |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 976 | /** |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 977 | * Old style constructor. |
| 978 | * @hide |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 979 | */ |
| 980 | @Deprecated |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 981 | public Builder(Context context) { |
| 982 | mContext = context; |
| 983 | } |
| 984 | |
| 985 | /** |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 986 | * Used with the old style constructor, kept for unit tests. |
| 987 | * @hide |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 988 | */ |
| 989 | @NonNull |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 990 | @Deprecated |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 991 | public Builder setId(@NonNull String id) { |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 992 | mId = Preconditions.checkStringNotEmpty(id, "id cannot be empty"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 993 | return this; |
| 994 | } |
| 995 | |
| 996 | /** |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 997 | * Constructor. |
| 998 | * |
| 999 | * @param context Client context. |
| 1000 | * @param id ID of the shortcut. |
| 1001 | */ |
| 1002 | public Builder(Context context, String id) { |
| 1003 | mContext = context; |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1004 | mId = Preconditions.checkStringNotEmpty(id, "id cannot be empty"); |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /** |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 1008 | * Sets the {@link LocusId} associated with this shortcut. |
| 1009 | * |
| 1010 | * <p>This method should be called when the {@link LocusId} is used in other places (such |
| 1011 | * as {@link Notification} and {@link ContentCaptureContext}) so the device's intelligence |
| 1012 | * services can correlate them. |
| 1013 | */ |
| 1014 | @NonNull |
| 1015 | public Builder setLocusId(@NonNull LocusId locusId) { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 1016 | mLocusId = Objects.requireNonNull(locusId, "locusId cannot be null"); |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 1017 | return this; |
| 1018 | } |
| 1019 | |
| 1020 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1021 | * Sets the target activity. A shortcut will be shown along with this activity's icon |
| 1022 | * on the launcher. |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1023 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1024 | * When selecting a target activity, keep the following in mind: |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1025 | * <ul> |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1026 | * <li>All dynamic shortcuts must have a target activity. When a shortcut with no target |
| 1027 | * activity is published using |
| 1028 | * {@link ShortcutManager#addDynamicShortcuts(List)} or |
| 1029 | * {@link ShortcutManager#setDynamicShortcuts(List)}, |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1030 | * the first main activity defined in the app's <code>AndroidManifest.xml</code> |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1031 | * file is used. |
| 1032 | * |
| 1033 | * <li>Only "main" activities—ones that define the {@link Intent#ACTION_MAIN} |
| 1034 | * and {@link Intent#CATEGORY_LAUNCHER} intent filters—can be target |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1035 | * activities. |
| 1036 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1037 | * <li>By default, the first main activity defined in the app's manifest is |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1038 | * the target activity. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1039 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1040 | * <li>A target activity must belong to the publisher app. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1041 | * </ul> |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1042 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1043 | * @see ShortcutInfo#getActivity() |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1044 | */ |
| 1045 | @NonNull |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1046 | public Builder setActivity(@NonNull ComponentName activity) { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 1047 | mActivity = Objects.requireNonNull(activity, "activity cannot be null"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1048 | return this; |
| 1049 | } |
| 1050 | |
| 1051 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1052 | * Sets an icon of a shortcut. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1053 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1054 | * <p>Icons are not available on {@link ShortcutInfo} instances |
| 1055 | * returned by {@link ShortcutManager} or {@link LauncherApps}. The default launcher |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1056 | * app can use {@link LauncherApps#getShortcutIconDrawable(ShortcutInfo, int)} |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1057 | * or {@link LauncherApps#getShortcutBadgedIconDrawable(ShortcutInfo, int)} to fetch |
| 1058 | * shortcut icons. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1059 | * |
| 1060 | * <p>Tints set with {@link Icon#setTint} or {@link Icon#setTintList} are not supported |
| 1061 | * and will be ignored. |
| 1062 | * |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1063 | * <p>Only icons created with {@link Icon#createWithBitmap(Bitmap)}, |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 1064 | * {@link Icon#createWithAdaptiveBitmap(Bitmap)} |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1065 | * and {@link Icon#createWithResource} are supported. |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1066 | * Other types, such as URI-based icons, are not supported. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1067 | * |
| 1068 | * @see LauncherApps#getShortcutIconDrawable(ShortcutInfo, int) |
| 1069 | * @see LauncherApps#getShortcutBadgedIconDrawable(ShortcutInfo, int) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1070 | */ |
| 1071 | @NonNull |
| 1072 | public Builder setIcon(Icon icon) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1073 | mIcon = validateIcon(icon); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1074 | return this; |
| 1075 | } |
| 1076 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1077 | /** |
| 1078 | * @hide We don't support resource strings for dynamic shortcuts for now. (But unit tests |
| 1079 | * use it.) |
| 1080 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1081 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1082 | public Builder setShortLabelResId(int shortLabelResId) { |
| 1083 | Preconditions.checkState(mTitle == null, "shortLabel already set"); |
| 1084 | mTitleResId = shortLabelResId; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1085 | return this; |
| 1086 | } |
| 1087 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1088 | /** |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1089 | * Sets the short title of a shortcut. |
| 1090 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1091 | * <p>This is a mandatory field when publishing a new shortcut with |
| 1092 | * {@link ShortcutManager#addDynamicShortcuts(List)} or |
| 1093 | * {@link ShortcutManager#setDynamicShortcuts(List)}. |
Makoto Onuki | 0e65d36 | 2016-03-29 14:46:50 -0700 | [diff] [blame] | 1094 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1095 | * <p>This field is intended to be a concise description of a shortcut. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1096 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1097 | * <p>The recommended maximum length is 10 characters. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1098 | * |
| 1099 | * @see ShortcutInfo#getShortLabel() |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1100 | */ |
| 1101 | @NonNull |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1102 | public Builder setShortLabel(@NonNull CharSequence shortLabel) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1103 | Preconditions.checkState(mTitleResId == 0, "shortLabelResId already set"); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1104 | mTitle = Preconditions.checkStringNotEmpty(shortLabel, "shortLabel cannot be empty"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1105 | return this; |
| 1106 | } |
| 1107 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1108 | /** |
| 1109 | * @hide We don't support resource strings for dynamic shortcuts for now. (But unit tests |
| 1110 | * use it.) |
| 1111 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1112 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1113 | public Builder setLongLabelResId(int longLabelResId) { |
| 1114 | Preconditions.checkState(mText == null, "longLabel already set"); |
| 1115 | mTextResId = longLabelResId; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1116 | return this; |
| 1117 | } |
| 1118 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1119 | /** |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1120 | * Sets the text of a shortcut. |
Makoto Onuki | 0e65d36 | 2016-03-29 14:46:50 -0700 | [diff] [blame] | 1121 | * |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1122 | * <p>This field is intended to be more descriptive than the shortcut title. The launcher |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1123 | * shows this instead of the short title when it has enough space. |
| 1124 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1125 | * <p>The recommend maximum length is 25 characters. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1126 | * |
| 1127 | * @see ShortcutInfo#getLongLabel() |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1128 | */ |
| 1129 | @NonNull |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1130 | public Builder setLongLabel(@NonNull CharSequence longLabel) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1131 | Preconditions.checkState(mTextResId == 0, "longLabelResId already set"); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1132 | mText = Preconditions.checkStringNotEmpty(longLabel, "longLabel cannot be empty"); |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1133 | return this; |
| 1134 | } |
| 1135 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1136 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1137 | @Deprecated |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1138 | public Builder setTitle(@NonNull CharSequence value) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1139 | return setShortLabel(value); |
| 1140 | } |
| 1141 | |
| 1142 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1143 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1144 | public Builder setTitleResId(int value) { |
| 1145 | return setShortLabelResId(value); |
| 1146 | } |
| 1147 | |
| 1148 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1149 | @Deprecated |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1150 | public Builder setText(@NonNull CharSequence value) { |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1151 | return setLongLabel(value); |
| 1152 | } |
| 1153 | |
| 1154 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1155 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1156 | public Builder setTextResId(int value) { |
| 1157 | return setLongLabelResId(value); |
| 1158 | } |
| 1159 | |
| 1160 | /** |
| 1161 | * @hide We don't support resource strings for dynamic shortcuts for now. (But unit tests |
| 1162 | * use it.) |
| 1163 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1164 | @Deprecated |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1165 | public Builder setDisabledMessageResId(int disabledMessageResId) { |
| 1166 | Preconditions.checkState(mDisabledMessage == null, "disabledMessage already set"); |
| 1167 | mDisabledMessageResId = disabledMessageResId; |
| 1168 | return this; |
| 1169 | } |
| 1170 | |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1171 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1172 | * Sets the message that should be shown when the user attempts to start a shortcut that |
| 1173 | * is disabled. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1174 | * |
| 1175 | * @see ShortcutInfo#getDisabledMessage() |
| 1176 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1177 | @NonNull |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1178 | public Builder setDisabledMessage(@NonNull CharSequence disabledMessage) { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1179 | Preconditions.checkState( |
| 1180 | mDisabledMessageResId == 0, "disabledMessageResId already set"); |
| 1181 | mDisabledMessage = |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1182 | Preconditions.checkStringNotEmpty(disabledMessage, |
| 1183 | "disabledMessage cannot be empty"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1184 | return this; |
| 1185 | } |
| 1186 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1187 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1188 | * Sets categories for a shortcut. Launcher apps may use this information to |
| 1189 | * categorize shortcuts. |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1190 | * |
| 1191 | * @see #SHORTCUT_CATEGORY_CONVERSATION |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1192 | * @see ShortcutInfo#getCategories() |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1193 | */ |
| 1194 | @NonNull |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 1195 | public Builder setCategories(Set<String> categories) { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1196 | mCategories = categories; |
| 1197 | return this; |
| 1198 | } |
| 1199 | |
| 1200 | /** |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 1201 | * Sets the intent of a shortcut. Alternatively, {@link #setIntents(Intent[])} can be used |
| 1202 | * to launch an activity with other activities in the back stack. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1203 | * |
| 1204 | * <p>This is a mandatory field when publishing a new shortcut with |
| 1205 | * {@link ShortcutManager#addDynamicShortcuts(List)} or |
| 1206 | * {@link ShortcutManager#setDynamicShortcuts(List)}. |
| 1207 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1208 | * <p>A shortcut can launch any intent that the publisher app has permission to |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1209 | * launch. For example, a shortcut can launch an unexported activity within the publisher |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1210 | * app. A shortcut intent doesn't have to point at the target activity. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1211 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1212 | * <p>The given {@code intent} can contain extras, but these extras must contain values |
| 1213 | * of primitive types in order for the system to persist these values. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1214 | * |
| 1215 | * @see ShortcutInfo#getIntent() |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1216 | * @see #setIntents(Intent[]) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1217 | */ |
| 1218 | @NonNull |
| 1219 | public Builder setIntent(@NonNull Intent intent) { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1220 | return setIntents(new Intent[]{intent}); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | /** |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 1224 | * Sets multiple intents instead of a single intent, in order to launch an activity with |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1225 | * other activities in back stack. Use {@link TaskStackBuilder} to build intents. The |
| 1226 | * last element in the list represents the only intent that doesn't place an activity on |
| 1227 | * the back stack. |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 1228 | * See the {@link ShortcutManager} javadoc for details. |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1229 | * |
| 1230 | * @see Builder#setIntent(Intent) |
| 1231 | * @see ShortcutInfo#getIntents() |
| 1232 | * @see Context#startActivities(Intent[]) |
| 1233 | * @see TaskStackBuilder |
| 1234 | */ |
| 1235 | @NonNull |
| 1236 | public Builder setIntents(@NonNull Intent[] intents) { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 1237 | Objects.requireNonNull(intents, "intents cannot be null"); |
| 1238 | Objects.requireNonNull(intents.length, "intents cannot be empty"); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1239 | for (Intent intent : intents) { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 1240 | Objects.requireNonNull(intent, "intents cannot contain null"); |
| 1241 | Objects.requireNonNull(intent.getAction(), "intent's action must be set"); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1242 | } |
| 1243 | // Make sure always clone incoming intents. |
| 1244 | mIntents = cloneIntents(intents); |
| 1245 | return this; |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /** |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1249 | * Add a person that is relevant to this shortcut. Alternatively, |
| 1250 | * {@link #setPersons(Person[])} can be used to add multiple persons to a shortcut. |
| 1251 | * |
| 1252 | * <p> This is an optional field, but the addition of person may cause this shortcut to |
| 1253 | * appear more prominently in the user interface (e.g. ShareSheet). |
| 1254 | * |
| 1255 | * <p> A person should usually contain a uri in order to benefit from the ranking boost. |
| 1256 | * However, even if no uri is provided, it's beneficial to provide people in the shortcut, |
| 1257 | * such that listeners and voice only devices can announce and handle them properly. |
| 1258 | * |
| 1259 | * @see Person |
| 1260 | * @see #setPersons(Person[]) |
| 1261 | */ |
| 1262 | @NonNull |
| 1263 | public Builder setPerson(@NonNull Person person) { |
| 1264 | return setPersons(new Person[]{person}); |
| 1265 | } |
| 1266 | |
| 1267 | /** |
| 1268 | * Sets multiple persons instead of a single person. |
| 1269 | * |
| 1270 | * @see Person |
| 1271 | * @see #setPerson(Person) |
| 1272 | */ |
| 1273 | @NonNull |
| 1274 | public Builder setPersons(@NonNull Person[] persons) { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 1275 | Objects.requireNonNull(persons, "persons cannot be null"); |
| 1276 | Objects.requireNonNull(persons.length, "persons cannot be empty"); |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1277 | for (Person person : persons) { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 1278 | Objects.requireNonNull(person, "persons cannot contain null"); |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1279 | } |
| 1280 | mPersons = clonePersons(persons); |
| 1281 | return this; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * Sets if a shortcut would be valid even if it has been unpublished/invisible by the app |
| 1286 | * (as a dynamic or pinned shortcut). If it is long lived, it can be cached by various |
| 1287 | * system services even after it has been unpublished as a dynamic shortcut. |
| 1288 | */ |
| 1289 | @NonNull |
Mehdi Alizadeh | 3d2ff4c | 2019-03-13 15:45:03 -0700 | [diff] [blame] | 1290 | public Builder setLongLived(boolean londLived) { |
| 1291 | mIsLongLived = londLived; |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1292 | return this; |
| 1293 | } |
| 1294 | |
| 1295 | /** |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1296 | * "Rank" of a shortcut, which is a non-negative value that's used by the launcher app |
| 1297 | * to sort shortcuts. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1298 | * |
| 1299 | * See {@link ShortcutInfo#getRank()} for details. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1300 | */ |
| 1301 | @NonNull |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1302 | public Builder setRank(int rank) { |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1303 | Preconditions.checkArgument((0 <= rank), |
| 1304 | "Rank cannot be negative or bigger than MAX_RANK"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1305 | mRank = rank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1306 | return this; |
| 1307 | } |
| 1308 | |
| 1309 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1310 | * Extras that the app can set for any purpose. |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1311 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1312 | * <p>Apps can store arbitrary shortcut metadata in extras and retrieve the |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1313 | * metadata later using {@link ShortcutInfo#getExtras()}. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1314 | */ |
| 1315 | @NonNull |
| 1316 | public Builder setExtras(@NonNull PersistableBundle extras) { |
| 1317 | mExtras = extras; |
| 1318 | return this; |
| 1319 | } |
| 1320 | |
Hakan Seyalioglu | 58fc95d | 2016-12-13 15:23:22 -0800 | [diff] [blame] | 1321 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1322 | * Creates a {@link ShortcutInfo} instance. |
| 1323 | */ |
| 1324 | @NonNull |
| 1325 | public ShortcutInfo build() { |
| 1326 | return new ShortcutInfo(this); |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1331 | * Returns the ID of a shortcut. |
| 1332 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1333 | * <p>Shortcut IDs are unique within each publisher app and must be stable across |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1334 | * devices so that shortcuts will still be valid when restored on a different device. |
| 1335 | * See {@link ShortcutManager} for details. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1336 | */ |
| 1337 | @NonNull |
| 1338 | public String getId() { |
| 1339 | return mId; |
| 1340 | } |
| 1341 | |
| 1342 | /** |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 1343 | * Gets the {@link LocusId} associated with this shortcut. |
| 1344 | * |
| 1345 | * <p>Used by the device's intelligence services to correlate objects (such as |
| 1346 | * {@link Notification} and {@link ContentCaptureContext}) that are correlated. |
| 1347 | */ |
| 1348 | @Nullable |
| 1349 | public LocusId getLocusId() { |
| 1350 | return mLocusId; |
| 1351 | } |
| 1352 | |
| 1353 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1354 | * Return the package name of the publisher app. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1355 | */ |
| 1356 | @NonNull |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1357 | public String getPackage() { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1358 | return mPackageName; |
| 1359 | } |
| 1360 | |
| 1361 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1362 | * Return the target activity. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1363 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1364 | * <p>This has nothing to do with the activity that this shortcut will launch. |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1365 | * Launcher apps should show the launcher icon for the returned activity alongside |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1366 | * this shortcut. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1367 | * |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1368 | * @see Builder#setActivity |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1369 | */ |
| 1370 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1371 | public ComponentName getActivity() { |
| 1372 | return mActivity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 1375 | /** @hide */ |
| 1376 | public void setActivity(ComponentName activity) { |
| 1377 | mActivity = activity; |
| 1378 | } |
| 1379 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1380 | /** |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1381 | * Returns the shortcut icon. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1382 | * |
| 1383 | * @hide |
| 1384 | */ |
| 1385 | @Nullable |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1386 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1387 | public Icon getIcon() { |
| 1388 | return mIcon; |
| 1389 | } |
| 1390 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1391 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1392 | @Nullable |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1393 | @Deprecated |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1394 | public CharSequence getTitle() { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1395 | return mTitle; |
| 1396 | } |
| 1397 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1398 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1399 | @Deprecated |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1400 | public int getTitleResId() { |
| 1401 | return mTitleResId; |
| 1402 | } |
| 1403 | |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1404 | /** @hide -- old signature, the internal code still uses it. */ |
| 1405 | @Nullable |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1406 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1407 | public CharSequence getText() { |
| 1408 | return mText; |
| 1409 | } |
| 1410 | |
| 1411 | /** @hide -- old signature, the internal code still uses it. */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1412 | @Deprecated |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1413 | public int getTextResId() { |
| 1414 | return mTextResId; |
| 1415 | } |
| 1416 | |
| 1417 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1418 | * Return the short description of a shortcut. |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1419 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1420 | * @see Builder#setShortLabel(CharSequence) |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1421 | */ |
| 1422 | @Nullable |
| 1423 | public CharSequence getShortLabel() { |
| 1424 | return mTitle; |
| 1425 | } |
| 1426 | |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 1427 | /** @hide */ |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1428 | public int getShortLabelResourceId() { |
| 1429 | return mTitleResId; |
| 1430 | } |
| 1431 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1432 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1433 | * Return the long description of a shortcut. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1434 | * |
| 1435 | * @see Builder#setLongLabel(CharSequence) |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1436 | */ |
| 1437 | @Nullable |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1438 | public CharSequence getLongLabel() { |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1439 | return mText; |
| 1440 | } |
| 1441 | |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 1442 | /** @hide */ |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1443 | public int getLongLabelResourceId() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1444 | return mTextResId; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1448 | * Return the message that should be shown when the user attempts to start a shortcut |
| 1449 | * that is disabled. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1450 | * |
| 1451 | * @see Builder#setDisabledMessage(CharSequence) |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1452 | */ |
| 1453 | @Nullable |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1454 | public CharSequence getDisabledMessage() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1455 | return mDisabledMessage; |
| 1456 | } |
| 1457 | |
Makoto Onuki | 598aca4 | 2016-07-06 16:05:03 -0700 | [diff] [blame] | 1458 | /** @hide */ |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 1459 | public int getDisabledMessageResourceId() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1460 | return mDisabledMessageResId; |
| 1461 | } |
| 1462 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1463 | /** @hide */ |
| 1464 | public void setDisabledReason(@DisabledReason int reason) { |
| 1465 | mDisabledReason = reason; |
| 1466 | } |
| 1467 | |
| 1468 | /** |
| 1469 | * Returns why a shortcut has been disabled. |
| 1470 | */ |
| 1471 | @DisabledReason |
| 1472 | public int getDisabledReason() { |
| 1473 | return mDisabledReason; |
| 1474 | } |
| 1475 | |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 1476 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1477 | * Return the shortcut's categories. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1478 | * |
| 1479 | * @see Builder#setCategories(Set) |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1480 | */ |
| 1481 | @Nullable |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 1482 | public Set<String> getCategories() { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1483 | return mCategories; |
| 1484 | } |
| 1485 | |
| 1486 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1487 | * Returns the intent that is executed when the user selects this shortcut. |
| 1488 | * If setIntents() was used, then return the last intent in the array. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1489 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1490 | * <p>Launcher apps <b>cannot</b> see the intent. If a {@link ShortcutInfo} is |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1491 | * obtained via {@link LauncherApps}, then this method will always return null. |
| 1492 | * Launchers can only start a shortcut intent with {@link LauncherApps#startShortcut}. |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 1493 | * |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1494 | * @see Builder#setIntent(Intent) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1495 | */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1496 | @Nullable |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1497 | public Intent getIntent() { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1498 | if (mIntents == null || mIntents.length == 0) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1499 | return null; |
| 1500 | } |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1501 | final int last = mIntents.length - 1; |
| 1502 | final Intent intent = new Intent(mIntents[last]); |
| 1503 | return setIntentExtras(intent, mIntentPersistableExtrases[last]); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | /** |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1507 | * Return the intent set with {@link Builder#setIntents(Intent[])}. |
| 1508 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1509 | * <p>Launcher apps <b>cannot</b> see the intents. If a {@link ShortcutInfo} is |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1510 | * obtained via {@link LauncherApps}, then this method will always return null. |
| 1511 | * Launchers can only start a shortcut intent with {@link LauncherApps#startShortcut}. |
| 1512 | * |
| 1513 | * @see Builder#setIntents(Intent[]) |
| 1514 | */ |
| 1515 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1516 | public Intent[] getIntents() { |
| 1517 | final Intent[] ret = new Intent[mIntents.length]; |
| 1518 | |
| 1519 | for (int i = 0; i < ret.length; i++) { |
| 1520 | ret[i] = new Intent(mIntents[i]); |
| 1521 | setIntentExtras(ret[i], mIntentPersistableExtrases[i]); |
| 1522 | } |
| 1523 | |
| 1524 | return ret; |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1528 | * Return "raw" intents, which is the original intents without the extras. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1529 | * @hide |
| 1530 | */ |
| 1531 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1532 | public Intent[] getIntentsNoExtras() { |
| 1533 | return mIntents; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1536 | /** |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1537 | * Return the Persons set with {@link Builder#setPersons(Person[])}. |
| 1538 | * |
| 1539 | * @hide |
| 1540 | */ |
| 1541 | @Nullable |
Mehdi Alizadeh | 8887365 | 2019-02-04 14:16:46 -0800 | [diff] [blame] | 1542 | @SystemApi |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1543 | public Person[] getPersons() { |
| 1544 | return clonePersons(mPersons); |
| 1545 | } |
| 1546 | |
| 1547 | /** |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1548 | * The extras in the intents. We convert extras into {@link PersistableBundle} so we can |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1549 | * persist them. |
| 1550 | * @hide |
| 1551 | */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1552 | @Nullable |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1553 | public PersistableBundle[] getIntentPersistableExtrases() { |
| 1554 | return mIntentPersistableExtrases; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1555 | } |
| 1556 | |
Hakan Seyalioglu | 58fc95d | 2016-12-13 15:23:22 -0800 | [diff] [blame] | 1557 | /** |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1558 | * "Rank" of a shortcut, which is a non-negative, sequential value that's unique for each |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1559 | * {@link #getActivity} for each of the two types of shortcuts (static and dynamic). |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1560 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1561 | * <p>Because static shortcuts and dynamic shortcuts have overlapping ranks, |
| 1562 | * when a launcher app shows shortcuts for an activity, it should first show |
| 1563 | * the static shortcuts, followed by the dynamic shortcuts. Within each of those categories, |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1564 | * shortcuts should be sorted by rank in ascending order. |
| 1565 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1566 | * <p><em>Floating shortcuts</em>, or shortcuts that are neither static nor dynamic, will all |
| 1567 | * have rank 0, because they aren't sorted. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1568 | * |
| 1569 | * See the {@link ShortcutManager}'s class javadoc for details. |
| 1570 | * |
| 1571 | * @see Builder#setRank(int) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1572 | */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1573 | public int getRank() { |
| 1574 | return mRank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1577 | /** @hide */ |
| 1578 | public boolean hasRank() { |
| 1579 | return mRank != RANK_NOT_SET; |
| 1580 | } |
| 1581 | |
| 1582 | /** @hide */ |
| 1583 | public void setRank(int rank) { |
| 1584 | mRank = rank; |
| 1585 | } |
| 1586 | |
| 1587 | /** @hide */ |
| 1588 | public void clearImplicitRankAndRankChangedFlag() { |
| 1589 | mImplicitRank = 0; |
| 1590 | } |
| 1591 | |
| 1592 | /** @hide */ |
| 1593 | public void setImplicitRank(int rank) { |
| 1594 | // Make sure to keep RANK_CHANGED_BIT. |
| 1595 | mImplicitRank = (mImplicitRank & RANK_CHANGED_BIT) | (rank & IMPLICIT_RANK_MASK); |
| 1596 | } |
| 1597 | |
| 1598 | /** @hide */ |
| 1599 | public int getImplicitRank() { |
| 1600 | return mImplicitRank & IMPLICIT_RANK_MASK; |
| 1601 | } |
| 1602 | |
| 1603 | /** @hide */ |
| 1604 | public void setRankChanged() { |
| 1605 | mImplicitRank |= RANK_CHANGED_BIT; |
| 1606 | } |
| 1607 | |
| 1608 | /** @hide */ |
| 1609 | public boolean isRankChanged() { |
| 1610 | return (mImplicitRank & RANK_CHANGED_BIT) != 0; |
| 1611 | } |
| 1612 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1613 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1614 | * Extras that the app can set for any purpose. |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1615 | * |
| 1616 | * @see Builder#setExtras(PersistableBundle) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1617 | */ |
| 1618 | @Nullable |
| 1619 | public PersistableBundle getExtras() { |
| 1620 | return mExtras; |
| 1621 | } |
| 1622 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1623 | /** @hide */ |
| 1624 | public int getUserId() { |
| 1625 | return mUserId; |
| 1626 | } |
| 1627 | |
| 1628 | /** |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1629 | * {@link UserHandle} on which the publisher created this shortcut. |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1630 | */ |
| 1631 | public UserHandle getUserHandle() { |
| 1632 | return UserHandle.of(mUserId); |
| 1633 | } |
| 1634 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1635 | /** |
| 1636 | * Last time when any of the fields was updated. |
| 1637 | */ |
| 1638 | public long getLastChangedTimestamp() { |
| 1639 | return mLastChangedTimestamp; |
| 1640 | } |
| 1641 | |
| 1642 | /** @hide */ |
| 1643 | @ShortcutFlags |
| 1644 | public int getFlags() { |
| 1645 | return mFlags; |
| 1646 | } |
| 1647 | |
| 1648 | /** @hide*/ |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1649 | public void replaceFlags(@ShortcutFlags int flags) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1650 | mFlags = flags; |
| 1651 | } |
| 1652 | |
| 1653 | /** @hide*/ |
| 1654 | public void addFlags(@ShortcutFlags int flags) { |
| 1655 | mFlags |= flags; |
| 1656 | } |
| 1657 | |
| 1658 | /** @hide*/ |
| 1659 | public void clearFlags(@ShortcutFlags int flags) { |
| 1660 | mFlags &= ~flags; |
| 1661 | } |
| 1662 | |
| 1663 | /** @hide*/ |
| 1664 | public boolean hasFlags(@ShortcutFlags int flags) { |
| 1665 | return (mFlags & flags) == flags; |
| 1666 | } |
| 1667 | |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 1668 | /** @hide */ |
| 1669 | public boolean isReturnedByServer() { |
| 1670 | return hasFlags(FLAG_RETURNED_BY_SERVICE); |
| 1671 | } |
| 1672 | |
| 1673 | /** @hide */ |
| 1674 | public void setReturnedByServer() { |
| 1675 | addFlags(FLAG_RETURNED_BY_SERVICE); |
| 1676 | } |
| 1677 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 1678 | /** @hide */ |
| 1679 | public boolean isLongLived() { |
| 1680 | return hasFlags(FLAG_LONG_LIVED); |
| 1681 | } |
| 1682 | |
| 1683 | /** @hide */ |
| 1684 | public void setLongLived() { |
| 1685 | addFlags(FLAG_LONG_LIVED); |
| 1686 | } |
| 1687 | |
Mehdi Alizadeh | 505fb76 | 2020-01-21 17:26:24 -0800 | [diff] [blame] | 1688 | /** @hide */ |
| 1689 | public void setCached() { |
| 1690 | addFlags(FLAG_CACHED); |
| 1691 | } |
| 1692 | |
| 1693 | /** Return whether a shortcut is cached. */ |
| 1694 | public boolean isCached() { |
| 1695 | return hasFlags(FLAG_CACHED); |
| 1696 | } |
| 1697 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1698 | /** Return whether a shortcut is dynamic. */ |
| 1699 | public boolean isDynamic() { |
| 1700 | return hasFlags(FLAG_DYNAMIC); |
| 1701 | } |
| 1702 | |
| 1703 | /** Return whether a shortcut is pinned. */ |
| 1704 | public boolean isPinned() { |
| 1705 | return hasFlags(FLAG_PINNED); |
| 1706 | } |
| 1707 | |
| 1708 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1709 | * Return whether a shortcut is static; that is, whether a shortcut is |
| 1710 | * published from AndroidManifest.xml. If {@code true}, the shortcut is |
| 1711 | * also {@link #isImmutable()}. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1712 | * |
| 1713 | * <p>When an app is upgraded and a shortcut is no longer published from AndroidManifest.xml, |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1714 | * this will be set to {@code false}. If the shortcut is not pinned, then it'll disappear. |
| 1715 | * However, if it's pinned, it will still be visible, {@link #isEnabled()} will be |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1716 | * {@code false} and {@link #isImmutable()} will be {@code true}. |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1717 | */ |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1718 | public boolean isDeclaredInManifest() { |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1719 | return hasFlags(FLAG_MANIFEST); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1722 | /** @hide kept for unit tests */ |
| 1723 | @Deprecated |
| 1724 | public boolean isManifestShortcut() { |
| 1725 | return isDeclaredInManifest(); |
| 1726 | } |
| 1727 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1728 | /** |
Makoto Onuki | 9fd9019 | 2017-01-06 18:31:03 +0000 | [diff] [blame] | 1729 | * @return true if pinned but neither static nor dynamic. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1730 | * @hide |
| 1731 | */ |
| 1732 | public boolean isFloating() { |
| 1733 | return isPinned() && !(isDynamic() || isManifestShortcut()); |
| 1734 | } |
| 1735 | |
| 1736 | /** @hide */ |
| 1737 | public boolean isOriginallyFromManifest() { |
| 1738 | return hasFlags(FLAG_IMMUTABLE); |
| 1739 | } |
| 1740 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1741 | /** @hide */ |
| 1742 | public boolean isDynamicVisible() { |
| 1743 | return isDynamic() && isVisibleToPublisher(); |
| 1744 | } |
| 1745 | |
| 1746 | /** @hide */ |
| 1747 | public boolean isPinnedVisible() { |
| 1748 | return isPinned() && isVisibleToPublisher(); |
| 1749 | } |
| 1750 | |
| 1751 | /** @hide */ |
| 1752 | public boolean isManifestVisible() { |
| 1753 | return isDeclaredInManifest() && isVisibleToPublisher(); |
| 1754 | } |
| 1755 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1756 | /** |
| 1757 | * Return if a shortcut is immutable, in which case it cannot be modified with any of |
| 1758 | * {@link ShortcutManager} APIs. |
| 1759 | * |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1760 | * <p>All static shortcuts are immutable. When a static shortcut is pinned and is then |
| 1761 | * disabled because it doesn't appear in AndroidManifest.xml for a newer version of the |
| 1762 | * app, {@link #isDeclaredInManifest()} returns {@code false}, but the shortcut |
| 1763 | * is still immutable. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1764 | * |
| 1765 | * <p>All shortcuts originally published via the {@link ShortcutManager} APIs |
| 1766 | * are all mutable. |
| 1767 | */ |
| 1768 | public boolean isImmutable() { |
| 1769 | return hasFlags(FLAG_IMMUTABLE); |
| 1770 | } |
| 1771 | |
| 1772 | /** |
| 1773 | * Returns {@code false} if a shortcut is disabled with |
| 1774 | * {@link ShortcutManager#disableShortcuts}. |
| 1775 | */ |
| 1776 | public boolean isEnabled() { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1777 | return !hasFlags(FLAG_DISABLED); |
| 1778 | } |
| 1779 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1780 | /** @hide */ |
| 1781 | public boolean isAlive() { |
Mehdi Alizadeh | 505fb76 | 2020-01-21 17:26:24 -0800 | [diff] [blame] | 1782 | return hasFlags(FLAG_PINNED) || hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST) |
| 1783 | || hasFlags(FLAG_CACHED); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | /** @hide */ |
| 1787 | public boolean usesQuota() { |
| 1788 | return hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST); |
| 1789 | } |
| 1790 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1791 | /** |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1792 | * Return whether a shortcut's icon is a resource in the owning package. |
| 1793 | * |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1794 | * @hide internal/unit tests only |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1795 | */ |
| 1796 | public boolean hasIconResource() { |
| 1797 | return hasFlags(FLAG_HAS_ICON_RES); |
| 1798 | } |
| 1799 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1800 | /** @hide */ |
| 1801 | public boolean hasStringResources() { |
| 1802 | return (mTitleResId != 0) || (mTextResId != 0) || (mDisabledMessageResId != 0); |
| 1803 | } |
| 1804 | |
| 1805 | /** @hide */ |
| 1806 | public boolean hasAnyResources() { |
| 1807 | return hasIconResource() || hasStringResources(); |
| 1808 | } |
| 1809 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1810 | /** |
| 1811 | * Return whether a shortcut's icon is stored as a file. |
| 1812 | * |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1813 | * @hide internal/unit tests only |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1814 | */ |
| 1815 | public boolean hasIconFile() { |
| 1816 | return hasFlags(FLAG_HAS_ICON_FILE); |
| 1817 | } |
| 1818 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1819 | /** |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 1820 | * Return whether a shortcut's icon is adaptive bitmap following design guideline |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 1821 | * defined in {@link android.graphics.drawable.AdaptiveIconDrawable}. |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1822 | * |
| 1823 | * @hide internal/unit tests only |
| 1824 | */ |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 1825 | public boolean hasAdaptiveBitmap() { |
| 1826 | return hasFlags(FLAG_ADAPTIVE_BITMAP); |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 1829 | /** @hide */ |
| 1830 | public boolean isIconPendingSave() { |
| 1831 | return hasFlags(FLAG_ICON_FILE_PENDING_SAVE); |
| 1832 | } |
| 1833 | |
| 1834 | /** @hide */ |
| 1835 | public void setIconPendingSave() { |
| 1836 | addFlags(FLAG_ICON_FILE_PENDING_SAVE); |
| 1837 | } |
| 1838 | |
| 1839 | /** @hide */ |
| 1840 | public void clearIconPendingSave() { |
| 1841 | clearFlags(FLAG_ICON_FILE_PENDING_SAVE); |
| 1842 | } |
| 1843 | |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 1844 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1845 | * When the system wasn't able to restore a shortcut, it'll still be registered to the system |
| 1846 | * but disabled, and such shortcuts will not be visible to the publisher. They're still visible |
| 1847 | * to launchers though. |
| 1848 | * |
| 1849 | * @hide |
| 1850 | */ |
| 1851 | @TestApi |
| 1852 | public boolean isVisibleToPublisher() { |
| 1853 | return !isDisabledForRestoreIssue(mDisabledReason); |
| 1854 | } |
| 1855 | |
| 1856 | /** |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1857 | * Return whether a shortcut only contains "key" information only or not. If true, only the |
| 1858 | * following fields are available. |
| 1859 | * <ul> |
| 1860 | * <li>{@link #getId()} |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1861 | * <li>{@link #getPackage()} |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 1862 | * <li>{@link #getActivity()} |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1863 | * <li>{@link #getLastChangedTimestamp()} |
| 1864 | * <li>{@link #isDynamic()} |
| 1865 | * <li>{@link #isPinned()} |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1866 | * <li>{@link #isDeclaredInManifest()} |
| 1867 | * <li>{@link #isImmutable()} |
| 1868 | * <li>{@link #isEnabled()} |
| 1869 | * <li>{@link #getUserHandle()} |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1870 | * </ul> |
Makoto Onuki | 4a91096 | 2016-07-07 13:57:34 -0700 | [diff] [blame] | 1871 | * |
Makoto Onuki | fe9c966 | 2016-07-25 15:12:23 -0700 | [diff] [blame] | 1872 | * <p>For performance reasons, shortcuts passed to |
| 1873 | * {@link LauncherApps.Callback#onShortcutsChanged(String, List, UserHandle)} as well as those |
| 1874 | * returned from {@link LauncherApps#getShortcuts(ShortcutQuery, UserHandle)} |
| 1875 | * while using the {@link ShortcutQuery#FLAG_GET_KEY_FIELDS_ONLY} option contain only key |
| 1876 | * information. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1877 | */ |
| 1878 | public boolean hasKeyFieldsOnly() { |
| 1879 | return hasFlags(FLAG_KEY_FIELDS_ONLY); |
| 1880 | } |
| 1881 | |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1882 | /** @hide */ |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1883 | public boolean hasStringResourcesResolved() { |
| 1884 | return hasFlags(FLAG_STRINGS_RESOLVED); |
| 1885 | } |
| 1886 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1887 | /** @hide */ |
| 1888 | public void updateTimestamp() { |
| 1889 | mLastChangedTimestamp = System.currentTimeMillis(); |
| 1890 | } |
| 1891 | |
| 1892 | /** @hide */ |
| 1893 | // VisibleForTesting |
| 1894 | public void setTimestamp(long value) { |
| 1895 | mLastChangedTimestamp = value; |
| 1896 | } |
| 1897 | |
| 1898 | /** @hide */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1899 | public void clearIcon() { |
| 1900 | mIcon = null; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | /** @hide */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1904 | public void setIconResourceId(int iconResourceId) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1905 | if (mIconResId != iconResourceId) { |
| 1906 | mIconResName = null; |
| 1907 | } |
| 1908 | mIconResId = iconResourceId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1909 | } |
| 1910 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1911 | /** |
| 1912 | * Get the resource ID for the icon, valid only when {@link #hasIconResource()} } is true. |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 1913 | * @hide internal / tests only. |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1914 | */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1915 | public int getIconResourceId() { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1916 | return mIconResId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1917 | } |
| 1918 | |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 1919 | /** |
| 1920 | * Bitmap path. Note this will be null even if {@link #hasIconFile()} is set when the save |
| 1921 | * is pending. Use {@link #isIconPendingSave()} to check it. |
| 1922 | * |
| 1923 | * @hide |
| 1924 | */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1925 | public String getBitmapPath() { |
| 1926 | return mBitmapPath; |
| 1927 | } |
| 1928 | |
| 1929 | /** @hide */ |
| 1930 | public void setBitmapPath(String bitmapPath) { |
| 1931 | mBitmapPath = bitmapPath; |
| 1932 | } |
| 1933 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1934 | /** @hide */ |
| 1935 | public void setDisabledMessageResId(int disabledMessageResId) { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1936 | if (mDisabledMessageResId != disabledMessageResId) { |
| 1937 | mDisabledMessageResName = null; |
| 1938 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1939 | mDisabledMessageResId = disabledMessageResId; |
| 1940 | mDisabledMessage = null; |
| 1941 | } |
| 1942 | |
| 1943 | /** @hide */ |
| 1944 | public void setDisabledMessage(String disabledMessage) { |
| 1945 | mDisabledMessage = disabledMessage; |
| 1946 | mDisabledMessageResId = 0; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1947 | mDisabledMessageResName = null; |
| 1948 | } |
| 1949 | |
| 1950 | /** @hide */ |
| 1951 | public String getTitleResName() { |
| 1952 | return mTitleResName; |
| 1953 | } |
| 1954 | |
| 1955 | /** @hide */ |
| 1956 | public void setTitleResName(String titleResName) { |
| 1957 | mTitleResName = titleResName; |
| 1958 | } |
| 1959 | |
| 1960 | /** @hide */ |
| 1961 | public String getTextResName() { |
| 1962 | return mTextResName; |
| 1963 | } |
| 1964 | |
| 1965 | /** @hide */ |
| 1966 | public void setTextResName(String textResName) { |
| 1967 | mTextResName = textResName; |
| 1968 | } |
| 1969 | |
| 1970 | /** @hide */ |
| 1971 | public String getDisabledMessageResName() { |
| 1972 | return mDisabledMessageResName; |
| 1973 | } |
| 1974 | |
| 1975 | /** @hide */ |
| 1976 | public void setDisabledMessageResName(String disabledMessageResName) { |
| 1977 | mDisabledMessageResName = disabledMessageResName; |
| 1978 | } |
| 1979 | |
| 1980 | /** @hide */ |
| 1981 | public String getIconResName() { |
| 1982 | return mIconResName; |
| 1983 | } |
| 1984 | |
| 1985 | /** @hide */ |
| 1986 | public void setIconResName(String iconResName) { |
| 1987 | mIconResName = iconResName; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1990 | /** |
Kevin Hufnagle | 68d699d | 2016-10-14 19:04:51 -0700 | [diff] [blame] | 1991 | * Replaces the intent. |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 1992 | * |
| 1993 | * @throws IllegalArgumentException when extra is not compatible with {@link PersistableBundle}. |
| 1994 | * |
| 1995 | * @hide |
| 1996 | */ |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1997 | public void setIntents(Intent[] intents) throws IllegalArgumentException { |
Daulet Zhanguzin | a2044e1 | 2019-12-30 16:34:59 +0000 | [diff] [blame] | 1998 | Objects.requireNonNull(intents); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1999 | Preconditions.checkArgument(intents.length > 0); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2000 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2001 | mIntents = cloneIntents(intents); |
| 2002 | fixUpIntentExtras(); |
| 2003 | } |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2004 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2005 | /** @hide */ |
| 2006 | public static Intent setIntentExtras(Intent intent, PersistableBundle extras) { |
| 2007 | if (extras == null) { |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2008 | intent.replaceExtras((Bundle) null); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2009 | } else { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2010 | intent.replaceExtras(new Bundle(extras)); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2011 | } |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2012 | return intent; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /** |
| 2016 | * Replaces the categories. |
| 2017 | * |
| 2018 | * @hide |
| 2019 | */ |
| 2020 | public void setCategories(Set<String> categories) { |
| 2021 | mCategories = cloneCategories(categories); |
| 2022 | } |
| 2023 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2024 | private ShortcutInfo(Parcel source) { |
| 2025 | final ClassLoader cl = getClass().getClassLoader(); |
| 2026 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 2027 | mUserId = source.readInt(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2028 | mId = source.readString(); |
| 2029 | mPackageName = source.readString(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2030 | mActivity = source.readParcelable(cl); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 2031 | mFlags = source.readInt(); |
| 2032 | mIconResId = source.readInt(); |
| 2033 | mLastChangedTimestamp = source.readLong(); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2034 | mDisabledReason = source.readInt(); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 2035 | |
| 2036 | if (source.readInt() == 0) { |
| 2037 | return; // key information only. |
| 2038 | } |
| 2039 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2040 | mIcon = source.readParcelable(cl); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2041 | mTitle = source.readCharSequence(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2042 | mTitleResId = source.readInt(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2043 | mText = source.readCharSequence(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2044 | mTextResId = source.readInt(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2045 | mDisabledMessage = source.readCharSequence(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2046 | mDisabledMessageResId = source.readInt(); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2047 | mIntents = source.readParcelableArray(cl, Intent.class); |
| 2048 | mIntentPersistableExtrases = source.readParcelableArray(cl, PersistableBundle.class); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2049 | mRank = source.readInt(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2050 | mExtras = source.readParcelable(cl); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2051 | mBitmapPath = source.readString(); |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2052 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2053 | mIconResName = source.readString(); |
| 2054 | mTitleResName = source.readString(); |
| 2055 | mTextResName = source.readString(); |
| 2056 | mDisabledMessageResName = source.readString(); |
| 2057 | |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2058 | int N = source.readInt(); |
| 2059 | if (N == 0) { |
| 2060 | mCategories = null; |
| 2061 | } else { |
| 2062 | mCategories = new ArraySet<>(N); |
| 2063 | for (int i = 0; i < N; i++) { |
| 2064 | mCategories.add(source.readString().intern()); |
| 2065 | } |
| 2066 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 2067 | |
| 2068 | mPersons = source.readParcelableArray(cl, Person.class); |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2069 | mLocusId = source.readParcelable(cl); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | @Override |
| 2073 | public void writeToParcel(Parcel dest, int flags) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 2074 | dest.writeInt(mUserId); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2075 | dest.writeString(mId); |
| 2076 | dest.writeString(mPackageName); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2077 | dest.writeParcelable(mActivity, flags); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 2078 | dest.writeInt(mFlags); |
| 2079 | dest.writeInt(mIconResId); |
| 2080 | dest.writeLong(mLastChangedTimestamp); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2081 | dest.writeInt(mDisabledReason); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 2082 | |
| 2083 | if (hasKeyFieldsOnly()) { |
| 2084 | dest.writeInt(0); |
| 2085 | return; |
| 2086 | } |
| 2087 | dest.writeInt(1); |
| 2088 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2089 | dest.writeParcelable(mIcon, flags); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2090 | dest.writeCharSequence(mTitle); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2091 | dest.writeInt(mTitleResId); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2092 | dest.writeCharSequence(mText); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2093 | dest.writeInt(mTextResId); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2094 | dest.writeCharSequence(mDisabledMessage); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2095 | dest.writeInt(mDisabledMessageResId); |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2096 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2097 | dest.writeParcelableArray(mIntents, flags); |
| 2098 | dest.writeParcelableArray(mIntentPersistableExtrases, flags); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2099 | dest.writeInt(mRank); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2100 | dest.writeParcelable(mExtras, flags); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2101 | dest.writeString(mBitmapPath); |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2102 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2103 | dest.writeString(mIconResName); |
| 2104 | dest.writeString(mTitleResName); |
| 2105 | dest.writeString(mTextResName); |
| 2106 | dest.writeString(mDisabledMessageResName); |
| 2107 | |
Makoto Onuki | be73a80 | 2016-04-15 14:46:35 -0700 | [diff] [blame] | 2108 | if (mCategories != null) { |
| 2109 | final int N = mCategories.size(); |
| 2110 | dest.writeInt(N); |
| 2111 | for (int i = 0; i < N; i++) { |
| 2112 | dest.writeString(mCategories.valueAt(i)); |
| 2113 | } |
| 2114 | } else { |
| 2115 | dest.writeInt(0); |
| 2116 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 2117 | |
| 2118 | dest.writeParcelableArray(mPersons, flags); |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2119 | dest.writeParcelable(mLocusId, flags); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 2122 | public static final @android.annotation.NonNull Creator<ShortcutInfo> CREATOR = |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2123 | new Creator<ShortcutInfo>() { |
| 2124 | public ShortcutInfo createFromParcel(Parcel source) { |
| 2125 | return new ShortcutInfo(source); |
| 2126 | } |
| 2127 | public ShortcutInfo[] newArray(int size) { |
| 2128 | return new ShortcutInfo[size]; |
| 2129 | } |
| 2130 | }; |
| 2131 | |
| 2132 | @Override |
| 2133 | public int describeContents() { |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2137 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2138 | /** |
| 2139 | * Return a string representation, intended for logging. Some fields will be retracted. |
| 2140 | */ |
| 2141 | @Override |
| 2142 | public String toString() { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2143 | return toStringInner(/* secure =*/ true, /* includeInternalData =*/ false, |
| 2144 | /*indent=*/ null); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | /** @hide */ |
| 2148 | public String toInsecureString() { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2149 | return toStringInner(/* secure =*/ false, /* includeInternalData =*/ true, |
| 2150 | /*indent=*/ null); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2151 | } |
| 2152 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2153 | /** @hide */ |
| 2154 | public String toDumpString(String indent) { |
| 2155 | return toStringInner(/* secure =*/ false, /* includeInternalData =*/ true, indent); |
| 2156 | } |
| 2157 | |
| 2158 | private void addIndentOrComma(StringBuilder sb, String indent) { |
| 2159 | if (indent != null) { |
| 2160 | sb.append("\n "); |
| 2161 | sb.append(indent); |
| 2162 | } else { |
| 2163 | sb.append(", "); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | private String toStringInner(boolean secure, boolean includeInternalData, String indent) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2168 | final StringBuilder sb = new StringBuilder(); |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2169 | |
| 2170 | if (indent != null) { |
| 2171 | sb.append(indent); |
| 2172 | } |
| 2173 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2174 | sb.append("ShortcutInfo {"); |
| 2175 | |
| 2176 | sb.append("id="); |
| 2177 | sb.append(secure ? "***" : mId); |
| 2178 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2179 | sb.append(", flags=0x"); |
| 2180 | sb.append(Integer.toHexString(mFlags)); |
| 2181 | sb.append(" ["); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2182 | if ((mFlags & FLAG_SHADOW) != 0) { |
| 2183 | // Note the shadow flag isn't actually used anywhere and it's just for dumpsys, so |
| 2184 | // we don't have an isXxx for this. |
| 2185 | sb.append("Sdw"); |
| 2186 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2187 | if (!isEnabled()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2188 | sb.append("Dis"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2189 | } |
| 2190 | if (isImmutable()) { |
| 2191 | sb.append("Im"); |
| 2192 | } |
| 2193 | if (isManifestShortcut()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2194 | sb.append("Man"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2195 | } |
| 2196 | if (isDynamic()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2197 | sb.append("Dyn"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2198 | } |
| 2199 | if (isPinned()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2200 | sb.append("Pin"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2201 | } |
| 2202 | if (hasIconFile()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2203 | sb.append("Ic-f"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2204 | } |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 2205 | if (isIconPendingSave()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2206 | sb.append("Pens"); |
Makoto Onuki | 475c365 | 2017-05-08 14:29:03 -0700 | [diff] [blame] | 2207 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2208 | if (hasIconResource()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2209 | sb.append("Ic-r"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2210 | } |
| 2211 | if (hasKeyFieldsOnly()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2212 | sb.append("Key"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2213 | } |
| 2214 | if (hasStringResourcesResolved()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2215 | sb.append("Str"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2216 | } |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 2217 | if (isReturnedByServer()) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2218 | sb.append("Rets"); |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 2219 | } |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 2220 | if (isLongLived()) { |
| 2221 | sb.append("Liv"); |
| 2222 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2223 | sb.append("]"); |
| 2224 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2225 | addIndentOrComma(sb, indent); |
| 2226 | |
| 2227 | sb.append("packageName="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2228 | sb.append(mPackageName); |
| 2229 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2230 | addIndentOrComma(sb, indent); |
| 2231 | |
| 2232 | sb.append("activity="); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2233 | sb.append(mActivity); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2234 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2235 | addIndentOrComma(sb, indent); |
| 2236 | |
| 2237 | sb.append("shortLabel="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2238 | sb.append(secure ? "***" : mTitle); |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 2239 | sb.append(", resId="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2240 | sb.append(mTitleResId); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2241 | sb.append("["); |
| 2242 | sb.append(mTitleResName); |
| 2243 | sb.append("]"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2244 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2245 | addIndentOrComma(sb, indent); |
| 2246 | |
| 2247 | sb.append("longLabel="); |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 2248 | sb.append(secure ? "***" : mText); |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 2249 | sb.append(", resId="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2250 | sb.append(mTextResId); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2251 | sb.append("["); |
| 2252 | sb.append(mTextResName); |
| 2253 | sb.append("]"); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2254 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2255 | addIndentOrComma(sb, indent); |
| 2256 | |
| 2257 | sb.append("disabledMessage="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2258 | sb.append(secure ? "***" : mDisabledMessage); |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 2259 | sb.append(", resId="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2260 | sb.append(mDisabledMessageResId); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2261 | sb.append("["); |
| 2262 | sb.append(mDisabledMessageResName); |
| 2263 | sb.append("]"); |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 2264 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2265 | addIndentOrComma(sb, indent); |
| 2266 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2267 | sb.append("disabledReason="); |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 2268 | sb.append(getDisabledReasonDebugString(mDisabledReason)); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2269 | |
| 2270 | addIndentOrComma(sb, indent); |
| 2271 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2272 | sb.append("categories="); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 2273 | sb.append(mCategories); |
| 2274 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2275 | addIndentOrComma(sb, indent); |
| 2276 | |
Mehdi Alizadeh | 14242af | 2018-12-20 20:11:35 -0800 | [diff] [blame] | 2277 | sb.append("persons="); |
| 2278 | sb.append(mPersons); |
| 2279 | |
| 2280 | addIndentOrComma(sb, indent); |
| 2281 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2282 | sb.append("icon="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2283 | sb.append(mIcon); |
| 2284 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2285 | addIndentOrComma(sb, indent); |
| 2286 | |
| 2287 | sb.append("rank="); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2288 | sb.append(mRank); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2289 | |
| 2290 | sb.append(", timestamp="); |
| 2291 | sb.append(mLastChangedTimestamp); |
| 2292 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2293 | addIndentOrComma(sb, indent); |
| 2294 | |
| 2295 | sb.append("intents="); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2296 | if (mIntents == null) { |
| 2297 | sb.append("null"); |
| 2298 | } else { |
| 2299 | if (secure) { |
| 2300 | sb.append("size:"); |
| 2301 | sb.append(mIntents.length); |
| 2302 | } else { |
| 2303 | final int size = mIntents.length; |
| 2304 | sb.append("["); |
| 2305 | String sep = ""; |
| 2306 | for (int i = 0; i < size; i++) { |
| 2307 | sb.append(sep); |
| 2308 | sep = ", "; |
| 2309 | sb.append(mIntents[i]); |
| 2310 | sb.append("/"); |
| 2311 | sb.append(mIntentPersistableExtrases[i]); |
| 2312 | } |
| 2313 | sb.append("]"); |
| 2314 | } |
| 2315 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2316 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2317 | addIndentOrComma(sb, indent); |
| 2318 | |
| 2319 | sb.append("extras="); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2320 | sb.append(mExtras); |
| 2321 | |
| 2322 | if (includeInternalData) { |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2323 | addIndentOrComma(sb, indent); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2324 | |
Makoto Onuki | 6208c67 | 2017-10-02 16:20:35 -0700 | [diff] [blame] | 2325 | sb.append("iconRes="); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2326 | sb.append(mIconResId); |
| 2327 | sb.append("["); |
| 2328 | sb.append(mIconResName); |
| 2329 | sb.append("]"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2330 | |
| 2331 | sb.append(", bitmapPath="); |
| 2332 | sb.append(mBitmapPath); |
| 2333 | } |
| 2334 | |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2335 | if (mLocusId != null) { |
| 2336 | sb.append("locusId="); sb.append(mLocusId); // LocusId.toString() is PII-safe. |
| 2337 | } |
| 2338 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2339 | sb.append("}"); |
| 2340 | return sb.toString(); |
| 2341 | } |
| 2342 | |
| 2343 | /** @hide */ |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 2344 | public ShortcutInfo( |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2345 | @UserIdInt int userId, String id, String packageName, ComponentName activity, |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2346 | Icon icon, CharSequence title, int titleResId, String titleResName, |
| 2347 | CharSequence text, int textResId, String textResName, |
| 2348 | CharSequence disabledMessage, int disabledMessageResId, String disabledMessageResName, |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2349 | Set<String> categories, Intent[] intentsWithExtras, int rank, PersistableBundle extras, |
| 2350 | long lastChangedTimestamp, |
Mehdi Alizadeh | ebb4b60 | 2019-02-05 15:52:18 -0800 | [diff] [blame] | 2351 | int flags, int iconResId, String iconResName, String bitmapPath, int disabledReason, |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2352 | Person[] persons, LocusId locusId) { |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 2353 | mUserId = userId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2354 | mId = id; |
| 2355 | mPackageName = packageName; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2356 | mActivity = activity; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2357 | mIcon = icon; |
| 2358 | mTitle = title; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2359 | mTitleResId = titleResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2360 | mTitleResName = titleResName; |
Makoto Onuki | e3ae7ec | 2016-03-29 15:45:25 -0700 | [diff] [blame] | 2361 | mText = text; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2362 | mTextResId = textResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2363 | mTextResName = textResName; |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2364 | mDisabledMessage = disabledMessage; |
| 2365 | mDisabledMessageResId = disabledMessageResId; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2366 | mDisabledMessageResName = disabledMessageResName; |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 2367 | mCategories = cloneCategories(categories); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2368 | mIntents = cloneIntents(intentsWithExtras); |
| 2369 | fixUpIntentExtras(); |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 2370 | mRank = rank; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2371 | mExtras = extras; |
| 2372 | mLastChangedTimestamp = lastChangedTimestamp; |
| 2373 | mFlags = flags; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 2374 | mIconResId = iconResId; |
| 2375 | mIconResName = iconResName; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2376 | mBitmapPath = bitmapPath; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2377 | mDisabledReason = disabledReason; |
Mehdi Alizadeh | ebb4b60 | 2019-02-05 15:52:18 -0800 | [diff] [blame] | 2378 | mPersons = persons; |
Felipe Leme | 90205ef4 | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2379 | mLocusId = locusId; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2380 | } |
| 2381 | } |