Loading core/java/android/content/pm/ShortcutServiceInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); } services/core/java/com/android/server/pm/ShortcutService.java +20 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +12 −4 Original line number Diff line number Diff line Loading @@ -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()), Loading services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +31 −0 Original line number Diff line number Diff line Loading @@ -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)); } } Loading
core/java/android/content/pm/ShortcutServiceInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); }
services/core/java/com/android/server/pm/ShortcutService.java +20 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading
services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +12 −4 Original line number Diff line number Diff line Loading @@ -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()), Loading
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +31 −0 Original line number Diff line number Diff line Loading @@ -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)); } }