diff options
| author | 2020-02-04 22:32:34 +0000 | |
|---|---|---|
| committer | 2020-02-06 10:11:34 +0000 | |
| commit | 2f167d3823df4c9c6972ee4aa751db2fab3d3b08 (patch) | |
| tree | d52a90cd1dfd76c2861fd909902a8f0b6b30c1a1 | |
| parent | 0a3a6c179cb3169afa851157984d566ba3de2b35 (diff) | |
Don't block app-rendered text toast on apps with targetSdk < 30
We've decided to gate the text toast move on targetSdk due to an app
crash (b/148438364) but decided not to gate the background custom toast
block (in NMS) on targetSdk temporarily to gather dogfood and DP
feedback. This meant that app-rendered text toasts (which are only
possible for apps with targetSdk < 30) were being blocked in NMS since
they were being considered custom toasts.
This brings back the boolean inside Toast class that differentiates
between custom and text toasts for apps with targetSdk < 30, since both
are app-rendered in this case. This code won't be present on final
version and is temporary to gather feedback on dogfood and DP, since
almost no app currently targets SDK 30+. We'll gate both changes (the
system UI move and the bg custom toast block) on targetSdk later on.
Bug: 148761979
Bug: 148794147
Bug: 144754526
Test: Verify that, while on the background:
App with | Custom toast | Text toast
targetSdk < 30 | Blocked | Allowed
targetSdk 30+ | Blocked | Allowed
Test: atest android.widget.cts.ToastTest android.widget.cts29.ToastTest
LegacyToastTest
Change-Id: Id529028bc463034cd2f64a6f2f97e71bc6ea7c36
3 files changed, 18 insertions, 5 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 4b1ba0278682..16c0910f1273 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -48,6 +48,8 @@ interface INotificationManager void clearData(String pkg, int uid, boolean fromApp); void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, int displayId, @nullable ITransientNotificationCallback callback); void enqueueToast(String pkg, IBinder token, ITransientNotification callback, int duration, int displayId); + // TODO(b/144152069): Remove this after assessing impact on dogfood. + void enqueueTextOrCustomToast(String pkg, IBinder token, ITransientNotification callback, int duration, int displayId, boolean isCustom); void cancelToast(String pkg, IBinder token); void finishToken(String pkg, IBinder token); diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java index db714c2439bd..b7c660479e9f 100644 --- a/core/java/android/widget/Toast.java +++ b/core/java/android/widget/Toast.java @@ -148,6 +148,9 @@ public class Toast { @Nullable private CharSequence mText; + // TODO(b/144152069): Remove this after assessing impact on dogfood. + private boolean mIsCustomToast; + /** * Construct an empty Toast object. You must call {@link #setView} before you * can call {@link #show}. @@ -214,7 +217,8 @@ public class Toast { service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback); } } else { - service.enqueueToast(pkg, mToken, tn, mDuration, displayId); + service.enqueueTextOrCustomToast(pkg, mToken, tn, mDuration, displayId, + mIsCustomToast); } } catch (RemoteException e) { // Empty @@ -252,6 +256,7 @@ public class Toast { */ @Deprecated public void setView(View view) { + mIsCustomToast = true; mNextView = view; } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index b52289e36b50..f07113591fa5 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2681,18 +2681,24 @@ public class NotificationManagerService extends SystemService { @Override public void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, int displayId, @Nullable ITransientNotificationCallback callback) { - enqueueToast(pkg, token, text, null, duration, displayId, callback); + enqueueToast(pkg, token, text, null, duration, displayId, callback, false); } @Override public void enqueueToast(String pkg, IBinder token, ITransientNotification callback, int duration, int displayId) { - enqueueToast(pkg, token, null, callback, duration, displayId, null); + enqueueToast(pkg, token, null, callback, duration, displayId, null, true); + } + + @Override + public void enqueueTextOrCustomToast(String pkg, IBinder token, + ITransientNotification callback, int duration, int displayId, boolean isCustom) { + enqueueToast(pkg, token, null, callback, duration, displayId, null, isCustom); } private void enqueueToast(String pkg, IBinder token, @Nullable CharSequence text, @Nullable ITransientNotification callback, int duration, int displayId, - @Nullable ITransientNotificationCallback textCallback) { + @Nullable ITransientNotificationCallback textCallback, boolean isCustom) { if (DBG) { Slog.i(TAG, "enqueueToast pkg=" + pkg + " token=" + token + " duration=" + duration + " displayId=" + displayId); @@ -2730,7 +2736,7 @@ public class NotificationManagerService extends SystemService { return; } - if (callback != null && !appIsForeground && !isSystemToast) { + if (callback != null && !appIsForeground && !isSystemToast && isCustom) { boolean block; long id = Binder.clearCallingIdentity(); try { |