summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/content/pm/ShortcutServiceInternal.java3
-rw-r--r--services/core/java/com/android/server/pm/ShortcutService.java20
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java16
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java31
4 files changed, 66 insertions, 4 deletions
diff --git a/core/java/android/content/pm/ShortcutServiceInternal.java b/core/java/android/content/pm/ShortcutServiceInternal.java
index dadfaa9f1a66..e6f682d22b14 100644
--- a/core/java/android/content/pm/ShortcutServiceInternal.java
+++ b/core/java/android/content/pm/ShortcutServiceInternal.java
@@ -81,4 +81,7 @@ public abstract class ShortcutServiceInternal {
@Nullable IntentSender resultIntent, int userId);
public abstract boolean isRequestPinItemSupported(int callingUserId, int requestType);
+
+ public abstract boolean isForegroundDefaultLauncher(@NonNull String callingPackage,
+ int callingUid);
}
diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java
index 0907dd7c5a9e..ee2f3742c811 100644
--- a/services/core/java/com/android/server/pm/ShortcutService.java
+++ b/services/core/java/com/android/server/pm/ShortcutService.java
@@ -2739,6 +2739,26 @@ public class ShortcutService extends IShortcutService.Stub {
public boolean isRequestPinItemSupported(int callingUserId, int requestType) {
return ShortcutService.this.isRequestPinItemSupported(callingUserId, requestType);
}
+
+ @Override
+ public boolean isForegroundDefaultLauncher(@NonNull String callingPackage, int callingUid) {
+ Preconditions.checkNotNull(callingPackage);
+
+ final int userId = UserHandle.getUserId(callingUid);
+ final ComponentName defaultLauncher = getDefaultLauncher(userId);
+ if (defaultLauncher == null) {
+ return false;
+ }
+ if (!callingPackage.equals(defaultLauncher.getPackageName())) {
+ return false;
+ }
+ synchronized (mLock) {
+ if (!isUidForegroundLocked(callingUid)) {
+ return false;
+ }
+ }
+ return true;
+ }
}
final BroadcastReceiver mReceiver = new BroadcastReceiver() {
diff --git a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java
index 926a9112ad29..8cf575eec4d9 100644
--- a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java
@@ -2121,24 +2121,32 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
PACKAGE_FALLBACK_LAUNCHER_PRIORITY);
}
- protected void makeCallerForeground() {
+ protected void makeUidForeground(int uid) {
try {
mService.mUidObserver.onUidStateChanged(
- mInjectedCallingUid, ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE, 0);
+ uid, ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE, 0);
} catch (RemoteException e) {
e.rethrowAsRuntimeException();
}
}
- protected void makeCallerBackground() {
+ protected void makeCallerForeground() {
+ makeUidForeground(mInjectedCallingUid);
+ }
+
+ protected void makeUidBackground(int uid) {
try {
mService.mUidObserver.onUidStateChanged(
- mInjectedCallingUid, ActivityManager.PROCESS_STATE_TOP_SLEEPING, 0);
+ uid, ActivityManager.PROCESS_STATE_TOP_SLEEPING, 0);
} catch (RemoteException e) {
e.rethrowAsRuntimeException();
}
}
+ protected void makeCallerBackground() {
+ makeUidBackground(mInjectedCallingUid);
+ }
+
protected void publishManifestShortcutsAsCaller(int resId) {
addManifestShortcutResource(
new ComponentName(getCallingPackage(), ShortcutActivity.class.getName()),
diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
index f92b575bc976..ee33e797b0ab 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
@@ -7912,4 +7912,35 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
.forAllShortcuts(si -> assertTrue(si.isReturnedByServer()));
});
}
+
+ public void testIsForegroundDefaultLauncher_true() {
+ final ComponentName defaultLauncher = new ComponentName("default", "launcher");
+ final int uid = 1024;
+
+ setDefaultLauncher(UserHandle.USER_SYSTEM, defaultLauncher);
+ makeUidForeground(uid);
+
+ assertTrue(mInternal.isForegroundDefaultLauncher("default", uid));
+ }
+
+
+ public void testIsForegroundDefaultLauncher_defaultButNotForeground() {
+ final ComponentName defaultLauncher = new ComponentName("default", "launcher");
+ final int uid = 1024;
+
+ setDefaultLauncher(UserHandle.USER_SYSTEM, defaultLauncher);
+ makeUidBackground(uid);
+
+ assertFalse(mInternal.isForegroundDefaultLauncher("default", uid));
+ }
+
+ public void testIsForegroundDefaultLauncher_foregroundButNotDefault() {
+ final ComponentName defaultLauncher = new ComponentName("default", "launcher");
+ final int uid = 1024;
+
+ setDefaultLauncher(UserHandle.USER_SYSTEM, defaultLauncher);
+ makeUidForeground(uid);
+
+ assertFalse(mInternal.isForegroundDefaultLauncher("another", uid));
+ }
}