Loading core/java/android/app/INotificationManager.aidl +0 −2 Original line number Original line Diff line number Diff line Loading @@ -48,8 +48,6 @@ interface INotificationManager void clearData(String pkg, int uid, boolean fromApp); void clearData(String pkg, int uid, boolean fromApp); void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, int displayId, @nullable ITransientNotificationCallback callback); 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); 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 cancelToast(String pkg, IBinder token); void finishToken(String pkg, IBinder token); void finishToken(String pkg, IBinder token); Loading core/java/android/widget/Toast.java +1 −6 Original line number Original line Diff line number Diff line Loading @@ -144,9 +144,6 @@ public class Toast { @Nullable @Nullable private CharSequence mText; 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 * Construct an empty Toast object. You must call {@link #setView} before you * can call {@link #show}. * can call {@link #show}. Loading Loading @@ -214,8 +211,7 @@ public class Toast { service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback); service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback); } } } else { } else { service.enqueueTextOrCustomToast(pkg, mToken, tn, mDuration, displayId, service.enqueueToast(pkg, mToken, tn, mDuration, displayId); mIsCustomToast); } } } catch (RemoteException e) { } catch (RemoteException e) { // Empty // Empty Loading Loading @@ -253,7 +249,6 @@ public class Toast { */ */ @Deprecated @Deprecated public void setView(View view) { public void setView(View view) { mIsCustomToast = true; mNextView = view; mNextView = view; } } Loading services/core/java/com/android/server/notification/NotificationManagerService.java +11 −18 Original line number Original line Diff line number Diff line Loading @@ -139,6 +139,7 @@ import android.app.usage.UsageEvents; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; import android.companion.ICompanionDeviceManager; import android.compat.annotation.ChangeId; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledAfter; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; import android.content.ContentProvider; import android.content.ContentProvider; Loading Loading @@ -387,10 +388,9 @@ public class NotificationManagerService extends SystemService { * still post toasts created with * still post toasts created with * {@link android.widget.Toast#makeText(Context, CharSequence, int)} and its variants while * {@link android.widget.Toast#makeText(Context, CharSequence, int)} and its variants while * in the background. * in the background. * * TODO(b/144152069): Add @EnabledAfter(Q) to target R+ after assessing impact on dogfood */ */ @ChangeId @ChangeId @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) private static final long CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK = 128611929L; private static final long CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK = 128611929L; private IActivityManager mAm; private IActivityManager mAm; Loading Loading @@ -2751,24 +2751,18 @@ public class NotificationManagerService extends SystemService { @Override @Override public void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, public void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, int displayId, @Nullable ITransientNotificationCallback callback) { int displayId, @Nullable ITransientNotificationCallback callback) { enqueueToast(pkg, token, text, null, duration, displayId, callback, false); enqueueToast(pkg, token, text, null, duration, displayId, callback); } } @Override @Override public void enqueueToast(String pkg, IBinder token, ITransientNotification callback, public void enqueueToast(String pkg, IBinder token, ITransientNotification callback, int duration, int displayId) { int duration, int displayId) { enqueueToast(pkg, token, null, callback, duration, displayId, null, true); enqueueToast(pkg, token, null, callback, duration, displayId, null); } @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, private void enqueueToast(String pkg, IBinder token, @Nullable CharSequence text, @Nullable ITransientNotification callback, int duration, int displayId, @Nullable ITransientNotification callback, int duration, int displayId, @Nullable ITransientNotificationCallback textCallback, boolean isCustom) { @Nullable ITransientNotificationCallback textCallback) { if (DBG) { if (DBG) { Slog.i(TAG, "enqueueToast pkg=" + pkg + " token=" + token Slog.i(TAG, "enqueueToast pkg=" + pkg + " token=" + token + " duration=" + duration + " displayId=" + displayId); + " duration=" + duration + " displayId=" + displayId); Loading Loading @@ -2807,11 +2801,15 @@ public class NotificationManagerService extends SystemService { } } boolean isAppRenderedToast = (callback != null); boolean isAppRenderedToast = (callback != null); if (isAppRenderedToast && isCustom && !isSystemToast if (isAppRenderedToast && !isSystemToast && !isPackageInForegroundForToast(pkg, && !isPackageInForegroundForToast(pkg, callingUid)) { callingUid)) { boolean block; boolean block; long id = Binder.clearCallingIdentity(); long id = Binder.clearCallingIdentity(); try { 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( block = mPlatformCompat.isChangeEnabledByPackageName( CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK, pkg, CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK, pkg, callingUser.getIdentifier()); callingUser.getIdentifier()); Loading @@ -2824,11 +2822,6 @@ public class NotificationManagerService extends SystemService { Binder.restoreCallingIdentity(id); Binder.restoreCallingIdentity(id); } } if (block) { 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 Slog.w(TAG, "Blocking custom toast from package " + pkg + " due to package not in the foreground"); + " due to package not in the foreground"); return; return; Loading Loading
core/java/android/app/INotificationManager.aidl +0 −2 Original line number Original line Diff line number Diff line Loading @@ -48,8 +48,6 @@ interface INotificationManager void clearData(String pkg, int uid, boolean fromApp); void clearData(String pkg, int uid, boolean fromApp); void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, int displayId, @nullable ITransientNotificationCallback callback); 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); 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 cancelToast(String pkg, IBinder token); void finishToken(String pkg, IBinder token); void finishToken(String pkg, IBinder token); Loading
core/java/android/widget/Toast.java +1 −6 Original line number Original line Diff line number Diff line Loading @@ -144,9 +144,6 @@ public class Toast { @Nullable @Nullable private CharSequence mText; 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 * Construct an empty Toast object. You must call {@link #setView} before you * can call {@link #show}. * can call {@link #show}. Loading Loading @@ -214,8 +211,7 @@ public class Toast { service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback); service.enqueueTextToast(pkg, mToken, mText, mDuration, displayId, callback); } } } else { } else { service.enqueueTextOrCustomToast(pkg, mToken, tn, mDuration, displayId, service.enqueueToast(pkg, mToken, tn, mDuration, displayId); mIsCustomToast); } } } catch (RemoteException e) { } catch (RemoteException e) { // Empty // Empty Loading Loading @@ -253,7 +249,6 @@ public class Toast { */ */ @Deprecated @Deprecated public void setView(View view) { public void setView(View view) { mIsCustomToast = true; mNextView = view; mNextView = view; } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +11 −18 Original line number Original line Diff line number Diff line Loading @@ -139,6 +139,7 @@ import android.app.usage.UsageEvents; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; import android.companion.ICompanionDeviceManager; import android.compat.annotation.ChangeId; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledAfter; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; import android.content.ContentProvider; import android.content.ContentProvider; Loading Loading @@ -387,10 +388,9 @@ public class NotificationManagerService extends SystemService { * still post toasts created with * still post toasts created with * {@link android.widget.Toast#makeText(Context, CharSequence, int)} and its variants while * {@link android.widget.Toast#makeText(Context, CharSequence, int)} and its variants while * in the background. * in the background. * * TODO(b/144152069): Add @EnabledAfter(Q) to target R+ after assessing impact on dogfood */ */ @ChangeId @ChangeId @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) private static final long CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK = 128611929L; private static final long CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK = 128611929L; private IActivityManager mAm; private IActivityManager mAm; Loading Loading @@ -2751,24 +2751,18 @@ public class NotificationManagerService extends SystemService { @Override @Override public void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, public void enqueueTextToast(String pkg, IBinder token, CharSequence text, int duration, int displayId, @Nullable ITransientNotificationCallback callback) { int displayId, @Nullable ITransientNotificationCallback callback) { enqueueToast(pkg, token, text, null, duration, displayId, callback, false); enqueueToast(pkg, token, text, null, duration, displayId, callback); } } @Override @Override public void enqueueToast(String pkg, IBinder token, ITransientNotification callback, public void enqueueToast(String pkg, IBinder token, ITransientNotification callback, int duration, int displayId) { int duration, int displayId) { enqueueToast(pkg, token, null, callback, duration, displayId, null, true); enqueueToast(pkg, token, null, callback, duration, displayId, null); } @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, private void enqueueToast(String pkg, IBinder token, @Nullable CharSequence text, @Nullable ITransientNotification callback, int duration, int displayId, @Nullable ITransientNotification callback, int duration, int displayId, @Nullable ITransientNotificationCallback textCallback, boolean isCustom) { @Nullable ITransientNotificationCallback textCallback) { if (DBG) { if (DBG) { Slog.i(TAG, "enqueueToast pkg=" + pkg + " token=" + token Slog.i(TAG, "enqueueToast pkg=" + pkg + " token=" + token + " duration=" + duration + " displayId=" + displayId); + " duration=" + duration + " displayId=" + displayId); Loading Loading @@ -2807,11 +2801,15 @@ public class NotificationManagerService extends SystemService { } } boolean isAppRenderedToast = (callback != null); boolean isAppRenderedToast = (callback != null); if (isAppRenderedToast && isCustom && !isSystemToast if (isAppRenderedToast && !isSystemToast && !isPackageInForegroundForToast(pkg, && !isPackageInForegroundForToast(pkg, callingUid)) { callingUid)) { boolean block; boolean block; long id = Binder.clearCallingIdentity(); long id = Binder.clearCallingIdentity(); try { 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( block = mPlatformCompat.isChangeEnabledByPackageName( CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK, pkg, CHANGE_BACKGROUND_CUSTOM_TOAST_BLOCK, pkg, callingUser.getIdentifier()); callingUser.getIdentifier()); Loading @@ -2824,11 +2822,6 @@ public class NotificationManagerService extends SystemService { Binder.restoreCallingIdentity(id); Binder.restoreCallingIdentity(id); } } if (block) { 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 Slog.w(TAG, "Blocking custom toast from package " + pkg + " due to package not in the foreground"); + " due to package not in the foreground"); return; return; Loading