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