summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/statusbar/IStatusBar.aidl3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java11
-rw-r--r--packages/SystemUI/src/com/android/systemui/toast/ToastUI.java10
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/toast/ToastUITest.java38
-rw-r--r--services/core/java/com/android/server/notification/toast/TextToastRecord.java3
-rw-r--r--services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java4
-rw-r--r--services/core/java/com/android/server/statusbar/StatusBarManagerService.java5
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java16
8 files changed, 53 insertions, 37 deletions
diff --git a/core/java/com/android/internal/statusbar/IStatusBar.aidl b/core/java/com/android/internal/statusbar/IStatusBar.aidl
index 634063a44b66..e93a7854f1cd 100644
--- a/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -242,7 +242,8 @@ oneway interface IStatusBar
* Displays a text toast.
*/
void showToast(int uid, String packageName, IBinder token, CharSequence text,
- IBinder windowToken, int duration, @nullable ITransientNotificationCallback callback);
+ IBinder windowToken, int duration, @nullable ITransientNotificationCallback callback,
+ int displayId);
/**
* Cancels toast with token {@code token} in {@code packageName}.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index aa80b730d24f..cc3121ddc0e9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -398,11 +398,11 @@ public class CommandQueue extends IStatusBar.Stub implements
/**
* @see IStatusBar#showToast(int, String, IBinder, CharSequence, IBinder, int,
- * ITransientNotificationCallback)
+ * ITransientNotificationCallback, int)
*/
default void showToast(int uid, String packageName, IBinder token, CharSequence text,
IBinder windowToken, int duration,
- @Nullable ITransientNotificationCallback callback) { }
+ @Nullable ITransientNotificationCallback callback, int displayId) { }
/**
* @see IStatusBar#hideToast(String, IBinder) (String, IBinder)
@@ -944,7 +944,8 @@ public class CommandQueue extends IStatusBar.Stub implements
@Override
public void showToast(int uid, String packageName, IBinder token, CharSequence text,
- IBinder windowToken, int duration, @Nullable ITransientNotificationCallback callback) {
+ IBinder windowToken, int duration, @Nullable ITransientNotificationCallback callback,
+ int displayId) {
synchronized (mLock) {
SomeArgs args = SomeArgs.obtain();
args.arg1 = packageName;
@@ -954,6 +955,7 @@ public class CommandQueue extends IStatusBar.Stub implements
args.arg5 = callback;
args.argi1 = uid;
args.argi2 = duration;
+ args.argi3 = displayId;
mHandler.obtainMessage(MSG_SHOW_TOAST, args).sendToTarget();
}
}
@@ -1600,9 +1602,10 @@ public class CommandQueue extends IStatusBar.Stub implements
(ITransientNotificationCallback) args.arg5;
int uid = args.argi1;
int duration = args.argi2;
+ int displayId = args.argi3;
for (Callbacks callbacks : mCallbacks) {
callbacks.showToast(uid, packageName, token, text, windowToken, duration,
- callback);
+ callback, displayId);
}
break;
}
diff --git a/packages/SystemUI/src/com/android/systemui/toast/ToastUI.java b/packages/SystemUI/src/com/android/systemui/toast/ToastUI.java
index 0758f8fc4fab..9eb34a42a0a9 100644
--- a/packages/SystemUI/src/com/android/systemui/toast/ToastUI.java
+++ b/packages/SystemUI/src/com/android/systemui/toast/ToastUI.java
@@ -27,6 +27,7 @@ import android.app.INotificationManager;
import android.app.ITransientNotificationCallback;
import android.content.Context;
import android.content.res.Configuration;
+import android.hardware.display.DisplayManager;
import android.os.IBinder;
import android.os.ServiceManager;
import android.os.UserHandle;
@@ -106,10 +107,15 @@ public class ToastUI extends CoreStartable implements CommandQueue.Callbacks {
@Override
@MainThread
public void showToast(int uid, String packageName, IBinder token, CharSequence text,
- IBinder windowToken, int duration, @Nullable ITransientNotificationCallback callback) {
+ IBinder windowToken, int duration, @Nullable ITransientNotificationCallback callback,
+ int displayId) {
Runnable showToastRunnable = () -> {
UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
Context context = mContext.createContextAsUser(userHandle, 0);
+
+ DisplayManager mDisplayManager = mContext.getSystemService(DisplayManager.class);
+ Context displayContext = context.createDisplayContext(
+ mDisplayManager.getDisplay(displayId));
mToast = mToastFactory.createToast(mContext /* sysuiContext */, text, packageName,
userHandle.getIdentifier(), mOrientation);
@@ -118,7 +124,7 @@ public class ToastUI extends CoreStartable implements CommandQueue.Callbacks {
}
mCallback = callback;
- mPresenter = new ToastPresenter(context, mIAccessibilityManager,
+ mPresenter = new ToastPresenter(displayContext, mIAccessibilityManager,
mNotificationManager, packageName);
// Set as trusted overlay so touches can pass through toasts
mPresenter.getLayoutParams().setTrustedOverlay();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/toast/ToastUITest.java b/packages/SystemUI/tests/src/com/android/systemui/toast/ToastUITest.java
index 84e6df23e740..797f86ae14c2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/toast/ToastUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/toast/ToastUITest.java
@@ -44,6 +44,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
+import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -122,6 +123,7 @@ public class ToastUITest extends SysuiTestCase {
mContextSpy = spy(mContext);
when(mContextSpy.getPackageManager()).thenReturn(mPackageManager);
doReturn(mContextSpy).when(mContextSpy).createContextAsUser(any(), anyInt());
+ doReturn(mContextSpy).when(mContextSpy).createDisplayContext(any());
mToastUI = new ToastUI(
mContextSpy,
mCommandQueue,
@@ -144,7 +146,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testShowToast_addsCorrectViewToWindowManager() {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- null);
+ null, Display.DEFAULT_DISPLAY);
verify(mWindowManager).addView(mViewCaptor.capture(), any());
View view = mViewCaptor.getValue();
@@ -154,7 +156,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testShowToast_addsViewWithCorrectLayoutParamsToWindowManager() {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- null);
+ null, Display.DEFAULT_DISPLAY);
verify(mWindowManager).addView(any(), mParamsCaptor.capture());
ViewGroup.LayoutParams params = mParamsCaptor.getValue();
@@ -170,7 +172,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testShowToast_forAndroidPackage_addsAllUserFlag() throws Exception {
mToastUI.showToast(ANDROID_UID, "android", TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- null);
+ null, Display.DEFAULT_DISPLAY);
verify(mWindowManager).addView(any(), mParamsCaptor.capture());
ViewGroup.LayoutParams params = mParamsCaptor.getValue();
@@ -183,7 +185,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testShowToast_forSystemUiPackage_addsAllUserFlag() throws Exception {
mToastUI.showToast(SYSTEMUI_UID, "com.android.systemui", TOKEN_1, TEXT, WINDOW_TOKEN_1,
- Toast.LENGTH_LONG, null);
+ Toast.LENGTH_LONG, null, Display.DEFAULT_DISPLAY);
verify(mWindowManager).addView(any(), mParamsCaptor.capture());
ViewGroup.LayoutParams params = mParamsCaptor.getValue();
@@ -196,7 +198,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testShowToast_callsCallback() throws Exception {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
verify(mCallback).onToastShown();
}
@@ -216,7 +218,7 @@ public class ToastUITest extends SysuiTestCase {
mAccessibilityManager).sendAccessibilityEvent(any(), anyInt());
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- null);
+ null, Display.DEFAULT_DISPLAY);
eventParcel.setDataPosition(0);
assertThat(eventParcel.dataSize()).isGreaterThan(0);
@@ -231,14 +233,14 @@ public class ToastUITest extends SysuiTestCase {
public void testShowToast_accessibilityManagerClientIsRemoved() throws Exception {
when(mContextSpy.getUserId()).thenReturn(USER_ID);
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- null);
+ null, Display.DEFAULT_DISPLAY);
verify(mAccessibilityManager).removeClient(any(), eq(USER_ID));
}
@Test
public void testHideToast_removesView() throws Exception {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
final SystemUIToast toast = mToastUI.mToast;
View view = verifyWmAddViewAndAttachToParent();
@@ -254,7 +256,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testHideToast_finishesToken() throws Exception {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
final SystemUIToast toast = mToastUI.mToast;
verifyWmAddViewAndAttachToParent();
@@ -270,7 +272,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testHideToast_callsCallback() throws RemoteException {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
final SystemUIToast toast = mToastUI.mToast;
verifyWmAddViewAndAttachToParent();
@@ -286,7 +288,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testHideToast_whenNotCurrentToastToken_doesNotHideToast() throws RemoteException {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
final SystemUIToast toast = mToastUI.mToast;
verifyWmAddViewAndAttachToParent();
@@ -302,7 +304,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testHideToast_whenNotCurrentToastPackage_doesNotHideToast() throws RemoteException {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
final SystemUIToast toast = mToastUI.mToast;
verifyWmAddViewAndAttachToParent();
@@ -318,12 +320,12 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testShowToast_afterShowToast_hidesCurrentToast() throws RemoteException {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
final SystemUIToast toast = mToastUI.mToast;
View view = verifyWmAddViewAndAttachToParent();
mToastUI.showToast(UID_2, PACKAGE_NAME_2, TOKEN_2, TEXT, WINDOW_TOKEN_2, Toast.LENGTH_LONG,
- null);
+ null, Display.DEFAULT_DISPLAY);
if (toast.getOutAnimation() != null) {
assertThat(toast.getOutAnimation().isRunning()).isTrue();
@@ -338,7 +340,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testShowToast_logs() {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
verify(mToastLogger).logOnShowToast(UID_1, PACKAGE_NAME_1, TEXT, TOKEN_1.toString());
}
@@ -354,7 +356,7 @@ public class ToastUITest extends SysuiTestCase {
// WHEN the package posts a toast
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
// THEN the view can have unlimited lines
assertThat(((TextView) mToastUI.mToast.getView()
@@ -373,7 +375,7 @@ public class ToastUITest extends SysuiTestCase {
// WHEN the package posts a toast
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
// THEN the view is limited to 2 lines
assertThat(((TextView) mToastUI.mToast.getView()
@@ -384,7 +386,7 @@ public class ToastUITest extends SysuiTestCase {
@Test
public void testHideToast_logs() {
mToastUI.showToast(UID_1, PACKAGE_NAME_1, TOKEN_1, TEXT, WINDOW_TOKEN_1, Toast.LENGTH_LONG,
- mCallback);
+ mCallback, Display.DEFAULT_DISPLAY);
verifyWmAddViewAndAttachToParent();
mToastUI.hideToast(PACKAGE_NAME_1, TOKEN_1);
verify(mToastLogger).logOnHideToast(PACKAGE_NAME_1, TOKEN_1.toString());
diff --git a/services/core/java/com/android/server/notification/toast/TextToastRecord.java b/services/core/java/com/android/server/notification/toast/TextToastRecord.java
index 7b36db2fe38c..559798a34662 100644
--- a/services/core/java/com/android/server/notification/toast/TextToastRecord.java
+++ b/services/core/java/com/android/server/notification/toast/TextToastRecord.java
@@ -62,7 +62,8 @@ public class TextToastRecord extends ToastRecord {
Slog.w(TAG, "StatusBar not available to show text toast for package " + pkg);
return false;
}
- mStatusBar.showToast(uid, pkg, token, text, windowToken, getDuration(), mCallback);
+ mStatusBar.showToast(uid, pkg, token, text, windowToken, getDuration(), mCallback,
+ displayId);
return true;
}
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
index 11fd99cf5b68..b00d8b47906a 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
@@ -144,11 +144,11 @@ public interface StatusBarManagerInternal {
/**
* @see com.android.internal.statusbar.IStatusBar#showToast(String, IBinder, CharSequence,
- * IBinder, int, ITransientNotificationCallback)
+ * IBinder, int, ITransientNotificationCallback, int)
*/
void showToast(int uid, String packageName, IBinder token, CharSequence text,
IBinder windowToken, int duration,
- @Nullable ITransientNotificationCallback textCallback);
+ @Nullable ITransientNotificationCallback textCallback, int displayId);
/** @see com.android.internal.statusbar.IStatusBar#hideToast(String, IBinder) */
void hideToast(String packageName, IBinder token);
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
index d48f26332017..46e7574e1c8a 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -631,10 +631,11 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
@Override
public void showToast(int uid, String packageName, IBinder token, CharSequence text,
IBinder windowToken, int duration,
- @Nullable ITransientNotificationCallback callback) {
+ @Nullable ITransientNotificationCallback callback, int displayId) {
if (mBar != null) {
try {
- mBar.showToast(uid, packageName, token, text, windowToken, duration, callback);
+ mBar.showToast(uid, packageName, token, text, windowToken, duration, callback,
+ displayId);
} catch (RemoteException ex) { }
}
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 0d56975f51d0..22721a1bcc92 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -6227,13 +6227,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// first time trying to show the toast, showToast gets called
nmService.enqueueTextToast(testPackage, token, "Text", 2000, 0, null);
verify(mStatusBar, times(1))
- .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any());
+ .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any(), anyInt());
// second time trying to show the same toast, showToast isn't called again (total number of
// invocations stays at one)
nmService.enqueueTextToast(testPackage, token, "Text", 2000, 0, null);
verify(mStatusBar, times(1))
- .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any());
+ .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any(), anyInt());
}
@Test
@@ -6255,7 +6255,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
nmService.enqueueTextToast(testPackage, token, "Text", 2000, 0, null);
verify(mStatusBar, times(0))
- .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any());
+ .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any(), anyInt());
}
@Test
@@ -6277,7 +6277,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
nmService.enqueueTextToast(testPackage, token, "Text", 2000, 0, null);
verify(mStatusBar, times(1))
- .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any());
+ .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any(), anyInt());
}
@Test
@@ -6297,7 +6297,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
INotificationManager nmService = (INotificationManager) mService.mService;
nmService.enqueueTextToast(testPackage, token, "Text", 2000, 0, null);
- verify(mStatusBar).showToast(anyInt(), any(), any(), any(), any(), anyInt(), any());
+ verify(mStatusBar).showToast(anyInt(), any(), any(), any(), any(), anyInt(), any(),
+ anyInt());
}
@Test
@@ -6326,7 +6327,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// but never shown
verify(mStatusBar, times(0))
- .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any());
+ .showToast(anyInt(), any(), any(), any(), any(), anyInt(), any(), anyInt());
// and removed when rate limited
verify(mWindowManagerInternal)
@@ -6417,7 +6418,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// enqueue toast -> no toasts enqueued
((INotificationManager) mService.mService).enqueueTextToast(testPackage, new Binder(),
"Text", 2000, 0, null);
- verify(mStatusBar).showToast(anyInt(), any(), any(), any(), any(), anyInt(), any());
+ verify(mStatusBar).showToast(anyInt(), any(), any(), any(), any(), anyInt(), any(),
+ anyInt());
}
@Test