diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index f590eb914aac1..78d3581a70129 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -48,8 +48,6 @@ 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 8943da4a2fc01..4f14539dd9765 100644 --- a/core/java/android/widget/Toast.java +++ b/core/java/android/widget/Toast.java @@ -144,9 +144,6 @@ 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,8 +211,7 @@ public class Toast { service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback); } } else { - service.enqueueTextOrCustomToast(pkg, mToken, tn, mDuration, displayId, - mIsCustomToast); + service.enqueueToast(pkg, mToken, tn, mDuration, displayId); } } catch (RemoteException e) { // Empty @@ -253,7 +249,6 @@ 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 60c387528c6a8..7f805bef520d1 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -139,6 +139,7 @@ import android.app.usage.UsageEvents; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; import android.compat.annotation.ChangeId; +import android.compat.annotation.EnabledAfter; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentProvider; @@ -387,10 +388,9 @@ public class NotificationManagerService extends SystemService { * still post toasts created with * {@link android.widget.Toast#makeText(Context, CharSequence, int)} and its variants while * in the background. - * - * TODO(b/144152069): Add @EnabledAfter(Q) to target R+ after assessing impact on dogfood */ @ChangeId + @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) private static final long CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK = 128611929L; private IActivityManager mAm; @@ -2751,24 +2751,18 @@ 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, false); + enqueueToast(pkg, token, text, null, duration, displayId, callback); } @Override public void enqueueToast(String pkg, IBinder token, ITransientNotification callback, int duration, int displayId) { - 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); + enqueueToast(pkg, token, null, callback, duration, displayId, null); } private void enqueueToast(String pkg, IBinder token, @Nullable CharSequence text, @Nullable ITransientNotification callback, int duration, int displayId, - @Nullable ITransientNotificationCallback textCallback, boolean isCustom) { + @Nullable ITransientNotificationCallback textCallback) { if (DBG) { Slog.i(TAG, "enqueueToast pkg=" + pkg + " token=" + token + " duration=" + duration + " displayId=" + displayId); @@ -2807,11 +2801,15 @@ public class NotificationManagerService extends SystemService { } boolean isAppRenderedToast = (callback != null); - if (isAppRenderedToast && isCustom && !isSystemToast - && !isPackageInForegroundForToast(pkg, callingUid)) { + if (isAppRenderedToast && !isSystemToast && !isPackageInForegroundForToast(pkg, + callingUid)) { boolean block; long id = Binder.clearCallingIdentity(); try { + // CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK is gated on targetSdk, so block will be + // false for apps with targetSdk < R. For apps with targetSdk R+, text toasts + // are not app-rendered, so isAppRenderedToast == true means it's a custom + // toast. block = mPlatformCompat.isChangeEnabledByPackageName( CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK, pkg, callingUser.getIdentifier()); @@ -2824,11 +2822,6 @@ public class NotificationManagerService extends SystemService { Binder.restoreCallingIdentity(id); } if (block) { - // TODO(b/144152069): Remove informative toast - mUiHandler.post(() -> Toast.makeText(getContext(), - "Background custom toast blocked for package " + pkg + ".\n" - + "See g.co/dev/toast.", - Toast.LENGTH_SHORT).show()); Slog.w(TAG, "Blocking custom toast from package " + pkg + " due to package not in the foreground"); return;