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
This commit is contained in:
Jacqueline Bronger
2021-06-24 13:51:37 +00:00
parent d8c8547954
commit 6c4798b19d

View File

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