diff options
5 files changed, 35 insertions, 5 deletions
diff --git a/core/java/android/content/pm/ShortcutManager.java b/core/java/android/content/pm/ShortcutManager.java index eaccb3aeab55..36ab804a0b02 100644 --- a/core/java/android/content/pm/ShortcutManager.java +++ b/core/java/android/content/pm/ShortcutManager.java @@ -17,6 +17,7 @@ package android.content.pm; import android.annotation.NonNull; import android.annotation.TestApi; +import android.annotation.UserIdInt; import android.app.usage.UsageStatsManager; import android.content.Context; import android.os.RemoteException; @@ -379,6 +380,22 @@ public class ShortcutManager { } } + /** + * Called internally when an application is considered to have come to foreground + * even when technically it's not. This method resets the throttling for this package. + * For example, when the user sends an "inline reply" on an notification, the system UI will + * call it. + * + * @hide + */ + public void onApplicationActive(@NonNull String packageName, @UserIdInt int userId) { + try { + mService.onApplicationActive(packageName, userId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** @hide injection point */ @VisibleForTesting protected int injectMyUserId() { diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 25dc3575d5f8..809774b2efb4 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -165,6 +165,9 @@ <!-- the ability to rename notifications posted by other apps --> <uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" /> + <!-- shortcut manager --> + <uses-permission android:name="android.permission.RESET_SHORTCUT_MANAGER_THROTTLING" /> + <application android:name=".SystemUIApplication" android:persistent="true" diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java index 7704a07449ac..a2289c84a315 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java @@ -21,6 +21,7 @@ import android.app.PendingIntent; import android.app.RemoteInput; import android.content.Context; import android.content.Intent; +import android.content.pm.ShortcutManager; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -132,6 +133,15 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene mEditText.mShowImeOnInputConnection = false; mController.remoteInputSent(mEntry); + // Tell ShortcutManager that this package has been "activated". ShortcutManager + // will reset the throttling for this package. + // Strictly speaking, the intent receiver may be different from the notification publisher, + // but that's an edge case, and also because we can't always know which package will receive + // an intent, so we just reset for the publisher. + getContext().getSystemService(ShortcutManager.class).onApplicationActive( + mEntry.notification.getPackageName(), + mEntry.notification.getUser().getIdentifier()); + MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_SEND, mEntry.notification.getPackageName()); try { 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 fe2d1eca1cf1..6a0ca11d8244 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java @@ -4384,11 +4384,11 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { public void testOnApplicationActive_permission() { assertExpectException(SecurityException.class, "Missing permission", () -> - mService.onApplicationActive(CALLING_PACKAGE_1, USER_0)); + mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0)); // Has permission, now it should pass. mCallerPermissions.add(permission.RESET_SHORTCUT_MANAGER_THROTTLING); - mService.onApplicationActive(CALLING_PACKAGE_1, USER_0); + mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0); } public void testDumpsys_crossProfile() { diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java index 399fddfcfb87..45a06eba06ea 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java @@ -1414,7 +1414,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { // Simulate a call from sys UI. mCallerPermissions.add(permission.RESET_SHORTCUT_MANAGER_THROTTLING); - mService.onApplicationActive(CALLING_PACKAGE_1, USER_0); + mManager.onApplicationActive(CALLING_PACKAGE_1, USER_0); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { assertEquals(3, mManager.getRemainingCallCount()); @@ -1435,7 +1435,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { MoreAsserts.assertNotEqual(3, mManager.getRemainingCallCount()); }); - mService.onApplicationActive(CALLING_PACKAGE_3, USER_0); + mManager.onApplicationActive(CALLING_PACKAGE_3, USER_0); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { assertEquals(3, mManager.getRemainingCallCount()); @@ -1456,7 +1456,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { MoreAsserts.assertNotEqual(3, mManager.getRemainingCallCount()); }); - mService.onApplicationActive(CALLING_PACKAGE_1, USER_10); + mManager.onApplicationActive(CALLING_PACKAGE_1, USER_10); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { assertEquals(3, mManager.getRemainingCallCount()); |