Post channel error toasts as android

Since we're using system_server's context, our
calling identity needs to match

Test: test app that posts a notification to a non-existant
channel
Fixes: 117519040

Change-Id: I599d2a2c3f086bceef9f4b5c50f4cc7c55bdb207
This commit is contained in:
Julia Reynolds
2018-10-11 09:21:11 -04:00
parent 803a52498b
commit bba26b18ec

View File

@@ -4282,14 +4282,16 @@ public class NotificationManagerService extends SystemService {
}
private void doChannelWarningToast(CharSequence toastText) {
final int defaultWarningEnabled = Build.IS_DEBUGGABLE ? 1 : 0;
final boolean warningEnabled = Settings.Global.getInt(getContext().getContentResolver(),
Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, defaultWarningEnabled) != 0;
if (warningEnabled) {
Toast toast = Toast.makeText(getContext(), mHandler.getLooper(), toastText,
Toast.LENGTH_SHORT);
toast.show();
}
Binder.withCleanCallingIdentity(() -> {
final int defaultWarningEnabled = Build.IS_DEBUGGABLE ? 1 : 0;
final boolean warningEnabled = Settings.Global.getInt(getContext().getContentResolver(),
Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, defaultWarningEnabled) != 0;
if (warningEnabled) {
Toast toast = Toast.makeText(getContext(), mHandler.getLooper(), toastText,
Toast.LENGTH_SHORT);
toast.show();
}
});
}
@VisibleForTesting