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 com.android.server.pm; |
| 17 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 18 | import static android.content.pm.ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED; |
| 19 | import static android.content.pm.ShortcutInfo.DISABLED_REASON_NOT_DISABLED; |
| 20 | import static android.content.pm.ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH; |
| 21 | import static android.content.pm.ShortcutInfo.DISABLED_REASON_VERSION_LOWER; |
| 22 | |
Makoto Onuki | d0010c5 | 2017-03-30 14:17:35 -0700 | [diff] [blame] | 23 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyOrNull; |
| 24 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyStringOrNull; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 25 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDisabled; |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 26 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDynamic; |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 27 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDynamicOrPinned; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 28 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllEnabled; |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 29 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllHaveIntents; |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 30 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllHaveTitle; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 31 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllImmutable; |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 32 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllKeyFieldsOnly; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 33 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllManifest; |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 34 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotHaveIntents; |
| 35 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotHaveTitle; |
| 36 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotKeyFieldsOnly; |
| 37 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotManifest; |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 38 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllPinned; |
| 39 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllUnique; |
| 40 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertBitmapSize; |
| 41 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertBundleEmpty; |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 42 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertCallbackNotReceived; |
| 43 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertCallbackReceived; |
| 44 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertCannotUpdateImmutable; |
| 45 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertDynamicAndPinned; |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 46 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertDynamicOnly; |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 47 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertDynamicShortcutCountExceeded; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 48 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertEmpty; |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 49 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertExpectException; |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 50 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertForLauncherCallback; |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 51 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertShortcutIds; |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 52 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertWith; |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 53 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.filterByActivity; |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 54 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.findShortcut; |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 55 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.hashSet; |
| 56 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.list; |
| 57 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.makeBundle; |
| 58 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.pfdToBitmap; |
| 59 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.resetAll; |
| 60 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.set; |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 61 | import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.waitOnMainThread; |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 62 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 63 | import static org.mockito.Matchers.any; |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 64 | import static org.mockito.Matchers.anyInt; |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 65 | import static org.mockito.Matchers.anyString; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 66 | import static org.mockito.Matchers.eq; |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 67 | import static org.mockito.Mockito.doReturn; |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 68 | import static org.mockito.Mockito.mock; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 69 | import static org.mockito.Mockito.reset; |
| 70 | import static org.mockito.Mockito.times; |
| 71 | import static org.mockito.Mockito.verify; |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 72 | |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 73 | import android.Manifest.permission; |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 74 | import android.app.ActivityManager; |
| 75 | import android.content.ActivityNotFoundException; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 76 | import android.content.ComponentName; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 77 | import android.content.Intent; |
Mehdi Alizadeh | c86dd1f | 2019-01-25 16:59:54 -0800 | [diff] [blame] | 78 | import android.content.IntentFilter; |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 79 | import android.content.pm.ApplicationInfo; |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 80 | import android.content.pm.LauncherApps; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 81 | import android.content.pm.LauncherApps.PinItemRequest; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 82 | import android.content.pm.LauncherApps.ShortcutQuery; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 83 | import android.content.pm.PackageInfo; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 84 | import android.content.pm.ShortcutInfo; |
Mehdi Alizadeh | 505fb76 | 2020-01-21 17:26:24 -0800 | [diff] [blame] | 85 | import android.content.pm.ShortcutManager; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 86 | import android.graphics.Bitmap; |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 87 | import android.graphics.Bitmap.CompressFormat; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 88 | import android.graphics.BitmapFactory; |
Hyunyoung Song | be8835e | 2017-02-17 11:25:08 -0800 | [diff] [blame] | 89 | import android.graphics.drawable.AdaptiveIconDrawable; |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 90 | import android.graphics.drawable.Drawable; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 91 | import android.graphics.drawable.Icon; |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 92 | import android.net.Uri; |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 93 | import android.os.Bundle; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 94 | import android.os.Handler; |
| 95 | import android.os.Looper; |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 96 | import android.os.Process; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 97 | import android.os.UserHandle; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 98 | import android.test.suitebuilder.annotation.SmallTest; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 99 | import android.util.Log; |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 100 | import android.util.SparseArray; |
Mehdi Alizadeh | abec319 | 2019-06-27 18:06:15 -0700 | [diff] [blame] | 101 | import android.util.Xml; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 102 | |
| 103 | import com.android.frameworks.servicestests.R; |
Mehdi Alizadeh | abec319 | 2019-06-27 18:06:15 -0700 | [diff] [blame] | 104 | import com.android.internal.util.FastXmlSerializer; |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 105 | import com.android.server.pm.ShortcutService.ConfigConstants; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 106 | import com.android.server.pm.ShortcutService.FileOutputStreamWithPath; |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 107 | import com.android.server.pm.ShortcutUser.PackageWithUser; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 108 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 109 | import org.mockito.ArgumentCaptor; |
Mehdi Alizadeh | abec319 | 2019-06-27 18:06:15 -0700 | [diff] [blame] | 110 | import org.xmlpull.v1.XmlPullParser; |
| 111 | import org.xmlpull.v1.XmlPullParserException; |
| 112 | import org.xmlpull.v1.XmlSerializer; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 113 | |
Mehdi Alizadeh | abec319 | 2019-06-27 18:06:15 -0700 | [diff] [blame] | 114 | import java.io.ByteArrayInputStream; |
| 115 | import java.io.ByteArrayOutputStream; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 116 | import java.io.File; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 117 | import java.io.IOException; |
Mehdi Alizadeh | abec319 | 2019-06-27 18:06:15 -0700 | [diff] [blame] | 118 | import java.io.InputStreamReader; |
| 119 | import java.nio.charset.StandardCharsets; |
Mehdi Alizadeh | 3277462 | 2018-11-05 17:32:01 -0800 | [diff] [blame] | 120 | import java.util.ArrayList; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 121 | import java.util.List; |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 122 | import java.util.Locale; |
Makoto Onuki | 82fb2eb | 2017-03-31 16:58:26 -0700 | [diff] [blame] | 123 | import java.util.function.BiConsumer; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Tests for ShortcutService and ShortcutManager. |
| 127 | * |
| 128 | m FrameworksServicesTests && |
| 129 | adb install \ |
| 130 | -r -g ${ANDROID_PRODUCT_OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk && |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 131 | adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest1 \ |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 132 | -w com.android.frameworks.servicestests/androidx.test.runner.AndroidJUnitRunner |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 133 | */ |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 134 | @SmallTest |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 135 | public class ShortcutManagerTest1 extends BaseShortcutManagerTest { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 136 | /** |
| 137 | * Test for the first launch path, no settings file available. |
| 138 | */ |
| 139 | public void testFirstInitialize() { |
| 140 | assertResetTimes(START_TIME, START_TIME + INTERVAL); |
| 141 | } |
| 142 | |
| 143 | /** |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 144 | * Test for {@link ShortcutService#getLastResetTimeLocked()} and |
| 145 | * {@link ShortcutService#getNextResetTimeLocked()}. |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 146 | */ |
| 147 | public void testUpdateAndGetNextResetTimeLocked() { |
| 148 | assertResetTimes(START_TIME, START_TIME + INTERVAL); |
| 149 | |
| 150 | // Advance clock. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 151 | mInjectedCurrentTimeMillis += 100; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 152 | |
| 153 | // Shouldn't have changed. |
| 154 | assertResetTimes(START_TIME, START_TIME + INTERVAL); |
| 155 | |
| 156 | // Advance clock, almost the reset time. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 157 | mInjectedCurrentTimeMillis = START_TIME + INTERVAL - 1; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 158 | |
| 159 | // Shouldn't have changed. |
| 160 | assertResetTimes(START_TIME, START_TIME + INTERVAL); |
| 161 | |
| 162 | // Advance clock. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 163 | mInjectedCurrentTimeMillis += 1; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 164 | |
| 165 | assertResetTimes(START_TIME + INTERVAL, START_TIME + 2 * INTERVAL); |
| 166 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 167 | // Advance further; 4 hours since start. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 168 | mInjectedCurrentTimeMillis = START_TIME + 4 * INTERVAL + 50; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 169 | |
| 170 | assertResetTimes(START_TIME + 4 * INTERVAL, START_TIME + 5 * INTERVAL); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Test for the restoration from saved file. |
| 175 | */ |
| 176 | public void testInitializeFromSavedFile() { |
| 177 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 178 | mInjectedCurrentTimeMillis = START_TIME + 4 * INTERVAL + 50; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 179 | assertResetTimes(START_TIME + 4 * INTERVAL, START_TIME + 5 * INTERVAL); |
| 180 | |
| 181 | mService.saveBaseStateLocked(); |
| 182 | |
| 183 | dumpBaseStateFile(); |
| 184 | |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 185 | mService.saveDirtyInfo(); |
| 186 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 187 | // Restore. |
| 188 | initService(); |
| 189 | |
| 190 | assertResetTimes(START_TIME + 4 * INTERVAL, START_TIME + 5 * INTERVAL); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Test for the restoration from restored file. |
| 195 | */ |
| 196 | public void testLoadFromBrokenFile() { |
| 197 | // TODO Add various broken cases. |
| 198 | } |
| 199 | |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 200 | public void testLoadConfig() { |
| 201 | mService.updateConfigurationLocked( |
| 202 | ConfigConstants.KEY_RESET_INTERVAL_SEC + "=123," |
| 203 | + ConfigConstants.KEY_MAX_SHORTCUTS + "=4," |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 204 | + ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL + "=5," |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 205 | + ConfigConstants.KEY_MAX_ICON_DIMENSION_DP + "=100," |
| 206 | + ConfigConstants.KEY_MAX_ICON_DIMENSION_DP_LOWRAM + "=50," |
| 207 | + ConfigConstants.KEY_ICON_FORMAT + "=WEBP," |
| 208 | + ConfigConstants.KEY_ICON_QUALITY + "=75"); |
| 209 | assertEquals(123000, mService.getResetIntervalForTest()); |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 210 | assertEquals(4, mService.getMaxShortcutsForTest()); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 211 | assertEquals(5, mService.getMaxUpdatesPerIntervalForTest()); |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 212 | assertEquals(100, mService.getMaxIconDimensionForTest()); |
| 213 | assertEquals(CompressFormat.WEBP, mService.getIconPersistFormatForTest()); |
| 214 | assertEquals(75, mService.getIconPersistQualityForTest()); |
| 215 | |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 216 | mInjectedIsLowRamDevice = true; |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 217 | mService.updateConfigurationLocked( |
| 218 | ConfigConstants.KEY_MAX_ICON_DIMENSION_DP + "=100," |
| 219 | + ConfigConstants.KEY_MAX_ICON_DIMENSION_DP_LOWRAM + "=50," |
| 220 | + ConfigConstants.KEY_ICON_FORMAT + "=JPEG"); |
| 221 | assertEquals(ShortcutService.DEFAULT_RESET_INTERVAL_SEC * 1000, |
| 222 | mService.getResetIntervalForTest()); |
| 223 | |
| 224 | assertEquals(ShortcutService.DEFAULT_MAX_SHORTCUTS_PER_APP, |
Makoto Onuki | b5a012f | 2016-06-21 11:13:53 -0700 | [diff] [blame] | 225 | mService.getMaxShortcutsForTest()); |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 226 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 227 | assertEquals(ShortcutService.DEFAULT_MAX_UPDATES_PER_INTERVAL, |
| 228 | mService.getMaxUpdatesPerIntervalForTest()); |
Makoto Onuki | 4362a66 | 2016-03-08 18:59:09 -0800 | [diff] [blame] | 229 | |
| 230 | assertEquals(50, mService.getMaxIconDimensionForTest()); |
| 231 | |
| 232 | assertEquals(CompressFormat.JPEG, mService.getIconPersistFormatForTest()); |
| 233 | |
| 234 | assertEquals(ShortcutService.DEFAULT_ICON_PERSIST_QUALITY, |
| 235 | mService.getIconPersistQualityForTest()); |
| 236 | } |
| 237 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 238 | // === Test for app side APIs === |
| 239 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 240 | /** Test for {@link android.content.pm.ShortcutManager#getMaxShortcutCountForActivity()} */ |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 241 | public void testGetMaxDynamicShortcutCount() { |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 242 | assertEquals(MAX_SHORTCUTS, mManager.getMaxShortcutCountForActivity()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** Test for {@link android.content.pm.ShortcutManager#getRemainingCallCount()} */ |
| 246 | public void testGetRemainingCallCount() { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 247 | assertEquals(MAX_UPDATES_PER_INTERVAL, mManager.getRemainingCallCount()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 250 | public void testGetIconMaxDimensions() { |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 251 | assertEquals(MAX_ICON_DIMENSION, mManager.getIconMaxWidth()); |
| 252 | assertEquals(MAX_ICON_DIMENSION, mManager.getIconMaxHeight()); |
| 253 | } |
| 254 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 255 | /** Test for {@link android.content.pm.ShortcutManager#getRateLimitResetTime()} */ |
| 256 | public void testGetRateLimitResetTime() { |
| 257 | assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime()); |
| 258 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 259 | mInjectedCurrentTimeMillis = START_TIME + 4 * INTERVAL + 50; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 260 | |
| 261 | assertEquals(START_TIME + 5 * INTERVAL, mManager.getRateLimitResetTime()); |
| 262 | } |
| 263 | |
| 264 | public void testSetDynamicShortcuts() { |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 265 | setCaller(CALLING_PACKAGE_1, USER_0); |
| 266 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 267 | final Icon icon1 = Icon.createWithResource(getTestContext(), R.drawable.icon1); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 268 | final Icon icon2 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 269 | getTestContext().getResources(), R.drawable.icon2)); |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 270 | final Icon icon3 = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 271 | getTestContext().getResources(), R.drawable.icon2)); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 272 | |
| 273 | final ShortcutInfo si1 = makeShortcut( |
| 274 | "shortcut1", |
| 275 | "Title 1", |
| 276 | makeComponent(ShortcutActivity.class), |
| 277 | icon1, |
| 278 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, |
| 279 | "key1", "val1", "nest", makeBundle("key", 123)), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 280 | /* weight */ 10); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 281 | |
| 282 | final ShortcutInfo si2 = makeShortcut( |
| 283 | "shortcut2", |
| 284 | "Title 2", |
| 285 | /* activity */ null, |
| 286 | icon2, |
| 287 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 288 | /* weight */ 12); |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 289 | final ShortcutInfo si3 = makeShortcut( |
| 290 | "shortcut3", |
| 291 | "Title 3", |
| 292 | /* activity */ null, |
| 293 | icon3, |
| 294 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 295 | /* weight */ 13); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 296 | |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 297 | assertTrue(mManager.setDynamicShortcuts(list(si1, si2, si3))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 298 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 299 | mManager.getDynamicShortcuts()), |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 300 | "shortcut1", "shortcut2", "shortcut3"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 301 | assertEquals(2, mManager.getRemainingCallCount()); |
| 302 | |
| 303 | // TODO: Check fields |
| 304 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 305 | assertTrue(mManager.setDynamicShortcuts(list(si1))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 306 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 307 | mManager.getDynamicShortcuts()), |
| 308 | "shortcut1"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 309 | assertEquals(1, mManager.getRemainingCallCount()); |
| 310 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 311 | assertTrue(mManager.setDynamicShortcuts(list())); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 312 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 313 | assertEquals(0, mManager.getRemainingCallCount()); |
| 314 | |
| 315 | dumpsysOnLogcat(); |
| 316 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 317 | mInjectedCurrentTimeMillis++; // Need to advance the clock for reset to work. |
Makoto Onuki | 4554d0e | 2016-03-14 15:51:41 -0700 | [diff] [blame] | 318 | mService.resetThrottlingInner(UserHandle.USER_SYSTEM); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 319 | |
| 320 | dumpsysOnLogcat(); |
| 321 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 322 | assertTrue(mManager.setDynamicShortcuts(list(si2, si3))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 323 | assertEquals(2, mManager.getDynamicShortcuts().size()); |
| 324 | |
| 325 | // TODO Check max number |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 326 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 327 | mRunningUsers.put(USER_10, true); |
| 328 | |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 329 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 330 | assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1")))); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 331 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | public void testAddDynamicShortcuts() { |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 335 | setCaller(CALLING_PACKAGE_1, USER_0); |
| 336 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 337 | final ShortcutInfo si1 = makeShortcut("shortcut1"); |
| 338 | final ShortcutInfo si2 = makeShortcut("shortcut2"); |
| 339 | final ShortcutInfo si3 = makeShortcut("shortcut3"); |
| 340 | |
| 341 | assertEquals(3, mManager.getRemainingCallCount()); |
| 342 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 343 | assertTrue(mManager.setDynamicShortcuts(list(si1))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 344 | assertEquals(2, mManager.getRemainingCallCount()); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 345 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 346 | mManager.getDynamicShortcuts()), |
| 347 | "shortcut1"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 348 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 349 | assertTrue(mManager.addDynamicShortcuts(list(si2, si3))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 350 | assertEquals(1, mManager.getRemainingCallCount()); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 351 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 352 | mManager.getDynamicShortcuts()), |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 353 | "shortcut1", "shortcut2", "shortcut3"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 354 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 355 | // This should not crash. It'll still consume the quota. |
| 356 | assertTrue(mManager.addDynamicShortcuts(list())); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 357 | assertEquals(0, mManager.getRemainingCallCount()); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 358 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 359 | mManager.getDynamicShortcuts()), |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 360 | "shortcut1", "shortcut2", "shortcut3"); |
| 361 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 362 | mInjectedCurrentTimeMillis += INTERVAL; // reset |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 363 | |
| 364 | // Add with the same ID |
| 365 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("shortcut1")))); |
| 366 | assertEquals(2, mManager.getRemainingCallCount()); |
| 367 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 368 | mManager.getDynamicShortcuts()), |
| 369 | "shortcut1", "shortcut2", "shortcut3"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 370 | |
| 371 | // TODO Check max number |
| 372 | |
| 373 | // TODO Check fields. |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 374 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 375 | mRunningUsers.put(USER_10, true); |
| 376 | |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 377 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 378 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("s1")))); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 379 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Makoto Onuki | 7d0fa81 | 2018-02-21 11:24:43 -0800 | [diff] [blame] | 382 | public void testUnlimitedCalls() { |
| 383 | setCaller(CALLING_PACKAGE_1, USER_0); |
| 384 | |
| 385 | final ShortcutInfo si1 = makeShortcut("shortcut1"); |
| 386 | |
| 387 | assertEquals(3, mManager.getRemainingCallCount()); |
| 388 | |
| 389 | assertTrue(mManager.setDynamicShortcuts(list(si1))); |
| 390 | assertEquals(2, mManager.getRemainingCallCount()); |
| 391 | |
| 392 | assertTrue(mManager.addDynamicShortcuts(list(si1))); |
| 393 | assertEquals(1, mManager.getRemainingCallCount()); |
| 394 | |
| 395 | assertTrue(mManager.updateShortcuts(list(si1))); |
| 396 | assertEquals(0, mManager.getRemainingCallCount()); |
| 397 | |
| 398 | // Unlimited now. |
| 399 | mInjectHasUnlimitedShortcutsApiCallsPermission = true; |
| 400 | |
| 401 | assertEquals(3, mManager.getRemainingCallCount()); |
| 402 | |
| 403 | assertTrue(mManager.setDynamicShortcuts(list(si1))); |
| 404 | assertEquals(3, mManager.getRemainingCallCount()); |
| 405 | |
| 406 | assertTrue(mManager.addDynamicShortcuts(list(si1))); |
| 407 | assertEquals(3, mManager.getRemainingCallCount()); |
| 408 | |
| 409 | assertTrue(mManager.updateShortcuts(list(si1))); |
| 410 | assertEquals(3, mManager.getRemainingCallCount()); |
| 411 | } |
| 412 | |
Mehdi Alizadeh | 3277462 | 2018-11-05 17:32:01 -0800 | [diff] [blame] | 413 | public void testPublishWithNoActivity() { |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 414 | // If activity is not explicitly set, use the default one. |
| 415 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 416 | mRunningUsers.put(USER_10, true); |
| 417 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 418 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
| 419 | // s1 and s3 has no activities. |
| 420 | final ShortcutInfo si1 = new ShortcutInfo.Builder(mClientContext, "si1") |
| 421 | .setShortLabel("label1") |
| 422 | .setIntent(new Intent("action1")) |
| 423 | .build(); |
| 424 | final ShortcutInfo si2 = new ShortcutInfo.Builder(mClientContext, "si2") |
| 425 | .setShortLabel("label2") |
| 426 | .setActivity(new ComponentName(getCallingPackage(), "abc")) |
| 427 | .setIntent(new Intent("action2")) |
| 428 | .build(); |
| 429 | final ShortcutInfo si3 = new ShortcutInfo.Builder(mClientContext, "si3") |
| 430 | .setShortLabel("label3") |
| 431 | .setIntent(new Intent("action3")) |
| 432 | .build(); |
| 433 | |
| 434 | // Set test 1 |
| 435 | assertTrue(mManager.setDynamicShortcuts(list(si1))); |
| 436 | |
| 437 | assertWith(getCallerShortcuts()) |
| 438 | .haveIds("si1") |
| 439 | .forShortcutWithId("si1", si -> { |
| 440 | assertEquals(new ComponentName(getCallingPackage(), |
| 441 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 442 | }); |
| 443 | |
| 444 | // Set test 2 |
| 445 | assertTrue(mManager.setDynamicShortcuts(list(si2, si1))); |
| 446 | |
| 447 | assertWith(getCallerShortcuts()) |
| 448 | .haveIds("si1", "si2") |
| 449 | .forShortcutWithId("si1", si -> { |
| 450 | assertEquals(new ComponentName(getCallingPackage(), |
| 451 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 452 | }) |
| 453 | .forShortcutWithId("si2", si -> { |
| 454 | assertEquals(new ComponentName(getCallingPackage(), |
| 455 | "abc"), si.getActivity()); |
| 456 | }); |
| 457 | |
| 458 | |
| 459 | // Set test 3 |
| 460 | assertTrue(mManager.setDynamicShortcuts(list(si3, si1))); |
| 461 | |
| 462 | assertWith(getCallerShortcuts()) |
| 463 | .haveIds("si1", "si3") |
| 464 | .forShortcutWithId("si1", si -> { |
| 465 | assertEquals(new ComponentName(getCallingPackage(), |
| 466 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 467 | }) |
| 468 | .forShortcutWithId("si3", si -> { |
| 469 | assertEquals(new ComponentName(getCallingPackage(), |
| 470 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 471 | }); |
| 472 | |
| 473 | mInjectedCurrentTimeMillis += INTERVAL; // reset throttling |
| 474 | |
| 475 | // Add test 1 |
| 476 | mManager.removeAllDynamicShortcuts(); |
| 477 | assertTrue(mManager.addDynamicShortcuts(list(si1))); |
| 478 | |
| 479 | assertWith(getCallerShortcuts()) |
| 480 | .haveIds("si1") |
| 481 | .forShortcutWithId("si1", si -> { |
| 482 | assertEquals(new ComponentName(getCallingPackage(), |
| 483 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 484 | }); |
| 485 | |
| 486 | // Add test 2 |
| 487 | mManager.removeAllDynamicShortcuts(); |
| 488 | assertTrue(mManager.addDynamicShortcuts(list(si2, si1))); |
| 489 | |
| 490 | assertWith(getCallerShortcuts()) |
| 491 | .haveIds("si1", "si2") |
| 492 | .forShortcutWithId("si1", si -> { |
| 493 | assertEquals(new ComponentName(getCallingPackage(), |
| 494 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 495 | }) |
| 496 | .forShortcutWithId("si2", si -> { |
| 497 | assertEquals(new ComponentName(getCallingPackage(), |
| 498 | "abc"), si.getActivity()); |
| 499 | }); |
| 500 | |
| 501 | |
| 502 | // Add test 3 |
| 503 | mManager.removeAllDynamicShortcuts(); |
| 504 | assertTrue(mManager.addDynamicShortcuts(list(si3, si1))); |
| 505 | |
| 506 | assertWith(getCallerShortcuts()) |
| 507 | .haveIds("si1", "si3") |
| 508 | .forShortcutWithId("si1", si -> { |
| 509 | assertEquals(new ComponentName(getCallingPackage(), |
| 510 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 511 | }) |
| 512 | .forShortcutWithId("si3", si -> { |
| 513 | assertEquals(new ComponentName(getCallingPackage(), |
| 514 | MAIN_ACTIVITY_CLASS), si.getActivity()); |
| 515 | }); |
| 516 | }); |
| 517 | } |
| 518 | |
| 519 | public void testPublishWithNoActivity_noMainActivityInPackage() { |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 520 | mRunningUsers.put(USER_10, true); |
| 521 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 522 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
| 523 | final ShortcutInfo si1 = new ShortcutInfo.Builder(mClientContext, "si1") |
| 524 | .setShortLabel("label1") |
| 525 | .setIntent(new Intent("action1")) |
| 526 | .build(); |
| 527 | |
| 528 | // Returning null means there's no main activity in this package. |
| 529 | mMainActivityFetcher = (packageName, userId) -> null; |
| 530 | |
| 531 | assertExpectException( |
| 532 | RuntimeException.class, "Launcher activity not found for", () -> { |
| 533 | assertTrue(mManager.setDynamicShortcuts(list(si1))); |
| 534 | }); |
| 535 | }); |
| 536 | } |
| 537 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 538 | public void testDeleteDynamicShortcuts() { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 539 | final ShortcutInfo si1 = makeShortcut("shortcut1"); |
| 540 | final ShortcutInfo si2 = makeShortcut("shortcut2"); |
| 541 | final ShortcutInfo si3 = makeShortcut("shortcut3"); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 542 | final ShortcutInfo si4 = makeShortcut("shortcut4"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 543 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 544 | assertTrue(mManager.setDynamicShortcuts(list(si1, si2, si3, si4))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 545 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 546 | mManager.getDynamicShortcuts()), |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 547 | "shortcut1", "shortcut2", "shortcut3", "shortcut4"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 548 | |
| 549 | assertEquals(2, mManager.getRemainingCallCount()); |
| 550 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 551 | mManager.removeDynamicShortcuts(list("shortcut1")); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 552 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 553 | mManager.getDynamicShortcuts()), |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 554 | "shortcut2", "shortcut3", "shortcut4"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 555 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 556 | mManager.removeDynamicShortcuts(list("shortcut1")); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 557 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 558 | mManager.getDynamicShortcuts()), |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 559 | "shortcut2", "shortcut3", "shortcut4"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 560 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 561 | mManager.removeDynamicShortcuts(list("shortcutXXX")); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 562 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 563 | mManager.getDynamicShortcuts()), |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 564 | "shortcut2", "shortcut3", "shortcut4"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 565 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 566 | mManager.removeDynamicShortcuts(list("shortcut2", "shortcut4")); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 567 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 568 | mManager.getDynamicShortcuts()), |
| 569 | "shortcut3"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 570 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 571 | mManager.removeDynamicShortcuts(list("shortcut3")); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 572 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 573 | mManager.getDynamicShortcuts())); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 574 | |
| 575 | // Still 2 calls left. |
| 576 | assertEquals(2, mManager.getRemainingCallCount()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | public void testDeleteAllDynamicShortcuts() { |
| 580 | final ShortcutInfo si1 = makeShortcut("shortcut1"); |
| 581 | final ShortcutInfo si2 = makeShortcut("shortcut2"); |
| 582 | final ShortcutInfo si3 = makeShortcut("shortcut3"); |
| 583 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 584 | assertTrue(mManager.setDynamicShortcuts(list(si1, si2, si3))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 585 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 586 | mManager.getDynamicShortcuts()), |
| 587 | "shortcut1", "shortcut2", "shortcut3"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 588 | |
| 589 | assertEquals(2, mManager.getRemainingCallCount()); |
| 590 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 591 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 592 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 593 | assertEquals(2, mManager.getRemainingCallCount()); |
| 594 | |
| 595 | // Note delete shouldn't affect throttling, so... |
| 596 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 597 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 598 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 599 | |
| 600 | // This should still work. |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 601 | assertTrue(mManager.setDynamicShortcuts(list(si1, si2, si3))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 602 | assertEquals(3, mManager.getDynamicShortcuts().size()); |
| 603 | |
| 604 | // Still 1 call left |
| 605 | assertEquals(1, mManager.getRemainingCallCount()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 606 | } |
| 607 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 608 | public void testIcons() throws IOException { |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 609 | final Icon res32x32 = Icon.createWithResource(getTestContext(), R.drawable.black_32x32); |
| 610 | final Icon res64x64 = Icon.createWithResource(getTestContext(), R.drawable.black_64x64); |
| 611 | final Icon res512x512 = Icon.createWithResource(getTestContext(), R.drawable.black_512x512); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 612 | |
| 613 | final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 614 | getTestContext().getResources(), R.drawable.black_32x32)); |
Hyunyoung Song | e4179e2 | 2017-03-01 12:51:26 -0800 | [diff] [blame] | 615 | final Icon bmp64x64_maskable = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 616 | getTestContext().getResources(), R.drawable.black_64x64)); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 617 | final Icon bmp512x512 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 618 | getTestContext().getResources(), R.drawable.black_512x512)); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 619 | |
| 620 | // Set from package 1 |
| 621 | setCaller(CALLING_PACKAGE_1); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 622 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 623 | makeShortcutWithIcon("res32x32", res32x32), |
| 624 | makeShortcutWithIcon("res64x64", res64x64), |
| 625 | makeShortcutWithIcon("bmp32x32", bmp32x32), |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 626 | makeShortcutWithIcon("bmp64x64", bmp64x64_maskable), |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 627 | makeShortcutWithIcon("bmp512x512", bmp512x512), |
| 628 | makeShortcut("none") |
| 629 | ))); |
| 630 | |
| 631 | // getDynamicShortcuts() shouldn't return icons, thus assertAllNotHaveIcon(). |
| 632 | assertShortcutIds(assertAllNotHaveIcon(mManager.getDynamicShortcuts()), |
| 633 | "res32x32", |
| 634 | "res64x64", |
| 635 | "bmp32x32", |
| 636 | "bmp64x64", |
| 637 | "bmp512x512", |
| 638 | "none"); |
| 639 | |
| 640 | // Call from another caller with the same ID, just to make sure storage is per-package. |
| 641 | setCaller(CALLING_PACKAGE_2); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 642 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 643 | makeShortcutWithIcon("res32x32", res512x512), |
| 644 | makeShortcutWithIcon("res64x64", res512x512), |
| 645 | makeShortcutWithIcon("none", res512x512) |
| 646 | ))); |
| 647 | assertShortcutIds(assertAllNotHaveIcon(mManager.getDynamicShortcuts()), |
| 648 | "res32x32", |
| 649 | "res64x64", |
| 650 | "none"); |
| 651 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 652 | // Different profile. Note the names and the contents don't match. |
| 653 | setCaller(CALLING_PACKAGE_1, USER_P0); |
| 654 | assertTrue(mManager.setDynamicShortcuts(list( |
| 655 | makeShortcutWithIcon("res32x32", res512x512), |
| 656 | makeShortcutWithIcon("bmp32x32", bmp512x512) |
| 657 | ))); |
| 658 | assertShortcutIds(assertAllNotHaveIcon(mManager.getDynamicShortcuts()), |
| 659 | "res32x32", |
| 660 | "bmp32x32"); |
| 661 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 662 | // Re-initialize and load from the files. |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 663 | mService.saveDirtyInfo(); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 664 | initService(); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 665 | |
| 666 | // Load from launcher. |
| 667 | Bitmap bmp; |
| 668 | |
| 669 | setCaller(LAUNCHER_1); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 670 | // Check hasIconResource()/hasIconFile(). |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 671 | assertShortcutIds(assertAllHaveIconResId( |
| 672 | list(getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "res32x32", USER_0))), |
| 673 | "res32x32"); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 674 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 675 | assertShortcutIds(assertAllHaveIconResId( |
| 676 | list(getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "res64x64", USER_0))), |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 677 | "res64x64"); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 678 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 679 | assertShortcutIds(assertAllHaveIconFile( |
| 680 | list(getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp32x32", USER_0))), |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 681 | "bmp32x32"); |
| 682 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 683 | assertShortcutIds(assertAllHaveIconFile( |
| 684 | list(getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp64x64", USER_0))), |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 685 | "bmp64x64"); |
| 686 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 687 | assertShortcutIds(assertAllHaveIconFile( |
| 688 | list(getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp512x512", USER_0))), |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 689 | "bmp512x512"); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 690 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 691 | assertShortcutIds(assertAllHaveIconResId( |
| 692 | list(getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "res32x32", USER_P0))), |
| 693 | "res32x32"); |
| 694 | assertShortcutIds(assertAllHaveIconFile( |
| 695 | list(getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp32x32", USER_P0))), |
| 696 | "bmp32x32"); |
| 697 | |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 698 | // Check |
| 699 | assertEquals( |
| 700 | R.drawable.black_32x32, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 701 | mLauncherApps.getShortcutIconResId( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 702 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "res32x32", USER_0))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 703 | |
| 704 | assertEquals( |
| 705 | R.drawable.black_64x64, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 706 | mLauncherApps.getShortcutIconResId( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 707 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "res64x64", USER_0))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 708 | |
| 709 | assertEquals( |
| 710 | 0, // because it's not a resource |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 711 | mLauncherApps.getShortcutIconResId( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 712 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp32x32", USER_0))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 713 | assertEquals( |
| 714 | 0, // because it's not a resource |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 715 | mLauncherApps.getShortcutIconResId( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 716 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp64x64", USER_0))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 717 | assertEquals( |
| 718 | 0, // because it's not a resource |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 719 | mLauncherApps.getShortcutIconResId( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 720 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp512x512", USER_0))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 721 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 722 | bmp = pfdToBitmap(mLauncherApps.getShortcutIconFd( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 723 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp32x32", USER_0))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 724 | assertBitmapSize(32, 32, bmp); |
| 725 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 726 | bmp = pfdToBitmap(mLauncherApps.getShortcutIconFd( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 727 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp64x64", USER_0))); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 728 | assertBitmapSize(64, 64, bmp); |
| 729 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 730 | bmp = pfdToBitmap(mLauncherApps.getShortcutIconFd( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 731 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp512x512", USER_0))); |
| 732 | assertBitmapSize(128, 128, bmp); |
| 733 | |
| 734 | assertEquals( |
| 735 | R.drawable.black_512x512, |
| 736 | mLauncherApps.getShortcutIconResId( |
| 737 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "res32x32", USER_P0))); |
| 738 | // Should be 512x512, so shrunk. |
| 739 | bmp = pfdToBitmap(mLauncherApps.getShortcutIconFd( |
| 740 | getShortcutInfoAsLauncher(CALLING_PACKAGE_1, "bmp32x32", USER_P0))); |
| 741 | assertBitmapSize(128, 128, bmp); |
| 742 | |
| 743 | // Also check the overload APIs too. |
| 744 | assertEquals( |
| 745 | R.drawable.black_32x32, |
| 746 | mLauncherApps.getShortcutIconResId(CALLING_PACKAGE_1, "res32x32", HANDLE_USER_0)); |
| 747 | assertEquals( |
| 748 | R.drawable.black_64x64, |
| 749 | mLauncherApps.getShortcutIconResId(CALLING_PACKAGE_1, "res64x64", HANDLE_USER_0)); |
| 750 | assertEquals( |
| 751 | R.drawable.black_512x512, |
| 752 | mLauncherApps.getShortcutIconResId(CALLING_PACKAGE_1, "res32x32", HANDLE_USER_P0)); |
| 753 | bmp = pfdToBitmap( |
| 754 | mLauncherApps.getShortcutIconFd(CALLING_PACKAGE_1, "bmp32x32", HANDLE_USER_P0)); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 755 | assertBitmapSize(128, 128, bmp); |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 756 | |
| 757 | Drawable dr = mLauncherApps.getShortcutIconDrawable( |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 758 | makeShortcutWithIcon("bmp64x64", bmp64x64_maskable), 0); |
Hyunyoung Song | be8835e | 2017-02-17 11:25:08 -0800 | [diff] [blame] | 759 | assertTrue(dr instanceof AdaptiveIconDrawable); |
Hyunyoung Song | 92e3da2 | 2017-04-06 23:04:19 -0700 | [diff] [blame] | 760 | float viewportPercentage = 1 / (1 + 2 * AdaptiveIconDrawable.getExtraInsetFraction()); |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 761 | assertEquals((int) (bmp64x64_maskable.getBitmap().getWidth() * viewportPercentage), |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 762 | dr.getIntrinsicWidth()); |
Hyunyoung Song | f281e7a | 2017-02-13 10:57:42 -0800 | [diff] [blame] | 763 | assertEquals((int) (bmp64x64_maskable.getBitmap().getHeight() * viewportPercentage), |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 764 | dr.getIntrinsicHeight()); |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 765 | } |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 766 | |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 767 | public void testCleanupDanglingBitmaps() throws Exception { |
| 768 | assertBitmapDirectories(USER_0, EMPTY_STRINGS); |
| 769 | assertBitmapDirectories(USER_10, EMPTY_STRINGS); |
| 770 | |
| 771 | // Make some shortcuts with bitmap icons. |
| 772 | final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
| 773 | getTestContext().getResources(), R.drawable.black_32x32)); |
| 774 | |
| 775 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 776 | mManager.setDynamicShortcuts(list( |
| 777 | makeShortcutWithIcon("s1", bmp32x32), |
| 778 | makeShortcutWithIcon("s2", bmp32x32), |
| 779 | makeShortcutWithIcon("s3", bmp32x32) |
| 780 | )); |
| 781 | }); |
| 782 | |
| 783 | // Increment the time (which actually we don't have to), which is used for filenames. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 784 | mInjectedCurrentTimeMillis++; |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 785 | |
| 786 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 787 | mManager.setDynamicShortcuts(list( |
| 788 | makeShortcutWithIcon("s4", bmp32x32), |
| 789 | makeShortcutWithIcon("s5", bmp32x32), |
| 790 | makeShortcutWithIcon("s6", bmp32x32) |
| 791 | )); |
| 792 | }); |
| 793 | |
| 794 | // Increment the time, which is used for filenames. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 795 | mInjectedCurrentTimeMillis++; |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 796 | |
| 797 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 798 | mManager.setDynamicShortcuts(list( |
| 799 | )); |
| 800 | }); |
| 801 | |
| 802 | // For USER-10, let's try without updating the times. |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 803 | mRunningUsers.put(USER_10, true); |
| 804 | |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 805 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 806 | mManager.setDynamicShortcuts(list( |
| 807 | makeShortcutWithIcon("10s1", bmp32x32), |
| 808 | makeShortcutWithIcon("10s2", bmp32x32), |
| 809 | makeShortcutWithIcon("10s3", bmp32x32) |
| 810 | )); |
| 811 | }); |
| 812 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
| 813 | mManager.setDynamicShortcuts(list( |
| 814 | makeShortcutWithIcon("10s4", bmp32x32), |
| 815 | makeShortcutWithIcon("10s5", bmp32x32), |
| 816 | makeShortcutWithIcon("10s6", bmp32x32) |
| 817 | )); |
| 818 | }); |
| 819 | runWithCaller(CALLING_PACKAGE_3, USER_10, () -> { |
| 820 | mManager.setDynamicShortcuts(list( |
| 821 | )); |
| 822 | }); |
| 823 | |
| 824 | dumpsysOnLogcat(); |
| 825 | |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 826 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 827 | // Check files and directories. |
| 828 | // Package 3 has no bitmaps, so we don't create a directory. |
| 829 | assertBitmapDirectories(USER_0, CALLING_PACKAGE_1, CALLING_PACKAGE_2); |
| 830 | assertBitmapDirectories(USER_10, CALLING_PACKAGE_1, CALLING_PACKAGE_2); |
| 831 | |
| 832 | assertBitmapFiles(USER_0, CALLING_PACKAGE_1, |
| 833 | getBitmapFilename(USER_0, CALLING_PACKAGE_1, "s1"), |
| 834 | getBitmapFilename(USER_0, CALLING_PACKAGE_1, "s2"), |
| 835 | getBitmapFilename(USER_0, CALLING_PACKAGE_1, "s3") |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 836 | ); |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 837 | assertBitmapFiles(USER_0, CALLING_PACKAGE_2, |
| 838 | getBitmapFilename(USER_0, CALLING_PACKAGE_2, "s4"), |
| 839 | getBitmapFilename(USER_0, CALLING_PACKAGE_2, "s5"), |
| 840 | getBitmapFilename(USER_0, CALLING_PACKAGE_2, "s6") |
| 841 | ); |
| 842 | assertBitmapFiles(USER_0, CALLING_PACKAGE_3, |
| 843 | EMPTY_STRINGS |
| 844 | ); |
| 845 | assertBitmapFiles(USER_10, CALLING_PACKAGE_1, |
| 846 | getBitmapFilename(USER_10, CALLING_PACKAGE_1, "10s1"), |
| 847 | getBitmapFilename(USER_10, CALLING_PACKAGE_1, "10s2"), |
| 848 | getBitmapFilename(USER_10, CALLING_PACKAGE_1, "10s3") |
| 849 | ); |
| 850 | assertBitmapFiles(USER_10, CALLING_PACKAGE_2, |
| 851 | getBitmapFilename(USER_10, CALLING_PACKAGE_2, "10s4"), |
| 852 | getBitmapFilename(USER_10, CALLING_PACKAGE_2, "10s5"), |
| 853 | getBitmapFilename(USER_10, CALLING_PACKAGE_2, "10s6") |
| 854 | ); |
| 855 | assertBitmapFiles(USER_10, CALLING_PACKAGE_3, |
| 856 | EMPTY_STRINGS |
| 857 | ); |
| 858 | |
| 859 | // Then create random directories and files. |
| 860 | makeFile(mService.getUserBitmapFilePath(USER_0), "a.b.c").mkdir(); |
| 861 | makeFile(mService.getUserBitmapFilePath(USER_0), "d.e.f").mkdir(); |
| 862 | makeFile(mService.getUserBitmapFilePath(USER_0), "d.e.f", "123").createNewFile(); |
| 863 | makeFile(mService.getUserBitmapFilePath(USER_0), "d.e.f", "456").createNewFile(); |
| 864 | |
| 865 | makeFile(mService.getUserBitmapFilePath(USER_0), CALLING_PACKAGE_3).mkdir(); |
| 866 | |
| 867 | makeFile(mService.getUserBitmapFilePath(USER_0), CALLING_PACKAGE_1, "1").createNewFile(); |
| 868 | makeFile(mService.getUserBitmapFilePath(USER_0), CALLING_PACKAGE_1, "2").createNewFile(); |
| 869 | makeFile(mService.getUserBitmapFilePath(USER_0), CALLING_PACKAGE_1, "3").createNewFile(); |
| 870 | makeFile(mService.getUserBitmapFilePath(USER_0), CALLING_PACKAGE_1, "4").createNewFile(); |
| 871 | |
| 872 | makeFile(mService.getUserBitmapFilePath(USER_10), "10a.b.c").mkdir(); |
| 873 | makeFile(mService.getUserBitmapFilePath(USER_10), "10d.e.f").mkdir(); |
| 874 | makeFile(mService.getUserBitmapFilePath(USER_10), "10d.e.f", "123").createNewFile(); |
| 875 | makeFile(mService.getUserBitmapFilePath(USER_10), "10d.e.f", "456").createNewFile(); |
| 876 | |
| 877 | makeFile(mService.getUserBitmapFilePath(USER_10), CALLING_PACKAGE_2, "1").createNewFile(); |
| 878 | makeFile(mService.getUserBitmapFilePath(USER_10), CALLING_PACKAGE_2, "2").createNewFile(); |
| 879 | makeFile(mService.getUserBitmapFilePath(USER_10), CALLING_PACKAGE_2, "3").createNewFile(); |
| 880 | makeFile(mService.getUserBitmapFilePath(USER_10), CALLING_PACKAGE_2, "4").createNewFile(); |
| 881 | |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 882 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 883 | assertBitmapDirectories(USER_0, CALLING_PACKAGE_1, CALLING_PACKAGE_2, CALLING_PACKAGE_3, |
| 884 | "a.b.c", "d.e.f"); |
| 885 | |
| 886 | // Save and load. When a user is loaded, we do the cleanup. |
| 887 | mService.saveDirtyInfo(); |
| 888 | initService(); |
| 889 | |
| 890 | mService.handleUnlockUser(USER_0); |
| 891 | mService.handleUnlockUser(USER_10); |
| 892 | mService.handleUnlockUser(20); // Make sure the logic will still work for nonexistent user. |
| 893 | |
| 894 | // The below check is the same as above, except this time USER_0 use the CALLING_PACKAGE_3 |
| 895 | // directory. |
| 896 | |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 897 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | 6c1dbd5 | 2016-05-02 15:19:32 -0700 | [diff] [blame] | 898 | assertBitmapDirectories(USER_0, CALLING_PACKAGE_1, CALLING_PACKAGE_2, CALLING_PACKAGE_3); |
| 899 | assertBitmapDirectories(USER_10, CALLING_PACKAGE_1, CALLING_PACKAGE_2); |
| 900 | |
| 901 | assertBitmapFiles(USER_0, CALLING_PACKAGE_1, |
| 902 | getBitmapFilename(USER_0, CALLING_PACKAGE_1, "s1"), |
| 903 | getBitmapFilename(USER_0, CALLING_PACKAGE_1, "s2"), |
| 904 | getBitmapFilename(USER_0, CALLING_PACKAGE_1, "s3") |
| 905 | ); |
| 906 | assertBitmapFiles(USER_0, CALLING_PACKAGE_2, |
| 907 | getBitmapFilename(USER_0, CALLING_PACKAGE_2, "s4"), |
| 908 | getBitmapFilename(USER_0, CALLING_PACKAGE_2, "s5"), |
| 909 | getBitmapFilename(USER_0, CALLING_PACKAGE_2, "s6") |
| 910 | ); |
| 911 | assertBitmapFiles(USER_0, CALLING_PACKAGE_3, |
| 912 | EMPTY_STRINGS |
| 913 | ); |
| 914 | assertBitmapFiles(USER_10, CALLING_PACKAGE_1, |
| 915 | getBitmapFilename(USER_10, CALLING_PACKAGE_1, "10s1"), |
| 916 | getBitmapFilename(USER_10, CALLING_PACKAGE_1, "10s2"), |
| 917 | getBitmapFilename(USER_10, CALLING_PACKAGE_1, "10s3") |
| 918 | ); |
| 919 | assertBitmapFiles(USER_10, CALLING_PACKAGE_2, |
| 920 | getBitmapFilename(USER_10, CALLING_PACKAGE_2, "10s4"), |
| 921 | getBitmapFilename(USER_10, CALLING_PACKAGE_2, "10s5"), |
| 922 | getBitmapFilename(USER_10, CALLING_PACKAGE_2, "10s6") |
| 923 | ); |
| 924 | assertBitmapFiles(USER_10, CALLING_PACKAGE_3, |
| 925 | EMPTY_STRINGS |
| 926 | ); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 927 | } |
| 928 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 929 | protected void checkShrinkBitmap(int expectedWidth, int expectedHeight, int resId, int maxSize) { |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 930 | assertBitmapSize(expectedWidth, expectedHeight, |
| 931 | ShortcutService.shrinkBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 932 | getTestContext().getResources(), resId), |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 933 | maxSize)); |
| 934 | } |
| 935 | |
| 936 | public void testShrinkBitmap() { |
| 937 | checkShrinkBitmap(32, 32, R.drawable.black_512x512, 32); |
| 938 | checkShrinkBitmap(511, 511, R.drawable.black_512x512, 511); |
| 939 | checkShrinkBitmap(512, 512, R.drawable.black_512x512, 512); |
| 940 | |
| 941 | checkShrinkBitmap(1024, 4096, R.drawable.black_1024x4096, 4096); |
| 942 | checkShrinkBitmap(1024, 4096, R.drawable.black_1024x4096, 4100); |
| 943 | checkShrinkBitmap(512, 2048, R.drawable.black_1024x4096, 2048); |
| 944 | |
| 945 | checkShrinkBitmap(4096, 1024, R.drawable.black_4096x1024, 4096); |
| 946 | checkShrinkBitmap(4096, 1024, R.drawable.black_4096x1024, 4100); |
| 947 | checkShrinkBitmap(2048, 512, R.drawable.black_4096x1024, 2048); |
| 948 | } |
| 949 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 950 | protected File openIconFileForWriteAndGetPath(int userId, String packageName) |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 951 | throws IOException { |
| 952 | // Shortcut IDs aren't used in the path, so just pass the same ID. |
| 953 | final FileOutputStreamWithPath out = |
| 954 | mService.openIconFileForWrite(userId, makePackageShortcut(packageName, "id")); |
| 955 | out.close(); |
| 956 | return out.getFile(); |
| 957 | } |
| 958 | |
| 959 | public void testOpenIconFileForWrite() throws IOException { |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 960 | mInjectedCurrentTimeMillis = 1000; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 961 | |
| 962 | final File p10_1_1 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_1); |
| 963 | final File p10_1_2 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_1); |
| 964 | |
| 965 | final File p10_2_1 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_2); |
| 966 | final File p10_2_2 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_2); |
| 967 | |
| 968 | final File p11_1_1 = openIconFileForWriteAndGetPath(11, CALLING_PACKAGE_1); |
| 969 | final File p11_1_2 = openIconFileForWriteAndGetPath(11, CALLING_PACKAGE_1); |
| 970 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 971 | mInjectedCurrentTimeMillis++; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 972 | |
| 973 | final File p10_1_3 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_1); |
| 974 | final File p10_1_4 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_1); |
| 975 | final File p10_1_5 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_1); |
| 976 | |
| 977 | final File p10_2_3 = openIconFileForWriteAndGetPath(10, CALLING_PACKAGE_2); |
| 978 | final File p11_1_3 = openIconFileForWriteAndGetPath(11, CALLING_PACKAGE_1); |
| 979 | |
| 980 | // Make sure their paths are all unique |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 981 | assertAllUnique(list( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 982 | p10_1_1, |
| 983 | p10_1_2, |
| 984 | p10_1_3, |
| 985 | p10_1_4, |
| 986 | p10_1_5, |
| 987 | |
| 988 | p10_2_1, |
| 989 | p10_2_2, |
| 990 | p10_2_3, |
| 991 | |
| 992 | p11_1_1, |
| 993 | p11_1_2, |
| 994 | p11_1_3 |
| 995 | )); |
| 996 | |
| 997 | // Check each set has the same parent. |
| 998 | assertEquals(p10_1_1.getParent(), p10_1_2.getParent()); |
| 999 | assertEquals(p10_1_1.getParent(), p10_1_3.getParent()); |
| 1000 | assertEquals(p10_1_1.getParent(), p10_1_4.getParent()); |
| 1001 | assertEquals(p10_1_1.getParent(), p10_1_5.getParent()); |
| 1002 | |
| 1003 | assertEquals(p10_2_1.getParent(), p10_2_2.getParent()); |
| 1004 | assertEquals(p10_2_1.getParent(), p10_2_3.getParent()); |
| 1005 | |
| 1006 | assertEquals(p11_1_1.getParent(), p11_1_2.getParent()); |
| 1007 | assertEquals(p11_1_1.getParent(), p11_1_3.getParent()); |
| 1008 | |
| 1009 | // Check the parents are still unique. |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1010 | assertAllUnique(list( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1011 | p10_1_1.getParent(), |
| 1012 | p10_2_1.getParent(), |
| 1013 | p11_1_1.getParent() |
| 1014 | )); |
| 1015 | |
| 1016 | // All files created at the same time for the same package/user, expcet for the first ones, |
| 1017 | // will have "_" in the path. |
| 1018 | assertFalse(p10_1_1.getName().contains("_")); |
| 1019 | assertTrue(p10_1_2.getName().contains("_")); |
| 1020 | assertFalse(p10_1_3.getName().contains("_")); |
| 1021 | assertTrue(p10_1_4.getName().contains("_")); |
| 1022 | assertTrue(p10_1_5.getName().contains("_")); |
| 1023 | |
| 1024 | assertFalse(p10_2_1.getName().contains("_")); |
| 1025 | assertTrue(p10_2_2.getName().contains("_")); |
| 1026 | assertFalse(p10_2_3.getName().contains("_")); |
| 1027 | |
| 1028 | assertFalse(p11_1_1.getName().contains("_")); |
| 1029 | assertTrue(p11_1_2.getName().contains("_")); |
| 1030 | assertFalse(p11_1_3.getName().contains("_")); |
| 1031 | } |
| 1032 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1033 | public void testUpdateShortcuts() { |
| 1034 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1035 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1036 | makeShortcut("s1"), |
| 1037 | makeShortcut("s2"), |
| 1038 | makeShortcut("s3"), |
| 1039 | makeShortcut("s4"), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1040 | makeShortcut("s5") |
| 1041 | ))); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1042 | }); |
| 1043 | runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1044 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1045 | makeShortcut("s1"), |
| 1046 | makeShortcut("s2"), |
| 1047 | makeShortcut("s3"), |
| 1048 | makeShortcut("s4"), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1049 | makeShortcut("s5") |
| 1050 | ))); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1051 | }); |
| 1052 | runWithCaller(LAUNCHER_1, UserHandle.USER_SYSTEM, () -> { |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1053 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2", "s3"), |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1054 | getCallingUser()); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1055 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s4", "s5"), |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1056 | getCallingUser()); |
| 1057 | }); |
| 1058 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1059 | mManager.removeDynamicShortcuts(list("s1")); |
| 1060 | mManager.removeDynamicShortcuts(list("s2")); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1061 | }); |
| 1062 | runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1063 | mManager.removeDynamicShortcuts(list("s1")); |
| 1064 | mManager.removeDynamicShortcuts(list("s3")); |
| 1065 | mManager.removeDynamicShortcuts(list("s5")); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1066 | }); |
| 1067 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
| 1068 | assertShortcutIds(assertAllDynamic( |
| 1069 | mManager.getDynamicShortcuts()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1070 | "s3", "s4", "s5"); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1071 | assertShortcutIds(assertAllPinned( |
| 1072 | mManager.getPinnedShortcuts()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1073 | "s2", "s3"); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1074 | }); |
| 1075 | runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> { |
| 1076 | assertShortcutIds(assertAllDynamic( |
| 1077 | mManager.getDynamicShortcuts()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1078 | "s2", "s4"); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1079 | assertShortcutIds(assertAllPinned( |
| 1080 | mManager.getPinnedShortcuts()), |
| 1081 | "s4", "s5"); |
| 1082 | }); |
| 1083 | |
| 1084 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
| 1085 | ShortcutInfo s2 = makeShortcutBuilder() |
| 1086 | .setId("s2") |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1087 | .setIcon(Icon.createWithResource(getTestContext(), R.drawable.black_32x32)) |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1088 | .build(); |
| 1089 | |
| 1090 | ShortcutInfo s4 = makeShortcutBuilder() |
| 1091 | .setId("s4") |
| 1092 | .setTitle("new title") |
| 1093 | .build(); |
| 1094 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1095 | mManager.updateShortcuts(list(s2, s4)); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1096 | }); |
| 1097 | runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> { |
| 1098 | ShortcutInfo s2 = makeShortcutBuilder() |
| 1099 | .setId("s2") |
| 1100 | .setIntent(makeIntent(Intent.ACTION_ANSWER, ShortcutActivity.class, |
| 1101 | "key1", "val1")) |
| 1102 | .build(); |
| 1103 | |
| 1104 | ShortcutInfo s4 = makeShortcutBuilder() |
| 1105 | .setId("s4") |
| 1106 | .setIntent(new Intent(Intent.ACTION_ALL_APPS)) |
| 1107 | .build(); |
| 1108 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1109 | mManager.updateShortcuts(list(s2, s4)); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1110 | }); |
| 1111 | |
| 1112 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
| 1113 | assertShortcutIds(assertAllDynamic( |
| 1114 | mManager.getDynamicShortcuts()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1115 | "s3", "s4", "s5"); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1116 | assertShortcutIds(assertAllPinned( |
| 1117 | mManager.getPinnedShortcuts()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1118 | "s2", "s3"); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1119 | |
| 1120 | ShortcutInfo s = getCallerShortcut("s2"); |
| 1121 | assertTrue(s.hasIconResource()); |
| 1122 | assertEquals(R.drawable.black_32x32, s.getIconResourceId()); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1123 | assertEquals("string/r" + R.drawable.black_32x32, s.getIconResName()); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1124 | assertEquals("Title-s2", s.getTitle()); |
| 1125 | |
| 1126 | s = getCallerShortcut("s4"); |
| 1127 | assertFalse(s.hasIconResource()); |
| 1128 | assertEquals(0, s.getIconResourceId()); |
| 1129 | assertEquals("new title", s.getTitle()); |
| 1130 | }); |
| 1131 | runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> { |
| 1132 | assertShortcutIds(assertAllDynamic( |
| 1133 | mManager.getDynamicShortcuts()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1134 | "s2", "s4"); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1135 | assertShortcutIds(assertAllPinned( |
| 1136 | mManager.getPinnedShortcuts()), |
| 1137 | "s4", "s5"); |
| 1138 | |
| 1139 | ShortcutInfo s = getCallerShortcut("s2"); |
| 1140 | assertFalse(s.hasIconResource()); |
| 1141 | assertEquals(0, s.getIconResourceId()); |
| 1142 | assertEquals("Title-s2", s.getTitle()); |
| 1143 | assertEquals(Intent.ACTION_ANSWER, s.getIntent().getAction()); |
| 1144 | assertEquals(1, s.getIntent().getExtras().size()); |
| 1145 | |
| 1146 | s = getCallerShortcut("s4"); |
| 1147 | assertFalse(s.hasIconResource()); |
| 1148 | assertEquals(0, s.getIconResourceId()); |
| 1149 | assertEquals("Title-s4", s.getTitle()); |
| 1150 | assertEquals(Intent.ACTION_ALL_APPS, s.getIntent().getAction()); |
| 1151 | assertBundleEmpty(s.getIntent().getExtras()); |
| 1152 | }); |
| 1153 | // TODO Check with other fields too. |
| 1154 | |
| 1155 | // TODO Check bitmap removal too. |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 1156 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 1157 | mRunningUsers.put(USER_11, true); |
| 1158 | |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 1159 | runWithCaller(CALLING_PACKAGE_2, USER_11, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1160 | mManager.updateShortcuts(list()); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 1161 | }); |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1164 | public void testUpdateShortcuts_icons() { |
| 1165 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
| 1166 | assertTrue(mManager.setDynamicShortcuts(list( |
| 1167 | makeShortcut("s1") |
| 1168 | ))); |
| 1169 | |
| 1170 | // Set resource icon |
| 1171 | assertTrue(mManager.updateShortcuts(list( |
| 1172 | new ShortcutInfo.Builder(mClientContext, "s1") |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1173 | .setIcon(Icon.createWithResource(getTestContext(), R.drawable.black_32x32)) |
| 1174 | .build() |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1175 | ))); |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 1176 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1177 | assertWith(getCallerShortcuts()) |
| 1178 | .forShortcutWithId("s1", si -> { |
| 1179 | assertTrue(si.hasIconResource()); |
| 1180 | assertEquals(R.drawable.black_32x32, si.getIconResourceId()); |
| 1181 | }); |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 1182 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1183 | // Set bitmap icon |
| 1184 | assertTrue(mManager.updateShortcuts(list( |
| 1185 | new ShortcutInfo.Builder(mClientContext, "s1") |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 1186 | .setIcon(Icon.createWithBitmap(BitmapFactory.decodeResource( |
| 1187 | getTestContext().getResources(), R.drawable.black_64x64))) |
| 1188 | .build() |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1189 | ))); |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 1190 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1191 | assertWith(getCallerShortcuts()) |
| 1192 | .forShortcutWithId("s1", si -> { |
| 1193 | assertTrue(si.hasIconFile()); |
| 1194 | }); |
| 1195 | |
| 1196 | mInjectedCurrentTimeMillis += INTERVAL; // reset throttling |
| 1197 | |
| 1198 | // Do it again, with the reverse order (bitmap -> icon) |
| 1199 | assertTrue(mManager.setDynamicShortcuts(list( |
| 1200 | makeShortcut("s1") |
| 1201 | ))); |
| 1202 | |
| 1203 | // Set bitmap icon |
| 1204 | assertTrue(mManager.updateShortcuts(list( |
| 1205 | new ShortcutInfo.Builder(mClientContext, "s1") |
| 1206 | .setIcon(Icon.createWithBitmap(BitmapFactory.decodeResource( |
| 1207 | getTestContext().getResources(), R.drawable.black_64x64))) |
| 1208 | .build() |
| 1209 | ))); |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 1210 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1211 | assertWith(getCallerShortcuts()) |
| 1212 | .forShortcutWithId("s1", si -> { |
| 1213 | assertTrue(si.hasIconFile()); |
| 1214 | }); |
| 1215 | |
| 1216 | // Set resource icon |
| 1217 | assertTrue(mManager.updateShortcuts(list( |
| 1218 | new ShortcutInfo.Builder(mClientContext, "s1") |
| 1219 | .setIcon(Icon.createWithResource(getTestContext(), R.drawable.black_32x32)) |
| 1220 | .build() |
| 1221 | ))); |
Makoto Onuki | ffa519c | 2017-12-13 13:14:38 -0800 | [diff] [blame] | 1222 | mService.waitForBitmapSavesForTest(); |
Makoto Onuki | dd09781 | 2016-06-29 13:10:09 -0700 | [diff] [blame] | 1223 | assertWith(getCallerShortcuts()) |
| 1224 | .forShortcutWithId("s1", si -> { |
| 1225 | assertTrue(si.hasIconResource()); |
| 1226 | assertEquals(R.drawable.black_32x32, si.getIconResourceId()); |
| 1227 | }); |
| 1228 | }); |
| 1229 | } |
| 1230 | |
Mehdi Alizadeh | 505fb76 | 2020-01-21 17:26:24 -0800 | [diff] [blame] | 1231 | public void testShortcutManagerGetShortcuts_shortcutTypes() { |
| 1232 | |
| 1233 | // Create 3 manifest and 3 dynamic shortcuts |
| 1234 | addManifestShortcutResource( |
| 1235 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 1236 | R.xml.shortcut_3); |
| 1237 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 1238 | mService.mPackageMonitor.onReceive(getTestContext(), |
| 1239 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 1240 | |
| 1241 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1242 | assertTrue(mManager.setDynamicShortcuts(list( |
| 1243 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 1244 | }); |
| 1245 | |
| 1246 | // Pin 2 and 3 |
| 1247 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1248 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms2", "ms3", "s2", "s3"), |
| 1249 | HANDLE_USER_0); |
| 1250 | }); |
| 1251 | |
| 1252 | // Cache 1 and 2 |
| 1253 | setCaller(CALLING_PACKAGE_1); |
| 1254 | getCallerShortcut("s1").setCached(); |
| 1255 | getCallerShortcut("s2").setCached(); |
| 1256 | |
| 1257 | // Get manifest shortcuts |
| 1258 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_MANIFEST), |
| 1259 | "ms1", "ms2", "ms3"); |
| 1260 | |
| 1261 | // Get dynamic shortcuts |
| 1262 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), |
| 1263 | "s1", "s2", "s3"); |
| 1264 | |
| 1265 | // Get pinned shortcuts |
| 1266 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), |
| 1267 | "ms2", "ms3", "s2", "s3"); |
| 1268 | |
| 1269 | // Get cached shortcuts |
| 1270 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), |
| 1271 | "s1", "s2"); |
| 1272 | |
| 1273 | // Get manifest and dynamic shortcuts |
| 1274 | assertShortcutIds(mManager.getShortcuts( |
| 1275 | ShortcutManager.FLAG_MATCH_MANIFEST | ShortcutManager.FLAG_MATCH_DYNAMIC), |
| 1276 | "ms1", "ms2", "ms3", "s1", "s2", "s3"); |
| 1277 | |
| 1278 | // Get manifest and pinned shortcuts |
| 1279 | assertShortcutIds(mManager.getShortcuts( |
| 1280 | ShortcutManager.FLAG_MATCH_MANIFEST | ShortcutManager.FLAG_MATCH_PINNED), |
| 1281 | "ms1", "ms2", "ms3", "s2", "s3"); |
| 1282 | |
| 1283 | // Get manifest and cached shortcuts |
| 1284 | assertShortcutIds(mManager.getShortcuts( |
| 1285 | ShortcutManager.FLAG_MATCH_MANIFEST | ShortcutManager.FLAG_MATCH_CACHED), |
| 1286 | "ms1", "ms2", "ms3", "s1", "s2"); |
| 1287 | |
| 1288 | // Get dynamic and pinned shortcuts |
| 1289 | assertShortcutIds(mManager.getShortcuts( |
| 1290 | ShortcutManager.FLAG_MATCH_DYNAMIC | ShortcutManager.FLAG_MATCH_PINNED), |
| 1291 | "ms2", "ms3", "s1", "s2", "s3"); |
| 1292 | |
| 1293 | // Get dynamic and cached shortcuts |
| 1294 | assertShortcutIds(mManager.getShortcuts( |
| 1295 | ShortcutManager.FLAG_MATCH_DYNAMIC | ShortcutManager.FLAG_MATCH_CACHED), |
| 1296 | "s1", "s2", "s3"); |
| 1297 | |
| 1298 | // Get pinned and cached shortcuts |
| 1299 | assertShortcutIds(mManager.getShortcuts( |
| 1300 | ShortcutManager.FLAG_MATCH_PINNED | ShortcutManager.FLAG_MATCH_CACHED), |
| 1301 | "ms2", "ms3", "s1", "s2", "s3"); |
| 1302 | |
| 1303 | // Remove a dynamic cached shortcut |
| 1304 | mManager.removeDynamicShortcuts(list("s1")); |
| 1305 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), "s2", "s3"); |
| 1306 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), "s1", "s2"); |
| 1307 | |
| 1308 | // Remove a dynamic cached and pinned shortcut |
| 1309 | mManager.removeDynamicShortcuts(list("s2")); |
| 1310 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), "s3"); |
| 1311 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), |
| 1312 | "ms2", "ms3", "s2", "s3"); |
| 1313 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), "s1", "s2"); |
| 1314 | } |
| 1315 | |
| 1316 | public void testCachedShortcuts() { |
| 1317 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1318 | assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1"), makeShortcut("s2"), |
| 1319 | makeShortcut("s3"), makeShortcut("s4")))); |
| 1320 | }); |
| 1321 | |
| 1322 | // Pin s2 |
| 1323 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1324 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2"), |
| 1325 | HANDLE_USER_0); |
| 1326 | }); |
| 1327 | |
| 1328 | // Cache 2, 3 and 4 |
| 1329 | setCaller(CALLING_PACKAGE_1); |
| 1330 | getCallerShortcut("s2").setCached(); |
| 1331 | getCallerShortcut("s3").setCached(); |
| 1332 | getCallerShortcut("s4").setCached(); |
| 1333 | |
| 1334 | // Get dynamic shortcuts |
| 1335 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), |
| 1336 | "s1", "s2", "s3", "s4"); |
| 1337 | // Get pinned shortcuts |
| 1338 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), |
| 1339 | "s2"); |
| 1340 | // Get cached shortcuts |
| 1341 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), |
| 1342 | "s2", "s3", "s4"); |
| 1343 | |
| 1344 | // Remove a dynamic cached shortcut |
| 1345 | mManager.removeDynamicShortcuts(list("s3")); |
| 1346 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), |
| 1347 | "s1", "s2", "s4"); |
| 1348 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), |
| 1349 | "s2", "s3", "s4"); |
| 1350 | |
| 1351 | // Remove dynamic cached long lived shortcuts |
| 1352 | mManager.removeLongLivedShortcuts(list("s3", "s4")); |
| 1353 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), |
| 1354 | "s1", "s2"); |
| 1355 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), |
| 1356 | "s2"); |
| 1357 | |
| 1358 | // Remove a dynamic cached pinned long lived shortcut |
| 1359 | mManager.removeLongLivedShortcuts(list("s2")); |
| 1360 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), |
| 1361 | "s1"); |
| 1362 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED)); |
| 1363 | assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), |
| 1364 | "s2"); |
| 1365 | } |
| 1366 | |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1367 | // === Test for launcher side APIs === |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1368 | |
| 1369 | public void testGetShortcuts() { |
| 1370 | |
| 1371 | // Set up shortcuts. |
| 1372 | |
| 1373 | setCaller(CALLING_PACKAGE_1); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1374 | final ShortcutInfo s1_1 = makeShortcut("s1"); |
| 1375 | final ShortcutInfo s1_2 = makeShortcut("s2"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1376 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1377 | assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1378 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1379 | // Because setDynamicShortcuts will update the timestamps when ranks are changing, |
| 1380 | // we explicitly set timestamps here. |
| 1381 | getCallerShortcut("s1").setTimestamp(5000); |
| 1382 | getCallerShortcut("s2").setTimestamp(1000); |
| 1383 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1384 | setCaller(CALLING_PACKAGE_2); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1385 | final ShortcutInfo s2_2 = makeShortcut("s2"); |
| 1386 | final ShortcutInfo s2_3 = makeShortcutWithActivity("s3", |
Makoto Onuki | 8569452 | 2016-05-04 12:53:37 -0700 | [diff] [blame] | 1387 | makeComponent(ShortcutActivity2.class)); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1388 | final ShortcutInfo s2_4 = makeShortcutWithActivity("s4", |
Makoto Onuki | 8569452 | 2016-05-04 12:53:37 -0700 | [diff] [blame] | 1389 | makeComponent(ShortcutActivity.class)); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1390 | assertTrue(mManager.setDynamicShortcuts(list(s2_2, s2_3, s2_4))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1391 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1392 | getCallerShortcut("s2").setTimestamp(1500); |
| 1393 | getCallerShortcut("s3").setTimestamp(3000); |
| 1394 | getCallerShortcut("s4").setTimestamp(500); |
| 1395 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1396 | setCaller(CALLING_PACKAGE_3); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1397 | final ShortcutInfo s3_2 = makeShortcut("s3"); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1398 | assertTrue(mManager.setDynamicShortcuts(list(s3_2))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1399 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 1400 | getCallerShortcut("s3").setTimestamp(START_TIME + 5000); |
| 1401 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1402 | setCaller(LAUNCHER_1); |
| 1403 | |
| 1404 | // Get dynamic |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1405 | assertAllDynamic(assertAllHaveTitle(assertAllNotHaveIntents(assertAllStringsResolved( |
| 1406 | assertShortcutIds( |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 1407 | assertAllNotKeyFieldsOnly( |
| 1408 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1409 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 1410 | "s1", "s2"))))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1411 | |
| 1412 | // Get pinned |
| 1413 | assertShortcutIds( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1414 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1415 | /* activity =*/ null, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1416 | ShortcutQuery.FLAG_GET_PINNED), getCallingUser()) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1417 | /* none */); |
| 1418 | |
| 1419 | // Get both, with timestamp |
| 1420 | assertAllDynamic(assertAllHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1421 | assertAllNotKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1422 | /* time =*/ 1000, CALLING_PACKAGE_2, |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1423 | /* activity =*/ null, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1424 | ShortcutQuery.FLAG_GET_PINNED | ShortcutQuery.FLAG_GET_DYNAMIC), |
| 1425 | getCallingUser())), |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1426 | "s2", "s3")))); |
| 1427 | |
| 1428 | // FLAG_GET_KEY_FIELDS_ONLY |
| 1429 | assertAllDynamic(assertAllNotHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1430 | assertAllKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1431 | /* time =*/ 1000, CALLING_PACKAGE_2, |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1432 | /* activity =*/ null, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1433 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY), |
| 1434 | getCallingUser())), |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1435 | "s2", "s3")))); |
| 1436 | |
Makoto Onuki | 8569452 | 2016-05-04 12:53:37 -0700 | [diff] [blame] | 1437 | // Filter by activity |
| 1438 | assertAllDynamic(assertAllHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
| 1439 | assertAllNotKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
| 1440 | /* time =*/ 0, CALLING_PACKAGE_2, |
| 1441 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 1442 | ShortcutQuery.FLAG_GET_PINNED | ShortcutQuery.FLAG_GET_DYNAMIC), |
| 1443 | getCallingUser())), |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1444 | "s4")))); |
Makoto Onuki | 8569452 | 2016-05-04 12:53:37 -0700 | [diff] [blame] | 1445 | |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1446 | // With ID. |
| 1447 | assertAllDynamic(assertAllNotHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
| 1448 | assertAllKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
| 1449 | /* time =*/ 1000, CALLING_PACKAGE_2, list("s3"), |
| 1450 | /* activity =*/ null, |
| 1451 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY), |
| 1452 | getCallingUser())), |
| 1453 | "s3")))); |
| 1454 | assertAllDynamic(assertAllNotHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
| 1455 | assertAllKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
| 1456 | /* time =*/ 1000, CALLING_PACKAGE_2, list("s3", "s2", "ss"), |
| 1457 | /* activity =*/ null, |
| 1458 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY), |
| 1459 | getCallingUser())), |
| 1460 | "s2", "s3")))); |
| 1461 | assertAllDynamic(assertAllNotHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
| 1462 | assertAllKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
| 1463 | /* time =*/ 1000, CALLING_PACKAGE_2, list("s3x", "s2x"), |
| 1464 | /* activity =*/ null, |
| 1465 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY), |
| 1466 | getCallingUser())) |
| 1467 | /* empty */)))); |
| 1468 | assertAllDynamic(assertAllNotHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
| 1469 | assertAllKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
| 1470 | /* time =*/ 1000, CALLING_PACKAGE_2, list(), |
| 1471 | /* activity =*/ null, |
| 1472 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY), |
| 1473 | getCallingUser())) |
| 1474 | /* empty */)))); |
| 1475 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1476 | // Pin some shortcuts. |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1477 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1478 | list("s3", "s4"), getCallingUser()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1479 | |
| 1480 | // Pinned ones only |
| 1481 | assertAllPinned(assertAllHaveTitle(assertAllNotHaveIntents(assertShortcutIds( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1482 | assertAllNotKeyFieldsOnly(mLauncherApps.getShortcuts(buildQuery( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1483 | /* time =*/ 1000, CALLING_PACKAGE_2, |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1484 | /* activity =*/ null, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1485 | ShortcutQuery.FLAG_GET_PINNED), |
| 1486 | getCallingUser())), |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1487 | "s3")))); |
| 1488 | |
| 1489 | // All packages. |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1490 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1491 | mLauncherApps.getShortcuts(buildQuery( |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1492 | /* time =*/ 5000, /* package= */ null, |
| 1493 | /* activity =*/ null, |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1494 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_PINNED), |
| 1495 | getCallingUser())), |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1496 | "s1", "s3"); |
| 1497 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 1498 | assertExpectException( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1499 | IllegalArgumentException.class, "package name must also be set", () -> { |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 1500 | mLauncherApps.getShortcuts(buildQuery( |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1501 | /* time =*/ 0, /* package= */ null, list("id"), |
| 1502 | /* activity =*/ null, /* flags */ 0), getCallingUser()); |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 1503 | }); |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 1504 | |
Makoto Onuki | 9fd9019 | 2017-01-06 18:31:03 +0000 | [diff] [blame] | 1505 | // TODO More tests: pinned but dynamic. |
Mehdi Alizadeh | 505fb76 | 2020-01-21 17:26:24 -0800 | [diff] [blame] | 1506 | |
| 1507 | // Cache some shortcuts |
| 1508 | setCaller(CALLING_PACKAGE_1); |
| 1509 | getCallerShortcut("s1").setCached(); |
| 1510 | |
| 1511 | setCaller(CALLING_PACKAGE_2); |
| 1512 | getCallerShortcut("s4").setCached(); |
| 1513 | |
| 1514 | setCaller(CALLING_PACKAGE_3); |
| 1515 | getCallerShortcut("s3").setCached(); |
| 1516 | |
| 1517 | setCaller(LAUNCHER_1); |
| 1518 | |
| 1519 | // Cached ones only |
| 1520 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 1521 | mLauncherApps.getShortcuts(buildQuery( |
| 1522 | /* time =*/ 0, CALLING_PACKAGE_2, |
| 1523 | /* activity =*/ null, |
| 1524 | ShortcutQuery.FLAG_MATCH_CACHED), |
| 1525 | getCallingUser())), |
| 1526 | "s4"); |
| 1527 | |
| 1528 | // All packages. |
| 1529 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 1530 | mLauncherApps.getShortcuts(buildQuery( |
| 1531 | /* time =*/ 0, /* package= */ null, |
| 1532 | /* activity =*/ null, |
| 1533 | ShortcutQuery.FLAG_MATCH_CACHED), |
| 1534 | getCallingUser())), |
| 1535 | "s1", "s4", "s3"); |
| 1536 | |
| 1537 | assertExpectException( |
| 1538 | IllegalArgumentException.class, "package name must also be set", () -> { |
| 1539 | mLauncherApps.getShortcuts(buildQuery( |
| 1540 | /* time =*/ 0, /* package= */ null, list("id"), |
| 1541 | /* activity =*/ null, /* flags */ 0), getCallingUser()); |
| 1542 | }); |
| 1543 | |
| 1544 | // Change Launcher. Cached shortcuts are the same for all launchers. |
| 1545 | setCaller(LAUNCHER_2); |
| 1546 | // All packages. |
| 1547 | assertShortcutIds(assertAllNotKeyFieldsOnly( |
| 1548 | mLauncherApps.getShortcuts(buildQuery( |
| 1549 | /* time =*/ 0, /* package= */ null, |
| 1550 | /* activity =*/ null, |
| 1551 | ShortcutQuery.FLAG_MATCH_CACHED), |
| 1552 | getCallingUser())), |
| 1553 | "s1", "s4", "s3"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 1556 | public void testGetShortcuts_shortcutKinds() throws Exception { |
| 1557 | // Create 3 manifest and 3 dynamic shortcuts |
| 1558 | addManifestShortcutResource( |
| 1559 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 1560 | R.xml.shortcut_3); |
| 1561 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 1562 | mService.mPackageMonitor.onReceive(getTestContext(), |
| 1563 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 1564 | |
| 1565 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1566 | assertTrue(mManager.setDynamicShortcuts(list( |
| 1567 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 1568 | }); |
| 1569 | |
| 1570 | // Pin 2 and 3 |
| 1571 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1572 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms2", "ms3", "s2", "s3"), |
| 1573 | HANDLE_USER_0); |
| 1574 | }); |
| 1575 | |
| 1576 | // Remove ms3 and s3 |
| 1577 | addManifestShortcutResource( |
| 1578 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 1579 | R.xml.shortcut_2); |
| 1580 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 1581 | mService.mPackageMonitor.onReceive(getTestContext(), |
| 1582 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 1583 | |
| 1584 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1585 | assertTrue(mManager.setDynamicShortcuts(list( |
| 1586 | makeShortcut("s1"), makeShortcut("s2")))); |
| 1587 | }); |
| 1588 | |
| 1589 | // Check their status. |
| 1590 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1591 | assertWith(getCallerShortcuts()) |
| 1592 | .haveIds("ms1", "ms2", "ms3", "s1", "s2", "s3") |
| 1593 | |
| 1594 | .selectByIds("ms1", "ms2") |
| 1595 | .areAllManifest() |
| 1596 | .areAllImmutable() |
| 1597 | .areAllNotDynamic() |
| 1598 | |
| 1599 | .revertToOriginalList() |
| 1600 | .selectByIds("ms3") |
| 1601 | .areAllNotManifest() |
| 1602 | .areAllImmutable() |
| 1603 | .areAllDisabled() |
| 1604 | .areAllNotDynamic() |
| 1605 | |
| 1606 | .revertToOriginalList() |
| 1607 | .selectByIds("s1", "s2") |
| 1608 | .areAllNotManifest() |
| 1609 | .areAllMutable() |
| 1610 | .areAllDynamic() |
| 1611 | |
| 1612 | .revertToOriginalList() |
| 1613 | .selectByIds("s3") |
| 1614 | .areAllNotManifest() |
| 1615 | .areAllMutable() |
| 1616 | .areAllEnabled() |
| 1617 | .areAllNotDynamic() |
| 1618 | |
| 1619 | .revertToOriginalList() |
| 1620 | .selectByIds("s1", "ms1") |
| 1621 | .areAllNotPinned() |
| 1622 | |
| 1623 | .revertToOriginalList() |
| 1624 | .selectByIds("s2", "s3", "ms2", "ms3") |
| 1625 | .areAllPinned() |
| 1626 | ; |
| 1627 | }); |
| 1628 | |
| 1629 | // Finally, actual tests. |
| 1630 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1631 | assertWith(mLauncherApps.getShortcuts( |
| 1632 | buildQueryWithFlags(ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)) |
| 1633 | .haveIds("s1", "s2"); |
| 1634 | assertWith(mLauncherApps.getShortcuts( |
| 1635 | buildQueryWithFlags(ShortcutQuery.FLAG_GET_MANIFEST), HANDLE_USER_0)) |
| 1636 | .haveIds("ms1", "ms2"); |
| 1637 | assertWith(mLauncherApps.getShortcuts( |
| 1638 | buildQueryWithFlags(ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)) |
| 1639 | .haveIds("s2", "s3", "ms2", "ms3"); |
| 1640 | |
| 1641 | assertWith(mLauncherApps.getShortcuts( |
| 1642 | buildQueryWithFlags( |
| 1643 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_PINNED |
| 1644 | ), HANDLE_USER_0)) |
| 1645 | .haveIds("s1", "s2", "s3", "ms2", "ms3"); |
| 1646 | |
| 1647 | assertWith(mLauncherApps.getShortcuts( |
| 1648 | buildQueryWithFlags( |
| 1649 | ShortcutQuery.FLAG_GET_MANIFEST | ShortcutQuery.FLAG_GET_PINNED |
| 1650 | ), HANDLE_USER_0)) |
| 1651 | .haveIds("ms1", "s2", "s3", "ms2", "ms3"); |
| 1652 | |
| 1653 | assertWith(mLauncherApps.getShortcuts( |
| 1654 | buildQueryWithFlags( |
| 1655 | ShortcutQuery.FLAG_GET_DYNAMIC | ShortcutQuery.FLAG_GET_MANIFEST |
| 1656 | ), HANDLE_USER_0)) |
| 1657 | .haveIds("ms1", "ms2", "s1", "s2"); |
| 1658 | |
| 1659 | assertWith(mLauncherApps.getShortcuts( |
| 1660 | buildQueryWithFlags( |
| 1661 | ShortcutQuery.FLAG_GET_ALL_KINDS |
| 1662 | ), HANDLE_USER_0)) |
| 1663 | .haveIds("ms1", "ms2", "ms3", "s1", "s2", "s3"); |
| 1664 | }); |
| 1665 | } |
| 1666 | |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1667 | public void testGetShortcuts_resolveStrings() throws Exception { |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1668 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1669 | ShortcutInfo si = new ShortcutInfo.Builder(mClientContext) |
| 1670 | .setId("id") |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1671 | .setActivity(new ComponentName(mClientContext, "dummy")) |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1672 | .setTitleResId(10) |
| 1673 | .setTextResId(11) |
| 1674 | .setDisabledMessageResId(12) |
| 1675 | .setIntent(makeIntent("action", ShortcutActivity.class)) |
| 1676 | .build(); |
| 1677 | mManager.setDynamicShortcuts(list(si)); |
| 1678 | }); |
| 1679 | runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> { |
| 1680 | ShortcutInfo si = new ShortcutInfo.Builder(mClientContext) |
| 1681 | .setId("id") |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1682 | .setActivity(new ComponentName(mClientContext, "dummy")) |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1683 | .setTitleResId(10) |
| 1684 | .setTextResId(11) |
| 1685 | .setDisabledMessageResId(12) |
| 1686 | .setIntent(makeIntent("action", ShortcutActivity.class)) |
| 1687 | .build(); |
| 1688 | mManager.setDynamicShortcuts(list(si)); |
| 1689 | }); |
| 1690 | |
| 1691 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1692 | final ShortcutQuery q = new ShortcutQuery(); |
| 1693 | q.setQueryFlags(ShortcutQuery.FLAG_GET_DYNAMIC); |
| 1694 | |
| 1695 | // USER 0 |
| 1696 | List<ShortcutInfo> ret = assertShortcutIds( |
| 1697 | assertAllStringsResolved(mLauncherApps.getShortcuts(q, HANDLE_USER_0)), |
| 1698 | "id"); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1699 | assertEquals("string-com.android.test.1-user:0-res:10/en", ret.get(0).getTitle()); |
| 1700 | assertEquals("string-com.android.test.1-user:0-res:11/en", ret.get(0).getText()); |
| 1701 | assertEquals("string-com.android.test.1-user:0-res:12/en", |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1702 | ret.get(0).getDisabledMessage()); |
| 1703 | |
| 1704 | // USER P0 |
| 1705 | ret = assertShortcutIds( |
| 1706 | assertAllStringsResolved(mLauncherApps.getShortcuts(q, HANDLE_USER_P0)), |
| 1707 | "id"); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 1708 | assertEquals("string-com.android.test.1-user:20-res:10/en", ret.get(0).getTitle()); |
| 1709 | assertEquals("string-com.android.test.1-user:20-res:11/en", ret.get(0).getText()); |
| 1710 | assertEquals("string-com.android.test.1-user:20-res:12/en", |
Makoto Onuki | 20c95f8 | 2016-05-11 16:51:01 -0700 | [diff] [blame] | 1711 | ret.get(0).getDisabledMessage()); |
| 1712 | }); |
| 1713 | } |
| 1714 | |
| 1715 | // TODO resource |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1716 | public void testGetShortcutInfo() { |
| 1717 | // Create shortcuts. |
| 1718 | setCaller(CALLING_PACKAGE_1); |
| 1719 | final ShortcutInfo s1_1 = makeShortcut( |
| 1720 | "s1", |
| 1721 | "Title 1", |
| 1722 | makeComponent(ShortcutActivity.class), |
| 1723 | /* icon =*/ null, |
| 1724 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, |
| 1725 | "key1", "val1", "nest", makeBundle("key", 123)), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1726 | /* weight */ 10); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1727 | |
| 1728 | final ShortcutInfo s1_2 = makeShortcut( |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1729 | "s2", |
| 1730 | "Title 2", |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1731 | /* activity */ null, |
| 1732 | /* icon =*/ null, |
| 1733 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1734 | /* weight */ 12); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1735 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1736 | assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1737 | dumpsysOnLogcat(); |
| 1738 | |
| 1739 | setCaller(CALLING_PACKAGE_2); |
| 1740 | final ShortcutInfo s2_1 = makeShortcut( |
| 1741 | "s1", |
| 1742 | "ABC", |
| 1743 | makeComponent(ShortcutActivity2.class), |
| 1744 | /* icon =*/ null, |
| 1745 | makeIntent(Intent.ACTION_ANSWER, ShortcutActivity2.class, |
| 1746 | "key1", "val1", "nest", makeBundle("key", 123)), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 1747 | /* weight */ 10); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1748 | assertTrue(mManager.setDynamicShortcuts(list(s2_1))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1749 | dumpsysOnLogcat(); |
| 1750 | |
| 1751 | // Pin some. |
| 1752 | setCaller(LAUNCHER_1); |
| 1753 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1754 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1755 | list("s2"), getCallingUser()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1756 | |
| 1757 | dumpsysOnLogcat(); |
| 1758 | |
| 1759 | // Delete some. |
| 1760 | setCaller(CALLING_PACKAGE_1); |
| 1761 | assertShortcutIds(mManager.getPinnedShortcuts(), "s2"); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1762 | mManager.removeDynamicShortcuts(list("s2")); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1763 | assertShortcutIds(mManager.getPinnedShortcuts(), "s2"); |
| 1764 | |
| 1765 | dumpsysOnLogcat(); |
| 1766 | |
| 1767 | setCaller(LAUNCHER_1); |
| 1768 | List<ShortcutInfo> list; |
| 1769 | |
| 1770 | // Note we don't guarantee the orders. |
| 1771 | list = assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents( |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 1772 | assertAllNotKeyFieldsOnly( |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 1773 | mLauncherApps.getShortcutInfo(CALLING_PACKAGE_1, |
| 1774 | list("s2", "s1", "s3", null), getCallingUser())))), |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1775 | "s1", "s2"); |
| 1776 | assertEquals("Title 1", findById(list, "s1").getTitle()); |
| 1777 | assertEquals("Title 2", findById(list, "s2").getTitle()); |
| 1778 | |
| 1779 | assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1780 | mLauncherApps.getShortcutInfo(CALLING_PACKAGE_1, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1781 | list("s3"), getCallingUser()))) |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1782 | /* none */); |
| 1783 | |
| 1784 | list = assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents( |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 1785 | mLauncherApps.getShortcutInfo(CALLING_PACKAGE_2, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1786 | list("s1", "s2", "s3"), getCallingUser()))), |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1787 | "s1"); |
| 1788 | assertEquals("ABC", findById(list, "s1").getTitle()); |
| 1789 | } |
| 1790 | |
| 1791 | public void testPinShortcutAndGetPinnedShortcuts() { |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1792 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1793 | final ShortcutInfo s1_1 = makeShortcutWithTimestamp("s1", 1000); |
| 1794 | final ShortcutInfo s1_2 = makeShortcutWithTimestamp("s2", 2000); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1795 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1796 | assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2))); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1797 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1798 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1799 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 1800 | final ShortcutInfo s2_2 = makeShortcutWithTimestamp("s2", 1500); |
| 1801 | final ShortcutInfo s2_3 = makeShortcutWithTimestamp("s3", 3000); |
| 1802 | final ShortcutInfo s2_4 = makeShortcutWithTimestamp("s4", 500); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1803 | assertTrue(mManager.setDynamicShortcuts(list(s2_2, s2_3, s2_4))); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1804 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1805 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1806 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 1807 | final ShortcutInfo s3_2 = makeShortcutWithTimestamp("s2", 1000); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1808 | assertTrue(mManager.setDynamicShortcuts(list(s3_2))); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1809 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1810 | |
| 1811 | // Pin some. |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1812 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1813 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1814 | list("s2", "s3"), getCallingUser()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1815 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1816 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1817 | list("s3", "s4", "s5"), getCallingUser()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1818 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1819 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_3, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1820 | list("s3"), getCallingUser()); // Note ID doesn't exist |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1821 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1822 | |
| 1823 | // Delete some. |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1824 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1825 | assertShortcutIds(mManager.getPinnedShortcuts(), "s2"); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1826 | mManager.removeDynamicShortcuts(list("s2")); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1827 | assertShortcutIds(mManager.getPinnedShortcuts(), "s2"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1828 | |
| 1829 | assertShortcutIds(mManager.getDynamicShortcuts(), "s1"); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1830 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1831 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1832 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 1833 | assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4"); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1834 | mManager.removeDynamicShortcuts(list("s3")); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1835 | assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1836 | |
| 1837 | assertShortcutIds(mManager.getDynamicShortcuts(), "s2", "s4"); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1838 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1839 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1840 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 1841 | assertShortcutIds(mManager.getPinnedShortcuts() /* none */); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 1842 | mManager.removeDynamicShortcuts(list("s2")); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1843 | assertShortcutIds(mManager.getPinnedShortcuts() /* none */); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1844 | |
| 1845 | assertEmpty(mManager.getDynamicShortcuts()); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1846 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1847 | |
| 1848 | // Get pinned shortcuts from launcher |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1849 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1850 | // CALLING_PACKAGE_1 deleted s2, but it's pinned, so it still exists. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1851 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled( |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1852 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1853 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))), |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1854 | "s2"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1855 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1856 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled( |
| 1857 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 1858 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))), |
| 1859 | "s3", "s4"); |
| 1860 | |
| 1861 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled( |
| 1862 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_3, |
| 1863 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))) |
| 1864 | /* none */); |
| 1865 | }); |
| 1866 | } |
| 1867 | |
| 1868 | /** |
| 1869 | * This is similar to the above test, except it used "disable" instead of "remove". It also |
| 1870 | * does "enable". |
| 1871 | */ |
| 1872 | public void testDisableAndEnableShortcuts() { |
| 1873 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1874 | final ShortcutInfo s1_1 = makeShortcutWithTimestamp("s1", 1000); |
| 1875 | final ShortcutInfo s1_2 = makeShortcutWithTimestamp("s2", 2000); |
| 1876 | |
| 1877 | assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2))); |
| 1878 | }); |
| 1879 | |
| 1880 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 1881 | final ShortcutInfo s2_2 = makeShortcutWithTimestamp("s2", 1500); |
| 1882 | final ShortcutInfo s2_3 = makeShortcutWithTimestamp("s3", 3000); |
| 1883 | final ShortcutInfo s2_4 = makeShortcutWithTimestamp("s4", 500); |
| 1884 | assertTrue(mManager.setDynamicShortcuts(list(s2_2, s2_3, s2_4))); |
| 1885 | }); |
| 1886 | |
| 1887 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 1888 | final ShortcutInfo s3_2 = makeShortcutWithTimestamp("s2", 1000); |
| 1889 | assertTrue(mManager.setDynamicShortcuts(list(s3_2))); |
| 1890 | }); |
| 1891 | |
| 1892 | // Pin some. |
| 1893 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1894 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 1895 | list("s2", "s3"), getCallingUser()); |
| 1896 | |
| 1897 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
| 1898 | list("s3", "s4", "s5"), getCallingUser()); |
| 1899 | |
| 1900 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_3, |
| 1901 | list("s3"), getCallingUser()); // Note ID doesn't exist |
| 1902 | }); |
| 1903 | |
| 1904 | // Disable some. |
| 1905 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1906 | assertShortcutIds(mManager.getPinnedShortcuts(), "s2"); |
| 1907 | |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 1908 | mManager.updateShortcuts(list( |
| 1909 | new ShortcutInfo.Builder(mClientContext, "s2").setDisabledMessage("xyz") |
| 1910 | .build())); |
| 1911 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1912 | mManager.disableShortcuts(list("s2")); |
| 1913 | |
| 1914 | assertShortcutIds(mManager.getPinnedShortcuts(), "s2"); |
| 1915 | assertShortcutIds(mManager.getDynamicShortcuts(), "s1"); |
| 1916 | }); |
| 1917 | |
| 1918 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 1919 | assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4"); |
| 1920 | |
| 1921 | // disable should work even if a shortcut is not dynamic, so try calling "remove" first |
| 1922 | // here. |
| 1923 | mManager.removeDynamicShortcuts(list("s3")); |
| 1924 | mManager.disableShortcuts(list("s3")); |
| 1925 | |
| 1926 | assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4"); |
| 1927 | assertShortcutIds(mManager.getDynamicShortcuts(), "s2", "s4"); |
| 1928 | }); |
| 1929 | |
| 1930 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 1931 | assertShortcutIds(mManager.getPinnedShortcuts() /* none */); |
| 1932 | |
| 1933 | mManager.disableShortcuts(list("s2")); |
| 1934 | |
| 1935 | assertShortcutIds(mManager.getPinnedShortcuts() /* none */); |
| 1936 | |
| 1937 | assertEmpty(mManager.getDynamicShortcuts()); |
| 1938 | assertEmpty(getCallerShortcuts()); |
| 1939 | }); |
| 1940 | |
| 1941 | // Get pinned shortcuts from launcher |
| 1942 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 1943 | // CALLING_PACKAGE_1 deleted s2, but it's pinned, so it still exists, and disabled. |
| 1944 | assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 1945 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())) |
| 1946 | .haveIds("s2") |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 1947 | .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_BY_APP) |
| 1948 | .forAllShortcuts(si -> { |
| 1949 | assertEquals("xyz", si.getDisabledMessage()); |
| 1950 | }) |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 1951 | .areAllPinned() |
| 1952 | .areAllNotWithKeyFieldsOnly() |
| 1953 | .areAllDisabled(); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1954 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 1955 | ActivityNotFoundException.class); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1956 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 1957 | // Here, s4 is still enabled and launchable, but s3 is disabled. |
| 1958 | assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 1959 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())) |
| 1960 | .haveIds("s3", "s4") |
| 1961 | .areAllPinned() |
| 1962 | .areAllNotWithKeyFieldsOnly() |
| 1963 | |
| 1964 | .selectByIds("s3") |
| 1965 | .areAllDisabled() |
| 1966 | |
| 1967 | .revertToOriginalList() |
| 1968 | .selectByIds("s4") |
| 1969 | .areAllEnabled(); |
| 1970 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 1971 | assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s3", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 1972 | ActivityNotFoundException.class); |
Makoto Onuki | ff14f73 | 2016-06-30 17:07:25 -0700 | [diff] [blame] | 1973 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s4", USER_0); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1974 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1975 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled( |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1976 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_3, |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1977 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))) |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 1978 | /* none */); |
| 1979 | }); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 1980 | |
| 1981 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1982 | mManager.enableShortcuts(list("s2")); |
| 1983 | |
| 1984 | assertShortcutIds(mManager.getPinnedShortcuts(), "s2"); |
| 1985 | assertShortcutIds(mManager.getDynamicShortcuts(), "s1"); |
| 1986 | }); |
| 1987 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 1988 | // CALLING_PACKAGE_1 deleted s2, but it's pinned, so it still exists. |
| 1989 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled( |
| 1990 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 1991 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))), |
| 1992 | "s2"); |
Makoto Onuki | ff14f73 | 2016-06-30 17:07:25 -0700 | [diff] [blame] | 1993 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0); |
| 1994 | }); |
| 1995 | } |
| 1996 | |
| 1997 | public void testDisableShortcuts_thenRepublish() { |
| 1998 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 1999 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2000 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 2001 | |
| 2002 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2003 | mLauncherApps.pinShortcuts( |
| 2004 | CALLING_PACKAGE_1, list("s1", "s2", "s3"), HANDLE_USER_0); |
| 2005 | }); |
| 2006 | |
| 2007 | mManager.disableShortcuts(list("s1", "s2", "s3")); |
| 2008 | |
| 2009 | assertWith(getCallerShortcuts()) |
| 2010 | .haveIds("s1", "s2", "s3") |
| 2011 | .areAllNotDynamic() |
| 2012 | .areAllPinned() |
| 2013 | .areAllDisabled(); |
| 2014 | |
| 2015 | // Make sure updateShortcuts() will not re-enable them. |
| 2016 | assertTrue(mManager.updateShortcuts(list( |
| 2017 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 2018 | |
| 2019 | assertWith(getCallerShortcuts()) |
| 2020 | .haveIds("s1", "s2", "s3") |
| 2021 | .areAllNotDynamic() |
| 2022 | .areAllPinned() |
| 2023 | .areAllDisabled(); |
| 2024 | |
| 2025 | // Re-publish s1 with setDynamicShortcuts. |
| 2026 | mInjectedCurrentTimeMillis += INTERVAL; // reset throttling |
| 2027 | |
| 2028 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2029 | makeShortcut("s1")))); |
| 2030 | |
| 2031 | assertWith(getCallerShortcuts()) |
| 2032 | .haveIds("s1", "s2", "s3") |
| 2033 | |
| 2034 | .selectByIds("s1") |
| 2035 | .areAllDynamic() |
| 2036 | .areAllPinned() |
| 2037 | .areAllEnabled() |
| 2038 | |
| 2039 | .revertToOriginalList() |
| 2040 | .selectByIds("s2", "s3") |
| 2041 | .areAllNotDynamic() |
| 2042 | .areAllPinned() |
| 2043 | .areAllDisabled(); |
| 2044 | |
| 2045 | // Re-publish s2 with addDynamicShortcuts. |
| 2046 | mInjectedCurrentTimeMillis += INTERVAL; // reset throttling |
| 2047 | |
| 2048 | assertTrue(mManager.addDynamicShortcuts(list( |
| 2049 | makeShortcut("s2")))); |
| 2050 | |
| 2051 | assertWith(getCallerShortcuts()) |
| 2052 | .haveIds("s1", "s2", "s3") |
| 2053 | |
| 2054 | .selectByIds("s1", "s2") |
| 2055 | .areAllDynamic() |
| 2056 | .areAllPinned() |
| 2057 | .areAllEnabled() |
| 2058 | |
| 2059 | .revertToOriginalList() |
| 2060 | .selectByIds("s3") |
| 2061 | .areAllNotDynamic() |
| 2062 | .areAllPinned() |
| 2063 | .areAllDisabled(); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 2064 | }); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2065 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2066 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2067 | public void testPinShortcutAndGetPinnedShortcuts_multi() { |
| 2068 | // Create some shortcuts. |
| 2069 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2070 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2071 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 2072 | }); |
| 2073 | |
| 2074 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2075 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2076 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 2077 | }); |
| 2078 | |
| 2079 | dumpsysOnLogcat(); |
| 2080 | |
| 2081 | // Pin some. |
| 2082 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2083 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2084 | list("s3", "s4"), getCallingUser()); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2085 | |
| 2086 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2087 | list("s1", "s2", "s4"), getCallingUser()); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2088 | }); |
| 2089 | |
| 2090 | dumpsysOnLogcat(); |
| 2091 | |
| 2092 | // Delete some. |
| 2093 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2094 | assertShortcutIds(mManager.getPinnedShortcuts(), "s3"); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 2095 | mManager.removeDynamicShortcuts(list("s3")); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2096 | assertShortcutIds(mManager.getPinnedShortcuts(), "s3"); |
| 2097 | }); |
| 2098 | |
| 2099 | dumpsysOnLogcat(); |
| 2100 | |
| 2101 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 2102 | assertShortcutIds(mManager.getPinnedShortcuts(), "s1", "s2"); |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 2103 | mManager.removeDynamicShortcuts(list("s1")); |
| 2104 | mManager.removeDynamicShortcuts(list("s3")); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2105 | assertShortcutIds(mManager.getPinnedShortcuts(), "s1", "s2"); |
| 2106 | }); |
| 2107 | |
| 2108 | dumpsysOnLogcat(); |
| 2109 | |
| 2110 | // Get pinned shortcuts from launcher |
| 2111 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2112 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2113 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2114 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2115 | "s3"); |
| 2116 | |
| 2117 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2118 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2119 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2120 | "s1", "s2"); |
| 2121 | |
| 2122 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2123 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2124 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2125 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2126 | "s1", "s2", "s3"); |
| 2127 | |
| 2128 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2129 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2130 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2131 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2132 | "s1", "s2"); |
| 2133 | }); |
| 2134 | |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 2135 | dumpsysOnLogcat("Before launcher 2"); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2136 | |
| 2137 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
| 2138 | // Launcher2 still has no pinned ones. |
| 2139 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2140 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2141 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))) |
| 2142 | /* none */); |
| 2143 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2144 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2145 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))) |
| 2146 | /* none */); |
| 2147 | |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 2148 | // Make sure FLAG_MATCH_ALL_PINNED will be ignored. |
| 2149 | assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2150 | /* activity =*/ null, ShortcutQuery.FLAG_MATCH_PINNED |
Makoto Onuki | 35559d6 | 2017-11-06 16:26:32 -0800 | [diff] [blame] | 2151 | | ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER), getCallingUser())) |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 2152 | .isEmpty(); |
| 2153 | |
| 2154 | // Make sure the special permission works. |
| 2155 | mInjectCheckAccessShortcutsPermission = true; |
| 2156 | |
| 2157 | dumpsysOnLogcat("All-pinned"); |
| 2158 | |
| 2159 | assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2160 | /* activity =*/ null, ShortcutQuery.FLAG_MATCH_PINNED |
Makoto Onuki | 35559d6 | 2017-11-06 16:26:32 -0800 | [diff] [blame] | 2161 | | ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER), getCallingUser())) |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 2162 | .haveIds("s1", "s2"); |
| 2163 | assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2164 | /* activity =*/ null, ShortcutQuery.FLAG_MATCH_PINNED), getCallingUser())) |
| 2165 | .isEmpty(); |
| 2166 | |
Makoto Onuki | 35559d6 | 2017-11-06 16:26:32 -0800 | [diff] [blame] | 2167 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", getCallingUser().getIdentifier()); |
| 2168 | |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 2169 | mInjectCheckAccessShortcutsPermission = false; |
| 2170 | |
Makoto Onuki | 35559d6 | 2017-11-06 16:26:32 -0800 | [diff] [blame] | 2171 | assertShortcutNotLaunched(CALLING_PACKAGE_2, "s1", getCallingUser().getIdentifier()); |
| 2172 | |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2173 | assertShortcutIds(assertAllDynamic( |
| 2174 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2175 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2176 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2177 | "s1", "s2"); |
| 2178 | assertShortcutIds(assertAllDynamic( |
| 2179 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2180 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2181 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2182 | "s2"); |
| 2183 | |
| 2184 | // Now pin some. |
| 2185 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2186 | list("s1", "s2"), getCallingUser()); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2187 | |
| 2188 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2189 | list("s1", "s2"), getCallingUser()); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2190 | |
| 2191 | assertShortcutIds(assertAllDynamic( |
| 2192 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2193 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2194 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2195 | "s1", "s2"); |
| 2196 | |
| 2197 | // S1 was not visible to it, so shouldn't be pinned. |
| 2198 | assertShortcutIds(assertAllDynamic( |
| 2199 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2200 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2201 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2202 | "s2"); |
| 2203 | }); |
| 2204 | |
| 2205 | // Re-initialize and load from the files. |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 2206 | mService.saveDirtyInfo(); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2207 | initService(); |
| 2208 | |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 2209 | // Load from file. |
| 2210 | mService.handleUnlockUser(USER_0); |
| 2211 | |
| 2212 | // Make sure package info is restored too. |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2213 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2214 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2215 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2216 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2217 | "s3"); |
| 2218 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2219 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2220 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2221 | "s1", "s2"); |
| 2222 | }); |
| 2223 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
| 2224 | assertShortcutIds(assertAllDynamic( |
| 2225 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2226 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2227 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2228 | "s1", "s2"); |
| 2229 | assertShortcutIds(assertAllDynamic( |
| 2230 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2231 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED |
| 2232 | | ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())), |
| 2233 | "s2"); |
| 2234 | }); |
| 2235 | |
| 2236 | // Delete all dynamic. |
| 2237 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 2238 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2239 | |
| 2240 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 2241 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s1", "s2", "s3"); |
| 2242 | }); |
| 2243 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 2244 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2245 | |
| 2246 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 2247 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s2", "s1"); |
| 2248 | }); |
| 2249 | |
| 2250 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2251 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2252 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2253 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2254 | "s3"); |
| 2255 | |
| 2256 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2257 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2258 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2259 | "s1", "s2"); |
| 2260 | |
| 2261 | // from all packages. |
| 2262 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2263 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, null, |
| 2264 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2265 | "s1", "s2", "s3"); |
| 2266 | |
| 2267 | // Update pined. Note s2 and s3 are actually available, but not visible to this |
| 2268 | // launcher, so still can't be pinned. |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2269 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s1", "s2", "s3", "s4"), |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2270 | getCallingUser()); |
| 2271 | |
| 2272 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2273 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2274 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2275 | "s3"); |
| 2276 | }); |
| 2277 | // Re-publish s1. |
| 2278 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 2279 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("s1")))); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2280 | |
| 2281 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), "s1"); |
| 2282 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s1", "s2", "s3"); |
| 2283 | }); |
| 2284 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2285 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2286 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2287 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2288 | "s3"); |
| 2289 | |
| 2290 | // Now "s1" is visible, so can be pinned. |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2291 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s1", "s2", "s3", "s4"), |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2292 | getCallingUser()); |
| 2293 | |
| 2294 | assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly( |
| 2295 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2296 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))), |
| 2297 | "s1", "s3"); |
| 2298 | }); |
| 2299 | |
| 2300 | // Now clear pinned shortcuts. First, from launcher 1. |
| 2301 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2302 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list(), getCallingUser()); |
| 2303 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list(), getCallingUser()); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2304 | |
| 2305 | assertEquals(0, |
| 2306 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2307 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()).size()); |
| 2308 | assertEquals(0, |
| 2309 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2310 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()).size()); |
| 2311 | }); |
| 2312 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2313 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), "s1"); |
| 2314 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s1", "s2"); |
| 2315 | }); |
| 2316 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 2317 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 2318 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s2"); |
| 2319 | }); |
| 2320 | |
| 2321 | // Clear all pins from launcher 2. |
| 2322 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2323 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list(), getCallingUser()); |
| 2324 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list(), getCallingUser()); |
Makoto Onuki | de66737 | 2016-03-15 14:29:20 -0700 | [diff] [blame] | 2325 | |
| 2326 | assertEquals(0, |
| 2327 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2328 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()).size()); |
| 2329 | assertEquals(0, |
| 2330 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2331 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()).size()); |
| 2332 | }); |
| 2333 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2334 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), "s1"); |
| 2335 | assertEquals(0, mManager.getPinnedShortcuts().size()); |
| 2336 | }); |
| 2337 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 2338 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 2339 | assertEquals(0, mManager.getPinnedShortcuts().size()); |
| 2340 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2341 | } |
| 2342 | |
Makoto Onuki | 35559d6 | 2017-11-06 16:26:32 -0800 | [diff] [blame] | 2343 | public void testPinShortcutAndGetPinnedShortcuts_assistant() { |
| 2344 | // Create some shortcuts. |
| 2345 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2346 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2347 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 2348 | }); |
| 2349 | |
| 2350 | // Pin some. |
| 2351 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2352 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 2353 | list("s3", "s4"), getCallingUser()); |
| 2354 | }); |
| 2355 | |
| 2356 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2357 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2358 | makeShortcut("s1")))); |
| 2359 | }); |
| 2360 | |
| 2361 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
| 2362 | final ShortcutQuery allPinned = new ShortcutQuery().setQueryFlags( |
| 2363 | ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER); |
| 2364 | |
| 2365 | assertWith(mLauncherApps.getShortcuts(allPinned, HANDLE_USER_0)) |
| 2366 | .isEmpty(); |
| 2367 | |
| 2368 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
| 2369 | assertShortcutNotLaunched(CALLING_PACKAGE_1, "s3", USER_0); |
| 2370 | assertShortcutNotLaunched(CALLING_PACKAGE_1, "s4", USER_0); |
| 2371 | |
| 2372 | // Make it the assistant app. |
| 2373 | mInternal.setShortcutHostPackage("assistant", LAUNCHER_2, USER_0); |
| 2374 | assertWith(mLauncherApps.getShortcuts(allPinned, HANDLE_USER_0)) |
| 2375 | .haveIds("s3"); |
| 2376 | |
| 2377 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
| 2378 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0); |
| 2379 | assertShortcutNotLaunched(CALLING_PACKAGE_1, "s4", USER_0); |
| 2380 | |
| 2381 | mInternal.setShortcutHostPackage("another-type", LAUNCHER_3, USER_0); |
| 2382 | assertWith(mLauncherApps.getShortcuts(allPinned, HANDLE_USER_0)) |
| 2383 | .haveIds("s3"); |
| 2384 | |
| 2385 | mInternal.setShortcutHostPackage("assistant", null, USER_0); |
| 2386 | assertWith(mLauncherApps.getShortcuts(allPinned, HANDLE_USER_0)) |
| 2387 | .isEmpty(); |
| 2388 | |
| 2389 | mInternal.setShortcutHostPackage("assistant", LAUNCHER_2, USER_0); |
| 2390 | assertWith(mLauncherApps.getShortcuts(allPinned, HANDLE_USER_0)) |
| 2391 | .haveIds("s3"); |
| 2392 | |
| 2393 | mInternal.setShortcutHostPackage("assistant", LAUNCHER_1, USER_0); |
| 2394 | assertWith(mLauncherApps.getShortcuts(allPinned, HANDLE_USER_0)) |
| 2395 | .isEmpty(); |
| 2396 | }); |
| 2397 | } |
| 2398 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2399 | public void testPinShortcutAndGetPinnedShortcuts_crossProfile_plusLaunch() { |
| 2400 | // Create some shortcuts. |
| 2401 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2402 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2403 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 2404 | }); |
| 2405 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 2406 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2407 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 2408 | }); |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 2409 | |
| 2410 | mRunningUsers.put(USER_10, true); |
| 2411 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2412 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 2413 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2414 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"), |
| 2415 | makeShortcut("s4"), makeShortcut("s5"), makeShortcut("s6")))); |
| 2416 | }); |
| 2417 | |
| 2418 | // Pin some shortcuts and see the result. |
| 2419 | |
| 2420 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2421 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 2422 | list("s1"), HANDLE_USER_0); |
| 2423 | |
| 2424 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
| 2425 | list("s1", "s2", "s3"), HANDLE_USER_0); |
| 2426 | }); |
| 2427 | |
| 2428 | runWithCaller(LAUNCHER_1, USER_P0, () -> { |
| 2429 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 2430 | list("s2"), HANDLE_USER_0); |
| 2431 | |
| 2432 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
| 2433 | list("s2", "s3"), HANDLE_USER_0); |
| 2434 | }); |
| 2435 | |
| 2436 | runWithCaller(LAUNCHER_2, USER_P0, () -> { |
| 2437 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 2438 | list("s3"), HANDLE_USER_0); |
| 2439 | |
| 2440 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
| 2441 | list("s3"), HANDLE_USER_0); |
| 2442 | }); |
| 2443 | |
| 2444 | runWithCaller(LAUNCHER_2, USER_10, () -> { |
| 2445 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 2446 | list("s1", "s2", "s3"), HANDLE_USER_10); |
| 2447 | }); |
| 2448 | |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 2449 | // First, make sure managed profile can't see other profiles. |
| 2450 | runWithCaller(LAUNCHER_1, USER_P1, () -> { |
| 2451 | |
| 2452 | final ShortcutQuery q = new ShortcutQuery().setQueryFlags( |
| 2453 | ShortcutQuery.FLAG_MATCH_DYNAMIC | ShortcutQuery.FLAG_MATCH_PINNED |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2454 | | ShortcutQuery.FLAG_MATCH_MANIFEST); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 2455 | |
| 2456 | // No shortcuts are visible. |
| 2457 | assertWith(mLauncherApps.getShortcuts(q, HANDLE_USER_0)).isEmpty(); |
| 2458 | |
| 2459 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s1"), HANDLE_USER_0); |
| 2460 | |
| 2461 | // Should have no effects. |
| 2462 | assertWith(mLauncherApps.getShortcuts(q, HANDLE_USER_0)).isEmpty(); |
| 2463 | |
| 2464 | assertShortcutNotLaunched(CALLING_PACKAGE_1, "s1", USER_0); |
| 2465 | }); |
| 2466 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2467 | // Cross profile pinning. |
| 2468 | final int PIN_AND_DYNAMIC = ShortcutQuery.FLAG_GET_PINNED | ShortcutQuery.FLAG_GET_DYNAMIC; |
| 2469 | |
| 2470 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2471 | assertShortcutIds(assertAllPinned( |
| 2472 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2473 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2474 | "s1"); |
| 2475 | assertShortcutIds(assertAllDynamic( |
| 2476 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2477 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2478 | "s1", "s2", "s3"); |
| 2479 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2480 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2481 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2482 | "s1", "s2", "s3"); |
| 2483 | |
| 2484 | assertShortcutIds(assertAllPinned( |
| 2485 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2486 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2487 | "s1", "s2", "s3"); |
| 2488 | assertShortcutIds(assertAllDynamic( |
| 2489 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2490 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2491 | "s1", "s2", "s3"); |
| 2492 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2493 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2494 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2495 | "s1", "s2", "s3"); |
| 2496 | |
| 2497 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
| 2498 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0); |
| 2499 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0); |
| 2500 | |
| 2501 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
| 2502 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s2", USER_0); |
| 2503 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2504 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2505 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2506 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2507 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2508 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2509 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2510 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2511 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2512 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2513 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2514 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2515 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2516 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2517 | }); |
| 2518 | runWithCaller(LAUNCHER_1, USER_P0, () -> { |
| 2519 | assertShortcutIds(assertAllPinned( |
| 2520 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2521 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2522 | "s2"); |
| 2523 | assertShortcutIds(assertAllDynamic( |
| 2524 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2525 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2526 | "s1", "s2", "s3"); |
| 2527 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2528 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2529 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2530 | "s1", "s2", "s3"); |
| 2531 | |
| 2532 | assertShortcutIds(assertAllPinned( |
| 2533 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2534 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2535 | "s2", "s3"); |
| 2536 | assertShortcutIds(assertAllDynamic( |
| 2537 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2538 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2539 | "s1", "s2", "s3"); |
| 2540 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2541 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2542 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2543 | "s1", "s2", "s3"); |
| 2544 | |
| 2545 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
| 2546 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0); |
| 2547 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0); |
| 2548 | |
| 2549 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
| 2550 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s2", USER_0); |
| 2551 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2552 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2553 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2554 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2555 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2556 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2557 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2558 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2559 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2560 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2561 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2562 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2563 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2564 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2565 | }); |
| 2566 | runWithCaller(LAUNCHER_2, USER_P0, () -> { |
| 2567 | assertShortcutIds(assertAllPinned( |
| 2568 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2569 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2570 | "s3"); |
| 2571 | assertShortcutIds(assertAllDynamic( |
| 2572 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2573 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2574 | "s1", "s2", "s3"); |
| 2575 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2576 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2577 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2578 | "s1", "s2", "s3"); |
| 2579 | |
| 2580 | assertShortcutIds(assertAllPinned( |
| 2581 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2582 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2583 | "s3"); |
| 2584 | assertShortcutIds(assertAllDynamic( |
| 2585 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2586 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2587 | "s1", "s2", "s3"); |
| 2588 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2589 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2590 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2591 | "s1", "s2", "s3"); |
| 2592 | |
| 2593 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
| 2594 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0); |
| 2595 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0); |
| 2596 | |
| 2597 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
| 2598 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s2", USER_0); |
| 2599 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2600 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2601 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2602 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2603 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2604 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2605 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2606 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2607 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2608 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2609 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2610 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2611 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2612 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2613 | }); |
| 2614 | runWithCaller(LAUNCHER_2, USER_10, () -> { |
| 2615 | assertShortcutIds(assertAllPinned( |
| 2616 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2617 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_10)), |
| 2618 | "s1", "s2", "s3"); |
| 2619 | assertShortcutIds(assertAllDynamic( |
| 2620 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2621 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_10)), |
| 2622 | "s1", "s2", "s3", "s4", "s5", "s6"); |
| 2623 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2624 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2625 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_10)), |
| 2626 | "s1", "s2", "s3", "s4", "s5", "s6"); |
| 2627 | }); |
| 2628 | |
| 2629 | // Remove some dynamic shortcuts. |
| 2630 | |
| 2631 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2632 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2633 | makeShortcut("s1")))); |
| 2634 | }); |
| 2635 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 2636 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2637 | makeShortcut("s1")))); |
| 2638 | }); |
| 2639 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 2640 | assertTrue(mManager.setDynamicShortcuts(list( |
| 2641 | makeShortcut("s1")))); |
| 2642 | }); |
| 2643 | |
| 2644 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2645 | assertShortcutIds(assertAllPinned( |
| 2646 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2647 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2648 | "s1"); |
| 2649 | assertShortcutIds(assertAllDynamic( |
| 2650 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2651 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2652 | "s1"); |
| 2653 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2654 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2655 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2656 | "s1"); |
| 2657 | |
| 2658 | assertShortcutIds(assertAllPinned( |
| 2659 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2660 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2661 | "s1", "s2", "s3"); |
| 2662 | assertShortcutIds(assertAllDynamic( |
| 2663 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2664 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2665 | "s1"); |
| 2666 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2667 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2668 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2669 | "s1", "s2", "s3"); |
| 2670 | |
| 2671 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2672 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2673 | ActivityNotFoundException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2674 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2675 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2676 | |
| 2677 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
| 2678 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s2", USER_0); |
| 2679 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2680 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2681 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2682 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2683 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2684 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2685 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2686 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2687 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2688 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2689 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2690 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2691 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2692 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2693 | }); |
| 2694 | runWithCaller(LAUNCHER_1, USER_P0, () -> { |
| 2695 | assertShortcutIds(assertAllPinned( |
| 2696 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2697 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2698 | "s2"); |
| 2699 | assertShortcutIds(assertAllDynamic( |
| 2700 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2701 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2702 | "s1"); |
| 2703 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2704 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2705 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2706 | "s1", "s2"); |
| 2707 | |
| 2708 | assertShortcutIds(assertAllPinned( |
| 2709 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2710 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2711 | "s2", "s3"); |
| 2712 | assertShortcutIds(assertAllDynamic( |
| 2713 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2714 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2715 | "s1"); |
| 2716 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2717 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2718 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2719 | "s1", "s2", "s3"); |
| 2720 | |
| 2721 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
| 2722 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2723 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2724 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2725 | |
| 2726 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
| 2727 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s2", USER_0); |
| 2728 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2729 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2730 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2731 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2732 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2733 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2734 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2735 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2736 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2737 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2738 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2739 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2740 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2741 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2742 | }); |
| 2743 | runWithCaller(LAUNCHER_2, USER_P0, () -> { |
| 2744 | assertShortcutIds(assertAllPinned( |
| 2745 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2746 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2747 | "s3"); |
| 2748 | assertShortcutIds(assertAllDynamic( |
| 2749 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2750 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2751 | "s1"); |
| 2752 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2753 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2754 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2755 | "s1", "s3"); |
| 2756 | |
| 2757 | assertShortcutIds(assertAllPinned( |
| 2758 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2759 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2760 | "s3"); |
| 2761 | assertShortcutIds(assertAllDynamic( |
| 2762 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2763 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2764 | "s1"); |
| 2765 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2766 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2767 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2768 | "s1", "s3"); |
| 2769 | |
| 2770 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2771 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2772 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2773 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0); |
| 2774 | |
| 2775 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2776 | assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2777 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2778 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2779 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2780 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2781 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2782 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2783 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2784 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2785 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2786 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2787 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2788 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2789 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2790 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2791 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2792 | }); |
| 2793 | runWithCaller(LAUNCHER_2, USER_10, () -> { |
| 2794 | assertShortcutIds(assertAllPinned( |
| 2795 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2796 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_10)), |
| 2797 | "s1", "s2", "s3"); |
| 2798 | assertShortcutIds(assertAllDynamic( |
| 2799 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2800 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_10)), |
| 2801 | "s1"); |
| 2802 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2803 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2804 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_10)), |
| 2805 | "s1", "s2", "s3"); |
| 2806 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2807 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2808 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2809 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2810 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2811 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2812 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2813 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2814 | assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s1", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2815 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2816 | assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2817 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2818 | assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s3", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2819 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2820 | |
| 2821 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_10); |
| 2822 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_10); |
| 2823 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_10); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2824 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2825 | ActivityNotFoundException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2826 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2827 | ActivityNotFoundException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2828 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2829 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2830 | }); |
| 2831 | |
| 2832 | // Save & load and make sure we still have the same information. |
| 2833 | mService.saveDirtyInfo(); |
| 2834 | initService(); |
| 2835 | mService.handleUnlockUser(USER_0); |
| 2836 | |
| 2837 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 2838 | assertShortcutIds(assertAllPinned( |
| 2839 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2840 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2841 | "s1"); |
| 2842 | assertShortcutIds(assertAllDynamic( |
| 2843 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2844 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2845 | "s1"); |
| 2846 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2847 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2848 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2849 | "s1"); |
| 2850 | |
| 2851 | assertShortcutIds(assertAllPinned( |
| 2852 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2853 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2854 | "s1", "s2", "s3"); |
| 2855 | assertShortcutIds(assertAllDynamic( |
| 2856 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2857 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2858 | "s1"); |
| 2859 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2860 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2861 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2862 | "s1", "s2", "s3"); |
| 2863 | |
| 2864 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2865 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2866 | ActivityNotFoundException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2867 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2868 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2869 | |
| 2870 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
| 2871 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s2", USER_0); |
| 2872 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2873 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2874 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2875 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2876 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2877 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2878 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2879 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2880 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2881 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2882 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2883 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2884 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2885 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2886 | }); |
| 2887 | runWithCaller(LAUNCHER_1, USER_P0, () -> { |
| 2888 | assertShortcutIds(assertAllPinned( |
| 2889 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2890 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2891 | "s2"); |
| 2892 | assertShortcutIds(assertAllDynamic( |
| 2893 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2894 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2895 | "s1"); |
| 2896 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2897 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2898 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2899 | "s1", "s2"); |
| 2900 | |
| 2901 | assertShortcutIds(assertAllPinned( |
| 2902 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2903 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2904 | "s2", "s3"); |
| 2905 | assertShortcutIds(assertAllDynamic( |
| 2906 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2907 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2908 | "s1"); |
| 2909 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2910 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2911 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2912 | "s1", "s2", "s3"); |
| 2913 | |
| 2914 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
| 2915 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2916 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2917 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2918 | |
| 2919 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
| 2920 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s2", USER_0); |
| 2921 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2922 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2923 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2924 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2925 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2926 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2927 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2928 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2929 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2930 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2931 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2932 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2933 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2934 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2935 | }); |
| 2936 | runWithCaller(LAUNCHER_2, USER_P0, () -> { |
| 2937 | assertShortcutIds(assertAllPinned( |
| 2938 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2939 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2940 | "s3"); |
| 2941 | assertShortcutIds(assertAllDynamic( |
| 2942 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2943 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2944 | "s1"); |
| 2945 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2946 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1, |
| 2947 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2948 | "s1", "s3"); |
| 2949 | |
| 2950 | assertShortcutIds(assertAllPinned( |
| 2951 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2952 | /* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), HANDLE_USER_0)), |
| 2953 | "s3"); |
| 2954 | assertShortcutIds(assertAllDynamic( |
| 2955 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2956 | /* activity =*/ null, ShortcutQuery.FLAG_GET_DYNAMIC), HANDLE_USER_0)), |
| 2957 | "s1"); |
| 2958 | assertShortcutIds(assertAllDynamicOrPinned( |
| 2959 | mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2, |
| 2960 | /* activity =*/ null, PIN_AND_DYNAMIC), HANDLE_USER_0)), |
| 2961 | "s1", "s3"); |
| 2962 | |
| 2963 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s1", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2964 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2965 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2966 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0); |
| 2967 | |
| 2968 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s1", USER_0); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2969 | assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s2", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2970 | ActivityNotFoundException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2971 | assertShortcutLaunchable(CALLING_PACKAGE_2, "s3", USER_0); |
| 2972 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2973 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2974 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2975 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2976 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2977 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s3", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2978 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2979 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s4", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2980 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2981 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s5", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2982 | SecurityException.class); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 2983 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s6", USER_10, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2984 | SecurityException.class); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 2985 | }); |
| 2986 | } |
| 2987 | |
| 2988 | public void testStartShortcut() { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 2989 | // Create some shortcuts. |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 2990 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 2991 | final ShortcutInfo s1_1 = makeShortcut( |
| 2992 | "s1", |
| 2993 | "Title 1", |
| 2994 | makeComponent(ShortcutActivity.class), |
Makoto Onuki | 7e5c3e8 | 2016-07-22 11:57:05 -0700 | [diff] [blame] | 2995 | /* icon =*/ null, |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2996 | new Intent[]{makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, |
Makoto Onuki | 7e5c3e8 | 2016-07-22 11:57:05 -0700 | [diff] [blame] | 2997 | "key1", "val1", "nest", makeBundle("key", 123)) |
| 2998 | .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK), |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 2999 | new Intent("act2").setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)}, |
Makoto Onuki | 7e5c3e8 | 2016-07-22 11:57:05 -0700 | [diff] [blame] | 3000 | /* rank */ 10); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3001 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3002 | final ShortcutInfo s1_2 = makeShortcut( |
| 3003 | "s2", |
| 3004 | "Title 2", |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3005 | /* activity */ null, |
| 3006 | /* icon =*/ null, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3007 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3008 | /* rank */ 12); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3009 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3010 | final ShortcutInfo s1_3 = makeShortcut("s3"); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3011 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3012 | assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3))); |
| 3013 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3014 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3015 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 3016 | final ShortcutInfo s2_1 = makeShortcut( |
| 3017 | "s1", |
| 3018 | "ABC", |
| 3019 | makeComponent(ShortcutActivity.class), |
| 3020 | /* icon =*/ null, |
| 3021 | makeIntent(Intent.ACTION_ANSWER, ShortcutActivity.class, |
| 3022 | "key1", "val1", "nest", makeBundle("key", 123)), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3023 | /* weight */ 10); |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3024 | assertTrue(mManager.setDynamicShortcuts(list(s2_1))); |
| 3025 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3026 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3027 | // Pin some. |
| 3028 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 3029 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 3030 | list("s1", "s2"), getCallingUser()); |
| 3031 | |
| 3032 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
| 3033 | list("s1"), getCallingUser()); |
| 3034 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3035 | |
| 3036 | // Just to make it complicated, delete some. |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3037 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3038 | mManager.removeDynamicShortcuts(list("s2")); |
| 3039 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3040 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3041 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | 7e5c3e8 | 2016-07-22 11:57:05 -0700 | [diff] [blame] | 3042 | final Intent[] intents = launchShortcutAndGetIntents(CALLING_PACKAGE_1, "s1", USER_0); |
| 3043 | assertEquals(ShortcutActivity2.class.getName(), |
| 3044 | intents[0].getComponent().getClassName()); |
| 3045 | assertEquals(Intent.ACTION_ASSIST, |
| 3046 | intents[0].getAction()); |
| 3047 | assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK, |
| 3048 | intents[0].getFlags()); |
| 3049 | |
| 3050 | assertEquals("act2", |
| 3051 | intents[1].getAction()); |
| 3052 | assertEquals(Intent.FLAG_ACTIVITY_NO_ANIMATION, |
| 3053 | intents[1].getFlags()); |
| 3054 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3055 | assertEquals( |
| 3056 | ShortcutActivity3.class.getName(), |
| 3057 | launchShortcutAndGetIntent(CALLING_PACKAGE_1, "s2", USER_0) |
| 3058 | .getComponent().getClassName()); |
| 3059 | assertEquals( |
| 3060 | ShortcutActivity.class.getName(), |
| 3061 | launchShortcutAndGetIntent(CALLING_PACKAGE_2, "s1", USER_0) |
| 3062 | .getComponent().getClassName()); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3063 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3064 | assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3065 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 3066 | assertShortcutNotLaunched("no-such-package", "s2", USER_0); |
| 3067 | assertShortcutNotLaunched(CALLING_PACKAGE_1, "xxxx", USER_0); |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3068 | }); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3069 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3070 | // LAUNCHER_1 is no longer the default launcher |
| 3071 | setDefaultLauncherChecker((pkg, userId) -> false); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3072 | |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3073 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 3074 | // Not the default launcher, but pinned shortcuts are still lauchable. |
Makoto Onuki | 7e5c3e8 | 2016-07-22 11:57:05 -0700 | [diff] [blame] | 3075 | final Intent[] intents = launchShortcutAndGetIntents(CALLING_PACKAGE_1, "s1", USER_0); |
| 3076 | assertEquals(ShortcutActivity2.class.getName(), |
| 3077 | intents[0].getComponent().getClassName()); |
| 3078 | assertEquals(Intent.ACTION_ASSIST, |
| 3079 | intents[0].getAction()); |
| 3080 | assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK, |
| 3081 | intents[0].getFlags()); |
| 3082 | |
| 3083 | assertEquals("act2", |
| 3084 | intents[1].getAction()); |
| 3085 | assertEquals(Intent.FLAG_ACTIVITY_NO_ANIMATION, |
| 3086 | intents[1].getFlags()); |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3087 | assertEquals( |
| 3088 | ShortcutActivity3.class.getName(), |
| 3089 | launchShortcutAndGetIntent(CALLING_PACKAGE_1, "s2", USER_0) |
| 3090 | .getComponent().getClassName()); |
| 3091 | assertEquals( |
| 3092 | ShortcutActivity.class.getName(), |
| 3093 | launchShortcutAndGetIntent(CALLING_PACKAGE_2, "s1", USER_0) |
| 3094 | .getComponent().getClassName()); |
| 3095 | |
| 3096 | // Not pinned, so not lauchable. |
| 3097 | }); |
| 3098 | |
| 3099 | // Test inner errors. |
| 3100 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 3101 | // Not launchable. |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 3102 | doReturn(ActivityManager.START_CLASS_NOT_FOUND) |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 3103 | .when(mMockActivityTaskManagerInternal).startActivitiesAsPackage( |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 3104 | anyStringOrNull(), anyInt(), |
| 3105 | anyOrNull(Intent[].class), anyOrNull(Bundle.class)); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 3106 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3107 | ActivityNotFoundException.class); |
| 3108 | |
| 3109 | // Still not launchable. |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 3110 | doReturn(ActivityManager.START_CLASS_NOT_FOUND) |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 3111 | .when(mMockActivityTaskManagerInternal) |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 3112 | .startActivitiesAsPackage( |
Makoto Onuki | d0010c5 | 2017-03-30 14:17:35 -0700 | [diff] [blame] | 3113 | anyStringOrNull(), anyInt(), |
| 3114 | anyOrNull(Intent[].class), anyOrNull(Bundle.class)); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 3115 | assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0, |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 3116 | ActivityNotFoundException.class); |
| 3117 | }); |
| 3118 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3119 | |
| 3120 | // TODO Check extra, etc |
| 3121 | } |
| 3122 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3123 | public void testLauncherCallback() throws Throwable { |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3124 | // Disable throttling for this test. |
| 3125 | mService.updateConfigurationLocked( |
| 3126 | ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL + "=99999999," |
| 3127 | + ConfigConstants.KEY_MAX_SHORTCUTS + "=99999999" |
| 3128 | ); |
| 3129 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3130 | setCaller(LAUNCHER_1, USER_0); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3131 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3132 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3133 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3134 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3135 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3136 | }); |
| 3137 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3138 | .haveIds("s1", "s2", "s3") |
| 3139 | .areAllWithKeyFieldsOnly() |
| 3140 | .areAllDynamic(); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3141 | |
| 3142 | // From different package. |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3143 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3144 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 3145 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3146 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3147 | }); |
| 3148 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_2, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3149 | .haveIds("s1", "s2", "s3") |
| 3150 | .areAllWithKeyFieldsOnly() |
| 3151 | .areAllDynamic(); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3152 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 3153 | mRunningUsers.put(USER_10, true); |
| 3154 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3155 | // Different user, callback shouldn't be called. |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3156 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3157 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 3158 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3159 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3160 | }); |
| 3161 | }).assertNoCallbackCalled(); |
| 3162 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3163 | |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3164 | // Test for addDynamicShortcuts. |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3165 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3166 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3167 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("s4")))); |
| 3168 | }); |
| 3169 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3170 | .haveIds("s1", "s2", "s3", "s4") |
| 3171 | .areAllWithKeyFieldsOnly() |
| 3172 | .areAllDynamic(); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3173 | |
| 3174 | // Test for remove |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3175 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3176 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3177 | mManager.removeDynamicShortcuts(list("s1")); |
| 3178 | }); |
| 3179 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3180 | .haveIds("s2", "s3", "s4") |
| 3181 | .areAllWithKeyFieldsOnly() |
| 3182 | .areAllDynamic(); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3183 | |
| 3184 | // Test for update |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3185 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3186 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3187 | assertTrue(mManager.updateShortcuts(list( |
| 3188 | makeShortcut("s1"), makeShortcut("s2")))); |
| 3189 | }); |
| 3190 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
| 3191 | // All remaining shortcuts will be passed regardless of what's been updated. |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3192 | .haveIds("s2", "s3", "s4") |
| 3193 | .areAllWithKeyFieldsOnly() |
| 3194 | .areAllDynamic(); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3195 | |
| 3196 | // Test for deleteAll |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3197 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3198 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3199 | mManager.removeAllDynamicShortcuts(); |
| 3200 | }); |
| 3201 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3202 | .isEmpty(); |
| 3203 | |
| 3204 | // Update package1 with manifest shortcuts |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3205 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3206 | addManifestShortcutResource( |
| 3207 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 3208 | R.xml.shortcut_2); |
| 3209 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 3210 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3211 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 3212 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3213 | .areAllManifest() |
| 3214 | .areAllWithKeyFieldsOnly() |
| 3215 | .haveIds("ms1", "ms2"); |
| 3216 | |
| 3217 | // Make sure pinned shortcuts are passed too. |
| 3218 | // 1. Add dynamic shortcuts. |
| 3219 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
| 3220 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3221 | makeShortcut("s1"), makeShortcut("s2")))); |
| 3222 | }); |
| 3223 | |
| 3224 | // 2. Pin some. |
| 3225 | runWithCaller(LAUNCHER_1, UserHandle.USER_SYSTEM, () -> { |
| 3226 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms2", "s2"), HANDLE_USER_0); |
| 3227 | }); |
| 3228 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
| 3229 | assertWith(getCallerShortcuts()) |
| 3230 | .haveIds("ms1", "ms2", "s1", "s2") |
| 3231 | .areAllEnabled() |
| 3232 | |
| 3233 | .selectByIds("ms1", "ms2") |
| 3234 | .areAllManifest() |
| 3235 | |
| 3236 | .revertToOriginalList() |
| 3237 | .selectByIds("s1", "s2") |
| 3238 | .areAllDynamic() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 3239 | ; |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3240 | }); |
| 3241 | |
| 3242 | // 3 Update the app with no manifest shortcuts. (Pinned one will survive.) |
| 3243 | addManifestShortcutResource( |
| 3244 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 3245 | R.xml.shortcut_0); |
| 3246 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 3247 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3248 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 3249 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3250 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3251 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3252 | mManager.removeDynamicShortcuts(list("s2")); |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3253 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3254 | assertWith(getCallerShortcuts()) |
| 3255 | .haveIds("ms2", "s1", "s2") |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3256 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3257 | .selectByIds("ms2") |
| 3258 | .areAllNotManifest() |
| 3259 | .areAllPinned() |
| 3260 | .areAllImmutable() |
| 3261 | .areAllDisabled() |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3262 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3263 | .revertToOriginalList() |
| 3264 | .selectByIds("s1") |
| 3265 | .areAllDynamic() |
| 3266 | .areAllNotPinned() |
| 3267 | .areAllEnabled() |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3268 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3269 | .revertToOriginalList() |
| 3270 | .selectByIds("s2") |
| 3271 | .areAllNotDynamic() |
| 3272 | .areAllPinned() |
| 3273 | .areAllEnabled() |
| 3274 | ; |
| 3275 | }); |
| 3276 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3277 | .haveIds("ms2", "s1", "s2") |
| 3278 | .areAllWithKeyFieldsOnly(); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3279 | |
| 3280 | // Remove CALLING_PACKAGE_2 |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3281 | assertForLauncherCallback(mLauncherApps, () -> { |
| 3282 | uninstallPackage(USER_0, CALLING_PACKAGE_2); |
| 3283 | mService.cleanUpPackageLocked(CALLING_PACKAGE_2, USER_0, USER_0, |
| 3284 | /* appStillExists = */ false); |
| 3285 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_2, HANDLE_USER_0) |
Makoto Onuki | 4d6b87f | 2016-06-17 13:47:40 -0700 | [diff] [blame] | 3286 | .isEmpty(); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3289 | public void testLauncherCallback_crossProfile() throws Throwable { |
| 3290 | prepareCrossProfileDataSet(); |
| 3291 | |
| 3292 | final Handler h = new Handler(Looper.getMainLooper()); |
| 3293 | |
| 3294 | final LauncherApps.Callback c0_1 = mock(LauncherApps.Callback.class); |
| 3295 | final LauncherApps.Callback c0_2 = mock(LauncherApps.Callback.class); |
| 3296 | final LauncherApps.Callback c0_3 = mock(LauncherApps.Callback.class); |
| 3297 | final LauncherApps.Callback c0_4 = mock(LauncherApps.Callback.class); |
| 3298 | |
| 3299 | final LauncherApps.Callback cP0_1 = mock(LauncherApps.Callback.class); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 3300 | final LauncherApps.Callback cP1_1 = mock(LauncherApps.Callback.class); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3301 | final LauncherApps.Callback c10_1 = mock(LauncherApps.Callback.class); |
| 3302 | final LauncherApps.Callback c10_2 = mock(LauncherApps.Callback.class); |
| 3303 | final LauncherApps.Callback c11_1 = mock(LauncherApps.Callback.class); |
| 3304 | |
| 3305 | final List<LauncherApps.Callback> all = |
| 3306 | list(c0_1, c0_2, c0_3, c0_4, cP0_1, c10_1, c11_1); |
| 3307 | |
| 3308 | setDefaultLauncherChecker((pkg, userId) -> { |
| 3309 | switch (userId) { |
| 3310 | case USER_0: |
| 3311 | return LAUNCHER_2.equals(pkg); |
| 3312 | case USER_P0: |
| 3313 | return LAUNCHER_1.equals(pkg); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 3314 | case USER_P1: |
| 3315 | return LAUNCHER_1.equals(pkg); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3316 | case USER_10: |
| 3317 | return LAUNCHER_1.equals(pkg); |
| 3318 | case USER_11: |
| 3319 | return LAUNCHER_1.equals(pkg); |
| 3320 | default: |
| 3321 | return false; |
| 3322 | } |
| 3323 | }); |
| 3324 | |
| 3325 | runWithCaller(LAUNCHER_1, USER_0, () -> mLauncherApps.registerCallback(c0_1, h)); |
| 3326 | runWithCaller(LAUNCHER_2, USER_0, () -> mLauncherApps.registerCallback(c0_2, h)); |
| 3327 | runWithCaller(LAUNCHER_3, USER_0, () -> mLauncherApps.registerCallback(c0_3, h)); |
| 3328 | runWithCaller(LAUNCHER_4, USER_0, () -> mLauncherApps.registerCallback(c0_4, h)); |
| 3329 | runWithCaller(LAUNCHER_1, USER_P0, () -> mLauncherApps.registerCallback(cP0_1, h)); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 3330 | runWithCaller(LAUNCHER_1, USER_P1, () -> mLauncherApps.registerCallback(cP1_1, h)); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3331 | runWithCaller(LAUNCHER_1, USER_10, () -> mLauncherApps.registerCallback(c10_1, h)); |
| 3332 | runWithCaller(LAUNCHER_2, USER_10, () -> mLauncherApps.registerCallback(c10_2, h)); |
| 3333 | runWithCaller(LAUNCHER_1, USER_11, () -> mLauncherApps.registerCallback(c11_1, h)); |
| 3334 | |
| 3335 | // User 0. |
| 3336 | |
| 3337 | resetAll(all); |
| 3338 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3339 | mManager.removeDynamicShortcuts(list()); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3340 | }); |
| 3341 | waitOnMainThread(); |
| 3342 | |
| 3343 | assertCallbackNotReceived(c0_1); |
| 3344 | assertCallbackNotReceived(c0_3); |
| 3345 | assertCallbackNotReceived(c0_4); |
| 3346 | assertCallbackNotReceived(c10_1); |
| 3347 | assertCallbackNotReceived(c10_2); |
| 3348 | assertCallbackNotReceived(c11_1); |
| 3349 | assertCallbackReceived(c0_2, HANDLE_USER_0, CALLING_PACKAGE_1, "s1", "s2", "s3"); |
| 3350 | assertCallbackReceived(cP0_1, HANDLE_USER_0, CALLING_PACKAGE_1, "s1", "s2", "s3", "s4"); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 3351 | assertCallbackNotReceived(cP1_1); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3352 | |
| 3353 | // User 0, different package. |
| 3354 | |
| 3355 | resetAll(all); |
| 3356 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3357 | mManager.removeDynamicShortcuts(list()); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3358 | }); |
| 3359 | waitOnMainThread(); |
| 3360 | |
| 3361 | assertCallbackNotReceived(c0_1); |
| 3362 | assertCallbackNotReceived(c0_3); |
| 3363 | assertCallbackNotReceived(c0_4); |
| 3364 | assertCallbackNotReceived(c10_1); |
| 3365 | assertCallbackNotReceived(c10_2); |
| 3366 | assertCallbackNotReceived(c11_1); |
| 3367 | assertCallbackReceived(c0_2, HANDLE_USER_0, CALLING_PACKAGE_3, "s1", "s2", "s3", "s4"); |
| 3368 | assertCallbackReceived(cP0_1, HANDLE_USER_0, CALLING_PACKAGE_3, |
| 3369 | "s1", "s2", "s3", "s4", "s5", "s6"); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 3370 | assertCallbackNotReceived(cP1_1); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3371 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 3372 | // Work profile. |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3373 | resetAll(all); |
| 3374 | runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3375 | mManager.removeDynamicShortcuts(list()); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3376 | }); |
| 3377 | waitOnMainThread(); |
| 3378 | |
| 3379 | assertCallbackNotReceived(c0_1); |
| 3380 | assertCallbackNotReceived(c0_3); |
| 3381 | assertCallbackNotReceived(c0_4); |
| 3382 | assertCallbackNotReceived(c10_1); |
| 3383 | assertCallbackNotReceived(c10_2); |
| 3384 | assertCallbackNotReceived(c11_1); |
| 3385 | assertCallbackReceived(c0_2, HANDLE_USER_P0, CALLING_PACKAGE_1, "s1", "s2", "s3", "s5"); |
| 3386 | assertCallbackReceived(cP0_1, HANDLE_USER_P0, CALLING_PACKAGE_1, "s1", "s2", "s3", "s4"); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 3387 | assertCallbackNotReceived(cP1_1); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3388 | |
| 3389 | // Normal secondary user. |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 3390 | mRunningUsers.put(USER_10, true); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3391 | |
| 3392 | resetAll(all); |
| 3393 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3394 | mManager.removeDynamicShortcuts(list()); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3395 | }); |
| 3396 | waitOnMainThread(); |
| 3397 | |
| 3398 | assertCallbackNotReceived(c0_1); |
| 3399 | assertCallbackNotReceived(c0_2); |
| 3400 | assertCallbackNotReceived(c0_3); |
| 3401 | assertCallbackNotReceived(c0_4); |
| 3402 | assertCallbackNotReceived(cP0_1); |
| 3403 | assertCallbackNotReceived(c10_2); |
| 3404 | assertCallbackNotReceived(c11_1); |
| 3405 | assertCallbackReceived(c10_1, HANDLE_USER_10, CALLING_PACKAGE_1, |
| 3406 | "x1", "x2", "x3", "x4", "x5"); |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 3407 | assertCallbackNotReceived(cP1_1); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3410 | // === Test for persisting === |
| 3411 | |
| 3412 | public void testSaveAndLoadUser_empty() { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3413 | assertTrue(mManager.setDynamicShortcuts(list())); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3414 | |
| 3415 | Log.i(TAG, "Saved state"); |
| 3416 | dumpsysOnLogcat(); |
| 3417 | dumpUserFile(0); |
| 3418 | |
| 3419 | // Restore. |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 3420 | mService.saveDirtyInfo(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3421 | initService(); |
| 3422 | |
| 3423 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 3424 | } |
| 3425 | |
| 3426 | /** |
| 3427 | * Try save and load, also stop/start the user. |
| 3428 | */ |
| 3429 | public void testSaveAndLoadUser() { |
| 3430 | // First, create some shortcuts and save. |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3431 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3432 | final Icon icon1 = Icon.createWithResource(getTestContext(), R.drawable.black_64x16); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3433 | final Icon icon2 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3434 | getTestContext().getResources(), R.drawable.icon2)); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3435 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3436 | final ShortcutInfo si1 = makeShortcut( |
| 3437 | "s1", |
| 3438 | "title1-1", |
| 3439 | makeComponent(ShortcutActivity.class), |
| 3440 | icon1, |
| 3441 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, |
| 3442 | "key1", "val1", "nest", makeBundle("key", 123)), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3443 | /* weight */ 10); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3444 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3445 | final ShortcutInfo si2 = makeShortcut( |
| 3446 | "s2", |
| 3447 | "title1-2", |
| 3448 | /* activity */ null, |
| 3449 | icon2, |
| 3450 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3451 | /* weight */ 12); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3452 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3453 | assertTrue(mManager.setDynamicShortcuts(list(si1, si2))); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3454 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3455 | assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime()); |
| 3456 | assertEquals(2, mManager.getRemainingCallCount()); |
| 3457 | }); |
| 3458 | runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> { |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3459 | final Icon icon1 = Icon.createWithResource(getTestContext(), R.drawable.black_16x64); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3460 | final Icon icon2 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3461 | getTestContext().getResources(), R.drawable.icon2)); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3462 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3463 | final ShortcutInfo si1 = makeShortcut( |
| 3464 | "s1", |
| 3465 | "title2-1", |
| 3466 | makeComponent(ShortcutActivity.class), |
| 3467 | icon1, |
| 3468 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3469 | "key1", "val1", "nest", makeBundle("key", 123)), |
| 3470 | /* weight */ 10); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3471 | |
| 3472 | final ShortcutInfo si2 = makeShortcut( |
| 3473 | "s2", |
| 3474 | "title2-2", |
| 3475 | /* activity */ null, |
| 3476 | icon2, |
| 3477 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3478 | /* weight */ 12); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3479 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3480 | assertTrue(mManager.setDynamicShortcuts(list(si1, si2))); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3481 | |
| 3482 | assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime()); |
| 3483 | assertEquals(2, mManager.getRemainingCallCount()); |
| 3484 | }); |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 3485 | |
| 3486 | mRunningUsers.put(USER_10, true); |
| 3487 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3488 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3489 | final Icon icon1 = Icon.createWithResource(getTestContext(), R.drawable.black_64x64); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3490 | final Icon icon2 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 3491 | getTestContext().getResources(), R.drawable.icon2)); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3492 | |
| 3493 | final ShortcutInfo si1 = makeShortcut( |
| 3494 | "s1", |
| 3495 | "title10-1-1", |
| 3496 | makeComponent(ShortcutActivity.class), |
| 3497 | icon1, |
| 3498 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, |
| 3499 | "key1", "val1", "nest", makeBundle("key", 123)), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3500 | /* weight */ 10); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3501 | |
| 3502 | final ShortcutInfo si2 = makeShortcut( |
| 3503 | "s2", |
| 3504 | "title10-1-2", |
| 3505 | /* activity */ null, |
| 3506 | icon2, |
| 3507 | makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 3508 | /* weight */ 12); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3509 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3510 | assertTrue(mManager.setDynamicShortcuts(list(si1, si2))); |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3511 | |
| 3512 | assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime()); |
| 3513 | assertEquals(2, mManager.getRemainingCallCount()); |
| 3514 | }); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3515 | |
Makoto Onuki | 1030520 | 2016-07-14 18:14:08 -0700 | [diff] [blame] | 3516 | mService.getShortcutsForTest().get(UserHandle.USER_SYSTEM).setLauncher( |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 3517 | new ComponentName("pkg1", "class")); |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 3518 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3519 | // Restore. |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 3520 | mService.saveDirtyInfo(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3521 | initService(); |
| 3522 | |
| 3523 | // Before the load, the map should be empty. |
| 3524 | assertEquals(0, mService.getShortcutsForTest().size()); |
| 3525 | |
| 3526 | // this will pre-load the per-user info. |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3527 | mService.handleUnlockUser(UserHandle.USER_SYSTEM); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3528 | |
| 3529 | // Now it's loaded. |
| 3530 | assertEquals(1, mService.getShortcutsForTest().size()); |
| 3531 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3532 | runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> { |
| 3533 | assertShortcutIds(assertAllDynamic(assertAllHaveIntents(assertAllHaveIcon( |
| 3534 | mManager.getDynamicShortcuts()))), "s1", "s2"); |
| 3535 | assertEquals(2, mManager.getRemainingCallCount()); |
| 3536 | |
| 3537 | assertEquals("title1-1", getCallerShortcut("s1").getTitle()); |
| 3538 | assertEquals("title1-2", getCallerShortcut("s2").getTitle()); |
| 3539 | }); |
| 3540 | runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> { |
| 3541 | assertShortcutIds(assertAllDynamic(assertAllHaveIntents(assertAllHaveIcon( |
| 3542 | mManager.getDynamicShortcuts()))), "s1", "s2"); |
| 3543 | assertEquals(2, mManager.getRemainingCallCount()); |
| 3544 | |
| 3545 | assertEquals("title2-1", getCallerShortcut("s1").getTitle()); |
| 3546 | assertEquals("title2-2", getCallerShortcut("s2").getTitle()); |
| 3547 | }); |
| 3548 | |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 3549 | assertEquals("pkg1", mService.getShortcutsForTest().get(UserHandle.USER_SYSTEM) |
Makoto Onuki | 1030520 | 2016-07-14 18:14:08 -0700 | [diff] [blame] | 3550 | .getLastKnownLauncher().getPackageName()); |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 3551 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3552 | // Start another user |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3553 | mService.handleUnlockUser(USER_10); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3554 | |
| 3555 | // Now the size is 2. |
| 3556 | assertEquals(2, mService.getShortcutsForTest().size()); |
| 3557 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3558 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 3559 | assertShortcutIds(assertAllDynamic(assertAllHaveIntents(assertAllHaveIcon( |
| 3560 | mManager.getDynamicShortcuts()))), "s1", "s2"); |
| 3561 | assertEquals(2, mManager.getRemainingCallCount()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3562 | |
Makoto Onuki | 41066a6 | 2016-03-09 16:18:44 -0800 | [diff] [blame] | 3563 | assertEquals("title10-1-1", getCallerShortcut("s1").getTitle()); |
| 3564 | assertEquals("title10-1-2", getCallerShortcut("s2").getTitle()); |
| 3565 | }); |
Makoto Onuki | 1030520 | 2016-07-14 18:14:08 -0700 | [diff] [blame] | 3566 | assertNull(mService.getShortcutsForTest().get(USER_10).getLastKnownLauncher()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3567 | |
| 3568 | // Try stopping the user |
Makoto Onuki | 01ce92b | 2017-04-28 12:24:16 -0700 | [diff] [blame] | 3569 | mService.handleStopUser(USER_10); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 3570 | |
| 3571 | // Now it's unloaded. |
| 3572 | assertEquals(1, mService.getShortcutsForTest().size()); |
| 3573 | |
| 3574 | // TODO Check all other fields |
| 3575 | } |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 3576 | |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3577 | public void testCleanupPackage() { |
| 3578 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3579 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3580 | makeShortcut("s0_1")))); |
| 3581 | }); |
| 3582 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3583 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3584 | makeShortcut("s0_2")))); |
| 3585 | }); |
| 3586 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3587 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s0_1"), |
| 3588 | HANDLE_USER_0); |
| 3589 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s0_2"), |
| 3590 | HANDLE_USER_0); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3591 | }); |
| 3592 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3593 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s0_1"), |
| 3594 | HANDLE_USER_0); |
| 3595 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s0_2"), |
| 3596 | HANDLE_USER_0); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3597 | }); |
| 3598 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 3599 | mRunningUsers.put(USER_10, true); |
| 3600 | |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3601 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3602 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3603 | makeShortcut("s10_1")))); |
| 3604 | }); |
| 3605 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3606 | assertTrue(mManager.setDynamicShortcuts(list( |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3607 | makeShortcut("s10_2")))); |
| 3608 | }); |
| 3609 | runWithCaller(LAUNCHER_1, USER_10, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3610 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s10_1"), |
| 3611 | HANDLE_USER_10); |
| 3612 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s10_2"), |
| 3613 | HANDLE_USER_10); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3614 | }); |
| 3615 | runWithCaller(LAUNCHER_2, USER_10, () -> { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3616 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s10_1"), |
| 3617 | HANDLE_USER_10); |
| 3618 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s10_2"), |
| 3619 | HANDLE_USER_10); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3620 | }); |
| 3621 | |
| 3622 | // Remove all dynamic shortcuts; now all shortcuts are just pinned. |
| 3623 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3624 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3625 | }); |
| 3626 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3627 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3628 | }); |
| 3629 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3630 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3631 | }); |
| 3632 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
Makoto Onuki | b6d3523 | 2016-04-04 15:57:17 -0700 | [diff] [blame] | 3633 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3634 | }); |
| 3635 | |
| 3636 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 3637 | final SparseArray<ShortcutUser> users = mService.getShortcutsForTest(); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3638 | assertEquals(2, users.size()); |
| 3639 | assertEquals(USER_0, users.keyAt(0)); |
| 3640 | assertEquals(USER_10, users.keyAt(1)); |
| 3641 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 3642 | final ShortcutUser user0 = users.get(USER_0); |
| 3643 | final ShortcutUser user10 = users.get(USER_10); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3644 | |
| 3645 | |
| 3646 | // Check the registered packages. |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3647 | dumpsysOnLogcat(); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3648 | assertEquals(set(CALLING_PACKAGE_1, CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3649 | hashSet(user0.getAllPackagesForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3650 | assertEquals(set(CALLING_PACKAGE_1, CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3651 | hashSet(user10.getAllPackagesForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3652 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3653 | set(PackageWithUser.of(USER_0, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3654 | PackageWithUser.of(USER_0, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3655 | hashSet(user0.getAllLaunchersForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3656 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3657 | set(PackageWithUser.of(USER_10, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3658 | PackageWithUser.of(USER_10, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3659 | hashSet(user10.getAllLaunchersForTest().keySet())); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3660 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_0), |
| 3661 | "s0_1", "s0_2"); |
| 3662 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_0), |
| 3663 | "s0_1", "s0_2"); |
| 3664 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_10), |
| 3665 | "s10_1", "s10_2"); |
| 3666 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_10), |
| 3667 | "s10_1", "s10_2"); |
| 3668 | assertShortcutExists(CALLING_PACKAGE_1, "s0_1", USER_0); |
| 3669 | assertShortcutExists(CALLING_PACKAGE_2, "s0_2", USER_0); |
| 3670 | assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10); |
| 3671 | assertShortcutExists(CALLING_PACKAGE_2, "s10_2", USER_10); |
| 3672 | |
| 3673 | mService.saveDirtyInfo(); |
| 3674 | |
| 3675 | // Nonexistent package. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 3676 | uninstallPackage(USER_0, "abc"); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3677 | mService.cleanUpPackageLocked("abc", USER_0, USER_0, /* appStillExists = */ false); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3678 | |
| 3679 | // No changes. |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3680 | assertEquals(set(CALLING_PACKAGE_1, CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3681 | hashSet(user0.getAllPackagesForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3682 | assertEquals(set(CALLING_PACKAGE_1, CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3683 | hashSet(user10.getAllPackagesForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3684 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3685 | set(PackageWithUser.of(USER_0, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3686 | PackageWithUser.of(USER_0, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3687 | hashSet(user0.getAllLaunchersForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3688 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3689 | set(PackageWithUser.of(USER_10, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3690 | PackageWithUser.of(USER_10, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3691 | hashSet(user10.getAllLaunchersForTest().keySet())); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3692 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_0), |
| 3693 | "s0_1", "s0_2"); |
| 3694 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_0), |
| 3695 | "s0_1", "s0_2"); |
| 3696 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_10), |
| 3697 | "s10_1", "s10_2"); |
| 3698 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_10), |
| 3699 | "s10_1", "s10_2"); |
| 3700 | assertShortcutExists(CALLING_PACKAGE_1, "s0_1", USER_0); |
| 3701 | assertShortcutExists(CALLING_PACKAGE_2, "s0_2", USER_0); |
| 3702 | assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10); |
| 3703 | assertShortcutExists(CALLING_PACKAGE_2, "s10_2", USER_10); |
| 3704 | |
| 3705 | mService.saveDirtyInfo(); |
| 3706 | |
| 3707 | // Remove a package. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 3708 | uninstallPackage(USER_0, CALLING_PACKAGE_1); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3709 | mService.cleanUpPackageLocked(CALLING_PACKAGE_1, USER_0, USER_0, |
| 3710 | /* appStillExists = */ false); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3711 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3712 | assertEquals(set(CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3713 | hashSet(user0.getAllPackagesForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3714 | assertEquals(set(CALLING_PACKAGE_1, CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3715 | hashSet(user10.getAllPackagesForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3716 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3717 | set(PackageWithUser.of(USER_0, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3718 | PackageWithUser.of(USER_0, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3719 | hashSet(user0.getAllLaunchersForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3720 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3721 | set(PackageWithUser.of(USER_10, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3722 | PackageWithUser.of(USER_10, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3723 | hashSet(user10.getAllLaunchersForTest().keySet())); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3724 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_0), |
| 3725 | "s0_2"); |
| 3726 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_0), |
| 3727 | "s0_2"); |
| 3728 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_10), |
| 3729 | "s10_1", "s10_2"); |
| 3730 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_10), |
| 3731 | "s10_1", "s10_2"); |
| 3732 | assertShortcutNotExists(CALLING_PACKAGE_1, "s0_1", USER_0); |
| 3733 | assertShortcutExists(CALLING_PACKAGE_2, "s0_2", USER_0); |
| 3734 | assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10); |
| 3735 | assertShortcutExists(CALLING_PACKAGE_2, "s10_2", USER_10); |
| 3736 | |
| 3737 | mService.saveDirtyInfo(); |
| 3738 | |
| 3739 | // Remove a launcher. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 3740 | uninstallPackage(USER_10, LAUNCHER_1); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3741 | mService.cleanUpPackageLocked(LAUNCHER_1, USER_10, USER_10, /* appStillExists = */ false); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3742 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3743 | assertEquals(set(CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3744 | hashSet(user0.getAllPackagesForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3745 | assertEquals(set(CALLING_PACKAGE_1, CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3746 | hashSet(user10.getAllPackagesForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3747 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3748 | set(PackageWithUser.of(USER_0, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3749 | PackageWithUser.of(USER_0, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3750 | hashSet(user0.getAllLaunchersForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3751 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3752 | set(PackageWithUser.of(USER_10, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3753 | hashSet(user10.getAllLaunchersForTest().keySet())); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3754 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_0), |
| 3755 | "s0_2"); |
| 3756 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_0), |
| 3757 | "s0_2"); |
| 3758 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_10), |
| 3759 | "s10_1", "s10_2"); |
| 3760 | assertShortcutNotExists(CALLING_PACKAGE_1, "s0_1", USER_0); |
| 3761 | assertShortcutExists(CALLING_PACKAGE_2, "s0_2", USER_0); |
| 3762 | assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10); |
| 3763 | assertShortcutExists(CALLING_PACKAGE_2, "s10_2", USER_10); |
| 3764 | |
| 3765 | mService.saveDirtyInfo(); |
| 3766 | |
| 3767 | // Remove a package. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 3768 | uninstallPackage(USER_10, CALLING_PACKAGE_2); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3769 | mService.cleanUpPackageLocked(CALLING_PACKAGE_2, USER_10, USER_10, |
| 3770 | /* appStillExists = */ false); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3771 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3772 | assertEquals(set(CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3773 | hashSet(user0.getAllPackagesForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3774 | assertEquals(set(CALLING_PACKAGE_1), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3775 | hashSet(user10.getAllPackagesForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3776 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3777 | set(PackageWithUser.of(USER_0, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3778 | PackageWithUser.of(USER_0, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3779 | hashSet(user0.getAllLaunchersForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3780 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3781 | set(PackageWithUser.of(USER_10, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3782 | hashSet(user10.getAllLaunchersForTest().keySet())); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3783 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_0), |
| 3784 | "s0_2"); |
| 3785 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_0), |
| 3786 | "s0_2"); |
| 3787 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_10), |
| 3788 | "s10_1"); |
| 3789 | assertShortcutNotExists(CALLING_PACKAGE_1, "s0_1", USER_0); |
| 3790 | assertShortcutExists(CALLING_PACKAGE_2, "s0_2", USER_0); |
| 3791 | assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10); |
| 3792 | assertShortcutNotExists(CALLING_PACKAGE_2, "s10_2", USER_10); |
| 3793 | |
| 3794 | mService.saveDirtyInfo(); |
| 3795 | |
| 3796 | // Remove the other launcher from user 10 too. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 3797 | uninstallPackage(USER_10, LAUNCHER_2); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3798 | mService.cleanUpPackageLocked(LAUNCHER_2, USER_10, USER_10, |
| 3799 | /* appStillExists = */ false); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3800 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3801 | assertEquals(set(CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3802 | hashSet(user0.getAllPackagesForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3803 | assertEquals(set(CALLING_PACKAGE_1), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3804 | hashSet(user10.getAllPackagesForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3805 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3806 | set(PackageWithUser.of(USER_0, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3807 | PackageWithUser.of(USER_0, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3808 | hashSet(user0.getAllLaunchersForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3809 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3810 | set(), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3811 | hashSet(user10.getAllLaunchersForTest().keySet())); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3812 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_0), |
| 3813 | "s0_2"); |
| 3814 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_0), |
| 3815 | "s0_2"); |
| 3816 | |
| 3817 | // Note the pinned shortcuts on user-10 no longer referred, so they should both be removed. |
| 3818 | assertShortcutNotExists(CALLING_PACKAGE_1, "s0_1", USER_0); |
| 3819 | assertShortcutExists(CALLING_PACKAGE_2, "s0_2", USER_0); |
| 3820 | assertShortcutNotExists(CALLING_PACKAGE_1, "s10_1", USER_10); |
| 3821 | assertShortcutNotExists(CALLING_PACKAGE_2, "s10_2", USER_10); |
| 3822 | |
| 3823 | mService.saveDirtyInfo(); |
| 3824 | |
| 3825 | // More remove. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 3826 | uninstallPackage(USER_10, CALLING_PACKAGE_1); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3827 | mService.cleanUpPackageLocked(CALLING_PACKAGE_1, USER_10, USER_10, |
| 3828 | /* appStillExists = */ false); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3829 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3830 | assertEquals(set(CALLING_PACKAGE_2), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3831 | hashSet(user0.getAllPackagesForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3832 | assertEquals(set(), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3833 | hashSet(user10.getAllPackagesForTest().keySet())); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3834 | assertEquals( |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3835 | set(PackageWithUser.of(USER_0, LAUNCHER_1), |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3836 | PackageWithUser.of(USER_0, LAUNCHER_2)), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3837 | hashSet(user0.getAllLaunchersForTest().keySet())); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 3838 | assertEquals(set(), |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 3839 | hashSet(user10.getAllLaunchersForTest().keySet())); |
Makoto Onuki | cdc78f7 | 2016-03-21 15:47:52 -0700 | [diff] [blame] | 3840 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_1, USER_0), |
| 3841 | "s0_2"); |
| 3842 | assertShortcutIds(getLauncherPinnedShortcuts(LAUNCHER_2, USER_0), |
| 3843 | "s0_2"); |
| 3844 | |
| 3845 | // Note the pinned shortcuts on user-10 no longer referred, so they should both be removed. |
| 3846 | assertShortcutNotExists(CALLING_PACKAGE_1, "s0_1", USER_0); |
| 3847 | assertShortcutExists(CALLING_PACKAGE_2, "s0_2", USER_0); |
| 3848 | assertShortcutNotExists(CALLING_PACKAGE_1, "s10_1", USER_10); |
| 3849 | assertShortcutNotExists(CALLING_PACKAGE_2, "s10_2", USER_10); |
| 3850 | |
| 3851 | mService.saveDirtyInfo(); |
| 3852 | } |
| 3853 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3854 | public void testCleanupPackage_republishManifests() { |
| 3855 | addManifestShortcutResource( |
| 3856 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 3857 | R.xml.shortcut_2); |
| 3858 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 3859 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3860 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 3861 | |
| 3862 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3863 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3864 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3865 | }); |
| 3866 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 3867 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 3868 | list("s2", "s3", "ms1", "ms2"), HANDLE_USER_0); |
| 3869 | }); |
| 3870 | |
| 3871 | // Remove ms2 from manifest. |
| 3872 | addManifestShortcutResource( |
| 3873 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 3874 | R.xml.shortcut_1); |
| 3875 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 3876 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 3877 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 3878 | |
| 3879 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3880 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3881 | makeShortcut("s1"), makeShortcut("s2")))); |
| 3882 | |
| 3883 | // Make sure the shortcuts are in the intended state. |
| 3884 | assertWith(getCallerShortcuts()) |
| 3885 | .haveIds("ms1", "ms2", "s1", "s2", "s3") |
| 3886 | |
| 3887 | .selectByIds("ms1") |
| 3888 | .areAllManifest() |
| 3889 | .areAllPinned() |
| 3890 | |
| 3891 | .revertToOriginalList() |
| 3892 | .selectByIds("ms2") |
| 3893 | .areAllNotManifest() |
| 3894 | .areAllPinned() |
| 3895 | |
| 3896 | .revertToOriginalList() |
| 3897 | .selectByIds("s1") |
| 3898 | .areAllDynamic() |
| 3899 | .areAllNotPinned() |
| 3900 | |
| 3901 | .revertToOriginalList() |
| 3902 | .selectByIds("s2") |
| 3903 | .areAllDynamic() |
| 3904 | .areAllPinned() |
| 3905 | |
| 3906 | .revertToOriginalList() |
| 3907 | .selectByIds("s3") |
| 3908 | .areAllNotDynamic() |
| 3909 | .areAllPinned(); |
| 3910 | }); |
| 3911 | |
| 3912 | // Clean up + re-publish manifests. |
| 3913 | mService.cleanUpPackageLocked(CALLING_PACKAGE_1, USER_0, USER_0, |
| 3914 | /* appStillExists = */ true); |
| 3915 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3916 | assertWith(getCallerShortcuts()) |
| 3917 | .haveIds("ms1") |
| 3918 | .areAllManifest(); |
| 3919 | }); |
| 3920 | } |
| 3921 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3922 | public void testHandleGonePackage_crossProfile() { |
| 3923 | // Create some shortcuts. |
| 3924 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 3925 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3926 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3927 | }); |
| 3928 | runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> { |
| 3929 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3930 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3931 | }); |
| 3932 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 3933 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3934 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3935 | }); |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 3936 | |
| 3937 | mRunningUsers.put(USER_10, true); |
| 3938 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 3939 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 3940 | assertTrue(mManager.setDynamicShortcuts(list( |
| 3941 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 3942 | }); |
| 3943 | |
| 3944 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 3945 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 3946 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 3947 | |
| 3948 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 3949 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 3950 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 3951 | |
| 3952 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 3953 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 3954 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 3955 | |
| 3956 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 3957 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 3958 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 3959 | |
| 3960 | // Pin some. |
| 3961 | |
| 3962 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 3963 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 3964 | list("s1"), HANDLE_USER_0); |
| 3965 | |
| 3966 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 3967 | list("s2"), UserHandle.of(USER_P0)); |
| 3968 | |
| 3969 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
| 3970 | list("s3"), HANDLE_USER_0); |
| 3971 | }); |
| 3972 | |
| 3973 | runWithCaller(LAUNCHER_1, USER_P0, () -> { |
| 3974 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 3975 | list("s2"), HANDLE_USER_0); |
| 3976 | |
| 3977 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 3978 | list("s3"), UserHandle.of(USER_P0)); |
| 3979 | |
| 3980 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, |
| 3981 | list("s1"), HANDLE_USER_0); |
| 3982 | }); |
| 3983 | |
| 3984 | runWithCaller(LAUNCHER_1, USER_10, () -> { |
| 3985 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 3986 | list("s3"), HANDLE_USER_10); |
| 3987 | }); |
| 3988 | |
| 3989 | // Check the state. |
| 3990 | |
| 3991 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 3992 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 3993 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 3994 | |
| 3995 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 3996 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 3997 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 3998 | |
| 3999 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4000 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4001 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4002 | |
| 4003 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4004 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4005 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4006 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4007 | // Make sure all the information is persisted. |
| 4008 | mService.saveDirtyInfo(); |
| 4009 | initService(); |
| 4010 | mService.handleUnlockUser(USER_0); |
| 4011 | mService.handleUnlockUser(USER_P0); |
| 4012 | mService.handleUnlockUser(USER_10); |
| 4013 | |
| 4014 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4015 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4016 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4017 | |
| 4018 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4019 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4020 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4021 | |
| 4022 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4023 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4024 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4025 | |
| 4026 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4027 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4028 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4029 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4030 | // Start uninstalling. |
| 4031 | uninstallPackage(USER_10, LAUNCHER_1); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4032 | mService.checkPackageChanges(USER_10); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4033 | |
| 4034 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4035 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4036 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4037 | |
| 4038 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4039 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4040 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4041 | |
| 4042 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4043 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4044 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4045 | |
| 4046 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4047 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4048 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4049 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4050 | // Uninstall. |
| 4051 | uninstallPackage(USER_10, CALLING_PACKAGE_1); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4052 | mService.checkPackageChanges(USER_10); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4053 | |
| 4054 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4055 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4056 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4057 | |
| 4058 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4059 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4060 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4061 | |
| 4062 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4063 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4064 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4065 | |
| 4066 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4067 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4068 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4069 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4070 | uninstallPackage(USER_P0, LAUNCHER_1); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4071 | mService.checkPackageChanges(USER_0); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4072 | |
| 4073 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4074 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4075 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4076 | |
| 4077 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4078 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4079 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4080 | |
| 4081 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4082 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4083 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4084 | |
| 4085 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4086 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4087 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4088 | |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4089 | mService.checkPackageChanges(USER_P0); |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 4090 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4091 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4092 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4093 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4094 | |
| 4095 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4096 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4097 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4098 | |
| 4099 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4100 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4101 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4102 | |
| 4103 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4104 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4105 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4106 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4107 | uninstallPackage(USER_P0, CALLING_PACKAGE_1); |
| 4108 | |
| 4109 | mService.saveDirtyInfo(); |
| 4110 | initService(); |
| 4111 | mService.handleUnlockUser(USER_0); |
| 4112 | mService.handleUnlockUser(USER_P0); |
| 4113 | mService.handleUnlockUser(USER_10); |
| 4114 | |
| 4115 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4116 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4117 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4118 | |
| 4119 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4120 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4121 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4122 | |
| 4123 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4124 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4125 | assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4126 | |
| 4127 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4128 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4129 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4130 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4131 | // Uninstall |
| 4132 | uninstallPackage(USER_0, LAUNCHER_1); |
| 4133 | |
| 4134 | mService.saveDirtyInfo(); |
| 4135 | initService(); |
| 4136 | mService.handleUnlockUser(USER_0); |
| 4137 | mService.handleUnlockUser(USER_P0); |
| 4138 | mService.handleUnlockUser(USER_10); |
| 4139 | |
| 4140 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4141 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4142 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4143 | |
| 4144 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4145 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4146 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4147 | |
| 4148 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4149 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4150 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4151 | |
| 4152 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4153 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4154 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
| 4155 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4156 | uninstallPackage(USER_0, CALLING_PACKAGE_2); |
| 4157 | |
| 4158 | mService.saveDirtyInfo(); |
| 4159 | initService(); |
| 4160 | mService.handleUnlockUser(USER_0); |
| 4161 | mService.handleUnlockUser(USER_P0); |
| 4162 | mService.handleUnlockUser(USER_10); |
| 4163 | |
| 4164 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4165 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0)); |
| 4166 | assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0)); |
| 4167 | |
| 4168 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0)); |
| 4169 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0)); |
| 4170 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0)); |
| 4171 | |
| 4172 | assertNull(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4173 | assertNull(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0)); |
| 4174 | assertNull(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0)); |
| 4175 | |
| 4176 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4177 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10)); |
| 4178 | assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10)); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4181 | protected void checkCanRestoreTo(int expected, ShortcutPackageInfo spi, |
| 4182 | boolean anyVersionOk, int version, boolean nowBackupAllowed, String... signatures) { |
| 4183 | final PackageInfo pi = genPackage("dummy", /* uid */ 0, version, signatures); |
| 4184 | if (!nowBackupAllowed) { |
| 4185 | pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_ALLOW_BACKUP; |
| 4186 | } |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 4187 | |
| 4188 | doReturn(expected != DISABLED_REASON_SIGNATURE_MISMATCH).when( |
| 4189 | mMockPackageManagerInternal).isDataRestoreSafe(any(byte[].class), anyString()); |
| 4190 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4191 | assertEquals(expected, spi.canRestoreTo(mService, pi, anyVersionOk)); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | public void testCanRestoreTo() { |
| 4195 | addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 10, "sig1"); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4196 | addPackage(CALLING_PACKAGE_2, CALLING_UID_2, 10, "sig1", "sig2"); |
| 4197 | addPackage(CALLING_PACKAGE_3, CALLING_UID_3, 10, "sig1"); |
| 4198 | |
| 4199 | updatePackageInfo(CALLING_PACKAGE_3, |
| 4200 | pi -> pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_ALLOW_BACKUP); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4201 | |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 4202 | final ShortcutPackageInfo spi1 = ShortcutPackageInfo.generateForInstalledPackageForTest( |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4203 | mService, CALLING_PACKAGE_1, USER_0); |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 4204 | final ShortcutPackageInfo spi2 = ShortcutPackageInfo.generateForInstalledPackageForTest( |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4205 | mService, CALLING_PACKAGE_2, USER_0); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4206 | final ShortcutPackageInfo spi3 = ShortcutPackageInfo.generateForInstalledPackageForTest( |
| 4207 | mService, CALLING_PACKAGE_3, USER_0); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4208 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4209 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi1, false, 10, true, "sig1"); |
| 4210 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi1, false, 10, true, "x", "sig1"); |
| 4211 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi1, false, 10, true, "sig1", "y"); |
| 4212 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi1, false, 10, true, "x", "sig1", "y"); |
| 4213 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi1, false, 11, true, "sig1"); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4214 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4215 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, spi1, false, 10, true/* empty */); |
| 4216 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, spi1, false, 10, true, "x"); |
| 4217 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, spi1, false, 10, true, "x", "y"); |
| 4218 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, spi1, false, 10, true, "x"); |
| 4219 | checkCanRestoreTo(DISABLED_REASON_VERSION_LOWER, spi1, false, 9, true, "sig1"); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4220 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4221 | // Any version okay. |
| 4222 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi1, true, 9, true, "sig1"); |
| 4223 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi1, true, 9, true, "sig1"); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4224 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4225 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "sig1", "sig2"); |
| 4226 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "sig2", "sig1"); |
| 4227 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "x", "sig1", "sig2"); |
| 4228 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "x", "sig2", "sig1"); |
| 4229 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "sig1", "sig2", "y"); |
| 4230 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "sig2", "sig1", "y"); |
| 4231 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "x", "sig1", "sig2", "y"); |
| 4232 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 10, true, "x", "sig2", "sig1", "y"); |
| 4233 | checkCanRestoreTo(DISABLED_REASON_NOT_DISABLED, spi2, false, 11, true, "x", "sig2", "sig1", "y"); |
| 4234 | |
| 4235 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4236 | spi2, false, 10, true, "sig1", "sig2x"); |
| 4237 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4238 | spi2, false, 10, true, "sig2", "sig1x"); |
| 4239 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4240 | spi2, false, 10, true, "x", "sig1x", "sig2"); |
| 4241 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4242 | spi2, false, 10, true, "x", "sig2x", "sig1"); |
| 4243 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4244 | spi2, false, 10, true, "sig1", "sig2x", "y"); |
| 4245 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4246 | spi2, false, 10, true, "sig2", "sig1x", "y"); |
| 4247 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4248 | spi2, false, 10, true, "x", "sig1x", "sig2", "y"); |
| 4249 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4250 | spi2, false, 10, true, "x", "sig2x", "sig1", "y"); |
| 4251 | checkCanRestoreTo(DISABLED_REASON_SIGNATURE_MISMATCH, |
| 4252 | spi2, false, 11, true, "x", "sig2x", "sig1", "y"); |
| 4253 | |
| 4254 | checkCanRestoreTo(DISABLED_REASON_BACKUP_NOT_SUPPORTED, spi1, true, 10, false, "sig1"); |
| 4255 | checkCanRestoreTo(DISABLED_REASON_BACKUP_NOT_SUPPORTED, spi3, true, 10, true, "sig1"); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4258 | public void testHandlePackageDelete() { |
Makoto Onuki | 82fb2eb | 2017-03-31 16:58:26 -0700 | [diff] [blame] | 4259 | checkHandlePackageDeleteInner((userId, packageName) -> { |
| 4260 | uninstallPackage(userId, packageName); |
| 4261 | mService.mPackageMonitor.onReceive(getTestContext(), |
| 4262 | genPackageDeleteIntent(packageName, userId)); |
| 4263 | }); |
| 4264 | } |
| 4265 | |
| 4266 | public void testHandlePackageDisable() { |
| 4267 | checkHandlePackageDeleteInner((userId, packageName) -> { |
| 4268 | disablePackage(userId, packageName); |
| 4269 | mService.mPackageMonitor.onReceive(getTestContext(), |
| 4270 | genPackageChangedIntent(packageName, userId)); |
| 4271 | }); |
| 4272 | } |
| 4273 | |
| 4274 | private void checkHandlePackageDeleteInner(BiConsumer<Integer, String> remover) { |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4275 | final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
| 4276 | getTestContext().getResources(), R.drawable.black_32x32)); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4277 | setCaller(CALLING_PACKAGE_1, USER_0); |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4278 | assertTrue(mManager.addDynamicShortcuts(list( |
| 4279 | makeShortcutWithIcon("s1", bmp32x32), makeShortcutWithIcon("s2", bmp32x32) |
| 4280 | ))); |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4281 | // Also add a manifest shortcut, which should be removed too. |
| 4282 | addManifestShortcutResource( |
| 4283 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 4284 | R.xml.shortcut_1); |
| 4285 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4286 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4287 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 4288 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4289 | assertWith(getCallerShortcuts()) |
| 4290 | .haveIds("s1", "s2", "ms1") |
| 4291 | |
| 4292 | .selectManifest() |
| 4293 | .haveIds("ms1"); |
| 4294 | }); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4295 | |
| 4296 | setCaller(CALLING_PACKAGE_2, USER_0); |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4297 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4298 | |
| 4299 | setCaller(CALLING_PACKAGE_3, USER_0); |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4300 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4301 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 4302 | mRunningUsers.put(USER_10, true); |
| 4303 | |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4304 | setCaller(CALLING_PACKAGE_1, USER_10); |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4305 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4306 | |
| 4307 | setCaller(CALLING_PACKAGE_2, USER_10); |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4308 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4309 | |
| 4310 | setCaller(CALLING_PACKAGE_3, USER_10); |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4311 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4312 | |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 4313 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4314 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4315 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); |
| 4316 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4317 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4318 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4319 | |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4320 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4321 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4322 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4323 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4324 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4325 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
| 4326 | |
Makoto Onuki | 82fb2eb | 2017-03-31 16:58:26 -0700 | [diff] [blame] | 4327 | remover.accept(USER_0, CALLING_PACKAGE_1); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4328 | |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 4329 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4330 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4331 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); |
| 4332 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4333 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4334 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4335 | |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4336 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4337 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4338 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4339 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4340 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4341 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
| 4342 | |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 4343 | mRunningUsers.put(USER_10, true); |
| 4344 | |
Makoto Onuki | 82fb2eb | 2017-03-31 16:58:26 -0700 | [diff] [blame] | 4345 | remover.accept(USER_10, CALLING_PACKAGE_2); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4346 | |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 4347 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4348 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4349 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); |
| 4350 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4351 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4352 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4353 | |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4354 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4355 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4356 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4357 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4358 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4359 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
| 4360 | |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4361 | mInjectedPackages.remove(CALLING_PACKAGE_1); |
| 4362 | mInjectedPackages.remove(CALLING_PACKAGE_3); |
| 4363 | |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4364 | mService.checkPackageChanges(USER_0); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 4365 | |
| 4366 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4367 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4368 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); // --------------- |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 4369 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4370 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4371 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4372 | |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4373 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4374 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4375 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4376 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4377 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4378 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
| 4379 | |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4380 | mService.checkPackageChanges(USER_10); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 4381 | |
| 4382 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4383 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4384 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); |
| 4385 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4386 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4387 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
Makoto Onuki | 0033b2a | 2016-04-14 17:19:16 -0700 | [diff] [blame] | 4388 | |
| 4389 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4390 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4391 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4392 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4393 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4394 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 4395 | } |
| 4396 | |
Makoto Onuki | 9ac59d0 | 2016-04-26 11:23:14 -0700 | [diff] [blame] | 4397 | /** Almost ame as testHandlePackageDelete, except it doesn't uninstall packages. */ |
| 4398 | public void testHandlePackageClearData() { |
| 4399 | final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
| 4400 | getTestContext().getResources(), R.drawable.black_32x32)); |
| 4401 | setCaller(CALLING_PACKAGE_1, USER_0); |
| 4402 | assertTrue(mManager.addDynamicShortcuts(list( |
| 4403 | makeShortcutWithIcon("s1", bmp32x32), makeShortcutWithIcon("s2", bmp32x32) |
| 4404 | ))); |
| 4405 | |
| 4406 | setCaller(CALLING_PACKAGE_2, USER_0); |
| 4407 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
| 4408 | |
| 4409 | setCaller(CALLING_PACKAGE_3, USER_0); |
| 4410 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
| 4411 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 4412 | mRunningUsers.put(USER_10, true); |
| 4413 | |
Makoto Onuki | 9ac59d0 | 2016-04-26 11:23:14 -0700 | [diff] [blame] | 4414 | setCaller(CALLING_PACKAGE_1, USER_10); |
| 4415 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
| 4416 | |
| 4417 | setCaller(CALLING_PACKAGE_2, USER_10); |
| 4418 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
| 4419 | |
| 4420 | setCaller(CALLING_PACKAGE_3, USER_10); |
| 4421 | assertTrue(mManager.addDynamicShortcuts(list(makeShortcutWithIcon("s1", bmp32x32)))); |
| 4422 | |
| 4423 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4424 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4425 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); |
| 4426 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4427 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4428 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
| 4429 | |
| 4430 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4431 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4432 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4433 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4434 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4435 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
| 4436 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4437 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 9ac59d0 | 2016-04-26 11:23:14 -0700 | [diff] [blame] | 4438 | genPackageDataClear(CALLING_PACKAGE_1, USER_0)); |
| 4439 | |
| 4440 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4441 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4442 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); |
| 4443 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4444 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4445 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
| 4446 | |
| 4447 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4448 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4449 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4450 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4451 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4452 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
| 4453 | |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 4454 | mRunningUsers.put(USER_10, true); |
| 4455 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4456 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 9ac59d0 | 2016-04-26 11:23:14 -0700 | [diff] [blame] | 4457 | genPackageDataClear(CALLING_PACKAGE_2, USER_10)); |
| 4458 | |
| 4459 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0)); |
| 4460 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0)); |
| 4461 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0)); |
| 4462 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10)); |
| 4463 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10)); |
| 4464 | assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10)); |
| 4465 | |
| 4466 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_0)); |
| 4467 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_0)); |
| 4468 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_0)); |
| 4469 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_1, USER_10)); |
| 4470 | assertFalse(bitmapDirectoryExists(CALLING_PACKAGE_2, USER_10)); |
| 4471 | assertTrue(bitmapDirectoryExists(CALLING_PACKAGE_3, USER_10)); |
| 4472 | } |
| 4473 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4474 | public void testHandlePackageClearData_manifestRepublished() { |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4475 | |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 4476 | mRunningUsers.put(USER_10, true); |
| 4477 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4478 | // Add two manifests and two dynamics. |
| 4479 | addManifestShortcutResource( |
| 4480 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 4481 | R.xml.shortcut_2); |
| 4482 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4483 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4484 | genPackageAddIntent(CALLING_PACKAGE_1, USER_10)); |
| 4485 | |
| 4486 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4487 | assertTrue(mManager.addDynamicShortcuts(list( |
| 4488 | makeShortcut("s1"), makeShortcut("s2")))); |
| 4489 | }); |
| 4490 | runWithCaller(LAUNCHER_1, USER_10, () -> { |
| 4491 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms2", "s2"), HANDLE_USER_10); |
| 4492 | }); |
| 4493 | |
| 4494 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4495 | assertWith(getCallerShortcuts()) |
| 4496 | .haveIds("ms1", "ms2", "s1", "s2") |
| 4497 | .areAllEnabled() |
| 4498 | |
| 4499 | .selectPinned() |
| 4500 | .haveIds("ms2", "s2"); |
| 4501 | }); |
| 4502 | |
| 4503 | // Clear data |
Makoto Onuki | 0b9d1db | 2016-07-18 14:16:41 -0700 | [diff] [blame] | 4504 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4505 | genPackageDataClear(CALLING_PACKAGE_1, USER_10)); |
| 4506 | |
| 4507 | // Only manifest shortcuts will remain, and are no longer pinned. |
| 4508 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4509 | assertWith(getCallerShortcuts()) |
| 4510 | .haveIds("ms1", "ms2") |
| 4511 | .areAllEnabled() |
| 4512 | .areAllNotPinned(); |
| 4513 | }); |
| 4514 | } |
| 4515 | |
| 4516 | public void testHandlePackageUpdate() throws Throwable { |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4517 | // Set up shortcuts and launchers. |
| 4518 | |
| 4519 | final Icon res32x32 = Icon.createWithResource(getTestContext(), R.drawable.black_32x32); |
| 4520 | final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource( |
| 4521 | getTestContext().getResources(), R.drawable.black_32x32)); |
| 4522 | |
| 4523 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4524 | assertTrue(mManager.setDynamicShortcuts(list( |
| 4525 | makeShortcut("s1"), |
| 4526 | makeShortcutWithIcon("s2", res32x32), |
| 4527 | makeShortcutWithIcon("s3", res32x32), |
| 4528 | makeShortcutWithIcon("s4", bmp32x32)))); |
| 4529 | }); |
| 4530 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 4531 | assertTrue(mManager.setDynamicShortcuts(list( |
| 4532 | makeShortcut("s1"), |
| 4533 | makeShortcutWithIcon("s2", bmp32x32)))); |
| 4534 | }); |
| 4535 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 4536 | assertTrue(mManager.setDynamicShortcuts(list( |
| 4537 | makeShortcutWithIcon("s1", res32x32)))); |
| 4538 | }); |
| 4539 | |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 4540 | mRunningUsers.put(USER_10, true); |
| 4541 | |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4542 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4543 | assertTrue(mManager.setDynamicShortcuts(list( |
| 4544 | makeShortcutWithIcon("s1", res32x32), |
| 4545 | makeShortcutWithIcon("s2", res32x32)))); |
| 4546 | }); |
| 4547 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
| 4548 | assertTrue(mManager.setDynamicShortcuts(list( |
| 4549 | makeShortcutWithIcon("s1", bmp32x32), |
| 4550 | makeShortcutWithIcon("s2", bmp32x32)))); |
| 4551 | }); |
| 4552 | |
| 4553 | LauncherApps.Callback c0 = mock(LauncherApps.Callback.class); |
| 4554 | LauncherApps.Callback c10 = mock(LauncherApps.Callback.class); |
| 4555 | |
| 4556 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 4557 | mLauncherApps.registerCallback(c0, new Handler(Looper.getMainLooper())); |
| 4558 | }); |
| 4559 | runWithCaller(LAUNCHER_1, USER_10, () -> { |
| 4560 | mLauncherApps.registerCallback(c10, new Handler(Looper.getMainLooper())); |
| 4561 | }); |
| 4562 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 4563 | mInjectedCurrentTimeMillis = START_TIME + 100; |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4564 | |
| 4565 | ArgumentCaptor<List> shortcuts; |
| 4566 | |
Makoto Onuki | 64183d5 | 2016-08-08 14:11:34 -0700 | [diff] [blame] | 4567 | // Update the version info for package 1. |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4568 | reset(c0); |
| 4569 | reset(c10); |
| 4570 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 4571 | |
| 4572 | // Then send the broadcast, to only user-0. |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4573 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4574 | genPackageUpdateIntent(CALLING_PACKAGE_1, USER_0)); |
| 4575 | |
| 4576 | waitOnMainThread(); |
| 4577 | |
| 4578 | // User-0 should get the notification. |
| 4579 | shortcuts = ArgumentCaptor.forClass(List.class); |
| 4580 | verify(c0).onShortcutsChanged( |
| 4581 | eq(CALLING_PACKAGE_1), |
| 4582 | shortcuts.capture(), |
| 4583 | eq(HANDLE_USER_0)); |
| 4584 | |
| 4585 | // User-10 shouldn't yet get the notification. |
| 4586 | verify(c10, times(0)).onShortcutsChanged( |
| 4587 | eq(CALLING_PACKAGE_1), |
| 4588 | any(List.class), |
| 4589 | any(UserHandle.class)); |
| 4590 | assertShortcutIds(shortcuts.getValue(), "s1", "s2", "s3", "s4"); |
| 4591 | assertEquals(START_TIME, |
| 4592 | findShortcut(shortcuts.getValue(), "s1").getLastChangedTimestamp()); |
| 4593 | assertEquals(START_TIME + 100, |
| 4594 | findShortcut(shortcuts.getValue(), "s2").getLastChangedTimestamp()); |
| 4595 | assertEquals(START_TIME + 100, |
| 4596 | findShortcut(shortcuts.getValue(), "s3").getLastChangedTimestamp()); |
| 4597 | assertEquals(START_TIME, |
| 4598 | findShortcut(shortcuts.getValue(), "s4").getLastChangedTimestamp()); |
| 4599 | |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4600 | // Next, send an unlock event on user-10. Now we scan packages on this user and send a |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4601 | // notification to the launcher. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 4602 | mInjectedCurrentTimeMillis = START_TIME + 200; |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4603 | |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 4604 | mRunningUsers.put(USER_10, true); |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4605 | mUnlockedUsers.put(USER_10, true); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4606 | |
| 4607 | reset(c0); |
| 4608 | reset(c10); |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4609 | setPackageLastUpdateTime(CALLING_PACKAGE_1, mInjectedCurrentTimeMillis); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4610 | mService.handleUnlockUser(USER_10); |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4611 | mService.checkPackageChanges(USER_10); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4612 | |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 4613 | waitOnMainThread(); |
| 4614 | |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4615 | shortcuts = ArgumentCaptor.forClass(List.class); |
| 4616 | verify(c0, times(0)).onShortcutsChanged( |
| 4617 | eq(CALLING_PACKAGE_1), |
| 4618 | any(List.class), |
| 4619 | any(UserHandle.class)); |
| 4620 | |
| 4621 | verify(c10).onShortcutsChanged( |
| 4622 | eq(CALLING_PACKAGE_1), |
| 4623 | shortcuts.capture(), |
| 4624 | eq(HANDLE_USER_10)); |
| 4625 | |
| 4626 | assertShortcutIds(shortcuts.getValue(), "s1", "s2"); |
| 4627 | assertEquals(START_TIME + 200, |
| 4628 | findShortcut(shortcuts.getValue(), "s1").getLastChangedTimestamp()); |
| 4629 | assertEquals(START_TIME + 200, |
| 4630 | findShortcut(shortcuts.getValue(), "s2").getLastChangedTimestamp()); |
| 4631 | |
| 4632 | |
| 4633 | // Do the same thing for package 2, which doesn't have resource icons. |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 4634 | mInjectedCurrentTimeMillis = START_TIME + 300; |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4635 | |
| 4636 | reset(c0); |
| 4637 | reset(c10); |
| 4638 | updatePackageVersion(CALLING_PACKAGE_2, 10); |
| 4639 | |
| 4640 | // Then send the broadcast, to only user-0. |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4641 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4642 | genPackageUpdateIntent(CALLING_PACKAGE_2, USER_0)); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4643 | |
| 4644 | waitOnMainThread(); |
| 4645 | |
| 4646 | verify(c0, times(0)).onShortcutsChanged( |
| 4647 | eq(CALLING_PACKAGE_1), |
| 4648 | any(List.class), |
| 4649 | any(UserHandle.class)); |
| 4650 | |
| 4651 | verify(c10, times(0)).onShortcutsChanged( |
| 4652 | eq(CALLING_PACKAGE_1), |
| 4653 | any(List.class), |
| 4654 | any(UserHandle.class)); |
| 4655 | |
| 4656 | // Do the same thing for package 3 |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 4657 | mInjectedCurrentTimeMillis = START_TIME + 400; |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4658 | |
| 4659 | reset(c0); |
| 4660 | reset(c10); |
| 4661 | updatePackageVersion(CALLING_PACKAGE_3, 100); |
| 4662 | |
| 4663 | // Then send the broadcast, to only user-0. |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4664 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4665 | genPackageUpdateIntent(CALLING_PACKAGE_3, USER_0)); |
Makoto Onuki | 085a05c | 2016-08-19 11:39:29 -0700 | [diff] [blame] | 4666 | mService.checkPackageChanges(USER_10); |
Makoto Onuki | 39686e8 | 2016-04-13 18:03:00 -0700 | [diff] [blame] | 4667 | |
| 4668 | waitOnMainThread(); |
| 4669 | |
| 4670 | shortcuts = ArgumentCaptor.forClass(List.class); |
| 4671 | verify(c0).onShortcutsChanged( |
| 4672 | eq(CALLING_PACKAGE_3), |
| 4673 | shortcuts.capture(), |
| 4674 | eq(HANDLE_USER_0)); |
| 4675 | |
| 4676 | // User 10 doesn't have package 3, so no callback. |
| 4677 | verify(c10, times(0)).onShortcutsChanged( |
| 4678 | eq(CALLING_PACKAGE_3), |
| 4679 | any(List.class), |
| 4680 | any(UserHandle.class)); |
| 4681 | |
| 4682 | assertShortcutIds(shortcuts.getValue(), "s1"); |
| 4683 | assertEquals(START_TIME + 400, |
| 4684 | findShortcut(shortcuts.getValue(), "s1").getLastChangedTimestamp()); |
| 4685 | } |
| 4686 | |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 4687 | /** |
| 4688 | * Test the case where an updated app has resource IDs changed. |
| 4689 | */ |
| 4690 | public void testHandlePackageUpdate_resIdChanged() throws Exception { |
| 4691 | final Icon icon1 = Icon.createWithResource(getTestContext(), /* res ID */ 1000); |
| 4692 | final Icon icon2 = Icon.createWithResource(getTestContext(), /* res ID */ 1001); |
| 4693 | |
| 4694 | // Set up shortcuts. |
| 4695 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4696 | // Note resource strings are not officially supported (they're hidden), but |
| 4697 | // should work. |
| 4698 | |
| 4699 | final ShortcutInfo s1 = new ShortcutInfo.Builder(mClientContext) |
| 4700 | .setId("s1") |
| 4701 | .setActivity(makeComponent(ShortcutActivity.class)) |
| 4702 | .setIntent(new Intent(Intent.ACTION_VIEW)) |
| 4703 | .setIcon(icon1) |
| 4704 | .setTitleResId(10000) |
| 4705 | .setTextResId(10001) |
| 4706 | .setDisabledMessageResId(10002) |
| 4707 | .build(); |
| 4708 | |
| 4709 | final ShortcutInfo s2 = new ShortcutInfo.Builder(mClientContext) |
| 4710 | .setId("s2") |
| 4711 | .setActivity(makeComponent(ShortcutActivity.class)) |
| 4712 | .setIntent(new Intent(Intent.ACTION_VIEW)) |
| 4713 | .setIcon(icon2) |
| 4714 | .setTitleResId(20000) |
| 4715 | .build(); |
| 4716 | |
| 4717 | assertTrue(mManager.setDynamicShortcuts(list(s1, s2))); |
| 4718 | }); |
| 4719 | |
| 4720 | // Verify. |
| 4721 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4722 | final ShortcutInfo s1 = getCallerShortcut("s1"); |
| 4723 | final ShortcutInfo s2 = getCallerShortcut("s2"); |
| 4724 | |
| 4725 | assertEquals(1000, s1.getIconResourceId()); |
| 4726 | assertEquals(10000, s1.getTitleResId()); |
| 4727 | assertEquals(10001, s1.getTextResId()); |
| 4728 | assertEquals(10002, s1.getDisabledMessageResourceId()); |
| 4729 | |
| 4730 | assertEquals(1001, s2.getIconResourceId()); |
| 4731 | assertEquals(20000, s2.getTitleResId()); |
| 4732 | assertEquals(0, s2.getTextResId()); |
| 4733 | assertEquals(0, s2.getDisabledMessageResourceId()); |
| 4734 | }); |
| 4735 | |
| 4736 | mService.saveDirtyInfo(); |
| 4737 | initService(); |
| 4738 | |
| 4739 | // Set up the mock resources again, with an "adjustment". |
| 4740 | // When the package is updated, the service will fetch the updated res-IDs with res-names, |
| 4741 | // and the new IDs will have this offset. |
| 4742 | setUpAppResources(10); |
| 4743 | |
| 4744 | // Update the package. |
| 4745 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4746 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 4747 | genPackageUpdateIntent(CALLING_PACKAGE_1, USER_0)); |
| 4748 | |
| 4749 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4750 | final ShortcutInfo s1 = getCallerShortcut("s1"); |
| 4751 | final ShortcutInfo s2 = getCallerShortcut("s2"); |
| 4752 | |
| 4753 | assertEquals(1010, s1.getIconResourceId()); |
| 4754 | assertEquals(10010, s1.getTitleResId()); |
| 4755 | assertEquals(10011, s1.getTextResId()); |
| 4756 | assertEquals(10012, s1.getDisabledMessageResourceId()); |
| 4757 | |
| 4758 | assertEquals(1011, s2.getIconResourceId()); |
| 4759 | assertEquals(20010, s2.getTitleResId()); |
| 4760 | assertEquals(0, s2.getTextResId()); |
| 4761 | assertEquals(0, s2.getDisabledMessageResourceId()); |
| 4762 | }); |
| 4763 | } |
| 4764 | |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4765 | public void testHandlePackageUpdate_systemAppUpdate() { |
| 4766 | |
| 4767 | // Package1 is a system app. Package 2 is not a system app, so it's not scanned |
| 4768 | // in this test at all. |
| 4769 | mSystemPackages.add(CALLING_PACKAGE_1); |
| 4770 | |
| 4771 | // Initial state: no shortcuts. |
| 4772 | mService.checkPackageChanges(USER_0); |
| 4773 | |
| 4774 | assertEquals(mInjectedCurrentTimeMillis, |
| 4775 | mService.getUserShortcutsLocked(USER_0).getLastAppScanTime()); |
| 4776 | assertEquals(mInjectedBuildFingerprint, |
| 4777 | mService.getUserShortcutsLocked(USER_0).getLastAppScanOsFingerprint()); |
| 4778 | |
| 4779 | // They have no shortcuts. |
| 4780 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4781 | assertWith(getCallerShortcuts()) |
| 4782 | .isEmpty(); |
| 4783 | }); |
| 4784 | |
| 4785 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 4786 | assertWith(getCallerShortcuts()) |
| 4787 | .isEmpty(); |
| 4788 | }); |
| 4789 | |
| 4790 | // Next. |
| 4791 | // Update the packages -- now they have 1 manifest shortcut. |
| 4792 | // But checkPackageChanges() don't notice it, since their version code / timestamp haven't |
| 4793 | // changed. |
| 4794 | addManifestShortcutResource( |
| 4795 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 4796 | R.xml.shortcut_1); |
| 4797 | addManifestShortcutResource( |
| 4798 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 4799 | R.xml.shortcut_1); |
| 4800 | mInjectedCurrentTimeMillis += 1000; |
| 4801 | mService.checkPackageChanges(USER_0); |
| 4802 | |
| 4803 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4804 | assertWith(getCallerShortcuts()) |
| 4805 | .isEmpty(); |
| 4806 | }); |
| 4807 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 4808 | assertWith(getCallerShortcuts()) |
| 4809 | .isEmpty(); |
| 4810 | }); |
| 4811 | |
| 4812 | // Next. |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4813 | // Update the build finger print. All apps will be scanned now. |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4814 | mInjectedBuildFingerprint = "update1"; |
| 4815 | mInjectedCurrentTimeMillis += 1000; |
| 4816 | mService.checkPackageChanges(USER_0); |
| 4817 | |
| 4818 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4819 | assertWith(getCallerShortcuts()) |
| 4820 | .haveIds("ms1"); |
| 4821 | }); |
| 4822 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 4823 | assertWith(getCallerShortcuts()) |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4824 | .haveIds("ms1"); |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4825 | }); |
| 4826 | |
| 4827 | // Next. |
| 4828 | // Update manifest shortcuts. |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4829 | addManifestShortcutResource( |
| 4830 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 4831 | R.xml.shortcut_2); |
| 4832 | addManifestShortcutResource( |
| 4833 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 4834 | R.xml.shortcut_2); |
| 4835 | mInjectedCurrentTimeMillis += 1000; |
| 4836 | mService.checkPackageChanges(USER_0); |
| 4837 | |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4838 | // Fingerprint hasn't changed, so there packages weren't scanned. |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4839 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4840 | assertWith(getCallerShortcuts()) |
| 4841 | .haveIds("ms1"); |
| 4842 | }); |
| 4843 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 4844 | assertWith(getCallerShortcuts()) |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4845 | .haveIds("ms1"); |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4846 | }); |
| 4847 | |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4848 | // Update the fingerprint. CALLING_PACKAGE_1's version code hasn't changed, but we scan |
| 4849 | // all apps anyway. |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4850 | mInjectedBuildFingerprint = "update2"; |
| 4851 | mInjectedCurrentTimeMillis += 1000; |
| 4852 | mService.checkPackageChanges(USER_0); |
| 4853 | |
| 4854 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 4855 | assertWith(getCallerShortcuts()) |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4856 | .haveIds("ms1", "ms2"); |
| 4857 | }); |
| 4858 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 4859 | assertWith(getCallerShortcuts()) |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 4860 | .haveIds("ms1", "ms2"); |
Makoto Onuki | 3366328 | 2016-08-22 16:19:04 -0700 | [diff] [blame] | 4861 | }); |
| 4862 | |
| 4863 | // Make sure getLastAppScanTime / getLastAppScanOsFingerprint are persisted. |
| 4864 | initService(); |
| 4865 | assertEquals(mInjectedCurrentTimeMillis, |
| 4866 | mService.getUserShortcutsLocked(USER_0).getLastAppScanTime()); |
| 4867 | assertEquals(mInjectedBuildFingerprint, |
| 4868 | mService.getUserShortcutsLocked(USER_0).getLastAppScanOsFingerprint()); |
| 4869 | } |
| 4870 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4871 | public void testHandlePackageChanged() { |
| 4872 | final ComponentName ACTIVITY1 = new ComponentName(CALLING_PACKAGE_1, "act1"); |
| 4873 | final ComponentName ACTIVITY2 = new ComponentName(CALLING_PACKAGE_1, "act2"); |
| 4874 | |
| 4875 | addManifestShortcutResource(ACTIVITY1, R.xml.shortcut_1); |
| 4876 | addManifestShortcutResource(ACTIVITY2, R.xml.shortcut_1_alt); |
| 4877 | |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 4878 | mRunningUsers.put(USER_10, true); |
| 4879 | |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4880 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4881 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4882 | genPackageAddIntent(CALLING_PACKAGE_1, USER_10)); |
| 4883 | |
| 4884 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4885 | assertTrue(mManager.addDynamicShortcuts(list( |
| 4886 | makeShortcutWithActivity("s1", ACTIVITY1), |
| 4887 | makeShortcutWithActivity("s2", ACTIVITY2) |
| 4888 | ))); |
| 4889 | }); |
| 4890 | runWithCaller(LAUNCHER_1, USER_10, () -> { |
| 4891 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms1-alt", "s2"), HANDLE_USER_10); |
| 4892 | }); |
| 4893 | |
| 4894 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4895 | assertWith(getCallerShortcuts()) |
| 4896 | .haveIds("ms1", "ms1-alt", "s1", "s2") |
| 4897 | .areAllEnabled() |
| 4898 | |
| 4899 | .selectPinned() |
| 4900 | .haveIds("ms1-alt", "s2") |
| 4901 | |
| 4902 | .revertToOriginalList() |
| 4903 | .selectByIds("ms1", "s1") |
| 4904 | .areAllWithActivity(ACTIVITY1) |
| 4905 | |
| 4906 | .revertToOriginalList() |
| 4907 | .selectByIds("ms1-alt", "s2") |
| 4908 | .areAllWithActivity(ACTIVITY2) |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4909 | ; |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4910 | }); |
| 4911 | |
| 4912 | // First, no changes. |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4913 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4914 | genPackageChangedIntent(CALLING_PACKAGE_1, USER_10)); |
| 4915 | |
| 4916 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4917 | assertWith(getCallerShortcuts()) |
| 4918 | .haveIds("ms1", "ms1-alt", "s1", "s2") |
| 4919 | .areAllEnabled() |
| 4920 | |
| 4921 | .selectPinned() |
| 4922 | .haveIds("ms1-alt", "s2") |
| 4923 | |
| 4924 | .revertToOriginalList() |
| 4925 | .selectByIds("ms1", "s1") |
| 4926 | .areAllWithActivity(ACTIVITY1) |
| 4927 | |
| 4928 | .revertToOriginalList() |
| 4929 | .selectByIds("ms1-alt", "s2") |
| 4930 | .areAllWithActivity(ACTIVITY2) |
| 4931 | ; |
| 4932 | }); |
| 4933 | |
| 4934 | // Disable activity 1 |
| 4935 | mEnabledActivityChecker = (activity, userId) -> !ACTIVITY1.equals(activity); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4936 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4937 | genPackageChangedIntent(CALLING_PACKAGE_1, USER_10)); |
| 4938 | |
| 4939 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4940 | assertWith(getCallerShortcuts()) |
| 4941 | .haveIds("ms1-alt", "s2") |
| 4942 | .areAllEnabled() |
| 4943 | |
| 4944 | .selectPinned() |
| 4945 | .haveIds("ms1-alt", "s2") |
| 4946 | |
| 4947 | .revertToOriginalList() |
| 4948 | .selectByIds("ms1-alt", "s2") |
| 4949 | .areAllWithActivity(ACTIVITY2) |
| 4950 | ; |
| 4951 | }); |
| 4952 | |
| 4953 | // Re-enable activity 1. |
| 4954 | // Manifest shortcuts will be re-published, but dynamic ones are not. |
| 4955 | mEnabledActivityChecker = (activity, userId) -> true; |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4956 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4957 | genPackageChangedIntent(CALLING_PACKAGE_1, USER_10)); |
| 4958 | |
| 4959 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4960 | assertWith(getCallerShortcuts()) |
| 4961 | .haveIds("ms1", "ms1-alt", "s2") |
| 4962 | .areAllEnabled() |
| 4963 | |
| 4964 | .selectPinned() |
| 4965 | .haveIds("ms1-alt", "s2") |
| 4966 | |
| 4967 | .revertToOriginalList() |
| 4968 | .selectByIds("ms1") |
| 4969 | .areAllWithActivity(ACTIVITY1) |
| 4970 | |
| 4971 | .revertToOriginalList() |
| 4972 | .selectByIds("ms1-alt", "s2") |
| 4973 | .areAllWithActivity(ACTIVITY2) |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4974 | ; |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4975 | }); |
| 4976 | |
| 4977 | // Disable activity 2 |
| 4978 | // Because "ms1-alt" and "s2" are both pinned, they will remain, but disabled. |
| 4979 | mEnabledActivityChecker = (activity, userId) -> !ACTIVITY2.equals(activity); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 4980 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 4981 | genPackageChangedIntent(CALLING_PACKAGE_1, USER_10)); |
| 4982 | |
| 4983 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 4984 | assertWith(getCallerShortcuts()) |
| 4985 | .haveIds("ms1", "ms1-alt", "s2") |
| 4986 | |
| 4987 | .selectDynamic().isEmpty().revertToOriginalList() // no dynamics. |
| 4988 | |
| 4989 | .selectPinned() |
| 4990 | .haveIds("ms1-alt", "s2") |
| 4991 | .areAllDisabled() |
| 4992 | |
| 4993 | .revertToOriginalList() |
| 4994 | .selectByIds("ms1") |
| 4995 | .areAllWithActivity(ACTIVITY1) |
| 4996 | .areAllEnabled() |
| 4997 | ; |
| 4998 | }); |
| 4999 | } |
| 5000 | |
| 5001 | public void testHandlePackageUpdate_activityNoLongerMain() throws Throwable { |
| 5002 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5003 | assertTrue(mManager.setDynamicShortcuts(list( |
| 5004 | makeShortcutWithActivity("s1a", |
| 5005 | new ComponentName(getCallingPackage(), "act1")), |
| 5006 | makeShortcutWithActivity("s1b", |
| 5007 | new ComponentName(getCallingPackage(), "act1")), |
| 5008 | makeShortcutWithActivity("s2a", |
| 5009 | new ComponentName(getCallingPackage(), "act2")), |
| 5010 | makeShortcutWithActivity("s2b", |
| 5011 | new ComponentName(getCallingPackage(), "act2")), |
| 5012 | makeShortcutWithActivity("s3a", |
| 5013 | new ComponentName(getCallingPackage(), "act3")), |
| 5014 | makeShortcutWithActivity("s3b", |
| 5015 | new ComponentName(getCallingPackage(), "act3")) |
| 5016 | ))); |
| 5017 | assertWith(getCallerShortcuts()) |
| 5018 | .haveIds("s1a", "s1b", "s2a", "s2b", "s3a", "s3b") |
| 5019 | .areAllDynamic(); |
| 5020 | }); |
| 5021 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5022 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 5023 | list("s1b", "s2b", "s3b"), |
| 5024 | HANDLE_USER_0); |
| 5025 | }); |
| 5026 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5027 | assertWith(getCallerShortcuts()) |
| 5028 | .haveIds("s1a", "s1b", "s2a", "s2b", "s3a", "s3b") |
| 5029 | .areAllDynamic() |
| 5030 | |
| 5031 | .selectByIds("s1b", "s2b", "s3b") |
| 5032 | .areAllPinned(); |
| 5033 | }); |
| 5034 | |
| 5035 | // Update the app and act2 and act3 are no longer main. |
| 5036 | mMainActivityChecker = (activity, userId) -> { |
| 5037 | return activity.getClassName().equals("act1"); |
| 5038 | }; |
| 5039 | |
| 5040 | setCaller(LAUNCHER_1, USER_0); |
| 5041 | assertForLauncherCallback(mLauncherApps, () -> { |
| 5042 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5043 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 5044 | genPackageUpdateIntent(CALLING_PACKAGE_1, USER_0)); |
| 5045 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
| 5046 | // Make sure the launcher gets callbacks. |
| 5047 | .haveIds("s1a", "s1b", "s2b", "s3b") |
| 5048 | .areAllWithKeyFieldsOnly(); |
| 5049 | |
| 5050 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5051 | // s2a and s3a are gone, but s2b and s3b will remain because they're pinned, and |
| 5052 | // disabled. |
| 5053 | assertWith(getCallerShortcuts()) |
| 5054 | .haveIds("s1a", "s1b", "s2b", "s3b") |
| 5055 | |
| 5056 | .selectByIds("s1a", "s1b") |
| 5057 | .areAllDynamic() |
| 5058 | .areAllEnabled() |
| 5059 | |
| 5060 | .revertToOriginalList() |
| 5061 | .selectByIds("s2b", "s3b") |
| 5062 | .areAllNotDynamic() |
| 5063 | .areAllDisabled() |
| 5064 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5065 | ; |
Makoto Onuki | b08790c | 2016-06-23 14:05:46 -0700 | [diff] [blame] | 5066 | }); |
| 5067 | } |
| 5068 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 5069 | protected void prepareForBackupTest() { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5070 | prepareCrossProfileDataSet(); |
| 5071 | |
| 5072 | backupAndRestore(); |
| 5073 | } |
| 5074 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5075 | /** |
| 5076 | * Make sure the backup data doesn't have the following information: |
| 5077 | * - Launchers on other users. |
| 5078 | * - Non-backup app information. |
| 5079 | * |
| 5080 | * But restores all other infomation. |
| 5081 | * |
| 5082 | * It also omits the following pieces of information, but that's tested in |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 5083 | * {@link ShortcutManagerTest2#testShortcutInfoSaveAndLoad_forBackup}. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5084 | * - Unpinned dynamic shortcuts |
| 5085 | * - Bitmaps |
| 5086 | */ |
| 5087 | public void testBackupAndRestore() { |
Makoto Onuki | 50a320e | 2017-05-31 14:38:42 -0700 | [diff] [blame] | 5088 | |
| 5089 | assertFileNotExists("user-0/shortcut_dump/restore-0-start.txt"); |
| 5090 | assertFileNotExists("user-0/shortcut_dump/restore-1-payload.xml"); |
| 5091 | assertFileNotExists("user-0/shortcut_dump/restore-2.txt"); |
| 5092 | assertFileNotExists("user-0/shortcut_dump/restore-3.txt"); |
| 5093 | assertFileNotExists("user-0/shortcut_dump/restore-4.txt"); |
| 5094 | assertFileNotExists("user-0/shortcut_dump/restore-5-finish.txt"); |
| 5095 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5096 | prepareForBackupTest(); |
| 5097 | |
Makoto Onuki | 50a320e | 2017-05-31 14:38:42 -0700 | [diff] [blame] | 5098 | assertFileExistsWithContent("user-0/shortcut_dump/restore-0-start.txt"); |
| 5099 | assertFileExistsWithContent("user-0/shortcut_dump/restore-1-payload.xml"); |
| 5100 | assertFileExistsWithContent("user-0/shortcut_dump/restore-2.txt"); |
| 5101 | assertFileExistsWithContent("user-0/shortcut_dump/restore-3.txt"); |
| 5102 | assertFileExistsWithContent("user-0/shortcut_dump/restore-4.txt"); |
| 5103 | assertFileExistsWithContent("user-0/shortcut_dump/restore-5-finish.txt"); |
| 5104 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5105 | checkBackupAndRestore_success(/*firstRestore=*/ true); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | public void testBackupAndRestore_backupRestoreTwice() { |
| 5109 | prepareForBackupTest(); |
| 5110 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5111 | checkBackupAndRestore_success(/*firstRestore=*/ true); |
| 5112 | |
| 5113 | // Run a backup&restore again. Note the shortcuts that weren't restored in the previous |
| 5114 | // restore are disabled, so they won't be restored again. |
| 5115 | dumpsysOnLogcat("Before second backup&restore"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5116 | |
| 5117 | backupAndRestore(); |
| 5118 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5119 | dumpsysOnLogcat("After second backup&restore"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5120 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5121 | checkBackupAndRestore_success(/*firstRestore=*/ false); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | public void testBackupAndRestore_restoreToNewVersion() { |
| 5125 | prepareForBackupTest(); |
| 5126 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5127 | addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 2); |
| 5128 | addPackage(LAUNCHER_1, LAUNCHER_UID_1, 5); |
| 5129 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5130 | checkBackupAndRestore_success(/*firstRestore=*/ true); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | public void testBackupAndRestore_restoreToSuperSetSignatures() { |
| 5134 | prepareForBackupTest(); |
| 5135 | |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 5136 | // Change package signatures. |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5137 | addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 1, "sigx", CALLING_PACKAGE_1); |
| 5138 | addPackage(LAUNCHER_1, LAUNCHER_UID_1, 4, LAUNCHER_1, "sigy"); |
| 5139 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5140 | checkBackupAndRestore_success(/*firstRestore=*/ true); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5141 | } |
| 5142 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5143 | protected void checkBackupAndRestore_success(boolean firstRestore) { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5144 | // Make sure non-system user is not restored. |
| 5145 | final ShortcutUser userP0 = mService.getUserShortcutsLocked(USER_P0); |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 5146 | assertEquals(0, userP0.getAllPackagesForTest().size()); |
| 5147 | assertEquals(0, userP0.getAllLaunchersForTest().size()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5148 | |
| 5149 | // Make sure only "allowBackup" apps are restored, and are shadow. |
| 5150 | final ShortcutUser user0 = mService.getUserShortcutsLocked(USER_0); |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 5151 | assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_1)); |
| 5152 | assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_2)); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5153 | |
| 5154 | assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_3)); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5155 | assertExistsAndShadow(user0.getAllLaunchersForTest().get( |
| 5156 | PackageWithUser.of(USER_0, LAUNCHER_1))); |
| 5157 | assertExistsAndShadow(user0.getAllLaunchersForTest().get( |
| 5158 | PackageWithUser.of(USER_0, LAUNCHER_2))); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5159 | |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 5160 | assertNull(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_0, LAUNCHER_3))); |
| 5161 | assertNull(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_P0, LAUNCHER_1))); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5162 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5163 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe(any(byte[].class), |
| 5164 | anyString()); |
| 5165 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5166 | installPackage(USER_0, CALLING_PACKAGE_1); |
| 5167 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5168 | assertWith(getCallerVisibleShortcuts()) |
| 5169 | .selectDynamic() |
| 5170 | .isEmpty() |
| 5171 | |
| 5172 | .revertToOriginalList() |
| 5173 | .selectPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5174 | .haveIds("s1", "s2") |
| 5175 | .areAllEnabled(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5176 | }); |
| 5177 | |
| 5178 | installPackage(USER_0, LAUNCHER_1); |
| 5179 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5180 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5181 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5182 | .haveIds("s1") |
| 5183 | .areAllEnabled(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5184 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5185 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5186 | .isEmpty(); |
| 5187 | |
| 5188 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5189 | .isEmpty(); |
| 5190 | |
| 5191 | assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) |
| 5192 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5193 | }); |
| 5194 | |
| 5195 | installPackage(USER_0, CALLING_PACKAGE_2); |
| 5196 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5197 | assertWith(getCallerVisibleShortcuts()) |
| 5198 | .selectDynamic() |
| 5199 | .isEmpty() |
| 5200 | |
| 5201 | .revertToOriginalList() |
| 5202 | .selectPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5203 | .haveIds("s1", "s2", "s3") |
| 5204 | .areAllEnabled(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5205 | }); |
| 5206 | |
| 5207 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5208 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5209 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5210 | .haveIds("s1") |
| 5211 | .areAllEnabled(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5212 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5213 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5214 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5215 | .haveIds("s1", "s2") |
| 5216 | .areAllEnabled(); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5217 | |
| 5218 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5219 | .isEmpty(); |
| 5220 | |
| 5221 | assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) |
| 5222 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5223 | }); |
| 5224 | |
| 5225 | // 3 shouldn't be backed up, so no pinned shortcuts. |
| 5226 | installPackage(USER_0, CALLING_PACKAGE_3); |
| 5227 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5228 | assertWith(getCallerVisibleShortcuts()) |
| 5229 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5230 | }); |
| 5231 | |
| 5232 | // Launcher on a different profile shouldn't be restored. |
| 5233 | runWithCaller(LAUNCHER_1, USER_P0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5234 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5235 | .isEmpty(); |
| 5236 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5237 | .isEmpty(); |
| 5238 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5239 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5240 | }); |
| 5241 | |
| 5242 | // Package on a different profile, no restore. |
| 5243 | installPackage(USER_P0, CALLING_PACKAGE_1); |
| 5244 | runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5245 | assertWith(getCallerVisibleShortcuts()) |
| 5246 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5247 | }); |
| 5248 | |
| 5249 | // Restore launcher 2 on user 0. |
| 5250 | installPackage(USER_0, LAUNCHER_2); |
| 5251 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5252 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5253 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5254 | .haveIds("s2") |
| 5255 | .areAllEnabled(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5256 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5257 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5258 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5259 | .haveIds("s2", "s3") |
| 5260 | .areAllEnabled(); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5261 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5262 | if (firstRestore) { |
| 5263 | assertWith( |
| 5264 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5265 | .haveIds("s2", "s3", "s4") |
| 5266 | .areAllDisabled() |
| 5267 | .areAllPinned() |
| 5268 | .areAllNotDynamic() |
| 5269 | .areAllWithDisabledReason( |
| 5270 | ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED); |
| 5271 | } else { |
| 5272 | assertWith( |
| 5273 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5274 | .isEmpty(); |
| 5275 | } |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5276 | |
| 5277 | assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) |
| 5278 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5279 | }); |
| 5280 | |
| 5281 | |
| 5282 | // Restoration of launcher2 shouldn't affect other packages; so do the same checks and |
| 5283 | // make sure they still have the same result. |
| 5284 | installPackage(USER_0, CALLING_PACKAGE_1); |
| 5285 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5286 | assertWith(getCallerVisibleShortcuts()) |
| 5287 | .areAllPinned() |
| 5288 | .haveIds("s1", "s2"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5289 | }); |
| 5290 | |
| 5291 | installPackage(USER_0, LAUNCHER_1); |
| 5292 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5293 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5294 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5295 | .haveIds("s1") |
| 5296 | .areAllEnabled(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5297 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5298 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5299 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5300 | .haveIds("s1", "s2") |
| 5301 | .areAllEnabled(); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5302 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5303 | if (firstRestore) { |
| 5304 | assertWith( |
| 5305 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5306 | .haveIds("s1", "s2", "s3") |
| 5307 | .areAllDisabled() |
| 5308 | .areAllPinned() |
| 5309 | .areAllNotDynamic() |
| 5310 | .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED); |
| 5311 | } else { |
| 5312 | assertWith( |
| 5313 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5314 | .isEmpty(); |
| 5315 | } |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5316 | |
| 5317 | assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) |
| 5318 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5319 | }); |
| 5320 | |
| 5321 | installPackage(USER_0, CALLING_PACKAGE_2); |
| 5322 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5323 | assertWith(getCallerVisibleShortcuts()) |
| 5324 | .areAllPinned() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5325 | .haveIds("s1", "s2", "s3") |
| 5326 | .areAllEnabled(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5327 | }); |
| 5328 | } |
| 5329 | |
| 5330 | public void testBackupAndRestore_publisherLowerVersion() { |
| 5331 | prepareForBackupTest(); |
| 5332 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5333 | addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 0); // Lower version |
| 5334 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5335 | checkBackupAndRestore_publisherNotRestored(ShortcutInfo.DISABLED_REASON_VERSION_LOWER); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | public void testBackupAndRestore_publisherWrongSignature() { |
| 5339 | prepareForBackupTest(); |
| 5340 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5341 | addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 10, "sigx"); // different signature |
| 5342 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5343 | checkBackupAndRestore_publisherNotRestored(ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5344 | } |
| 5345 | |
| 5346 | public void testBackupAndRestore_publisherNoLongerBackupTarget() { |
| 5347 | prepareForBackupTest(); |
| 5348 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5349 | updatePackageInfo(CALLING_PACKAGE_1, |
| 5350 | pi -> pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_ALLOW_BACKUP); |
| 5351 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5352 | checkBackupAndRestore_publisherNotRestored( |
| 5353 | ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5354 | } |
| 5355 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5356 | protected void checkBackupAndRestore_publisherNotRestored( |
| 5357 | int package1DisabledReason) { |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5358 | doReturn(package1DisabledReason != ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH).when( |
| 5359 | mMockPackageManagerInternal).isDataRestoreSafe(any(byte[].class), |
| 5360 | eq(CALLING_PACKAGE_1)); |
| 5361 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5362 | installPackage(USER_0, CALLING_PACKAGE_1); |
| 5363 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5364 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5365 | assertEquals(0, mManager.getPinnedShortcuts().size()); |
| 5366 | }); |
Makoto Onuki | fac592f | 2016-11-21 13:41:32 -0800 | [diff] [blame] | 5367 | assertFalse(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, USER_0) |
| 5368 | .getPackageInfo().isShadow()); |
| 5369 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5370 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe( |
| 5371 | any(byte[].class), anyString()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5372 | |
| 5373 | installPackage(USER_0, CALLING_PACKAGE_2); |
| 5374 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 5375 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5376 | assertShortcutIds(assertAllPinned( |
| 5377 | mManager.getPinnedShortcuts()), |
| 5378 | "s1", "s2", "s3"); |
| 5379 | }); |
Makoto Onuki | fac592f | 2016-11-21 13:41:32 -0800 | [diff] [blame] | 5380 | assertFalse(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, USER_0) |
| 5381 | .getPackageInfo().isShadow()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5382 | |
| 5383 | installPackage(USER_0, LAUNCHER_1); |
| 5384 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5385 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5386 | .haveIds("s1") |
| 5387 | .areAllPinned() |
| 5388 | .areAllDisabled() |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 5389 | .areAllWithDisabledReason(package1DisabledReason) |
| 5390 | .forAllShortcuts(si -> { |
| 5391 | switch (package1DisabledReason) { |
| 5392 | case ShortcutInfo.DISABLED_REASON_VERSION_LOWER: |
Makoto Onuki | 7eb8b95 | 2018-02-01 11:31:03 -0800 | [diff] [blame] | 5393 | assertEquals("App version downgraded, or isn’t compatible" |
| 5394 | + " with this shortcut", |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 5395 | si.getDisabledMessage()); |
| 5396 | break; |
| 5397 | case ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH: |
| 5398 | assertEquals( |
| 5399 | "Couldn\u2019t restore shortcut because of app" |
| 5400 | + " signature mismatch", |
| 5401 | si.getDisabledMessage()); |
| 5402 | break; |
| 5403 | case ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED: |
| 5404 | assertEquals( |
| 5405 | "Couldn\u2019t restore shortcut because app" |
| 5406 | + " doesn\u2019t support backup and restore", |
| 5407 | si.getDisabledMessage()); |
| 5408 | break; |
| 5409 | default: |
| 5410 | fail("Unhandled disabled reason: " + package1DisabledReason); |
| 5411 | } |
| 5412 | }); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5413 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5414 | .haveIds("s1", "s2") |
| 5415 | .areAllPinned() |
| 5416 | .areAllEnabled(); |
| 5417 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5418 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5419 | }); |
| 5420 | installPackage(USER_0, LAUNCHER_2); |
| 5421 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5422 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5423 | .haveIds("s2") |
| 5424 | .areAllPinned() |
| 5425 | .areAllDisabled() |
| 5426 | .areAllWithDisabledReason(package1DisabledReason); |
| 5427 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5428 | .haveIds("s2", "s3") |
| 5429 | .areAllPinned() |
| 5430 | .areAllEnabled(); |
| 5431 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5432 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5433 | }); |
| 5434 | |
| 5435 | installPackage(USER_0, CALLING_PACKAGE_3); |
| 5436 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 5437 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5438 | assertEquals(0, mManager.getPinnedShortcuts().size()); |
| 5439 | }); |
| 5440 | |
| 5441 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5442 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5443 | .haveIds("s1") |
| 5444 | .areAllPinned() |
| 5445 | .areAllDisabled() |
| 5446 | .areAllWithDisabledReason(package1DisabledReason); |
| 5447 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5448 | .haveIds("s1", "s2") |
| 5449 | .areAllPinned() |
| 5450 | .areAllEnabled(); |
| 5451 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5452 | .haveIds("s1", "s2", "s3") |
| 5453 | .areAllPinned() |
| 5454 | .areAllDisabled() |
| 5455 | .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5456 | }); |
| 5457 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5458 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5459 | .haveIds("s2") |
| 5460 | .areAllPinned() |
| 5461 | .areAllDisabled() |
| 5462 | .areAllWithDisabledReason(package1DisabledReason); |
| 5463 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5464 | .haveIds("s2", "s3") |
| 5465 | .areAllPinned() |
| 5466 | .areAllEnabled(); |
| 5467 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5468 | .haveIds("s2", "s3", "s4") |
| 5469 | .areAllPinned() |
| 5470 | .areAllDisabled() |
| 5471 | .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5472 | }); |
| 5473 | } |
| 5474 | |
| 5475 | public void testBackupAndRestore_launcherLowerVersion() { |
| 5476 | prepareForBackupTest(); |
| 5477 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5478 | addPackage(LAUNCHER_1, LAUNCHER_UID_1, 0); // Lower version |
| 5479 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5480 | // Note, we restore pinned shortcuts even if the launcher is of a lower version. |
| 5481 | checkBackupAndRestore_success(/*firstRestore=*/ true); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | public void testBackupAndRestore_launcherWrongSignature() { |
| 5485 | prepareForBackupTest(); |
| 5486 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5487 | addPackage(LAUNCHER_1, LAUNCHER_UID_1, 10, "sigx"); // different signature |
| 5488 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5489 | checkBackupAndRestore_launcherNotRestored(true); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | public void testBackupAndRestore_launcherNoLongerBackupTarget() { |
| 5493 | prepareForBackupTest(); |
| 5494 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5495 | updatePackageInfo(LAUNCHER_1, |
| 5496 | pi -> pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_ALLOW_BACKUP); |
| 5497 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5498 | checkBackupAndRestore_launcherNotRestored(false); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5499 | } |
| 5500 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5501 | protected void checkBackupAndRestore_launcherNotRestored(boolean differentSignatures) { |
| 5502 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe( |
| 5503 | any(byte[].class), anyString()); |
| 5504 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5505 | installPackage(USER_0, CALLING_PACKAGE_1); |
| 5506 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5507 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5508 | |
| 5509 | // s1 was pinned by launcher 1, which is not restored, yet, so we still see "s1" here. |
| 5510 | assertShortcutIds(assertAllPinned( |
| 5511 | mManager.getPinnedShortcuts()), |
| 5512 | "s1", "s2"); |
| 5513 | }); |
| 5514 | |
| 5515 | installPackage(USER_0, CALLING_PACKAGE_2); |
| 5516 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 5517 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5518 | assertShortcutIds(assertAllPinned( |
| 5519 | mManager.getPinnedShortcuts()), |
| 5520 | "s1", "s2", "s3"); |
| 5521 | }); |
| 5522 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5523 | doReturn(!differentSignatures).when(mMockPackageManagerInternal).isDataRestoreSafe( |
| 5524 | any(byte[].class), eq(LAUNCHER_1)); |
| 5525 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5526 | // Now we try to restore launcher 1. Then we realize it's not restorable, so L1 has no pinned |
| 5527 | // shortcuts. |
| 5528 | installPackage(USER_0, LAUNCHER_1); |
| 5529 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5530 | assertShortcutIds(assertAllPinned( |
| 5531 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5532 | /* empty */); |
| 5533 | assertShortcutIds(assertAllPinned( |
| 5534 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5535 | /* empty */); |
| 5536 | assertShortcutIds(assertAllPinned( |
| 5537 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5538 | /* empty */); |
| 5539 | }); |
Makoto Onuki | fac592f | 2016-11-21 13:41:32 -0800 | [diff] [blame] | 5540 | assertFalse(mService.getLauncherShortcutForTest(LAUNCHER_1, USER_0) |
| 5541 | .getPackageInfo().isShadow()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5542 | |
| 5543 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5544 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5545 | |
| 5546 | // Now CALLING_PACKAGE_1 realizes "s1" is no longer pinned. |
| 5547 | assertShortcutIds(assertAllPinned( |
| 5548 | mManager.getPinnedShortcuts()), |
| 5549 | "s2"); |
| 5550 | }); |
| 5551 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5552 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe( |
| 5553 | any(byte[].class), anyString()); |
| 5554 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5555 | installPackage(USER_0, LAUNCHER_2); |
| 5556 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
| 5557 | assertShortcutIds(assertAllPinned( |
| 5558 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)), |
| 5559 | "s2"); |
| 5560 | assertShortcutIds(assertAllPinned( |
| 5561 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)), |
| 5562 | "s2", "s3"); |
| 5563 | assertShortcutIds(assertAllPinned( |
| 5564 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5565 | /* empty */); |
| 5566 | }); |
Makoto Onuki | fac592f | 2016-11-21 13:41:32 -0800 | [diff] [blame] | 5567 | assertFalse(mService.getLauncherShortcutForTest(LAUNCHER_2, USER_0) |
| 5568 | .getPackageInfo().isShadow()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5569 | |
| 5570 | installPackage(USER_0, CALLING_PACKAGE_3); |
| 5571 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 5572 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5573 | assertEquals(0, mManager.getPinnedShortcuts().size()); |
| 5574 | }); |
| 5575 | |
| 5576 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5577 | assertShortcutIds(assertAllPinned( |
| 5578 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5579 | /* empty */); |
| 5580 | assertShortcutIds(assertAllPinned( |
| 5581 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5582 | /* empty */); |
| 5583 | assertShortcutIds(assertAllPinned( |
| 5584 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5585 | /* empty */); |
| 5586 | }); |
| 5587 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
| 5588 | assertShortcutIds(assertAllPinned( |
| 5589 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)), |
| 5590 | "s2"); |
| 5591 | assertShortcutIds(assertAllPinned( |
| 5592 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)), |
| 5593 | "s2", "s3"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5594 | }); |
| 5595 | } |
| 5596 | |
| 5597 | public void testBackupAndRestore_launcherAndPackageNoLongerBackupTarget() { |
| 5598 | prepareForBackupTest(); |
| 5599 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5600 | updatePackageInfo(CALLING_PACKAGE_1, |
| 5601 | pi -> pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_ALLOW_BACKUP); |
| 5602 | |
| 5603 | updatePackageInfo(LAUNCHER_1, |
| 5604 | pi -> pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_ALLOW_BACKUP); |
| 5605 | |
| 5606 | checkBackupAndRestore_publisherAndLauncherNotRestored(); |
| 5607 | } |
| 5608 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 5609 | protected void checkBackupAndRestore_publisherAndLauncherNotRestored() { |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5610 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe(any(byte[].class), |
| 5611 | anyString()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5612 | installPackage(USER_0, CALLING_PACKAGE_1); |
| 5613 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5614 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5615 | assertEquals(0, mManager.getPinnedShortcuts().size()); |
| 5616 | }); |
| 5617 | |
| 5618 | installPackage(USER_0, CALLING_PACKAGE_2); |
| 5619 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 5620 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5621 | assertShortcutIds(assertAllPinned( |
| 5622 | mManager.getPinnedShortcuts()), |
| 5623 | "s1", "s2", "s3"); |
| 5624 | }); |
| 5625 | |
| 5626 | installPackage(USER_0, LAUNCHER_1); |
| 5627 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5628 | assertShortcutIds(assertAllPinned( |
| 5629 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5630 | /* empty */); |
| 5631 | assertShortcutIds(assertAllPinned( |
| 5632 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5633 | /* empty */); |
| 5634 | assertShortcutIds(assertAllPinned( |
| 5635 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5636 | /* empty */); |
| 5637 | }); |
| 5638 | installPackage(USER_0, LAUNCHER_2); |
| 5639 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5640 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5641 | .areAllPinned() |
| 5642 | .haveIds("s2") |
| 5643 | .areAllDisabled(); |
| 5644 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5645 | .areAllPinned() |
| 5646 | .haveIds("s2", "s3"); |
| 5647 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5648 | .isEmpty(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5649 | }); |
| 5650 | |
| 5651 | // Because launcher 1 wasn't restored, "s1" is no longer pinned. |
| 5652 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 5653 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5654 | assertShortcutIds(assertAllPinned( |
| 5655 | mManager.getPinnedShortcuts()), |
| 5656 | "s2", "s3"); |
| 5657 | }); |
| 5658 | |
| 5659 | installPackage(USER_0, CALLING_PACKAGE_3); |
| 5660 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 5661 | assertEquals(0, mManager.getDynamicShortcuts().size()); |
| 5662 | assertEquals(0, mManager.getPinnedShortcuts().size()); |
| 5663 | }); |
| 5664 | |
| 5665 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5666 | assertShortcutIds(assertAllPinned( |
| 5667 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5668 | /* empty */); |
| 5669 | assertShortcutIds(assertAllPinned( |
| 5670 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5671 | /* empty */); |
| 5672 | assertShortcutIds(assertAllPinned( |
| 5673 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5674 | /* empty */); |
| 5675 | }); |
| 5676 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5677 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5678 | .areAllPinned() |
| 5679 | .haveIds("s2") |
| 5680 | .areAllDisabled(); |
| 5681 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5682 | .areAllPinned() |
| 5683 | .haveIds("s2", "s3"); |
| 5684 | assertWith( |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5685 | mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5686 | .haveIds("s2", "s3", "s4") |
| 5687 | .areAllDisabled() |
| 5688 | .areAllPinned() |
| 5689 | .areAllNotDynamic() |
| 5690 | .areAllWithDisabledReason( |
| 5691 | ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 5692 | }); |
| 5693 | } |
| 5694 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5695 | public void testBackupAndRestore_disabled() { |
| 5696 | prepareCrossProfileDataSet(); |
| 5697 | |
| 5698 | // Before doing backup & restore, disable s1. |
| 5699 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5700 | mManager.disableShortcuts(list("s1")); |
| 5701 | }); |
| 5702 | |
| 5703 | backupAndRestore(); |
| 5704 | |
| 5705 | // Below is copied from checkBackupAndRestore_success. |
| 5706 | |
| 5707 | // Make sure non-system user is not restored. |
| 5708 | final ShortcutUser userP0 = mService.getUserShortcutsLocked(USER_P0); |
| 5709 | assertEquals(0, userP0.getAllPackagesForTest().size()); |
| 5710 | assertEquals(0, userP0.getAllLaunchersForTest().size()); |
| 5711 | |
| 5712 | // Make sure only "allowBackup" apps are restored, and are shadow. |
| 5713 | final ShortcutUser user0 = mService.getUserShortcutsLocked(USER_0); |
| 5714 | assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_1)); |
| 5715 | assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_2)); |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5716 | assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_3)); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5717 | assertExistsAndShadow(user0.getAllLaunchersForTest().get( |
| 5718 | PackageWithUser.of(USER_0, LAUNCHER_1))); |
| 5719 | assertExistsAndShadow(user0.getAllLaunchersForTest().get( |
| 5720 | PackageWithUser.of(USER_0, LAUNCHER_2))); |
| 5721 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5722 | assertNull(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_0, LAUNCHER_3))); |
| 5723 | assertNull(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_P0, LAUNCHER_1))); |
| 5724 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5725 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe(any(byte[].class), |
| 5726 | anyString()); |
| 5727 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5728 | installPackage(USER_0, CALLING_PACKAGE_1); |
| 5729 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5730 | assertWith(getCallerVisibleShortcuts()) |
| 5731 | .areAllEnabled() // disabled shortcuts shouldn't be restored. |
| 5732 | |
| 5733 | .selectDynamic() |
| 5734 | .isEmpty() |
| 5735 | |
| 5736 | .revertToOriginalList() |
| 5737 | .selectPinned() |
| 5738 | // s1 is not restored. |
| 5739 | .haveIds("s2"); |
| 5740 | }); |
| 5741 | |
| 5742 | installPackage(USER_0, LAUNCHER_1); |
| 5743 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5744 | // Note, s1 was pinned by launcher 1, but was disabled, so isn't restored. |
| 5745 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) |
| 5746 | .isEmpty(); |
| 5747 | |
| 5748 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) |
| 5749 | .isEmpty(); |
| 5750 | |
| 5751 | assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) |
| 5752 | .isEmpty(); |
| 5753 | |
| 5754 | assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) |
| 5755 | .isEmpty(); |
| 5756 | }); |
| 5757 | } |
| 5758 | |
| 5759 | |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5760 | public void testBackupAndRestore_manifestRePublished() { |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5761 | // Publish two manifest shortcuts. |
| 5762 | addManifestShortcutResource( |
| 5763 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 5764 | R.xml.shortcut_2); |
| 5765 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 5766 | mService.mPackageMonitor.onReceive(mServiceContext, |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5767 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 5768 | |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5769 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5770 | assertTrue(mManager.setDynamicShortcuts(list( |
| 5771 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 5772 | }); |
| 5773 | |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5774 | // Pin from launcher 1. |
| 5775 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5776 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 5777 | list("ms1", "ms2", "s1", "s2"), HANDLE_USER_0); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5778 | }); |
| 5779 | |
| 5780 | // Update and now ms2 is gone -> disabled. |
| 5781 | addManifestShortcutResource( |
| 5782 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 5783 | R.xml.shortcut_1); |
| 5784 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 5785 | mService.mPackageMonitor.onReceive(mServiceContext, |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5786 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 5787 | |
| 5788 | // Make sure the manifest shortcuts have been published. |
| 5789 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5790 | assertWith(getCallerShortcuts()) |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5791 | .selectManifest() |
| 5792 | .haveIds("ms1") |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5793 | |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5794 | .revertToOriginalList() |
| 5795 | .selectDynamic() |
| 5796 | .haveIds("s1", "s2", "s3") |
| 5797 | |
| 5798 | .revertToOriginalList() |
| 5799 | .selectPinned() |
| 5800 | .haveIds("ms1", "ms2", "s1", "s2") |
| 5801 | |
| 5802 | .revertToOriginalList() |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5803 | .selectByIds("ms1") |
| 5804 | .areAllManifest() |
| 5805 | .areAllEnabled() |
| 5806 | |
| 5807 | .revertToOriginalList() |
| 5808 | .selectByIds("ms2") |
| 5809 | .areAllNotManifest() |
| 5810 | .areAllDisabled(); |
| 5811 | }); |
| 5812 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5813 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe( |
| 5814 | any(byte[].class), anyString()); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5815 | backupAndRestore(); |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5816 | |
| 5817 | // When re-installing the app, the manifest shortcut should be re-published. |
| 5818 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 5819 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 5820 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 5821 | genPackageAddIntent(LAUNCHER_1, USER_0)); |
| 5822 | |
| 5823 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5824 | assertWith(getCallerVisibleShortcuts()) |
| 5825 | .selectPinned() |
| 5826 | // ms2 was disabled, so not restored. |
| 5827 | .haveIds("ms1", "s1", "s2") |
| 5828 | .areAllEnabled() |
| 5829 | |
| 5830 | .revertToOriginalList() |
| 5831 | .selectByIds("ms1") |
| 5832 | .areAllManifest() |
| 5833 | |
| 5834 | .revertToOriginalList() |
| 5835 | .selectByIds("s1", "s2") |
| 5836 | .areAllNotDynamic() |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5837 | ; |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5838 | }); |
| 5839 | } |
| 5840 | |
| 5841 | /** |
| 5842 | * It's the case with preintalled apps -- when applyRestore() is called, the system |
| 5843 | * apps are already installed, so manifest shortcuts need to be re-published. |
Makoto Onuki | fc4cf2d | 2016-08-24 11:10:26 -0700 | [diff] [blame] | 5844 | * |
| 5845 | * Also, when a restore target app is already installed, and |
| 5846 | * - if it has allowBackup=true, we'll restore normally, so all existing shortcuts will be |
| 5847 | * replaced. (but manifest shortcuts will be re-published anyway.) We log a warning on |
| 5848 | * logcat. |
| 5849 | * - if it has allowBackup=false, we don't touch any of the existing shortcuts. |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5850 | */ |
| 5851 | public void testBackupAndRestore_appAlreadyInstalledWhenRestored() { |
| 5852 | // Pre-backup. Same as testBackupAndRestore_manifestRePublished(). |
| 5853 | |
| 5854 | // Publish two manifest shortcuts. |
| 5855 | addManifestShortcutResource( |
| 5856 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 5857 | R.xml.shortcut_2); |
| 5858 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 5859 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 5860 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 5861 | |
| 5862 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5863 | assertTrue(mManager.setDynamicShortcuts(list( |
| 5864 | makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); |
| 5865 | }); |
| 5866 | |
| 5867 | // Pin from launcher 1. |
| 5868 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5869 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 5870 | list("ms1", "ms2", "s1", "s2"), HANDLE_USER_0); |
| 5871 | }); |
| 5872 | |
| 5873 | // Update and now ms2 is gone -> disabled. |
| 5874 | addManifestShortcutResource( |
| 5875 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 5876 | R.xml.shortcut_1); |
| 5877 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 5878 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 5879 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 5880 | |
Makoto Onuki | fc4cf2d | 2016-08-24 11:10:26 -0700 | [diff] [blame] | 5881 | // Set up shortcuts for package 3, which won't be backed up / restored. |
| 5882 | addManifestShortcutResource( |
| 5883 | new ComponentName(CALLING_PACKAGE_3, ShortcutActivity.class.getName()), |
| 5884 | R.xml.shortcut_1); |
| 5885 | updatePackageVersion(CALLING_PACKAGE_3, 1); |
| 5886 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 5887 | genPackageAddIntent(CALLING_PACKAGE_3, USER_0)); |
| 5888 | |
| 5889 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 5890 | assertTrue(getManager().setDynamicShortcuts(list( |
| 5891 | makeShortcut("s1")))); |
| 5892 | }); |
| 5893 | |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5894 | // Make sure the manifest shortcuts have been published. |
| 5895 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5896 | assertWith(getCallerShortcuts()) |
| 5897 | .selectManifest() |
| 5898 | .haveIds("ms1") |
| 5899 | |
| 5900 | .revertToOriginalList() |
| 5901 | .selectDynamic() |
| 5902 | .haveIds("s1", "s2", "s3") |
| 5903 | |
| 5904 | .revertToOriginalList() |
| 5905 | .selectPinned() |
| 5906 | .haveIds("ms1", "ms2", "s1", "s2") |
| 5907 | |
| 5908 | .revertToOriginalList() |
| 5909 | .selectByIds("ms1") |
| 5910 | .areAllManifest() |
| 5911 | .areAllEnabled() |
| 5912 | |
| 5913 | .revertToOriginalList() |
| 5914 | .selectByIds("ms2") |
| 5915 | .areAllNotManifest() |
| 5916 | .areAllDisabled(); |
| 5917 | }); |
| 5918 | |
Makoto Onuki | fc4cf2d | 2016-08-24 11:10:26 -0700 | [diff] [blame] | 5919 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 5920 | assertWith(getCallerShortcuts()) |
| 5921 | .haveIds("s1", "ms1"); |
| 5922 | }); |
| 5923 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5924 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe(any(byte[].class), |
| 5925 | anyString()); |
Makoto Onuki | 377b797 | 2016-08-09 14:43:55 -0700 | [diff] [blame] | 5926 | // Backup and *without restarting the service, just call applyRestore()*. |
| 5927 | { |
| 5928 | int prevUid = mInjectedCallingUid; |
| 5929 | mInjectedCallingUid = Process.SYSTEM_UID; // Only system can call it. |
| 5930 | |
| 5931 | dumpsysOnLogcat("Before backup"); |
| 5932 | |
| 5933 | final byte[] payload = mService.getBackupPayload(USER_0); |
| 5934 | if (ENABLE_DUMP) { |
| 5935 | final String xml = new String(payload); |
| 5936 | Log.v(TAG, "Backup payload:"); |
| 5937 | for (String line : xml.split("\n")) { |
| 5938 | Log.v(TAG, line); |
| 5939 | } |
| 5940 | } |
| 5941 | mService.applyRestore(payload, USER_0); |
| 5942 | |
| 5943 | dumpsysOnLogcat("After restore"); |
| 5944 | |
| 5945 | mInjectedCallingUid = prevUid; |
| 5946 | } |
| 5947 | |
| 5948 | // The check is also the same as testBackupAndRestore_manifestRePublished(). |
| 5949 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5950 | assertWith(getCallerVisibleShortcuts()) |
| 5951 | .selectPinned() |
| 5952 | // ms2 was disabled, so not restored. |
| 5953 | .haveIds("ms1", "s1", "s2") |
| 5954 | .areAllEnabled() |
| 5955 | |
| 5956 | .revertToOriginalList() |
| 5957 | .selectByIds("ms1") |
| 5958 | .areAllManifest() |
| 5959 | |
| 5960 | .revertToOriginalList() |
| 5961 | .selectByIds("s1", "s2") |
| 5962 | .areAllNotDynamic() |
| 5963 | ; |
| 5964 | }); |
Makoto Onuki | fc4cf2d | 2016-08-24 11:10:26 -0700 | [diff] [blame] | 5965 | |
| 5966 | // Package 3 still has the same shortcuts. |
| 5967 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 5968 | assertWith(getCallerShortcuts()) |
| 5969 | .haveIds("s1", "ms1"); |
| 5970 | }); |
Makoto Onuki | f3ba2e0 | 2016-07-12 09:18:50 -0700 | [diff] [blame] | 5971 | } |
| 5972 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 5973 | |
| 5974 | /** |
| 5975 | * Restored to a lower version with no manifest shortcuts. All shortcuts are now invisible, |
| 5976 | * and all calls from the publisher should ignore them. |
| 5977 | */ |
| 5978 | public void testBackupAndRestore_disabledShortcutsAreIgnored() { |
| 5979 | // Publish two manifest shortcuts. |
| 5980 | addManifestShortcutResource( |
| 5981 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 5982 | R.xml.shortcut_5_altalt); |
| 5983 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 5984 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 5985 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 5986 | |
| 5987 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 5988 | assertTrue(mManager.setDynamicShortcuts(list( |
| 5989 | makeShortcutWithShortLabel("s1", "original-title"), |
| 5990 | makeShortcut("s2"), makeShortcut("s3")))); |
| 5991 | }); |
| 5992 | |
| 5993 | // Pin from launcher 1. |
| 5994 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 5995 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 5996 | list("ms1", "ms2", "ms3", "ms4", "s1", "s2"), HANDLE_USER_0); |
| 5997 | }); |
| 5998 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 5999 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe( |
| 6000 | any(byte[].class), anyString()); |
| 6001 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 6002 | backupAndRestore(); |
| 6003 | |
| 6004 | // Lower the version and remove the manifest shortcuts. |
| 6005 | addManifestShortcutResource( |
| 6006 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 6007 | R.xml.shortcut_0); |
| 6008 | addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 0); // Lower version |
| 6009 | |
| 6010 | // When re-installing the app, the manifest shortcut should be re-published. |
| 6011 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 6012 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 6013 | mService.mPackageMonitor.onReceive(mServiceContext, |
| 6014 | genPackageAddIntent(LAUNCHER_1, USER_0)); |
| 6015 | |
| 6016 | // No shortcuts should be visible to the publisher. |
| 6017 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6018 | assertWith(getCallerVisibleShortcuts()) |
| 6019 | .isEmpty(); |
| 6020 | }); |
| 6021 | |
| 6022 | final Runnable checkAllDisabledForLauncher = () -> { |
| 6023 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6024 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6025 | .areAllPinned() |
| 6026 | .haveIds("ms1", "ms2", "ms3", "ms4", "s1", "s2") |
| 6027 | .areAllDisabled() |
| 6028 | .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_VERSION_LOWER) |
| 6029 | |
| 6030 | .forShortcutWithId("s1", si -> { |
| 6031 | assertEquals("original-title", si.getShortLabel()); |
| 6032 | }) |
| 6033 | .forShortcutWithId("ms1", si -> { |
| 6034 | assertEquals("string-com.android.test.1-user:0-res:" |
| 6035 | + R.string.shortcut_title1 + "/en" |
| 6036 | , si.getShortLabel()); |
| 6037 | }) |
| 6038 | .forShortcutWithId("ms2", si -> { |
| 6039 | assertEquals("string-com.android.test.1-user:0-res:" |
| 6040 | + R.string.shortcut_title2 + "/en" |
| 6041 | , si.getShortLabel()); |
| 6042 | }) |
| 6043 | .forShortcutWithId("ms3", si -> { |
| 6044 | assertEquals("string-com.android.test.1-user:0-res:" |
| 6045 | + R.string.shortcut_title1 + "/en" |
| 6046 | , si.getShortLabel()); |
| 6047 | assertEquals("string-com.android.test.1-user:0-res:" |
| 6048 | + R.string.shortcut_title2 + "/en" |
| 6049 | , si.getLongLabel()); |
| 6050 | }) |
| 6051 | .forShortcutWithId("ms4", si -> { |
| 6052 | assertEquals("string-com.android.test.1-user:0-res:" |
| 6053 | + R.string.shortcut_title2 + "/en" |
| 6054 | , si.getShortLabel()); |
| 6055 | assertEquals("string-com.android.test.1-user:0-res:" |
| 6056 | + R.string.shortcut_title2 + "/en" |
| 6057 | , si.getLongLabel()); |
| 6058 | }); |
| 6059 | }); |
| 6060 | }; |
| 6061 | |
| 6062 | checkAllDisabledForLauncher.run(); |
| 6063 | |
| 6064 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6065 | |
| 6066 | makeCallerForeground(); // CALLING_PACKAGE_1 is now in the foreground. |
| 6067 | |
| 6068 | // All changing API calls should be ignored. |
| 6069 | |
| 6070 | getManager().enableShortcuts(list("ms1", "ms2", "ms3", "ms4", "s1", "s2")); |
| 6071 | checkAllDisabledForLauncher.run(); |
| 6072 | |
| 6073 | getManager().enableShortcuts(list("ms1", "ms2", "ms3", "ms4", "s1", "s2")); |
| 6074 | checkAllDisabledForLauncher.run(); |
| 6075 | |
| 6076 | getManager().enableShortcuts(list("ms1", "ms2", "ms3", "ms4", "s1", "s2")); |
| 6077 | checkAllDisabledForLauncher.run(); |
| 6078 | |
| 6079 | getManager().removeAllDynamicShortcuts(); |
| 6080 | getManager().removeDynamicShortcuts(list("ms1", "ms2", "ms3", "ms4", "s1", "s2")); |
| 6081 | checkAllDisabledForLauncher.run(); |
| 6082 | |
| 6083 | getManager().updateShortcuts(list(makeShortcutWithShortLabel("s1", "new-title"))); |
| 6084 | checkAllDisabledForLauncher.run(); |
| 6085 | |
| 6086 | |
| 6087 | // Add a shortcut -- even though ms1 was immutable, it will succeed. |
| 6088 | assertTrue(getManager().addDynamicShortcuts(list( |
| 6089 | makeShortcutWithShortLabel("ms1", "original-title")))); |
| 6090 | |
| 6091 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6092 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6093 | .haveIds("ms1", "ms2", "ms3", "ms4", "s1", "s2") |
| 6094 | |
| 6095 | .selectByIds("ms1") |
| 6096 | .areAllEnabled() |
| 6097 | .areAllDynamic() |
| 6098 | .areAllPinned() |
| 6099 | .forAllShortcuts(si -> { |
| 6100 | assertEquals("original-title", si.getShortLabel()); |
| 6101 | }) |
| 6102 | |
| 6103 | // The rest still exist and disabled. |
| 6104 | .revertToOriginalList() |
| 6105 | .selectByIds("ms2", "ms3", "ms4", "s1", "s2") |
| 6106 | .areAllDisabled() |
| 6107 | .areAllPinned() |
| 6108 | ; |
| 6109 | }); |
| 6110 | |
| 6111 | assertTrue(getManager().setDynamicShortcuts(list( |
| 6112 | makeShortcutWithShortLabel("ms2", "new-title-2")))); |
| 6113 | |
| 6114 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6115 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6116 | .haveIds("ms1", "ms2", "ms3", "ms4", "s1", "s2") |
| 6117 | |
| 6118 | .selectByIds("ms1") |
| 6119 | .areAllEnabled() |
| 6120 | .areAllNotDynamic() // ms1 was not in the list, so no longer dynamic. |
| 6121 | .areAllPinned() |
| 6122 | .areAllMutable() |
| 6123 | .forAllShortcuts(si -> { |
| 6124 | assertEquals("original-title", si.getShortLabel()); |
| 6125 | }) |
| 6126 | |
| 6127 | .revertToOriginalList() |
| 6128 | .selectByIds("ms2") |
| 6129 | .areAllEnabled() |
| 6130 | .areAllDynamic() |
| 6131 | .areAllPinned() |
| 6132 | .areAllMutable() |
| 6133 | .forAllShortcuts(si -> { |
| 6134 | assertEquals("new-title-2", si.getShortLabel()); |
| 6135 | }) |
| 6136 | |
| 6137 | // The rest still exist and disabled. |
| 6138 | .revertToOriginalList() |
| 6139 | .selectByIds("ms3", "ms4", "s1", "s2") |
| 6140 | .areAllDisabled() |
| 6141 | .areAllPinned() |
| 6142 | ; |
| 6143 | }); |
| 6144 | |
| 6145 | // Prepare for requestPinShortcut(). |
| 6146 | setDefaultLauncher(USER_0, mMainActivityFetcher.apply(LAUNCHER_1, USER_0)); |
| 6147 | mPinConfirmActivityFetcher = (packageName, userId) -> |
| 6148 | new ComponentName(packageName, PIN_CONFIRM_ACTIVITY_CLASS); |
| 6149 | |
| 6150 | mManager.requestPinShortcut( |
| 6151 | makeShortcutWithShortLabel("ms3", "new-title-3"), |
| 6152 | /*PendingIntent=*/ null); |
| 6153 | |
| 6154 | // Note this was pinned, so it'll be accepted right away. |
| 6155 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6156 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6157 | .selectByIds("ms3") |
| 6158 | .areAllEnabled() |
| 6159 | .areAllNotDynamic() |
| 6160 | .areAllPinned() |
| 6161 | .areAllMutable() |
| 6162 | .forAllShortcuts(si -> { |
| 6163 | assertEquals("new-title-3", si.getShortLabel()); |
| 6164 | // The new one replaces the old manifest shortcut, so the long label |
| 6165 | // should be gone now. |
| 6166 | assertNull(si.getLongLabel()); |
| 6167 | }); |
| 6168 | }); |
| 6169 | |
| 6170 | // Now, change the launcher to launcher2, and request pin again. |
| 6171 | setDefaultLauncher(USER_0, mMainActivityFetcher.apply(LAUNCHER_2, USER_0)); |
| 6172 | |
| 6173 | reset(mServiceContext); |
| 6174 | |
| 6175 | assertTrue(mManager.isRequestPinShortcutSupported()); |
| 6176 | mManager.requestPinShortcut( |
| 6177 | makeShortcutWithShortLabel("ms4", "new-title-4"), |
| 6178 | /*PendingIntent=*/ null); |
| 6179 | |
| 6180 | // Initially there should be no pinned shortcuts for L2. |
| 6181 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
| 6182 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6183 | .selectPinned() |
| 6184 | .isEmpty(); |
| 6185 | |
| 6186 | final ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class); |
| 6187 | |
| 6188 | verify(mServiceContext).startActivityAsUser(intent.capture(), eq(HANDLE_USER_0)); |
| 6189 | |
| 6190 | assertEquals(LauncherApps.ACTION_CONFIRM_PIN_SHORTCUT, |
| 6191 | intent.getValue().getAction()); |
| 6192 | assertEquals(LAUNCHER_2, intent.getValue().getComponent().getPackageName()); |
| 6193 | |
| 6194 | // Check the request object. |
| 6195 | final PinItemRequest request = mLauncherApps.getPinItemRequest(intent.getValue()); |
| 6196 | |
| 6197 | assertNotNull(request); |
| 6198 | assertEquals(PinItemRequest.REQUEST_TYPE_SHORTCUT, request.getRequestType()); |
| 6199 | |
| 6200 | assertWith(request.getShortcutInfo()) |
| 6201 | .haveIds("ms4") |
| 6202 | .areAllOrphan() |
| 6203 | .forAllShortcuts(si -> { |
| 6204 | assertEquals("new-title-4", si.getShortLabel()); |
| 6205 | // The new one replaces the old manifest shortcut, so the long label |
| 6206 | // should be gone now. |
| 6207 | assertNull(si.getLongLabel()); |
| 6208 | }); |
| 6209 | assertTrue(request.accept()); |
| 6210 | |
| 6211 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6212 | .selectPinned() |
| 6213 | .haveIds("ms4") |
| 6214 | .areAllEnabled(); |
| 6215 | }); |
| 6216 | }); |
| 6217 | } |
| 6218 | |
| 6219 | /** |
| 6220 | * Test for restoring the pre-P backup format. |
| 6221 | */ |
| 6222 | public void testBackupAndRestore_api27format() throws Exception { |
| 6223 | final byte[] payload = readTestAsset("shortcut/shortcut_api27_backup.xml").getBytes(); |
| 6224 | |
| 6225 | addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 10, "22222"); |
| 6226 | addPackage(LAUNCHER_1, LAUNCHER_UID_1, 10, "11111"); |
| 6227 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 6228 | doReturn(true).when(mMockPackageManagerInternal).isDataRestoreSafe( |
| 6229 | any(byte[].class), anyString()); |
| 6230 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 6231 | runWithSystemUid(() -> mService.applyRestore(payload, USER_0)); |
| 6232 | |
| 6233 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6234 | assertWith(getCallerShortcuts()) |
| 6235 | .areAllPinned() |
| 6236 | .haveIds("s1") |
| 6237 | .areAllEnabled(); |
| 6238 | }); |
| 6239 | |
| 6240 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6241 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6242 | .areAllPinned() |
| 6243 | .haveIds("s1") |
| 6244 | .areAllEnabled(); |
| 6245 | }); |
| 6246 | // Make sure getBackupSourceVersionCode and isBackupSourceBackupAllowed |
| 6247 | // are correct. We didn't have them in the old format. |
| 6248 | assertEquals(8, mService.getPackageShortcutForTest(CALLING_PACKAGE_1, USER_0) |
| 6249 | .getPackageInfo().getBackupSourceVersionCode()); |
| 6250 | assertTrue(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, USER_0) |
| 6251 | .getPackageInfo().isBackupSourceBackupAllowed()); |
| 6252 | |
| 6253 | assertEquals(9, mService.getLauncherShortcutForTest(LAUNCHER_1, USER_0) |
| 6254 | .getPackageInfo().getBackupSourceVersionCode()); |
| 6255 | assertTrue(mService.getLauncherShortcutForTest(LAUNCHER_1, USER_0) |
| 6256 | .getPackageInfo().isBackupSourceBackupAllowed()); |
| 6257 | |
| 6258 | } |
| 6259 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6260 | public void testSaveAndLoad_crossProfile() { |
| 6261 | prepareCrossProfileDataSet(); |
| 6262 | |
| 6263 | dumpsysOnLogcat("Before save & load"); |
| 6264 | |
| 6265 | mService.saveDirtyInfo(); |
| 6266 | initService(); |
| 6267 | |
| 6268 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6269 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6270 | "s1", "s2", "s3"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6271 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), |
| 6272 | "s1", "s2", "s3", "s4"); |
| 6273 | }); |
| 6274 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6275 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6276 | "s1", "s2", "s3"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6277 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), |
| 6278 | "s1", "s2", "s3", "s4", "s5"); |
| 6279 | }); |
| 6280 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 6281 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6282 | "s1", "s2", "s3"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6283 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), |
| 6284 | "s1", "s2", "s3", "s4", "s5", "s6"); |
| 6285 | }); |
| 6286 | runWithCaller(CALLING_PACKAGE_4, USER_0, () -> { |
| 6287 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()) |
| 6288 | /* empty */); |
| 6289 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()) |
| 6290 | /* empty */); |
| 6291 | }); |
| 6292 | runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> { |
| 6293 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6294 | "s1", "s2", "s3"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6295 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), |
| 6296 | "s1", "s2", "s3", "s4", "s5", "s6"); |
| 6297 | }); |
| 6298 | runWithCaller(CALLING_PACKAGE_2, USER_P0, () -> { |
| 6299 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()) |
| 6300 | /* empty */); |
| 6301 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()) |
| 6302 | /* empty */); |
| 6303 | }); |
| 6304 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 6305 | assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6306 | "x1", "x2", "x3"); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6307 | assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), |
| 6308 | "x4", "x5"); |
| 6309 | }); |
| 6310 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6311 | assertShortcutIds( |
| 6312 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_0), |
| 6313 | "s1"); |
| 6314 | assertShortcutIds( |
| 6315 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_0), |
| 6316 | "s1", "s2"); |
| 6317 | assertShortcutIds( |
| 6318 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_3), HANDLE_USER_0), |
| 6319 | "s1", "s2", "s3"); |
| 6320 | assertShortcutIds( |
| 6321 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_4), HANDLE_USER_0) |
| 6322 | /* empty */); |
| 6323 | assertShortcutIds( |
| 6324 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_P0), |
| 6325 | "s1", "s4"); |
| 6326 | assertShortcutIds( |
| 6327 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_P0) |
| 6328 | /* empty */); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 6329 | assertExpectException( |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6330 | SecurityException.class, "", () -> { |
| 6331 | mLauncherApps.getShortcuts( |
| 6332 | buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_10); |
| 6333 | }); |
| 6334 | }); |
| 6335 | runWithCaller(LAUNCHER_2, USER_0, () -> { |
| 6336 | assertShortcutIds( |
| 6337 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_0), |
| 6338 | "s2"); |
| 6339 | assertShortcutIds( |
| 6340 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_0), |
| 6341 | "s2", "s3"); |
| 6342 | assertShortcutIds( |
| 6343 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_3), HANDLE_USER_0), |
| 6344 | "s2", "s3", "s4"); |
| 6345 | assertShortcutIds( |
| 6346 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_4), HANDLE_USER_0) |
| 6347 | /* empty */); |
| 6348 | assertShortcutIds( |
| 6349 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_P0), |
| 6350 | "s2", "s5"); |
| 6351 | assertShortcutIds( |
| 6352 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_P0) |
| 6353 | /* empty */); |
| 6354 | }); |
| 6355 | runWithCaller(LAUNCHER_3, USER_0, () -> { |
| 6356 | assertShortcutIds( |
| 6357 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_0), |
| 6358 | "s3"); |
| 6359 | assertShortcutIds( |
| 6360 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_0), |
| 6361 | "s3", "s4"); |
| 6362 | assertShortcutIds( |
| 6363 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_3), HANDLE_USER_0), |
| 6364 | "s3", "s4", "s5"); |
| 6365 | assertShortcutIds( |
| 6366 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_4), HANDLE_USER_0) |
| 6367 | /* empty */); |
| 6368 | assertShortcutIds( |
| 6369 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_P0), |
| 6370 | "s3", "s6"); |
| 6371 | assertShortcutIds( |
| 6372 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_P0) |
| 6373 | /* empty */); |
| 6374 | }); |
| 6375 | runWithCaller(LAUNCHER_4, USER_0, () -> { |
| 6376 | assertShortcutIds( |
| 6377 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_0) |
| 6378 | /* empty */); |
| 6379 | assertShortcutIds( |
| 6380 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_0) |
| 6381 | /* empty */); |
| 6382 | assertShortcutIds( |
| 6383 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_3), HANDLE_USER_0) |
| 6384 | /* empty */); |
| 6385 | assertShortcutIds( |
| 6386 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_4), HANDLE_USER_0) |
| 6387 | /* empty */); |
| 6388 | assertShortcutIds( |
| 6389 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_P0) |
| 6390 | /* empty */); |
| 6391 | assertShortcutIds( |
| 6392 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_P0) |
| 6393 | /* empty */); |
| 6394 | }); |
| 6395 | runWithCaller(LAUNCHER_1, USER_P0, () -> { |
| 6396 | assertShortcutIds( |
| 6397 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_0), |
| 6398 | "s3", "s4"); |
| 6399 | assertShortcutIds( |
| 6400 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_0), |
| 6401 | "s3", "s4", "s5"); |
| 6402 | assertShortcutIds( |
| 6403 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_3), HANDLE_USER_0), |
| 6404 | "s3", "s4", "s5", "s6"); |
| 6405 | assertShortcutIds( |
| 6406 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_P0), |
| 6407 | "s1", "s4"); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 6408 | assertExpectException( |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6409 | SecurityException.class, "unrelated profile", () -> { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6410 | mLauncherApps.getShortcuts( |
| 6411 | buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_10); |
| 6412 | }); |
| 6413 | }); |
| 6414 | runWithCaller(LAUNCHER_1, USER_10, () -> { |
| 6415 | assertShortcutIds( |
| 6416 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_1), HANDLE_USER_10), |
| 6417 | "x4", "x5"); |
| 6418 | assertShortcutIds( |
| 6419 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_2), HANDLE_USER_10) |
| 6420 | /* empty */); |
| 6421 | assertShortcutIds( |
| 6422 | mLauncherApps.getShortcuts(buildPinnedQuery(CALLING_PACKAGE_3), HANDLE_USER_10) |
| 6423 | /* empty */); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 6424 | assertExpectException( |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6425 | SecurityException.class, "unrelated profile", () -> { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6426 | mLauncherApps.getShortcuts( |
| 6427 | buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0); |
| 6428 | }); |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 6429 | assertExpectException( |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 6430 | SecurityException.class, "unrelated profile", () -> { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6431 | mLauncherApps.getShortcuts( |
| 6432 | buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_P0); |
| 6433 | }); |
| 6434 | }); |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 6435 | // Check the user-IDs. |
| 6436 | assertEquals(USER_0, |
| 6437 | mService.getUserShortcutsLocked(USER_0).getPackageShortcuts(CALLING_PACKAGE_1) |
| 6438 | .getOwnerUserId()); |
| 6439 | assertEquals(USER_0, |
| 6440 | mService.getUserShortcutsLocked(USER_0).getPackageShortcuts(CALLING_PACKAGE_1) |
| 6441 | .getPackageUserId()); |
| 6442 | assertEquals(USER_P0, |
| 6443 | mService.getUserShortcutsLocked(USER_P0).getPackageShortcuts(CALLING_PACKAGE_1) |
| 6444 | .getOwnerUserId()); |
| 6445 | assertEquals(USER_P0, |
| 6446 | mService.getUserShortcutsLocked(USER_P0).getPackageShortcuts(CALLING_PACKAGE_1) |
| 6447 | .getPackageUserId()); |
| 6448 | |
| 6449 | assertEquals(USER_0, |
| 6450 | mService.getUserShortcutsLocked(USER_0).getLauncherShortcuts(LAUNCHER_1, USER_0) |
| 6451 | .getOwnerUserId()); |
| 6452 | assertEquals(USER_0, |
| 6453 | mService.getUserShortcutsLocked(USER_0).getLauncherShortcuts(LAUNCHER_1, USER_0) |
| 6454 | .getPackageUserId()); |
| 6455 | assertEquals(USER_P0, |
| 6456 | mService.getUserShortcutsLocked(USER_P0).getLauncherShortcuts(LAUNCHER_1, USER_0) |
| 6457 | .getOwnerUserId()); |
| 6458 | assertEquals(USER_0, |
| 6459 | mService.getUserShortcutsLocked(USER_P0).getLauncherShortcuts(LAUNCHER_1, USER_0) |
| 6460 | .getPackageUserId()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6461 | } |
| 6462 | |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 6463 | public void testOnApplicationActive_permission() { |
| 6464 | assertExpectException(SecurityException.class, "Missing permission", () -> |
Makoto Onuki | d6e1f3b | 2016-06-14 11:17:59 -0700 | [diff] [blame] | 6465 | mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0)); |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 6466 | |
| 6467 | // Has permission, now it should pass. |
| 6468 | mCallerPermissions.add(permission.RESET_SHORTCUT_MANAGER_THROTTLING); |
Makoto Onuki | d6e1f3b | 2016-06-14 11:17:59 -0700 | [diff] [blame] | 6469 | mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0); |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
Mehdi Alizadeh | c86dd1f | 2019-01-25 16:59:54 -0800 | [diff] [blame] | 6472 | public void testGetShareTargets_permission() { |
| 6473 | IntentFilter filter = new IntentFilter(); |
| 6474 | |
| 6475 | assertExpectException(SecurityException.class, "Missing permission", () -> |
| 6476 | mManager.getShareTargets(filter)); |
| 6477 | |
| 6478 | // Has permission, now it should pass. |
| 6479 | mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS); |
| 6480 | mManager.getShareTargets(filter); |
| 6481 | } |
| 6482 | |
Mehdi Alizadeh | 627d4db | 2019-02-04 13:52:03 -0800 | [diff] [blame] | 6483 | public void testHasShareTargets_permission() { |
| 6484 | assertExpectException(SecurityException.class, "Missing permission", () -> |
| 6485 | mManager.hasShareTargets(CALLING_PACKAGE_1)); |
| 6486 | |
| 6487 | // Has permission, now it should pass. |
| 6488 | mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS); |
| 6489 | mManager.hasShareTargets(CALLING_PACKAGE_1); |
| 6490 | } |
| 6491 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6492 | public void testDumpsys_crossProfile() { |
| 6493 | prepareCrossProfileDataSet(); |
| 6494 | dumpsysOnLogcat("test1", /* force= */ true); |
| 6495 | } |
| 6496 | |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 6497 | public void testDumpsys_withIcons() throws IOException { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 6498 | testIcons(); |
| 6499 | // Dump after having some icons. |
| 6500 | dumpsysOnLogcat("test1", /* force= */ true); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 6501 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6502 | |
| 6503 | public void testManifestShortcut_publishOnUnlockUser() { |
| 6504 | addManifestShortcutResource( |
| 6505 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 6506 | R.xml.shortcut_1); |
| 6507 | addManifestShortcutResource( |
| 6508 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 6509 | R.xml.shortcut_2); |
| 6510 | addManifestShortcutResource( |
| 6511 | new ComponentName(CALLING_PACKAGE_3, ShortcutActivity.class.getName()), |
| 6512 | R.xml.shortcut_5); |
| 6513 | |
| 6514 | // Unlock user-0. |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 6515 | mInjectedCurrentTimeMillis += 100; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6516 | mService.handleUnlockUser(USER_0); |
| 6517 | |
| 6518 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6519 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6520 | mManager.getManifestShortcuts()))), |
| 6521 | "ms1"); |
| 6522 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6523 | }); |
| 6524 | |
| 6525 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6526 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6527 | mManager.getManifestShortcuts()))), |
| 6528 | "ms1", "ms2"); |
| 6529 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6530 | }); |
| 6531 | |
| 6532 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 6533 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6534 | mManager.getManifestShortcuts()))), |
| 6535 | "ms1", "ms2", "ms3", "ms4", "ms5"); |
| 6536 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6537 | }); |
| 6538 | |
| 6539 | // Try on another user, with some packages uninstalled. |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 6540 | mRunningUsers.put(USER_10, true); |
| 6541 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6542 | uninstallPackage(USER_10, CALLING_PACKAGE_1); |
| 6543 | uninstallPackage(USER_10, CALLING_PACKAGE_3); |
| 6544 | |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 6545 | mInjectedCurrentTimeMillis += 100; |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6546 | mService.handleUnlockUser(USER_10); |
| 6547 | |
| 6548 | runWithCaller(CALLING_PACKAGE_1, USER_10, () -> { |
| 6549 | assertEmpty(mManager.getManifestShortcuts()); |
| 6550 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6551 | }); |
| 6552 | |
| 6553 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
| 6554 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6555 | mManager.getManifestShortcuts()))), |
| 6556 | "ms1", "ms2"); |
| 6557 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6558 | }); |
| 6559 | |
| 6560 | runWithCaller(CALLING_PACKAGE_3, USER_10, () -> { |
| 6561 | assertEmpty(mManager.getManifestShortcuts()); |
| 6562 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6563 | }); |
| 6564 | |
| 6565 | // Now change the resources for package 1, and unlock again. |
| 6566 | // But we still see *old* shortcuts, because the package version and install time |
| 6567 | // hasn't changed. |
| 6568 | shutdownServices(); |
| 6569 | |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 6570 | mInjectedCurrentTimeMillis += 100; |
| 6571 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6572 | addManifestShortcutResource( |
| 6573 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 6574 | R.xml.shortcut_5); |
| 6575 | addManifestShortcutResource( |
| 6576 | new ComponentName(CALLING_PACKAGE_3, ShortcutActivity.class.getName()), |
| 6577 | R.xml.shortcut_1); |
| 6578 | |
| 6579 | initService(); |
| 6580 | mService.handleUnlockUser(USER_0); |
| 6581 | |
| 6582 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 6583 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( // FAIL |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6584 | mManager.getManifestShortcuts()))), |
| 6585 | "ms1"); |
| 6586 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6587 | }); |
| 6588 | |
| 6589 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6590 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6591 | mManager.getManifestShortcuts()))), |
| 6592 | "ms1", "ms2"); |
| 6593 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6594 | }); |
| 6595 | |
| 6596 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 6597 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6598 | mManager.getManifestShortcuts()))), |
| 6599 | "ms1", "ms2", "ms3", "ms4", "ms5"); |
| 6600 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6601 | }); |
| 6602 | |
| 6603 | // Do it again, but this time we change the app version, so we do detect the changes. |
| 6604 | shutdownServices(); |
| 6605 | |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 6606 | mInjectedCurrentTimeMillis += 100; |
| 6607 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6608 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 6609 | updatePackageLastUpdateTime(CALLING_PACKAGE_3, 1); |
| 6610 | |
| 6611 | initService(); |
| 6612 | mService.handleUnlockUser(USER_0); |
| 6613 | |
| 6614 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6615 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6616 | mManager.getManifestShortcuts()))), |
| 6617 | "ms1", "ms2", "ms3", "ms4", "ms5"); |
| 6618 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6619 | }); |
| 6620 | |
| 6621 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6622 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6623 | mManager.getManifestShortcuts()))), |
| 6624 | "ms1", "ms2"); |
| 6625 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6626 | }); |
| 6627 | |
| 6628 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 6629 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6630 | mManager.getManifestShortcuts()))), |
| 6631 | "ms1"); |
| 6632 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6633 | }); |
| 6634 | |
| 6635 | // Next, try removing all shortcuts, with some of them pinned. |
| 6636 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6637 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms3"), HANDLE_USER_0); |
| 6638 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("ms2"), HANDLE_USER_0); |
| 6639 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_3, list("ms1"), HANDLE_USER_0); |
| 6640 | }); |
| 6641 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6642 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6643 | mManager.getManifestShortcuts()))), |
| 6644 | "ms1", "ms2", "ms3", "ms4", "ms5"); |
| 6645 | assertShortcutIds(assertAllImmutable(assertAllPinned(assertAllManifest( |
| 6646 | assertAllEnabled(mManager.getPinnedShortcuts())))), |
| 6647 | "ms3"); |
| 6648 | }); |
| 6649 | |
| 6650 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6651 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6652 | mManager.getManifestShortcuts()))), |
| 6653 | "ms1", "ms2"); |
| 6654 | assertShortcutIds(assertAllImmutable(assertAllPinned(assertAllManifest( |
| 6655 | assertAllEnabled(mManager.getPinnedShortcuts())))), |
| 6656 | "ms2"); |
| 6657 | }); |
| 6658 | |
| 6659 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 6660 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6661 | mManager.getManifestShortcuts()))), |
| 6662 | "ms1"); |
| 6663 | assertShortcutIds(assertAllImmutable(assertAllPinned(assertAllManifest( |
| 6664 | assertAllEnabled(mManager.getPinnedShortcuts())))), |
| 6665 | "ms1"); |
| 6666 | }); |
| 6667 | |
| 6668 | shutdownServices(); |
| 6669 | |
Makoto Onuki | 248a0ef | 2016-11-03 15:59:01 -0700 | [diff] [blame] | 6670 | mInjectedCurrentTimeMillis += 100; |
| 6671 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6672 | addManifestShortcutResource( |
| 6673 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 6674 | R.xml.shortcut_0); |
| 6675 | addManifestShortcutResource( |
| 6676 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 6677 | R.xml.shortcut_1); |
| 6678 | addManifestShortcutResource( |
| 6679 | new ComponentName(CALLING_PACKAGE_3, ShortcutActivity.class.getName()), |
| 6680 | R.xml.shortcut_0); |
| 6681 | |
| 6682 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 6683 | updatePackageVersion(CALLING_PACKAGE_2, 1); |
| 6684 | updatePackageVersion(CALLING_PACKAGE_3, 1); |
| 6685 | |
| 6686 | initService(); |
| 6687 | mService.handleUnlockUser(USER_0); |
| 6688 | |
| 6689 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6690 | assertEmpty(mManager.getManifestShortcuts()); |
| 6691 | assertShortcutIds(assertAllImmutable(assertAllPinned(assertAllNotManifest( |
| 6692 | assertAllDisabled(mManager.getPinnedShortcuts())))), |
| 6693 | "ms3"); |
| 6694 | }); |
| 6695 | |
| 6696 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6697 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6698 | mManager.getManifestShortcuts()))), |
| 6699 | "ms1"); |
| 6700 | assertShortcutIds(assertAllImmutable(assertAllPinned(assertAllNotManifest( |
| 6701 | assertAllDisabled(mManager.getPinnedShortcuts())))), |
| 6702 | "ms2"); |
| 6703 | }); |
| 6704 | |
| 6705 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 6706 | assertEmpty(mManager.getManifestShortcuts()); |
| 6707 | assertShortcutIds(assertAllImmutable(assertAllPinned(assertAllNotManifest( |
| 6708 | assertAllDisabled(mManager.getPinnedShortcuts())))), |
| 6709 | "ms1"); |
| 6710 | }); |
| 6711 | |
| 6712 | // Make sure we don't have ShortcutPackage for packages that don't have shortcuts. |
| 6713 | assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_4, USER_0)); |
| 6714 | assertNull(mService.getPackageShortcutForTest(LAUNCHER_1, USER_0)); |
| 6715 | } |
| 6716 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6717 | public void testManifestShortcut_publishOnBroadcast() { |
| 6718 | // First, no packages are installed. |
| 6719 | uninstallPackage(USER_0, CALLING_PACKAGE_1); |
| 6720 | uninstallPackage(USER_0, CALLING_PACKAGE_2); |
| 6721 | uninstallPackage(USER_0, CALLING_PACKAGE_3); |
| 6722 | uninstallPackage(USER_0, CALLING_PACKAGE_4); |
| 6723 | uninstallPackage(USER_10, CALLING_PACKAGE_1); |
| 6724 | uninstallPackage(USER_10, CALLING_PACKAGE_2); |
| 6725 | uninstallPackage(USER_10, CALLING_PACKAGE_3); |
| 6726 | uninstallPackage(USER_10, CALLING_PACKAGE_4); |
| 6727 | |
| 6728 | mService.handleUnlockUser(USER_0); |
Makoto Onuki | 9c85001 | 2016-07-26 15:50:50 -0700 | [diff] [blame] | 6729 | |
| 6730 | mRunningUsers.put(USER_10, true); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6731 | mService.handleUnlockUser(USER_10); |
| 6732 | |
| 6733 | // Originally no manifest shortcuts. |
| 6734 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6735 | assertEmpty(mManager.getManifestShortcuts()); |
| 6736 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6737 | }); |
| 6738 | |
| 6739 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6740 | assertEmpty(mManager.getManifestShortcuts()); |
| 6741 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6742 | }); |
| 6743 | |
| 6744 | runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { |
| 6745 | assertEmpty(mManager.getManifestShortcuts()); |
| 6746 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6747 | }); |
| 6748 | |
| 6749 | // Package 1 updated, with manifest shortcuts. |
| 6750 | addManifestShortcutResource( |
| 6751 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 6752 | R.xml.shortcut_1); |
| 6753 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6754 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6755 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 6756 | |
| 6757 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6758 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6759 | mManager.getManifestShortcuts()))), |
| 6760 | "ms1"); |
| 6761 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6762 | }); |
| 6763 | |
| 6764 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6765 | assertEmpty(mManager.getManifestShortcuts()); |
| 6766 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6767 | }); |
| 6768 | |
| 6769 | // Package 2 updated, with manifest shortcuts. |
| 6770 | |
| 6771 | addManifestShortcutResource( |
| 6772 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 6773 | R.xml.shortcut_5_altalt); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6774 | updatePackageVersion(CALLING_PACKAGE_2, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6775 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6776 | genPackageAddIntent(CALLING_PACKAGE_2, USER_0)); |
| 6777 | |
| 6778 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6779 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6780 | mManager.getManifestShortcuts()))), |
| 6781 | "ms1"); |
| 6782 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6783 | }); |
| 6784 | |
| 6785 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6786 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6787 | mManager.getManifestShortcuts()))), |
| 6788 | "ms1", "ms2", "ms3", "ms4", "ms5"); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 6789 | assertWith(getCallerShortcuts()).selectManifest() |
| 6790 | .selectByActivity( |
| 6791 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName())) |
| 6792 | .haveRanksInOrder("ms1", "ms2", "ms3", "ms4", "ms5"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6793 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6794 | }); |
| 6795 | |
| 6796 | // Package 2 updated, with less manifest shortcuts. |
| 6797 | // This time we use updatePackageLastUpdateTime() instead of updatePackageVersion(). |
| 6798 | |
| 6799 | dumpsysOnLogcat("Before pinning"); |
| 6800 | |
| 6801 | // Also pin some. |
| 6802 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6803 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("ms2", "ms3"), HANDLE_USER_0); |
| 6804 | }); |
| 6805 | |
| 6806 | dumpsysOnLogcat("After pinning"); |
| 6807 | |
| 6808 | addManifestShortcutResource( |
| 6809 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 6810 | R.xml.shortcut_2); |
| 6811 | updatePackageLastUpdateTime(CALLING_PACKAGE_2, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6812 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6813 | genPackageAddIntent(CALLING_PACKAGE_2, USER_0)); |
| 6814 | |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 6815 | dumpsysOnLogcat("After updating package 2"); |
| 6816 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6817 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6818 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6819 | mManager.getManifestShortcuts()))), |
| 6820 | "ms1"); |
| 6821 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6822 | }); |
| 6823 | |
| 6824 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6825 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6826 | mManager.getManifestShortcuts()))), |
| 6827 | "ms1", "ms2"); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 6828 | assertWith(getCallerShortcuts()).selectManifest() |
| 6829 | .selectByActivity( |
| 6830 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName())) |
| 6831 | .haveRanksInOrder("ms1", "ms2"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6832 | assertShortcutIds(assertAllImmutable(assertAllPinned( |
| 6833 | mManager.getPinnedShortcuts())), |
| 6834 | "ms2", "ms3"); |
| 6835 | // ms3 is no longer in manifest, so should be disabled. |
| 6836 | // but ms1 and ms2 should be enabled. |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 6837 | assertWith(getCallerShortcuts()) |
| 6838 | .selectByIds("ms1", "ms2") |
| 6839 | .areAllEnabled() |
| 6840 | |
| 6841 | .revertToOriginalList() |
| 6842 | .selectByIds("ms3") |
| 6843 | .areAllDisabled() |
| 6844 | .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_APP_CHANGED); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6845 | }); |
| 6846 | |
Makoto Onuki | b1588c0 | 2017-10-12 15:11:45 -0700 | [diff] [blame] | 6847 | // Make sure the launcher see the correct disabled reason. |
| 6848 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 6849 | assertWith(getShortcutAsLauncher(USER_0)) |
| 6850 | .forShortcutWithId("ms3", si -> { |
| 6851 | assertEquals("string-com.android.test.2-user:0-res:" |
| 6852 | + R.string.shortcut_disabled_message3 + "/en", |
| 6853 | si.getDisabledMessage()); |
| 6854 | }); |
| 6855 | }); |
| 6856 | |
| 6857 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6858 | // Package 2 on user 10 has no shortcuts yet. |
| 6859 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
| 6860 | assertEmpty(mManager.getManifestShortcuts()); |
| 6861 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6862 | }); |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 6863 | // Send add broadcast, but the user is not running, so should be ignored. |
Makoto Onuki | 01ce92b | 2017-04-28 12:24:16 -0700 | [diff] [blame] | 6864 | mService.handleStopUser(USER_10); |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 6865 | mRunningUsers.put(USER_10, false); |
| 6866 | mUnlockedUsers.put(USER_10, false); |
| 6867 | |
Makoto Onuki | 4e6cef4 | 2016-07-13 16:14:01 -0700 | [diff] [blame] | 6868 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 6869 | genPackageAddIntent(CALLING_PACKAGE_2, USER_10)); |
| 6870 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
Makoto Onuki | 4e6cef4 | 2016-07-13 16:14:01 -0700 | [diff] [blame] | 6871 | // Don't use the mManager APIs to get shortcuts, because they'll trigger the package |
| 6872 | // update check. |
| 6873 | // So look the internal data directly using getCallerShortcuts(). |
| 6874 | assertEmpty(getCallerShortcuts()); |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 6875 | }); |
| 6876 | |
| 6877 | // Try again, but the user is locked, so still ignored. |
| 6878 | mRunningUsers.put(USER_10, true); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6879 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 6880 | genPackageAddIntent(CALLING_PACKAGE_2, USER_10)); |
| 6881 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
Makoto Onuki | 4e6cef4 | 2016-07-13 16:14:01 -0700 | [diff] [blame] | 6882 | // Don't use the mManager APIs to get shortcuts, because they'll trigger the package |
| 6883 | // update check. |
| 6884 | // So look the internal data directly using getCallerShortcuts(). |
| 6885 | assertEmpty(getCallerShortcuts()); |
Makoto Onuki | a224183 | 2016-07-06 13:28:37 -0700 | [diff] [blame] | 6886 | }); |
| 6887 | |
| 6888 | // Unlock the user, now it should work. |
| 6889 | mUnlockedUsers.put(USER_10, true); |
| 6890 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6891 | // Send PACKAGE_ADD broadcast to have Package 2 on user-10 publish manifest shortcuts. |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6892 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6893 | genPackageAddIntent(CALLING_PACKAGE_2, USER_10)); |
| 6894 | |
| 6895 | runWithCaller(CALLING_PACKAGE_2, USER_10, () -> { |
| 6896 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6897 | mManager.getManifestShortcuts()))), |
| 6898 | "ms1", "ms2"); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 6899 | assertWith(getCallerShortcuts()).selectManifest() |
| 6900 | .selectByActivity( |
| 6901 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName())) |
| 6902 | .haveRanksInOrder("ms1", "ms2"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6903 | assertEmpty(mManager.getPinnedShortcuts()); |
| 6904 | }); |
| 6905 | |
| 6906 | // But it shouldn't affect user-0. |
| 6907 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6908 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6909 | mManager.getManifestShortcuts()))), |
| 6910 | "ms1", "ms2"); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 6911 | assertWith(getCallerShortcuts()).selectManifest() |
| 6912 | .selectByActivity( |
| 6913 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName())) |
| 6914 | .haveRanksInOrder("ms1", "ms2"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6915 | assertShortcutIds(assertAllImmutable(assertAllPinned( |
| 6916 | mManager.getPinnedShortcuts())), |
| 6917 | "ms2", "ms3"); |
| 6918 | assertAllEnabled(list(getCallerShortcut("ms1"))); |
| 6919 | assertAllEnabled(list(getCallerShortcut("ms2"))); |
| 6920 | assertAllDisabled(list(getCallerShortcut("ms3"))); |
| 6921 | }); |
| 6922 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 6923 | // Multiple activities. |
| 6924 | // Add shortcuts on activity 2 for package 2. |
| 6925 | addManifestShortcutResource( |
| 6926 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 6927 | R.xml.shortcut_5_alt); |
| 6928 | addManifestShortcutResource( |
| 6929 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity2.class.getName()), |
| 6930 | R.xml.shortcut_5_reverse); |
| 6931 | |
| 6932 | updatePackageLastUpdateTime(CALLING_PACKAGE_2, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6933 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 6934 | genPackageAddIntent(CALLING_PACKAGE_2, USER_0)); |
| 6935 | |
| 6936 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6937 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 6938 | mManager.getManifestShortcuts()))), |
| 6939 | "ms1", "ms2", "ms3", "ms4", "ms5", |
| 6940 | "ms1_alt", "ms2_alt", "ms3_alt", "ms4_alt", "ms5_alt"); |
| 6941 | |
| 6942 | // Make sure they have the correct ranks, regardless of their ID's alphabetical order. |
| 6943 | assertWith(getCallerShortcuts()).selectManifest() |
| 6944 | .selectByActivity( |
| 6945 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName())) |
| 6946 | .haveRanksInOrder("ms1_alt", "ms2_alt", "ms3_alt", "ms4_alt", "ms5_alt"); |
| 6947 | assertWith(getCallerShortcuts()).selectManifest() |
| 6948 | .selectByActivity( |
| 6949 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity2.class.getName())) |
| 6950 | .haveRanksInOrder("ms5", "ms4", "ms3", "ms2", "ms1"); |
| 6951 | }); |
| 6952 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6953 | // Package 2 now has no manifest shortcuts. |
| 6954 | addManifestShortcutResource( |
| 6955 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity.class.getName()), |
| 6956 | R.xml.shortcut_0); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 6957 | addManifestShortcutResource( |
| 6958 | new ComponentName(CALLING_PACKAGE_2, ShortcutActivity2.class.getName()), |
| 6959 | R.xml.shortcut_0); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6960 | updatePackageLastUpdateTime(CALLING_PACKAGE_2, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6961 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6962 | genPackageAddIntent(CALLING_PACKAGE_2, USER_0)); |
| 6963 | |
| 6964 | // No manifest shortcuts, and pinned ones are disabled. |
| 6965 | runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { |
| 6966 | assertEmpty(mManager.getManifestShortcuts()); |
| 6967 | assertShortcutIds(assertAllImmutable(assertAllPinned(assertAllDisabled( |
| 6968 | mManager.getPinnedShortcuts()))), |
| 6969 | "ms2", "ms3"); |
| 6970 | }); |
| 6971 | } |
| 6972 | |
| 6973 | public void testManifestShortcuts_missingMandatoryFields() { |
| 6974 | // Start with no apps installed. |
| 6975 | uninstallPackage(USER_0, CALLING_PACKAGE_1); |
| 6976 | uninstallPackage(USER_0, CALLING_PACKAGE_2); |
| 6977 | uninstallPackage(USER_0, CALLING_PACKAGE_3); |
| 6978 | uninstallPackage(USER_0, CALLING_PACKAGE_4); |
| 6979 | |
| 6980 | mService.handleUnlockUser(USER_0); |
| 6981 | |
| 6982 | // Make sure no manifest shortcuts. |
| 6983 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 6984 | assertEmpty(mManager.getManifestShortcuts()); |
| 6985 | }); |
| 6986 | |
| 6987 | // Package 1 updated, which has one valid manifest shortcut and one invalid. |
| 6988 | addManifestShortcutResource( |
| 6989 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 6990 | R.xml.shortcut_error_1); |
| 6991 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 6992 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 6993 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 6994 | |
| 6995 | // Only the valid one is published. |
| 6996 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | 6771d73 | 2016-07-14 12:58:40 -0700 | [diff] [blame] | 6997 | assertWith(getCallerShortcuts()) |
| 6998 | .areAllManifest() |
| 6999 | .areAllImmutable() |
| 7000 | .areAllEnabled() |
| 7001 | .haveIds("x1"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7002 | }); |
| 7003 | |
| 7004 | // Package 1 updated, which has one valid manifest shortcut and one invalid. |
| 7005 | addManifestShortcutResource( |
| 7006 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7007 | R.xml.shortcut_error_2); |
| 7008 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7009 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7010 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7011 | |
| 7012 | // Only the valid one is published. |
| 7013 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | 6771d73 | 2016-07-14 12:58:40 -0700 | [diff] [blame] | 7014 | assertWith(getCallerShortcuts()) |
| 7015 | .areAllManifest() |
| 7016 | .areAllImmutable() |
| 7017 | .areAllEnabled() |
| 7018 | .haveIds("x2"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7019 | }); |
| 7020 | |
| 7021 | // Package 1 updated, which has one valid manifest shortcut and one invalid. |
| 7022 | addManifestShortcutResource( |
| 7023 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7024 | R.xml.shortcut_error_3); |
| 7025 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7026 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7027 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7028 | |
| 7029 | // Only the valid one is published. |
| 7030 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | 6771d73 | 2016-07-14 12:58:40 -0700 | [diff] [blame] | 7031 | assertWith(getCallerShortcuts()) |
| 7032 | .areAllManifest() |
| 7033 | .areAllImmutable() |
| 7034 | .areAllEnabled() |
| 7035 | .haveIds("x3") |
| 7036 | .forShortcutWithId("x3", si -> { |
| 7037 | assertEquals(set("cat2"), si.getCategories()); |
| 7038 | }); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7039 | }); |
| 7040 | } |
| 7041 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7042 | public void testManifestShortcuts_intentDefinitions() { |
| 7043 | addManifestShortcutResource( |
| 7044 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7045 | R.xml.shortcut_error_4); |
| 7046 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7047 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7048 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7049 | |
| 7050 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7051 | // Make sure invalid ones are not published. |
| 7052 | // Note that at this point disabled ones don't show up because they weren't pinned. |
| 7053 | assertWith(getCallerShortcuts()) |
| 7054 | .haveIds("ms1", "ms2") |
| 7055 | .areAllManifest() |
| 7056 | .areAllNotDynamic() |
| 7057 | .areAllNotPinned() |
| 7058 | .areAllImmutable() |
| 7059 | .areAllEnabled() |
| 7060 | .forShortcutWithId("ms1", si -> { |
| 7061 | assertTrue(si.isEnabled()); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 7062 | assertEquals(1, si.getIntents().length); |
| 7063 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7064 | assertEquals("action1", si.getIntent().getAction()); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 7065 | assertEquals("value1", si.getIntent().getStringExtra("key1")); |
| 7066 | assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 7067 | Intent.FLAG_ACTIVITY_CLEAR_TASK | |
| 7068 | Intent.FLAG_ACTIVITY_TASK_ON_HOME, si.getIntent().getFlags()); |
| 7069 | |
| 7070 | assertEquals("action1", si.getIntents()[0].getAction()); |
| 7071 | assertEquals("value1", si.getIntents()[0].getStringExtra("key1")); |
| 7072 | assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 7073 | Intent.FLAG_ACTIVITY_CLEAR_TASK | |
| 7074 | Intent.FLAG_ACTIVITY_TASK_ON_HOME, si.getIntents()[0].getFlags()); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7075 | }) |
| 7076 | .forShortcutWithId("ms2", si -> { |
| 7077 | assertTrue(si.isEnabled()); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 7078 | assertEquals(2, si.getIntents().length); |
| 7079 | |
| 7080 | // getIntent will return the last one. |
| 7081 | assertEquals("action2_2", si.getIntent().getAction()); |
| 7082 | assertEquals("value2", si.getIntent().getStringExtra("key2")); |
| 7083 | assertEquals(0, si.getIntent().getFlags()); |
| 7084 | |
| 7085 | final Intent i1 = si.getIntents()[0]; |
| 7086 | final Intent i2 = si.getIntents()[1]; |
| 7087 | |
| 7088 | assertEquals("action2_1", i1.getAction()); |
| 7089 | assertEquals("value1", i1.getStringExtra("key1")); |
| 7090 | assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 7091 | Intent.FLAG_ACTIVITY_CLEAR_TASK | |
| 7092 | Intent.FLAG_ACTIVITY_TASK_ON_HOME, i1.getFlags()); |
| 7093 | |
| 7094 | assertEquals("action2_2", i2.getAction()); |
| 7095 | assertEquals("value2", i2.getStringExtra("key2")); |
| 7096 | assertEquals(0, i2.getFlags()); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7097 | }); |
| 7098 | }); |
| 7099 | |
| 7100 | // Publish 5 enabled to pin some, so we can later test disabled manfiest shortcuts.. |
| 7101 | addManifestShortcutResource( |
| 7102 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7103 | R.xml.shortcut_5); |
| 7104 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7105 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7106 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7107 | |
| 7108 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7109 | // Make sure 5 manifest shortcuts are published. |
| 7110 | assertWith(getCallerShortcuts()) |
| 7111 | .haveIds("ms1", "ms2", "ms3", "ms4", "ms5") |
| 7112 | .areAllManifest() |
| 7113 | .areAllNotDynamic() |
| 7114 | .areAllNotPinned() |
| 7115 | .areAllImmutable() |
| 7116 | .areAllEnabled(); |
| 7117 | }); |
| 7118 | |
| 7119 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 7120 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 7121 | list("ms3", "ms4", "ms5"), HANDLE_USER_0); |
| 7122 | }); |
| 7123 | |
| 7124 | // Make sure they're pinned. |
| 7125 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7126 | assertWith(getCallerShortcuts()) |
| 7127 | .haveIds("ms1", "ms2", "ms3", "ms4", "ms5") |
| 7128 | .selectByIds("ms1", "ms2") |
| 7129 | .areAllNotPinned() |
| 7130 | .areAllEnabled() |
| 7131 | |
| 7132 | .revertToOriginalList() |
| 7133 | .selectByIds("ms3", "ms4", "ms5") |
| 7134 | .areAllPinned() |
| 7135 | .areAllEnabled(); |
| 7136 | }); |
| 7137 | |
| 7138 | // Update the app. |
| 7139 | addManifestShortcutResource( |
| 7140 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7141 | R.xml.shortcut_error_4); |
| 7142 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7143 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7144 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7145 | |
| 7146 | // Make sure 3, 4 and 5 still exist but disabled. |
| 7147 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7148 | assertWith(getCallerShortcuts()) |
| 7149 | .haveIds("ms1", "ms2", "ms3", "ms4", "ms5") |
| 7150 | .areAllNotDynamic() |
| 7151 | .areAllImmutable() |
| 7152 | |
| 7153 | .selectByIds("ms1", "ms2") |
| 7154 | .areAllManifest() |
| 7155 | .areAllNotPinned() |
| 7156 | .areAllEnabled() |
| 7157 | |
| 7158 | .revertToOriginalList() |
| 7159 | .selectByIds("ms3", "ms4", "ms5") |
| 7160 | .areAllNotManifest() |
| 7161 | .areAllPinned() |
| 7162 | .areAllDisabled() |
| 7163 | |
| 7164 | .revertToOriginalList() |
| 7165 | .forShortcutWithId("ms1", si -> { |
| 7166 | assertEquals(si.getId(), "action1", si.getIntent().getAction()); |
| 7167 | }) |
| 7168 | .forShortcutWithId("ms2", si -> { |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 7169 | // getIntent returns the last one. |
| 7170 | assertEquals(si.getId(), "action2_2", si.getIntent().getAction()); |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7171 | }) |
| 7172 | .forShortcutWithId("ms3", si -> { |
| 7173 | assertEquals(si.getId(), Intent.ACTION_VIEW, si.getIntent().getAction()); |
| 7174 | }) |
| 7175 | .forShortcutWithId("ms4", si -> { |
| 7176 | assertEquals(si.getId(), Intent.ACTION_VIEW, si.getIntent().getAction()); |
| 7177 | }) |
| 7178 | .forShortcutWithId("ms5", si -> { |
| 7179 | assertEquals(si.getId(), "action", si.getIntent().getAction()); |
| 7180 | }); |
| 7181 | }); |
| 7182 | } |
| 7183 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7184 | public void testManifestShortcuts_checkAllFields() { |
| 7185 | mService.handleUnlockUser(USER_0); |
| 7186 | |
| 7187 | // Package 1 updated, which has one valid manifest shortcut and one invalid. |
| 7188 | addManifestShortcutResource( |
| 7189 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7190 | R.xml.shortcut_5); |
| 7191 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7192 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7193 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7194 | |
| 7195 | // Only the valid one is published. |
| 7196 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7197 | assertWith(getCallerShortcuts()) |
| 7198 | .haveIds("ms1", "ms2", "ms3", "ms4", "ms5") |
| 7199 | .areAllManifest() |
| 7200 | .areAllImmutable() |
| 7201 | .areAllEnabled() |
| 7202 | .areAllNotPinned() |
| 7203 | .areAllNotDynamic() |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7204 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7205 | .forShortcutWithId("ms1", si -> { |
| 7206 | assertEquals(R.drawable.icon1, si.getIconResourceId()); |
| 7207 | assertEquals(new ComponentName(CALLING_PACKAGE_1, |
| 7208 | ShortcutActivity.class.getName()), |
| 7209 | si.getActivity()); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7210 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7211 | assertEquals(R.string.shortcut_title1, si.getTitleResId()); |
| 7212 | assertEquals("r" + R.string.shortcut_title1, si.getTitleResName()); |
| 7213 | assertEquals(R.string.shortcut_text1, si.getTextResId()); |
| 7214 | assertEquals("r" + R.string.shortcut_text1, si.getTextResName()); |
| 7215 | assertEquals(R.string.shortcut_disabled_message1, |
| 7216 | si.getDisabledMessageResourceId()); |
| 7217 | assertEquals("r" + R.string.shortcut_disabled_message1, |
| 7218 | si.getDisabledMessageResName()); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7219 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7220 | assertEquals(set("android.shortcut.conversation", "android.shortcut.media"), |
| 7221 | si.getCategories()); |
| 7222 | assertEquals("action1", si.getIntent().getAction()); |
| 7223 | assertEquals(Uri.parse("http://a.b.c/1"), si.getIntent().getData()); |
| 7224 | }) |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7225 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7226 | .forShortcutWithId("ms2", si -> { |
| 7227 | assertEquals("ms2", si.getId()); |
| 7228 | assertEquals(R.drawable.icon2, si.getIconResourceId()); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7229 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7230 | assertEquals(R.string.shortcut_title2, si.getTitleResId()); |
| 7231 | assertEquals("r" + R.string.shortcut_title2, si.getTitleResName()); |
| 7232 | assertEquals(R.string.shortcut_text2, si.getTextResId()); |
| 7233 | assertEquals("r" + R.string.shortcut_text2, si.getTextResName()); |
| 7234 | assertEquals(R.string.shortcut_disabled_message2, |
| 7235 | si.getDisabledMessageResourceId()); |
| 7236 | assertEquals("r" + R.string.shortcut_disabled_message2, |
| 7237 | si.getDisabledMessageResName()); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7238 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7239 | assertEquals(set("android.shortcut.conversation"), si.getCategories()); |
| 7240 | assertEquals("action2", si.getIntent().getAction()); |
| 7241 | assertEquals(null, si.getIntent().getData()); |
| 7242 | }) |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7243 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7244 | .forShortcutWithId("ms3", si -> { |
| 7245 | assertEquals(0, si.getIconResourceId()); |
| 7246 | assertEquals(R.string.shortcut_title1, si.getTitleResId()); |
| 7247 | assertEquals("r" + R.string.shortcut_title1, si.getTitleResName()); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7248 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7249 | assertEquals(0, si.getTextResId()); |
| 7250 | assertEquals(null, si.getTextResName()); |
| 7251 | assertEquals(0, si.getDisabledMessageResourceId()); |
| 7252 | assertEquals(null, si.getDisabledMessageResName()); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7253 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7254 | assertEmpty(si.getCategories()); |
| 7255 | assertEquals("android.intent.action.VIEW", si.getIntent().getAction()); |
| 7256 | assertEquals(null, si.getIntent().getData()); |
| 7257 | }) |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7258 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7259 | .forShortcutWithId("ms4", si -> { |
| 7260 | assertEquals(0, si.getIconResourceId()); |
| 7261 | assertEquals(R.string.shortcut_title2, si.getTitleResId()); |
| 7262 | assertEquals("r" + R.string.shortcut_title2, si.getTitleResName()); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7263 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7264 | assertEquals(0, si.getTextResId()); |
| 7265 | assertEquals(null, si.getTextResName()); |
| 7266 | assertEquals(0, si.getDisabledMessageResourceId()); |
| 7267 | assertEquals(null, si.getDisabledMessageResName()); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7268 | |
Makoto Onuki | df6da04 | 2016-06-16 09:51:40 -0700 | [diff] [blame] | 7269 | assertEquals(set("cat"), si.getCategories()); |
| 7270 | assertEquals("android.intent.action.VIEW2", si.getIntent().getAction()); |
| 7271 | assertEquals(null, si.getIntent().getData()); |
| 7272 | }) |
| 7273 | |
| 7274 | .forShortcutWithId("ms5", si -> { |
| 7275 | si = getCallerShortcut("ms5"); |
| 7276 | assertEquals("action", si.getIntent().getAction()); |
| 7277 | assertEquals("http://www/", si.getIntent().getData().toString()); |
| 7278 | assertEquals("foo/bar", si.getIntent().getType()); |
| 7279 | assertEquals( |
| 7280 | new ComponentName("abc", ".xyz"), si.getIntent().getComponent()); |
| 7281 | |
| 7282 | assertEquals(set("cat1", "cat2"), si.getIntent().getCategories()); |
| 7283 | assertEquals("value1", si.getIntent().getStringExtra("key1")); |
| 7284 | assertEquals("value2", si.getIntent().getStringExtra("key2")); |
| 7285 | }); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7286 | }); |
| 7287 | } |
| 7288 | |
Makoto Onuki | 4e6cef4 | 2016-07-13 16:14:01 -0700 | [diff] [blame] | 7289 | public void testManifestShortcuts_localeChange() throws InterruptedException { |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7290 | mService.handleUnlockUser(USER_0); |
| 7291 | |
| 7292 | // Package 1 updated, which has one valid manifest shortcut and one invalid. |
| 7293 | addManifestShortcutResource( |
| 7294 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7295 | R.xml.shortcut_2); |
| 7296 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7297 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7298 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7299 | |
| 7300 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7301 | mManager.setDynamicShortcuts(list(makeShortcutWithTitle("s1", "title"))); |
| 7302 | |
| 7303 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 7304 | mManager.getManifestShortcuts()))), |
| 7305 | "ms1", "ms2"); |
| 7306 | |
| 7307 | // check first shortcut. |
| 7308 | ShortcutInfo si = getCallerShortcut("ms1"); |
| 7309 | |
| 7310 | assertEquals("ms1", si.getId()); |
| 7311 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title1 + "/en", |
| 7312 | si.getTitle()); |
| 7313 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text1 + "/en", |
| 7314 | si.getText()); |
| 7315 | assertEquals("string-com.android.test.1-user:0-res:" |
| 7316 | + R.string.shortcut_disabled_message1 + "/en", |
| 7317 | si.getDisabledMessage()); |
| 7318 | assertEquals(START_TIME, si.getLastChangedTimestamp()); |
| 7319 | |
| 7320 | // check another |
| 7321 | si = getCallerShortcut("ms2"); |
| 7322 | |
| 7323 | assertEquals("ms2", si.getId()); |
| 7324 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title2 + "/en", |
| 7325 | si.getTitle()); |
| 7326 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text2 + "/en", |
| 7327 | si.getText()); |
| 7328 | assertEquals("string-com.android.test.1-user:0-res:" |
| 7329 | + R.string.shortcut_disabled_message2 + "/en", |
| 7330 | si.getDisabledMessage()); |
| 7331 | assertEquals(START_TIME, si.getLastChangedTimestamp()); |
| 7332 | |
| 7333 | // Check the dynamic one. |
| 7334 | si = getCallerShortcut("s1"); |
| 7335 | |
| 7336 | assertEquals("s1", si.getId()); |
| 7337 | assertEquals("title", si.getTitle()); |
| 7338 | assertEquals(null, si.getText()); |
| 7339 | assertEquals(null, si.getDisabledMessage()); |
| 7340 | assertEquals(START_TIME, si.getLastChangedTimestamp()); |
| 7341 | }); |
| 7342 | |
| 7343 | mInjectedCurrentTimeMillis++; |
| 7344 | |
Makoto Onuki | 4e6cef4 | 2016-07-13 16:14:01 -0700 | [diff] [blame] | 7345 | // Change the locale and send the broadcast, make sure the launcher gets a callback too. |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7346 | mInjectedLocale = Locale.JAPANESE; |
Makoto Onuki | 4e6cef4 | 2016-07-13 16:14:01 -0700 | [diff] [blame] | 7347 | |
| 7348 | setCaller(LAUNCHER_1, USER_0); |
| 7349 | |
| 7350 | assertForLauncherCallback(mLauncherApps, () -> { |
| 7351 | mService.mReceiver.onReceive(mServiceContext, new Intent(Intent.ACTION_LOCALE_CHANGED)); |
| 7352 | }).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0) |
| 7353 | .haveIds("ms1", "ms2", "s1"); |
Makoto Onuki | 157b162 | 2016-06-02 16:13:10 -0700 | [diff] [blame] | 7354 | |
| 7355 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7356 | // check first shortcut. |
| 7357 | ShortcutInfo si = getCallerShortcut("ms1"); |
| 7358 | |
| 7359 | assertEquals("ms1", si.getId()); |
| 7360 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title1 + "/ja", |
| 7361 | si.getTitle()); |
| 7362 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text1 + "/ja", |
| 7363 | si.getText()); |
| 7364 | assertEquals("string-com.android.test.1-user:0-res:" |
| 7365 | + R.string.shortcut_disabled_message1 + "/ja", |
| 7366 | si.getDisabledMessage()); |
| 7367 | assertEquals(START_TIME + 1, si.getLastChangedTimestamp()); |
| 7368 | |
| 7369 | // check another |
| 7370 | si = getCallerShortcut("ms2"); |
| 7371 | |
| 7372 | assertEquals("ms2", si.getId()); |
| 7373 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title2 + "/ja", |
| 7374 | si.getTitle()); |
| 7375 | assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text2 + "/ja", |
| 7376 | si.getText()); |
| 7377 | assertEquals("string-com.android.test.1-user:0-res:" |
| 7378 | + R.string.shortcut_disabled_message2 + "/ja", |
| 7379 | si.getDisabledMessage()); |
| 7380 | assertEquals(START_TIME + 1, si.getLastChangedTimestamp()); |
| 7381 | |
| 7382 | // Check the dynamic one. (locale change shouldn't affect.) |
| 7383 | si = getCallerShortcut("s1"); |
| 7384 | |
| 7385 | assertEquals("s1", si.getId()); |
| 7386 | assertEquals("title", si.getTitle()); |
| 7387 | assertEquals(null, si.getText()); |
| 7388 | assertEquals(null, si.getDisabledMessage()); |
| 7389 | assertEquals(START_TIME, si.getLastChangedTimestamp()); // Not changed. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7390 | }); |
| 7391 | } |
| 7392 | |
| 7393 | public void testManifestShortcuts_updateAndDisabled_notPinned() { |
| 7394 | mService.handleUnlockUser(USER_0); |
| 7395 | |
| 7396 | // First, just publish a manifest shortcut. |
| 7397 | addManifestShortcutResource( |
| 7398 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7399 | R.xml.shortcut_1); |
| 7400 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7401 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7402 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7403 | |
| 7404 | // Only the valid one is published. |
| 7405 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7406 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 7407 | mManager.getManifestShortcuts()))), |
| 7408 | "ms1"); |
| 7409 | assertEmpty(mManager.getPinnedShortcuts()); |
| 7410 | |
| 7411 | // Make sure there's no other dangling shortcuts. |
| 7412 | assertShortcutIds(getCallerShortcuts(), "ms1"); |
| 7413 | }); |
| 7414 | |
| 7415 | // Now version up, the manifest shortcut is disabled now. |
| 7416 | addManifestShortcutResource( |
| 7417 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7418 | R.xml.shortcut_1_disable); |
| 7419 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7420 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7421 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7422 | |
| 7423 | // Because shortcut 1 wasn't pinned, it'll just go away. |
| 7424 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7425 | assertEmpty(mManager.getManifestShortcuts()); |
| 7426 | assertEmpty(mManager.getPinnedShortcuts()); |
| 7427 | |
| 7428 | // Make sure there's no other dangling shortcuts. |
| 7429 | assertEmpty(getCallerShortcuts()); |
| 7430 | }); |
| 7431 | } |
| 7432 | |
| 7433 | public void testManifestShortcuts_updateAndDisabled_pinned() { |
| 7434 | mService.handleUnlockUser(USER_0); |
| 7435 | |
| 7436 | // First, just publish a manifest shortcut. |
| 7437 | addManifestShortcutResource( |
| 7438 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7439 | R.xml.shortcut_1); |
| 7440 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7441 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7442 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7443 | |
| 7444 | // Only the valid one is published. |
| 7445 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7446 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 7447 | mManager.getManifestShortcuts()))), |
| 7448 | "ms1"); |
| 7449 | assertEmpty(mManager.getPinnedShortcuts()); |
| 7450 | |
| 7451 | // Make sure there's no other dangling shortcuts. |
| 7452 | assertShortcutIds(getCallerShortcuts(), "ms1"); |
| 7453 | }); |
| 7454 | |
| 7455 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 7456 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms1"), HANDLE_USER_0); |
| 7457 | }); |
| 7458 | |
| 7459 | // Now upgrade, the manifest shortcut is disabled now. |
| 7460 | addManifestShortcutResource( |
| 7461 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7462 | R.xml.shortcut_1_disable); |
| 7463 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7464 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7465 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7466 | |
| 7467 | // Because shortcut 1 was pinned, it'll still exist as pinned, but disabled. |
| 7468 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7469 | assertEmpty(mManager.getManifestShortcuts()); |
| 7470 | assertShortcutIds(assertAllNotManifest(assertAllImmutable(assertAllDisabled( |
| 7471 | mManager.getPinnedShortcuts()))), |
| 7472 | "ms1"); |
| 7473 | |
| 7474 | // Make sure the fields are updated. |
| 7475 | ShortcutInfo si = getCallerShortcut("ms1"); |
| 7476 | |
| 7477 | assertEquals("ms1", si.getId()); |
| 7478 | assertEquals(R.drawable.icon2, si.getIconResourceId()); |
| 7479 | assertEquals(R.string.shortcut_title2, si.getTitleResId()); |
| 7480 | assertEquals(R.string.shortcut_text2, si.getTextResId()); |
Makoto Onuki | eddbfec | 2016-05-31 17:04:34 -0700 | [diff] [blame] | 7481 | assertEquals(R.string.shortcut_disabled_message2, si.getDisabledMessageResourceId()); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7482 | assertEquals(Intent.ACTION_VIEW, si.getIntent().getAction()); |
| 7483 | |
| 7484 | // Make sure there's no other dangling shortcuts. |
| 7485 | assertShortcutIds(getCallerShortcuts(), "ms1"); |
| 7486 | }); |
| 7487 | } |
| 7488 | |
| 7489 | public void testManifestShortcuts_duplicateInSingleActivity() { |
| 7490 | mService.handleUnlockUser(USER_0); |
| 7491 | |
| 7492 | // The XML has two shortcuts with the same ID. |
| 7493 | addManifestShortcutResource( |
| 7494 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7495 | R.xml.shortcut_2_duplicate); |
| 7496 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7497 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7498 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7499 | |
| 7500 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7501 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 7502 | mManager.getManifestShortcuts()))), |
| 7503 | "ms1"); |
| 7504 | |
| 7505 | // Make sure the first one has survived. (the second one has a different title.) |
| 7506 | ShortcutInfo si = getCallerShortcut("ms1"); |
| 7507 | assertEquals(R.string.shortcut_title1, si.getTitleResId()); |
| 7508 | |
| 7509 | // Make sure there's no other dangling shortcuts. |
| 7510 | assertShortcutIds(getCallerShortcuts(), "ms1"); |
| 7511 | }); |
| 7512 | } |
| 7513 | |
| 7514 | public void testManifestShortcuts_duplicateInTwoActivities() { |
| 7515 | mService.handleUnlockUser(USER_0); |
| 7516 | |
| 7517 | // ShortcutActivity has shortcut ms1 |
| 7518 | addManifestShortcutResource( |
| 7519 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7520 | R.xml.shortcut_1); |
| 7521 | |
| 7522 | // ShortcutActivity2 has two shortcuts, ms1 and ms2. |
| 7523 | addManifestShortcutResource( |
| 7524 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 7525 | R.xml.shortcut_5); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7526 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7527 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7528 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7529 | |
| 7530 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7531 | assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled( |
| 7532 | mManager.getManifestShortcuts()))), |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 7533 | "ms1", "ms2", "ms3", "ms4", "ms5"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7534 | |
| 7535 | // ms1 should belong to ShortcutActivity. |
| 7536 | ShortcutInfo si = getCallerShortcut("ms1"); |
| 7537 | assertEquals(R.string.shortcut_title1, si.getTitleResId()); |
| 7538 | assertEquals(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7539 | si.getActivity()); |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 7540 | assertEquals(0, si.getRank()); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7541 | |
| 7542 | // ms2 should belong to ShortcutActivity*2*. |
| 7543 | si = getCallerShortcut("ms2"); |
| 7544 | assertEquals(R.string.shortcut_title2, si.getTitleResId()); |
| 7545 | assertEquals(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), |
| 7546 | si.getActivity()); |
| 7547 | |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 7548 | // Also check the ranks |
| 7549 | assertWith(getCallerShortcuts()).selectManifest() |
| 7550 | .selectByActivity( |
| 7551 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName())) |
| 7552 | .haveRanksInOrder("ms1"); |
| 7553 | assertWith(getCallerShortcuts()).selectManifest() |
| 7554 | .selectByActivity( |
| 7555 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName())) |
| 7556 | .haveRanksInOrder("ms2", "ms3", "ms4", "ms5"); |
| 7557 | |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7558 | // Make sure there's no other dangling shortcuts. |
Makoto Onuki | 9e1f559 | 2016-06-08 12:30:23 -0700 | [diff] [blame] | 7559 | assertShortcutIds(getCallerShortcuts(), "ms1", "ms2", "ms3", "ms4", "ms5"); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7560 | }); |
| 7561 | } |
| 7562 | |
| 7563 | /** |
| 7564 | * Manifest shortcuts cannot override shortcuts that were published via the APIs. |
| 7565 | */ |
| 7566 | public void testManifestShortcuts_cannotOverrideNonManifest() { |
| 7567 | mService.handleUnlockUser(USER_0); |
| 7568 | |
| 7569 | // Create a non-pinned dynamic shortcut and a non-dynamic pinned shortcut. |
| 7570 | |
| 7571 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7572 | mManager.setDynamicShortcuts(list( |
| 7573 | makeShortcut("ms1", "title1", |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 7574 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 7575 | /* icon */ null, new Intent("action1"), /* rank */ 0), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7576 | makeShortcut("ms2", "title2", |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 7577 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 7578 | /* icon */ null, new Intent("action1"), /* rank */ 0))); |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7579 | }); |
| 7580 | |
| 7581 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 7582 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms2"), HANDLE_USER_0); |
| 7583 | }); |
| 7584 | |
| 7585 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7586 | mManager.removeDynamicShortcuts(list("ms2")); |
| 7587 | |
| 7588 | assertShortcutIds(mManager.getDynamicShortcuts(), "ms1"); |
| 7589 | assertShortcutIds(mManager.getPinnedShortcuts(), "ms2"); |
| 7590 | assertEmpty(mManager.getManifestShortcuts()); |
| 7591 | }); |
| 7592 | |
| 7593 | // Then update the app with 5 manifest shortcuts. |
| 7594 | // Make sure "ms1" and "ms2" won't be replaced. |
| 7595 | addManifestShortcutResource( |
| 7596 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7597 | R.xml.shortcut_5); |
| 7598 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7599 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7600 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7601 | |
| 7602 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7603 | assertShortcutIds(assertAllNotManifest(mManager.getDynamicShortcuts()), "ms1"); |
| 7604 | assertShortcutIds(assertAllNotManifest(mManager.getPinnedShortcuts()), "ms2"); |
| 7605 | assertShortcutIds(assertAllManifest(mManager.getManifestShortcuts()), |
| 7606 | "ms3", "ms4", "ms5"); |
| 7607 | |
| 7608 | // ms1 and ms2 shouold keep the original title. |
| 7609 | ShortcutInfo si = getCallerShortcut("ms1"); |
| 7610 | assertEquals("title1", si.getTitle()); |
| 7611 | |
| 7612 | si = getCallerShortcut("ms2"); |
| 7613 | assertEquals("title2", si.getTitle()); |
| 7614 | }); |
| 7615 | } |
| 7616 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 7617 | protected void checkManifestShortcuts_immutable_verify() { |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7618 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7619 | assertShortcutIds(assertAllNotManifest(assertAllEnabled( |
| 7620 | mManager.getDynamicShortcuts())), |
| 7621 | "s1"); |
| 7622 | assertShortcutIds(assertAllManifest(assertAllEnabled( |
| 7623 | mManager.getManifestShortcuts())), |
| 7624 | "ms1"); |
| 7625 | assertShortcutIds(assertAllNotManifest(assertAllDisabled( |
| 7626 | mManager.getPinnedShortcuts())), |
| 7627 | "ms2"); |
| 7628 | |
| 7629 | assertEquals("t1", getCallerShortcut("s1").getTitle()); |
| 7630 | |
| 7631 | // Make sure there are no other shortcuts. |
| 7632 | assertShortcutIds(getCallerShortcuts(), "s1", "ms1", "ms2"); |
| 7633 | }); |
| 7634 | } |
| 7635 | |
| 7636 | /** |
| 7637 | * Make sure the APIs won't work on manifest shortcuts. |
| 7638 | */ |
| 7639 | public void testManifestShortcuts_immutable() { |
| 7640 | mService.handleUnlockUser(USER_0); |
| 7641 | |
| 7642 | // Create a non-pinned manifest shortcut, a pinned shortcut that was originally |
| 7643 | // a manifest shortcut, as well as a dynamic shortcut. |
| 7644 | |
| 7645 | addManifestShortcutResource( |
| 7646 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7647 | R.xml.shortcut_2); |
| 7648 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7649 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7650 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7651 | |
| 7652 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 7653 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms2"), HANDLE_USER_0); |
| 7654 | }); |
| 7655 | |
| 7656 | addManifestShortcutResource( |
| 7657 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7658 | R.xml.shortcut_1); |
| 7659 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7660 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 7661 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7662 | |
| 7663 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7664 | mManager.addDynamicShortcuts(list(makeShortcutWithTitle("s1", "t1"))); |
| 7665 | }); |
| 7666 | |
| 7667 | checkManifestShortcuts_immutable_verify(); |
| 7668 | |
| 7669 | // Note that even though the first argument is not immutable and only the second one |
| 7670 | // is immutable, the first argument should not be executed either. |
| 7671 | |
| 7672 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7673 | assertCannotUpdateImmutable(() -> { |
| 7674 | mManager.setDynamicShortcuts(list(makeShortcut("xx"), makeShortcut("ms1"))); |
| 7675 | }); |
| 7676 | assertCannotUpdateImmutable(() -> { |
| 7677 | mManager.setDynamicShortcuts(list(makeShortcut("xx"), makeShortcut("ms2"))); |
| 7678 | }); |
| 7679 | }); |
| 7680 | checkManifestShortcuts_immutable_verify(); |
| 7681 | |
| 7682 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7683 | assertCannotUpdateImmutable(() -> { |
| 7684 | mManager.addDynamicShortcuts(list(makeShortcut("xx"), makeShortcut("ms1"))); |
| 7685 | }); |
| 7686 | assertCannotUpdateImmutable(() -> { |
| 7687 | mManager.addDynamicShortcuts(list(makeShortcut("xx"), makeShortcut("ms2"))); |
| 7688 | }); |
| 7689 | }); |
| 7690 | checkManifestShortcuts_immutable_verify(); |
| 7691 | |
| 7692 | |
| 7693 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7694 | assertCannotUpdateImmutable(() -> { |
| 7695 | mManager.updateShortcuts(list(makeShortcut("s1"), makeShortcut("ms1"))); |
| 7696 | }); |
| 7697 | assertCannotUpdateImmutable(() -> { |
| 7698 | mManager.updateShortcuts(list(makeShortcut("s1"), makeShortcut("ms2"))); |
| 7699 | }); |
| 7700 | }); |
| 7701 | checkManifestShortcuts_immutable_verify(); |
| 7702 | |
| 7703 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7704 | assertCannotUpdateImmutable(() -> { |
| 7705 | mManager.removeDynamicShortcuts(list("s1", "ms1")); |
| 7706 | }); |
| 7707 | assertCannotUpdateImmutable(() -> { |
| 7708 | mManager.removeDynamicShortcuts(list("s2", "ms2")); |
| 7709 | }); |
| 7710 | }); |
| 7711 | checkManifestShortcuts_immutable_verify(); |
| 7712 | |
| 7713 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7714 | assertCannotUpdateImmutable(() -> { |
| 7715 | mManager.disableShortcuts(list("s1", "ms1")); |
| 7716 | }); |
| 7717 | }); |
| 7718 | checkManifestShortcuts_immutable_verify(); |
| 7719 | |
| 7720 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7721 | assertCannotUpdateImmutable(() -> { |
| 7722 | mManager.enableShortcuts(list("s1", "ms2")); |
| 7723 | }); |
| 7724 | }); |
| 7725 | checkManifestShortcuts_immutable_verify(); |
| 7726 | } |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 7727 | |
Makoto Onuki | 51ab2b3 | 2016-06-02 11:03:51 -0700 | [diff] [blame] | 7728 | |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 7729 | /** |
| 7730 | * Make sure the APIs won't work on manifest shortcuts. |
| 7731 | */ |
| 7732 | public void testManifestShortcuts_tooMany() { |
| 7733 | // Change the max number of shortcuts. |
| 7734 | mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3"); |
| 7735 | |
| 7736 | mService.handleUnlockUser(USER_0); |
| 7737 | |
| 7738 | addManifestShortcutResource( |
| 7739 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7740 | R.xml.shortcut_5); |
| 7741 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7742 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 7743 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7744 | |
| 7745 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7746 | // Only the first 3 should be published. |
| 7747 | assertShortcutIds(mManager.getManifestShortcuts(), "ms1", "ms2", "ms3"); |
| 7748 | }); |
| 7749 | } |
| 7750 | |
| 7751 | public void testMaxShortcutCount_set() { |
| 7752 | // Change the max number of shortcuts. |
| 7753 | mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3"); |
| 7754 | |
| 7755 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7756 | final ComponentName a1 = new ComponentName(mClientContext, ShortcutActivity.class); |
| 7757 | final ComponentName a2 = new ComponentName(mClientContext, ShortcutActivity2.class); |
| 7758 | final ShortcutInfo s1_1 = makeShortcutWithActivity("s11", a1); |
| 7759 | final ShortcutInfo s1_2 = makeShortcutWithActivity("s12", a1); |
| 7760 | final ShortcutInfo s1_3 = makeShortcutWithActivity("s13", a1); |
| 7761 | final ShortcutInfo s1_4 = makeShortcutWithActivity("s14", a1); |
| 7762 | final ShortcutInfo s1_5 = makeShortcutWithActivity("s15", a1); |
| 7763 | final ShortcutInfo s1_6 = makeShortcutWithActivity("s16", a1); |
| 7764 | final ShortcutInfo s2_1 = makeShortcutWithActivity("s21", a2); |
| 7765 | final ShortcutInfo s2_2 = makeShortcutWithActivity("s22", a2); |
| 7766 | final ShortcutInfo s2_3 = makeShortcutWithActivity("s23", a2); |
| 7767 | final ShortcutInfo s2_4 = makeShortcutWithActivity("s24", a2); |
| 7768 | |
| 7769 | // 3 shortcuts for 2 activities -> okay |
| 7770 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3)); |
| 7771 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7772 | "s11", "s12", "s13", "s21", "s22", "s23"); |
| 7773 | |
| 7774 | mManager.removeAllDynamicShortcuts(); |
| 7775 | |
| 7776 | // 4 shortcut for activity 1 -> too many. |
| 7777 | assertDynamicShortcutCountExceeded(() -> { |
| 7778 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s1_4, s2_1, s2_2, s2_3)); |
| 7779 | }); |
| 7780 | assertEmpty(mManager.getDynamicShortcuts()); |
| 7781 | |
| 7782 | // 4 shortcut for activity 2 -> too many. |
| 7783 | assertDynamicShortcutCountExceeded(() -> { |
| 7784 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3, s2_4)); |
| 7785 | }); |
| 7786 | assertEmpty(mManager.getDynamicShortcuts()); |
| 7787 | |
| 7788 | // First, set 3. Then set 4, which should be ignored. |
| 7789 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3)); |
| 7790 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7791 | "s11", "s12", "s13"); |
| 7792 | assertDynamicShortcutCountExceeded(() -> { |
| 7793 | mManager.setDynamicShortcuts(list(s2_1, s2_2, s2_3, s2_4)); |
| 7794 | }); |
| 7795 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7796 | "s11", "s12", "s13"); |
| 7797 | |
| 7798 | // Set will remove the old dynamic set, unlike add, so the following should pass. |
| 7799 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3)); |
| 7800 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7801 | "s11", "s12", "s13"); |
| 7802 | mManager.setDynamicShortcuts(list(s1_4, s1_5, s1_6)); |
| 7803 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7804 | "s14", "s15", "s16"); |
| 7805 | |
| 7806 | // Now, test with 2 manifest shortcuts. |
| 7807 | mManager.removeAllDynamicShortcuts(); |
| 7808 | addManifestShortcutResource( |
| 7809 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7810 | R.xml.shortcut_2); |
| 7811 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7812 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 7813 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7814 | assertEquals(2, mManager.getManifestShortcuts().size()); |
| 7815 | |
| 7816 | // Setting 1 to activity 1 will work. |
| 7817 | mManager.setDynamicShortcuts(list(s1_1, s2_1, s2_2, s2_3)); |
| 7818 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7819 | "s11", "s21", "s22", "s23"); |
| 7820 | assertEquals(2, mManager.getManifestShortcuts().size()); |
| 7821 | |
| 7822 | // But setting 2 will not. |
| 7823 | mManager.removeAllDynamicShortcuts(); |
| 7824 | assertDynamicShortcutCountExceeded(() -> { |
| 7825 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s2_1, s2_2, s2_3)); |
| 7826 | }); |
| 7827 | assertEmpty(mManager.getDynamicShortcuts()); |
| 7828 | assertEquals(2, mManager.getManifestShortcuts().size()); |
| 7829 | }); |
| 7830 | } |
| 7831 | |
| 7832 | public void testMaxShortcutCount_add() { |
| 7833 | // Change the max number of shortcuts. |
| 7834 | mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3"); |
| 7835 | |
| 7836 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7837 | final ComponentName a1 = new ComponentName(mClientContext, ShortcutActivity.class); |
| 7838 | final ComponentName a2 = new ComponentName(mClientContext, ShortcutActivity2.class); |
| 7839 | final ShortcutInfo s1_1 = makeShortcutWithActivity("s11", a1); |
| 7840 | final ShortcutInfo s1_2 = makeShortcutWithActivity("s12", a1); |
| 7841 | final ShortcutInfo s1_3 = makeShortcutWithActivity("s13", a1); |
| 7842 | final ShortcutInfo s1_4 = makeShortcutWithActivity("s14", a1); |
| 7843 | final ShortcutInfo s2_1 = makeShortcutWithActivity("s21", a2); |
| 7844 | final ShortcutInfo s2_2 = makeShortcutWithActivity("s22", a2); |
| 7845 | final ShortcutInfo s2_3 = makeShortcutWithActivity("s23", a2); |
| 7846 | final ShortcutInfo s2_4 = makeShortcutWithActivity("s24", a2); |
| 7847 | |
| 7848 | // 3 shortcuts for 2 activities -> okay |
| 7849 | mManager.addDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3)); |
| 7850 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7851 | "s11", "s12", "s13", "s21", "s22", "s23"); |
| 7852 | |
| 7853 | mManager.removeAllDynamicShortcuts(); |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 7854 | |
| 7855 | // 4 shortcut for activity 1 -> too many. |
| 7856 | assertDynamicShortcutCountExceeded(() -> { |
| 7857 | mManager.addDynamicShortcuts(list(s1_1, s1_2, s1_3, s1_4, s2_1, s2_2, s2_3)); |
| 7858 | }); |
| 7859 | assertEmpty(mManager.getDynamicShortcuts()); |
| 7860 | |
| 7861 | // 4 shortcut for activity 2 -> too many. |
| 7862 | assertDynamicShortcutCountExceeded(() -> { |
| 7863 | mManager.addDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3, s2_4)); |
| 7864 | }); |
| 7865 | assertEmpty(mManager.getDynamicShortcuts()); |
| 7866 | |
| 7867 | // First, set 3. Then add 1 more, which should be ignored. |
| 7868 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3)); |
| 7869 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7870 | "s11", "s12", "s13"); |
| 7871 | assertDynamicShortcutCountExceeded(() -> { |
| 7872 | mManager.addDynamicShortcuts(list(s1_4, s2_1)); |
| 7873 | }); |
| 7874 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7875 | "s11", "s12", "s13"); |
| 7876 | |
| 7877 | // Update existing one, which should work. |
| 7878 | mManager.addDynamicShortcuts(list(makeShortcutWithActivityAndTitle( |
| 7879 | "s11", a1, "xxx"), s2_1)); |
| 7880 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7881 | "s11", "s12", "s13", "s21"); |
| 7882 | assertEquals("xxx", getCallerShortcut("s11").getTitle()); |
| 7883 | |
| 7884 | // Make sure pinned shortcuts won't affect. |
| 7885 | // - Pin s11 - s13, and remove all dynamic. |
| 7886 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 7887 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s11", "s12", "s13"), |
| 7888 | HANDLE_USER_0); |
| 7889 | }); |
| 7890 | mManager.removeAllDynamicShortcuts(); |
| 7891 | |
| 7892 | assertEmpty(mManager.getDynamicShortcuts()); |
| 7893 | assertShortcutIds(mManager.getPinnedShortcuts(), |
| 7894 | "s11", "s12", "s13"); |
| 7895 | |
| 7896 | // Then add dynamic. |
| 7897 | mManager.addDynamicShortcuts(list(s1_4, s2_1, s2_2, s2_3)); |
| 7898 | |
| 7899 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7900 | "s14", "s21", "s22", "s23"); |
| 7901 | assertShortcutIds(mManager.getPinnedShortcuts(), |
| 7902 | "s11", "s12", "s13"); |
| 7903 | |
| 7904 | // Adding "s11" and "s12" back, should work |
| 7905 | mManager.addDynamicShortcuts(list(s1_1, s1_2)); |
| 7906 | |
| 7907 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7908 | "s14", "s11", "s12", "s21", "s22", "s23"); |
| 7909 | assertShortcutIds(mManager.getPinnedShortcuts(), |
| 7910 | "s11", "s12", "s13"); |
| 7911 | |
| 7912 | // Adding back s13 doesn't work. |
| 7913 | assertDynamicShortcutCountExceeded(() -> { |
| 7914 | mManager.addDynamicShortcuts(list(s1_3)); |
| 7915 | }); |
| 7916 | |
| 7917 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), |
| 7918 | "s11", "s12", "s14"); |
| 7919 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), |
| 7920 | "s21", "s22", "s23"); |
| 7921 | |
| 7922 | // Now swap the activities. |
| 7923 | mManager.updateShortcuts(list( |
| 7924 | makeShortcutWithActivity("s11", a2), |
| 7925 | makeShortcutWithActivity("s21", a1))); |
| 7926 | |
| 7927 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), |
| 7928 | "s21", "s12", "s14"); |
| 7929 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), |
| 7930 | "s11", "s22", "s23"); |
| 7931 | |
| 7932 | // Now, test with 2 manifest shortcuts. |
| 7933 | mManager.removeAllDynamicShortcuts(); |
| 7934 | addManifestShortcutResource( |
| 7935 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 7936 | R.xml.shortcut_2); |
| 7937 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 7938 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 7939 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 7940 | |
| 7941 | assertEquals(2, mManager.getManifestShortcuts().size()); |
| 7942 | |
| 7943 | // Adding one shortcut to activity 1 works fine. |
| 7944 | mManager.addDynamicShortcuts(list(s1_1, s2_1, s2_2, s2_3)); |
| 7945 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7946 | "s11", "s21", "s22", "s23"); |
| 7947 | assertEquals(2, mManager.getManifestShortcuts().size()); |
| 7948 | |
| 7949 | // But adding one more doesn't. |
| 7950 | assertDynamicShortcutCountExceeded(() -> { |
| 7951 | mManager.addDynamicShortcuts(list(s1_4, s2_1)); |
| 7952 | }); |
| 7953 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7954 | "s11", "s21", "s22", "s23"); |
| 7955 | assertEquals(2, mManager.getManifestShortcuts().size()); |
| 7956 | }); |
| 7957 | } |
| 7958 | |
| 7959 | public void testMaxShortcutCount_update() { |
| 7960 | // Change the max number of shortcuts. |
| 7961 | mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3"); |
| 7962 | |
| 7963 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 7964 | final ComponentName a1 = new ComponentName(mClientContext, ShortcutActivity.class); |
| 7965 | final ComponentName a2 = new ComponentName(mClientContext, ShortcutActivity2.class); |
| 7966 | final ShortcutInfo s1_1 = makeShortcutWithActivity("s11", a1); |
| 7967 | final ShortcutInfo s1_2 = makeShortcutWithActivity("s12", a1); |
| 7968 | final ShortcutInfo s1_3 = makeShortcutWithActivity("s13", a1); |
| 7969 | final ShortcutInfo s1_4 = makeShortcutWithActivity("s14", a1); |
| 7970 | final ShortcutInfo s1_5 = makeShortcutWithActivity("s15", a1); |
| 7971 | final ShortcutInfo s2_1 = makeShortcutWithActivity("s21", a2); |
| 7972 | final ShortcutInfo s2_2 = makeShortcutWithActivity("s22", a2); |
| 7973 | final ShortcutInfo s2_3 = makeShortcutWithActivity("s23", a2); |
| 7974 | final ShortcutInfo s2_4 = makeShortcutWithActivity("s24", a2); |
| 7975 | |
| 7976 | // 3 shortcuts for 2 activities -> okay |
| 7977 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3)); |
| 7978 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7979 | "s11", "s12", "s13", "s21", "s22", "s23"); |
| 7980 | |
| 7981 | // Trying to move s11 from a1 to a2 should fail. |
| 7982 | assertDynamicShortcutCountExceeded(() -> { |
| 7983 | mManager.updateShortcuts(list(makeShortcutWithActivity("s11", a2))); |
| 7984 | }); |
| 7985 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7986 | "s11", "s12", "s13", "s21", "s22", "s23"); |
| 7987 | |
| 7988 | // Trying to move s21 from a2 to a1 should also fail. |
| 7989 | assertDynamicShortcutCountExceeded(() -> { |
| 7990 | mManager.updateShortcuts(list(makeShortcutWithActivity("s21", a1))); |
| 7991 | }); |
| 7992 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 7993 | "s11", "s12", "s13", "s21", "s22", "s23"); |
| 7994 | |
| 7995 | // But, if we do these two at the same time, it should work. |
| 7996 | mManager.updateShortcuts(list( |
| 7997 | makeShortcutWithActivity("s11", a2), |
| 7998 | makeShortcutWithActivity("s21", a1))); |
| 7999 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 8000 | "s11", "s12", "s13", "s21", "s22", "s23"); |
| 8001 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), |
| 8002 | "s21", "s12", "s13"); |
| 8003 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), |
| 8004 | "s11", "s22", "s23"); |
| 8005 | |
| 8006 | // Then reset. |
| 8007 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3)); |
| 8008 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 8009 | "s11", "s12", "s13", "s21", "s22", "s23"); |
| 8010 | |
| 8011 | // Pin some to have more shortcuts for a1. |
| 8012 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 8013 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s11", "s12", "s13"), |
| 8014 | HANDLE_USER_0); |
| 8015 | }); |
| 8016 | mManager.setDynamicShortcuts(list(s1_4, s1_5, s2_1, s2_2, s2_3)); |
| 8017 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 8018 | "s14", "s15", "s21", "s22", "s23"); |
| 8019 | assertShortcutIds(mManager.getPinnedShortcuts(), |
| 8020 | "s11", "s12", "s13"); |
| 8021 | |
| 8022 | // a1 already has 2 dynamic shortcuts (and 3 pinned shortcuts that used to belong on it) |
| 8023 | // But that doesn't matter for update -- the following should still work. |
| 8024 | mManager.updateShortcuts(list( |
| 8025 | makeShortcutWithActivityAndTitle("s11", a1, "xxx1"), |
| 8026 | makeShortcutWithActivityAndTitle("s12", a1, "xxx2"), |
| 8027 | makeShortcutWithActivityAndTitle("s13", a1, "xxx3"), |
| 8028 | makeShortcutWithActivityAndTitle("s14", a1, "xxx4"), |
| 8029 | makeShortcutWithActivityAndTitle("s15", a1, "xxx5"))); |
| 8030 | // All the shortcuts should still exist they all belong on same activities, |
| 8031 | // with the updated titles. |
| 8032 | assertShortcutIds(mManager.getDynamicShortcuts(), |
| 8033 | "s14", "s15", "s21", "s22", "s23"); |
| 8034 | assertShortcutIds(mManager.getPinnedShortcuts(), |
| 8035 | "s11", "s12", "s13"); |
| 8036 | |
| 8037 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), |
| 8038 | "s14", "s15"); |
| 8039 | assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), |
| 8040 | "s21", "s22", "s23"); |
| 8041 | |
| 8042 | assertEquals("xxx1", getCallerShortcut("s11").getTitle()); |
| 8043 | assertEquals("xxx2", getCallerShortcut("s12").getTitle()); |
| 8044 | assertEquals("xxx3", getCallerShortcut("s13").getTitle()); |
| 8045 | assertEquals("xxx4", getCallerShortcut("s14").getTitle()); |
| 8046 | assertEquals("xxx5", getCallerShortcut("s15").getTitle()); |
| 8047 | }); |
| 8048 | } |
| 8049 | |
| 8050 | public void testShortcutsPushedOutByManifest() { |
| 8051 | // Change the max number of shortcuts. |
| 8052 | mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3"); |
| 8053 | |
| 8054 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 8055 | final ComponentName a1 = new ComponentName(mClientContext, ShortcutActivity.class); |
| 8056 | final ComponentName a2 = new ComponentName(mClientContext, ShortcutActivity2.class); |
| 8057 | final ShortcutInfo s1_1 = makeShortcutWithActivityAndRank("s11", a1, 4); |
| 8058 | final ShortcutInfo s1_2 = makeShortcutWithActivityAndRank("s12", a1, 3); |
| 8059 | final ShortcutInfo s1_3 = makeShortcutWithActivityAndRank("s13", a1, 2); |
| 8060 | final ShortcutInfo s1_4 = makeShortcutWithActivityAndRank("s14", a1, 1); |
| 8061 | final ShortcutInfo s1_5 = makeShortcutWithActivityAndRank("s15", a1, 0); |
| 8062 | final ShortcutInfo s2_1 = makeShortcutWithActivityAndRank("s21", a2, 0); |
| 8063 | final ShortcutInfo s2_2 = makeShortcutWithActivityAndRank("s22", a2, 1); |
| 8064 | final ShortcutInfo s2_3 = makeShortcutWithActivityAndRank("s23", a2, 2); |
| 8065 | final ShortcutInfo s2_4 = makeShortcutWithActivityAndRank("s24", a2, 3); |
| 8066 | final ShortcutInfo s2_5 = makeShortcutWithActivityAndRank("s25", a2, 4); |
| 8067 | |
| 8068 | // Initial state. |
| 8069 | mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3)); |
| 8070 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 8071 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s11", "s12", "s21", "s22"), |
| 8072 | HANDLE_USER_0); |
| 8073 | }); |
| 8074 | mManager.setDynamicShortcuts(list(s1_2, s1_3, s1_4, s2_2, s2_3, s2_4)); |
| 8075 | assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), |
| 8076 | "s12", "s13", "s14", |
| 8077 | "s22", "s23", "s24"); |
| 8078 | assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), |
| 8079 | "s11", "s12", |
| 8080 | "s21", "s22"); |
| 8081 | |
| 8082 | // Add 1 manifest shortcut to a1. |
| 8083 | addManifestShortcutResource( |
| 8084 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 8085 | R.xml.shortcut_1); |
| 8086 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 8087 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 8088 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 8089 | assertEquals(1, mManager.getManifestShortcuts().size()); |
| 8090 | |
| 8091 | // s12 removed. |
| 8092 | assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), |
| 8093 | "s13", "s14", |
| 8094 | "s22", "s23", "s24"); |
| 8095 | assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), |
| 8096 | "s11", "s12", |
| 8097 | "s21", "s22"); |
| 8098 | |
| 8099 | // Add more manifest shortcuts. |
| 8100 | addManifestShortcutResource( |
| 8101 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 8102 | R.xml.shortcut_2); |
| 8103 | addManifestShortcutResource( |
| 8104 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), |
| 8105 | R.xml.shortcut_1_alt); |
| 8106 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 8107 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 8108 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 8109 | assertEquals(3, mManager.getManifestShortcuts().size()); |
| 8110 | |
| 8111 | // Note the ones with the highest rank values (== least important) will be removed. |
| 8112 | assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), |
| 8113 | "s14", |
| 8114 | "s22", "s23"); |
| 8115 | assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), |
| 8116 | "s11", "s12", |
| 8117 | "s21", "s22"); |
| 8118 | |
| 8119 | // Add more manifest shortcuts. |
| 8120 | addManifestShortcutResource( |
| 8121 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 8122 | R.xml.shortcut_2); |
| 8123 | addManifestShortcutResource( |
| 8124 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), |
| 8125 | R.xml.shortcut_5_alt); // manifest has 5, but max is 3, so a2 will have 3. |
| 8126 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 8127 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 8128 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 8129 | assertEquals(5, mManager.getManifestShortcuts().size()); |
| 8130 | |
| 8131 | assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), |
| 8132 | "s14" // a1 has 1 dynamic |
| 8133 | ); // a2 has no dynamic |
| 8134 | assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), |
| 8135 | "s11", "s12", |
| 8136 | "s21", "s22"); |
| 8137 | |
| 8138 | // Update, no manifest shortucts. This doesn't affect anything. |
| 8139 | addManifestShortcutResource( |
| 8140 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 8141 | R.xml.shortcut_0); |
| 8142 | addManifestShortcutResource( |
| 8143 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), |
| 8144 | R.xml.shortcut_0); |
| 8145 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
Makoto Onuki | f34c308 | 2016-07-13 10:25:25 -0700 | [diff] [blame] | 8146 | mService.mPackageMonitor.onReceive(getTestContext(), |
Makoto Onuki | 7001a61 | 2016-05-27 13:24:28 -0700 | [diff] [blame] | 8147 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 8148 | assertEquals(0, mManager.getManifestShortcuts().size()); |
| 8149 | |
| 8150 | assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), |
| 8151 | "s14"); |
| 8152 | assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), |
| 8153 | "s11", "s12", |
| 8154 | "s21", "s22"); |
| 8155 | }); |
| 8156 | } |
Makoto Onuki | bf563b6 | 2017-05-04 10:25:30 -0700 | [diff] [blame] | 8157 | |
| 8158 | public void testReturnedByServer() { |
| 8159 | // Package 1 updated, with manifest shortcuts. |
| 8160 | addManifestShortcutResource( |
| 8161 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 8162 | R.xml.shortcut_1); |
| 8163 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 8164 | mService.mPackageMonitor.onReceive(getTestContext(), |
| 8165 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 8166 | |
| 8167 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 8168 | assertWith(mManager.getManifestShortcuts()) |
| 8169 | .haveIds("ms1") |
| 8170 | .forAllShortcuts(si -> assertTrue(si.isReturnedByServer())); |
| 8171 | |
| 8172 | assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1")))); |
| 8173 | |
| 8174 | assertWith(mManager.getDynamicShortcuts()) |
| 8175 | .haveIds("s1") |
| 8176 | .forAllShortcuts(si -> assertTrue(si.isReturnedByServer())); |
| 8177 | }); |
| 8178 | |
| 8179 | // Pin them. |
| 8180 | runWithCaller(LAUNCHER_1, USER_0, () -> { |
| 8181 | mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, |
| 8182 | list("ms1", "s1"), getCallingUser()); |
| 8183 | assertWith(getShortcutAsLauncher(USER_0)) |
| 8184 | .haveIds("ms1", "s1") |
| 8185 | .forAllShortcuts(si -> assertTrue(si.isReturnedByServer())); |
| 8186 | }); |
| 8187 | |
| 8188 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 8189 | assertWith(mManager.getPinnedShortcuts()) |
| 8190 | .haveIds("ms1", "s1") |
| 8191 | .forAllShortcuts(si -> assertTrue(si.isReturnedByServer())); |
| 8192 | }); |
| 8193 | |
| 8194 | runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { |
| 8195 | // This shows a warning log, but should still work. |
| 8196 | assertTrue(mManager.setDynamicShortcuts(mManager.getDynamicShortcuts())); |
| 8197 | |
| 8198 | assertWith(mManager.getDynamicShortcuts()) |
| 8199 | .haveIds("s1") |
| 8200 | .forAllShortcuts(si -> assertTrue(si.isReturnedByServer())); |
| 8201 | }); |
| 8202 | } |
Tony Mak | ed6ef62 | 2017-12-07 16:36:16 +0000 | [diff] [blame] | 8203 | |
| 8204 | public void testIsForegroundDefaultLauncher_true() { |
| 8205 | final ComponentName defaultLauncher = new ComponentName("default", "launcher"); |
| 8206 | final int uid = 1024; |
| 8207 | |
| 8208 | setDefaultLauncher(UserHandle.USER_SYSTEM, defaultLauncher); |
| 8209 | makeUidForeground(uid); |
| 8210 | |
| 8211 | assertTrue(mInternal.isForegroundDefaultLauncher("default", uid)); |
| 8212 | } |
| 8213 | |
| 8214 | |
| 8215 | public void testIsForegroundDefaultLauncher_defaultButNotForeground() { |
| 8216 | final ComponentName defaultLauncher = new ComponentName("default", "launcher"); |
| 8217 | final int uid = 1024; |
| 8218 | |
| 8219 | setDefaultLauncher(UserHandle.USER_SYSTEM, defaultLauncher); |
| 8220 | makeUidBackground(uid); |
| 8221 | |
| 8222 | assertFalse(mInternal.isForegroundDefaultLauncher("default", uid)); |
| 8223 | } |
| 8224 | |
| 8225 | public void testIsForegroundDefaultLauncher_foregroundButNotDefault() { |
| 8226 | final ComponentName defaultLauncher = new ComponentName("default", "launcher"); |
| 8227 | final int uid = 1024; |
| 8228 | |
| 8229 | setDefaultLauncher(UserHandle.USER_SYSTEM, defaultLauncher); |
| 8230 | makeUidForeground(uid); |
| 8231 | |
| 8232 | assertFalse(mInternal.isForegroundDefaultLauncher("another", uid)); |
| 8233 | } |
Mehdi Alizadeh | 3277462 | 2018-11-05 17:32:01 -0800 | [diff] [blame] | 8234 | |
| 8235 | public void testParseShareTargetsFromManifest() { |
| 8236 | // These values must exactly match the content of shortcuts_share_targets.xml resource |
| 8237 | List<ShareTargetInfo> expectedValues = new ArrayList<>(); |
| 8238 | expectedValues.add(new ShareTargetInfo( |
| 8239 | new ShareTargetInfo.TargetData[]{new ShareTargetInfo.TargetData( |
| 8240 | "http", "www.google.com", "1234", "somePath", "somePathPattern", |
| 8241 | "somePathPrefix", "text/plain")}, "com.test.directshare.TestActivity1", |
| 8242 | new String[]{"com.test.category.CATEGORY1", "com.test.category.CATEGORY2"})); |
| 8243 | expectedValues.add(new ShareTargetInfo(new ShareTargetInfo.TargetData[]{ |
| 8244 | new ShareTargetInfo.TargetData(null, null, null, null, null, null, "video/mp4"), |
| 8245 | new ShareTargetInfo.TargetData("content", null, null, null, null, null, "video/*")}, |
| 8246 | "com.test.directshare.TestActivity5", |
| 8247 | new String[]{"com.test.category.CATEGORY5", "com.test.category.CATEGORY6"})); |
| 8248 | |
| 8249 | addManifestShortcutResource( |
| 8250 | new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), |
| 8251 | R.xml.shortcut_share_targets); |
| 8252 | updatePackageVersion(CALLING_PACKAGE_1, 1); |
| 8253 | mService.mPackageMonitor.onReceive(getTestContext(), |
| 8254 | genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); |
| 8255 | |
| 8256 | List<ShareTargetInfo> shareTargets = getCallerShareTargets(); |
| 8257 | |
| 8258 | assertNotNull(shareTargets); |
| 8259 | assertEquals(expectedValues.size(), shareTargets.size()); |
| 8260 | |
| 8261 | for (int i = 0; i < expectedValues.size(); i++) { |
| 8262 | ShareTargetInfo expected = expectedValues.get(i); |
| 8263 | ShareTargetInfo actual = shareTargets.get(i); |
| 8264 | |
| 8265 | assertEquals(expected.mTargetData.length, actual.mTargetData.length); |
| 8266 | for (int j = 0; j < expected.mTargetData.length; j++) { |
| 8267 | assertEquals(expected.mTargetData[j].mScheme, actual.mTargetData[j].mScheme); |
| 8268 | assertEquals(expected.mTargetData[j].mHost, actual.mTargetData[j].mHost); |
| 8269 | assertEquals(expected.mTargetData[j].mPort, actual.mTargetData[j].mPort); |
| 8270 | assertEquals(expected.mTargetData[j].mPath, actual.mTargetData[j].mPath); |
| 8271 | assertEquals(expected.mTargetData[j].mPathPrefix, |
| 8272 | actual.mTargetData[j].mPathPrefix); |
| 8273 | assertEquals(expected.mTargetData[j].mPathPattern, |
| 8274 | actual.mTargetData[j].mPathPattern); |
| 8275 | assertEquals(expected.mTargetData[j].mMimeType, actual.mTargetData[j].mMimeType); |
| 8276 | } |
| 8277 | |
| 8278 | assertEquals(expected.mTargetClass, actual.mTargetClass); |
| 8279 | |
| 8280 | assertEquals(expected.mCategories.length, actual.mCategories.length); |
| 8281 | for (int j = 0; j < expected.mCategories.length; j++) { |
| 8282 | assertEquals(expected.mCategories[j], actual.mCategories[j]); |
| 8283 | } |
| 8284 | } |
| 8285 | } |
Mehdi Alizadeh | abec319 | 2019-06-27 18:06:15 -0700 | [diff] [blame] | 8286 | |
| 8287 | public void testShareTargetInfo_saveToXml() throws IOException, XmlPullParserException { |
| 8288 | List<ShareTargetInfo> expectedValues = new ArrayList<>(); |
| 8289 | expectedValues.add(new ShareTargetInfo( |
| 8290 | new ShareTargetInfo.TargetData[]{new ShareTargetInfo.TargetData( |
| 8291 | "http", "www.google.com", "1234", "somePath", "somePathPattern", |
| 8292 | "somePathPrefix", "text/plain")}, "com.test.directshare.TestActivity1", |
| 8293 | new String[]{"com.test.category.CATEGORY1", "com.test.category.CATEGORY2"})); |
| 8294 | expectedValues.add(new ShareTargetInfo(new ShareTargetInfo.TargetData[]{ |
| 8295 | new ShareTargetInfo.TargetData(null, null, null, null, null, null, "video/mp4"), |
| 8296 | new ShareTargetInfo.TargetData("content", null, null, null, null, null, "video/*")}, |
| 8297 | "com.test.directshare.TestActivity5", |
| 8298 | new String[]{"com.test.category.CATEGORY5", "com.test.category.CATEGORY6"})); |
| 8299 | |
| 8300 | // Write ShareTargets to Xml |
| 8301 | ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
| 8302 | final XmlSerializer outXml = new FastXmlSerializer(); |
| 8303 | outXml.setOutput(outStream, StandardCharsets.UTF_8.name()); |
| 8304 | outXml.startDocument(null, true); |
| 8305 | for (int i = 0; i < expectedValues.size(); i++) { |
| 8306 | expectedValues.get(i).saveToXml(outXml); |
| 8307 | } |
| 8308 | outXml.endDocument(); |
| 8309 | outXml.flush(); |
| 8310 | |
| 8311 | // Read ShareTargets from Xml |
| 8312 | ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); |
| 8313 | XmlPullParser parser = Xml.newPullParser(); |
| 8314 | parser.setInput(new InputStreamReader(inStream)); |
| 8315 | List<ShareTargetInfo> shareTargets = new ArrayList<>(); |
| 8316 | int type; |
| 8317 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
| 8318 | if (type == XmlPullParser.START_TAG && parser.getName().equals("share-target")) { |
| 8319 | shareTargets.add(ShareTargetInfo.loadFromXml(parser)); |
| 8320 | } |
| 8321 | } |
| 8322 | |
| 8323 | // Assert two lists are equal |
| 8324 | assertNotNull(shareTargets); |
| 8325 | assertEquals(expectedValues.size(), shareTargets.size()); |
| 8326 | |
| 8327 | for (int i = 0; i < expectedValues.size(); i++) { |
| 8328 | ShareTargetInfo expected = expectedValues.get(i); |
| 8329 | ShareTargetInfo actual = shareTargets.get(i); |
| 8330 | |
| 8331 | assertEquals(expected.mTargetData.length, actual.mTargetData.length); |
| 8332 | for (int j = 0; j < expected.mTargetData.length; j++) { |
| 8333 | assertEquals(expected.mTargetData[j].mScheme, actual.mTargetData[j].mScheme); |
| 8334 | assertEquals(expected.mTargetData[j].mHost, actual.mTargetData[j].mHost); |
| 8335 | assertEquals(expected.mTargetData[j].mPort, actual.mTargetData[j].mPort); |
| 8336 | assertEquals(expected.mTargetData[j].mPath, actual.mTargetData[j].mPath); |
| 8337 | assertEquals(expected.mTargetData[j].mPathPrefix, |
| 8338 | actual.mTargetData[j].mPathPrefix); |
| 8339 | assertEquals(expected.mTargetData[j].mPathPattern, |
| 8340 | actual.mTargetData[j].mPathPattern); |
| 8341 | assertEquals(expected.mTargetData[j].mMimeType, actual.mTargetData[j].mMimeType); |
| 8342 | } |
| 8343 | |
| 8344 | assertEquals(expected.mTargetClass, actual.mTargetClass); |
| 8345 | |
| 8346 | assertEquals(expected.mCategories.length, actual.mCategories.length); |
| 8347 | for (int j = 0; j < expected.mCategories.length; j++) { |
| 8348 | assertEquals(expected.mCategories[j], actual.mCategories[j]); |
| 8349 | } |
| 8350 | } |
| 8351 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 8352 | } |