Add WindowParams privateflag to Toast so it appears on SysUI Notifications.
Test: Manual. For example, put showToast(context, R.string.assist_action_failed_toast); on line 203 and verify that the toast appears when the Play button on a Message Notification is clicked.
Bug: 138210976
Change-Id: I6137127d1f17128ac31e983054ec358c08d8d2d2
diff --git a/src/com/android/car/notification/NotificationClickHandlerFactory.java b/src/com/android/car/notification/NotificationClickHandlerFactory.java
index 8acb662..0fb3d89 100644
--- a/src/com/android/car/notification/NotificationClickHandlerFactory.java
+++ b/src/com/android/car/notification/NotificationClickHandlerFactory.java
@@ -29,6 +29,7 @@
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.view.View;
+import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
@@ -261,7 +262,13 @@
}
private void showToast(Context context, int resourceId) {
- Toast.makeText(context, context.getString(resourceId), Toast.LENGTH_LONG).show();
+ Toast toast = Toast.makeText(context, context.getString(resourceId), Toast.LENGTH_LONG);
+ // This flag is needed for the Toast to show up on the active user's screen since
+ // Notifications is part of SystemUI. SystemUI is owned by a system process, which runs in
+ // the background, so without this, the toast will never appear in the foreground.
+ toast.getWindowParams().privateFlags |=
+ WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
+ toast.show();
}
private boolean shouldAutoCancel(StatusBarNotification sbn) {