From 6c4798b19d2b1faf977032ae320ce49ac376e458 Mon Sep 17 00:00:00 2001 From: Jacqueline Bronger Date: Thu, 24 Jun 2021 13:51:37 +0000 Subject: [PATCH] Enable sensor use notification on TVs. Notification is shown as an alternative to the bottom sheet / dialog when the a blocked sensor is being accessed. Only show the notification briefly to notify the user but don't keep it. Test: manual - change code to use notification instead of bottom sheet, block sensor (camera or mic), start appop for that sensor, notification shows up but isn't in the notification list afterwards. Bug: 186720349 Change-Id: I08d860812d14be4b36b84cf8869fe034941f5268 --- .../java/com/android/server/SensorPrivacyService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/core/java/com/android/server/SensorPrivacyService.java b/services/core/java/com/android/server/SensorPrivacyService.java index c07d6690e5a0f..a85ea72809136 100644 --- a/services/core/java/com/android/server/SensorPrivacyService.java +++ b/services/core/java/com/android/server/SensorPrivacyService.java @@ -58,6 +58,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.graphics.drawable.Icon; import android.hardware.ISensorPrivacyListener; import android.hardware.ISensorPrivacyManager; @@ -602,9 +603,19 @@ public final class SensorPrivacyService extends SystemService { new Intent(Settings.ACTION_PRIVACY_SETTINGS), PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)) + .extend(new Notification.TvExtender()) + .setTimeoutAfter(isTelevision(mContext) + ? /* dismiss immediately */ 1 + : /* no timeout */ 0) .build()); } + private boolean isTelevision(Context context) { + int uiMode = context.getResources().getConfiguration().uiMode; + return (uiMode & Configuration.UI_MODE_TYPE_MASK) + == Configuration.UI_MODE_TYPE_TELEVISION; + } + /** * Sets the sensor privacy to the provided state and notifies all listeners of the new * state.