Loading services/core/java/com/android/server/pm/ShortcutService.java +5 −1 Original line number Diff line number Diff line Loading @@ -4052,7 +4052,8 @@ public class ShortcutService extends IShortcutService.Stub { // Due to b/38267327, ActivityInfo.enabled may not reflect the current state of the component // and we need to check the enabled state via PackageManager.getComponentEnabledSetting. private boolean isEnabled(@Nullable ActivityInfo ai, int userId) { @VisibleForTesting boolean isEnabled(@Nullable ActivityInfo ai, int userId) { if (ai == null) { return false; } Loading @@ -4062,6 +4063,9 @@ public class ShortcutService extends IShortcutService.Stub { try { enabledFlag = mIPackageManager.getComponentEnabledSetting( ai.getComponentName(), userId); } catch (IllegalArgumentException e) { Slog.w(TAG, "Failed to get component enabled setting of " + ai.getComponentName(), e); return false; } catch (RemoteException e) { // Shouldn't happen. Slog.wtf(TAG, "RemoteException", e); Loading services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest5.java +28 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ package com.android.server.pm; import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.set; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.app.Activity; import android.content.ComponentName; import android.content.pm.ActivityInfo; Loading Loading @@ -202,6 +205,31 @@ public class ShortcutManagerTest5 extends BaseShortcutManagerTest { new ComponentName(mMyPackage, "a.ShortcutDisabled"), mMyUserId)); assertFalse(mShortcutService.injectIsActivityEnabledAndExported( new ComponentName(mMyPackage, "a.ShortcutUnexported"), mMyUserId)); } public void testIsEnabled() { ActivityInfo ai = mShortcutService.getActivityInfoWithMetadata( new ComponentName(mMyPackage, "a.Shortcut1"), mMyUserId); // Should return true for an existing and enabled activity. assertTrue(mShortcutService.isEnabled(ai, mMyUserId)); // Should return false for an existing and disabled activity. ai = mShortcutService.getActivityInfoWithMetadata( new ComponentName(mMyPackage, "a.ShortcutDisabled"), mMyUserId); assertFalse(mShortcutService.isEnabled(ai, mMyUserId)); // Should return false (not throw) for a nonexistent or null activity. ai = mock(ActivityInfo.class); when(ai.getComponentName()).thenReturn( ComponentName.unflattenFromString("com.android.settings/.xxx")); assertFalse(mShortcutService.isEnabled(ai, mMyUserId)); ai = mock(ActivityInfo.class); when(ai.getComponentName()).thenReturn( ComponentName.unflattenFromString("no.such.package/.xxx")); assertFalse(mShortcutService.isEnabled(ai, mMyUserId)); assertFalse(mShortcutService.isEnabled(null, mMyUserId)); } } Loading
services/core/java/com/android/server/pm/ShortcutService.java +5 −1 Original line number Diff line number Diff line Loading @@ -4052,7 +4052,8 @@ public class ShortcutService extends IShortcutService.Stub { // Due to b/38267327, ActivityInfo.enabled may not reflect the current state of the component // and we need to check the enabled state via PackageManager.getComponentEnabledSetting. private boolean isEnabled(@Nullable ActivityInfo ai, int userId) { @VisibleForTesting boolean isEnabled(@Nullable ActivityInfo ai, int userId) { if (ai == null) { return false; } Loading @@ -4062,6 +4063,9 @@ public class ShortcutService extends IShortcutService.Stub { try { enabledFlag = mIPackageManager.getComponentEnabledSetting( ai.getComponentName(), userId); } catch (IllegalArgumentException e) { Slog.w(TAG, "Failed to get component enabled setting of " + ai.getComponentName(), e); return false; } catch (RemoteException e) { // Shouldn't happen. Slog.wtf(TAG, "RemoteException", e); Loading
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest5.java +28 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ package com.android.server.pm; import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.set; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.app.Activity; import android.content.ComponentName; import android.content.pm.ActivityInfo; Loading Loading @@ -202,6 +205,31 @@ public class ShortcutManagerTest5 extends BaseShortcutManagerTest { new ComponentName(mMyPackage, "a.ShortcutDisabled"), mMyUserId)); assertFalse(mShortcutService.injectIsActivityEnabledAndExported( new ComponentName(mMyPackage, "a.ShortcutUnexported"), mMyUserId)); } public void testIsEnabled() { ActivityInfo ai = mShortcutService.getActivityInfoWithMetadata( new ComponentName(mMyPackage, "a.Shortcut1"), mMyUserId); // Should return true for an existing and enabled activity. assertTrue(mShortcutService.isEnabled(ai, mMyUserId)); // Should return false for an existing and disabled activity. ai = mShortcutService.getActivityInfoWithMetadata( new ComponentName(mMyPackage, "a.ShortcutDisabled"), mMyUserId); assertFalse(mShortcutService.isEnabled(ai, mMyUserId)); // Should return false (not throw) for a nonexistent or null activity. ai = mock(ActivityInfo.class); when(ai.getComponentName()).thenReturn( ComponentName.unflattenFromString("com.android.settings/.xxx")); assertFalse(mShortcutService.isEnabled(ai, mMyUserId)); ai = mock(ActivityInfo.class); when(ai.getComponentName()).thenReturn( ComponentName.unflattenFromString("no.such.package/.xxx")); assertFalse(mShortcutService.isEnabled(ai, mMyUserId)); assertFalse(mShortcutService.isEnabled(null, mMyUserId)); } }