Merge "Gate toast block and remove warning" into rvc-dev

This commit is contained in:
Bernardo Rufino
2020-03-25 09:32:40 +00:00
committed by Android (Google) Code Review
3 changed files with 12 additions and 26 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;