Merge "Add support for Predictive Back in SensorUseStartedActivity" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ea07782541
@@ -29,6 +29,8 @@ import android.hardware.SensorPrivacyManager.EXTRA_SENSOR
|
|||||||
import android.hardware.SensorPrivacyManager.Sources.DIALOG
|
import android.hardware.SensorPrivacyManager.Sources.DIALOG
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
import android.window.OnBackInvokedDispatcher
|
||||||
|
import androidx.annotation.OpenForTesting
|
||||||
import com.android.internal.util.FrameworkStatsLog.PRIVACY_TOGGLE_DIALOG_INTERACTION
|
import com.android.internal.util.FrameworkStatsLog.PRIVACY_TOGGLE_DIALOG_INTERACTION
|
||||||
import com.android.internal.util.FrameworkStatsLog.PRIVACY_TOGGLE_DIALOG_INTERACTION__ACTION__CANCEL
|
import com.android.internal.util.FrameworkStatsLog.PRIVACY_TOGGLE_DIALOG_INTERACTION__ACTION__CANCEL
|
||||||
import com.android.internal.util.FrameworkStatsLog.PRIVACY_TOGGLE_DIALOG_INTERACTION__ACTION__ENABLE
|
import com.android.internal.util.FrameworkStatsLog.PRIVACY_TOGGLE_DIALOG_INTERACTION__ACTION__ENABLE
|
||||||
@@ -45,7 +47,8 @@ import javax.inject.Inject
|
|||||||
*
|
*
|
||||||
* <p>The dialog is started for the user the app is running for which might be a secondary users.
|
* <p>The dialog is started for the user the app is running for which might be a secondary users.
|
||||||
*/
|
*/
|
||||||
class SensorUseStartedActivity @Inject constructor(
|
@OpenForTesting
|
||||||
|
open class SensorUseStartedActivity @Inject constructor(
|
||||||
private val sensorPrivacyController: IndividualSensorPrivacyController,
|
private val sensorPrivacyController: IndividualSensorPrivacyController,
|
||||||
private val keyguardStateController: KeyguardStateController,
|
private val keyguardStateController: KeyguardStateController,
|
||||||
private val keyguardDismissUtil: KeyguardDismissUtil,
|
private val keyguardDismissUtil: KeyguardDismissUtil,
|
||||||
@@ -67,9 +70,10 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
private lateinit var sensorUsePackageName: String
|
private lateinit var sensorUsePackageName: String
|
||||||
private var unsuppressImmediately = false
|
private var unsuppressImmediately = false
|
||||||
|
|
||||||
private lateinit var sensorPrivacyListener: IndividualSensorPrivacyController.Callback
|
private var sensorPrivacyListener: IndividualSensorPrivacyController.Callback? = null
|
||||||
|
|
||||||
private var mDialog: AlertDialog? = null
|
private var mDialog: AlertDialog? = null
|
||||||
|
private val mBackCallback = this::onBackInvoked
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -84,15 +88,14 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
|
|
||||||
if (intent.getBooleanExtra(EXTRA_ALL_SENSORS, false)) {
|
if (intent.getBooleanExtra(EXTRA_ALL_SENSORS, false)) {
|
||||||
sensor = ALL_SENSORS
|
sensor = ALL_SENSORS
|
||||||
sensorPrivacyListener =
|
val callback = IndividualSensorPrivacyController.Callback { _, _ ->
|
||||||
IndividualSensorPrivacyController.Callback { _, _ ->
|
if (!sensorPrivacyController.isSensorBlocked(MICROPHONE) &&
|
||||||
if (!sensorPrivacyController.isSensorBlocked(MICROPHONE) &&
|
!sensorPrivacyController.isSensorBlocked(CAMERA)) {
|
||||||
!sensorPrivacyController.isSensorBlocked(CAMERA)) {
|
finish()
|
||||||
finish()
|
}
|
||||||
}
|
}
|
||||||
}
|
sensorPrivacyListener = callback
|
||||||
|
sensorPrivacyController.addCallback(callback)
|
||||||
sensorPrivacyController.addCallback(sensorPrivacyListener)
|
|
||||||
if (!sensorPrivacyController.isSensorBlocked(MICROPHONE) &&
|
if (!sensorPrivacyController.isSensorBlocked(MICROPHONE) &&
|
||||||
!sensorPrivacyController.isSensorBlocked(CAMERA)) {
|
!sensorPrivacyController.isSensorBlocked(CAMERA)) {
|
||||||
finish()
|
finish()
|
||||||
@@ -105,14 +108,14 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sensorPrivacyListener =
|
val callback = IndividualSensorPrivacyController.Callback {
|
||||||
IndividualSensorPrivacyController.Callback { whichSensor: Int,
|
whichSensor: Int, isBlocked: Boolean ->
|
||||||
isBlocked: Boolean ->
|
if (whichSensor == sensor && !isBlocked) {
|
||||||
if (whichSensor == sensor && !isBlocked) {
|
finish()
|
||||||
finish()
|
}
|
||||||
}
|
}
|
||||||
}
|
sensorPrivacyListener = callback
|
||||||
sensorPrivacyController.addCallback(sensorPrivacyListener)
|
sensorPrivacyController.addCallback(callback)
|
||||||
|
|
||||||
if (!sensorPrivacyController.isSensorBlocked(sensor)) {
|
if (!sensorPrivacyController.isSensorBlocked(sensor)) {
|
||||||
finish()
|
finish()
|
||||||
@@ -122,6 +125,10 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
|
|
||||||
mDialog = SensorUseDialog(this, sensor, this, this)
|
mDialog = SensorUseDialog(this, sensor, this, this)
|
||||||
mDialog!!.show()
|
mDialog!!.show()
|
||||||
|
|
||||||
|
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||||
|
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||||
|
mBackCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@@ -180,10 +187,15 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
mDialog?.dismiss()
|
mDialog?.dismiss()
|
||||||
sensorPrivacyController.removeCallback(sensorPrivacyListener)
|
sensorPrivacyListener?.also { sensorPrivacyController.removeCallback(it) }
|
||||||
|
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(mBackCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
onBackInvoked()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onBackInvoked() {
|
||||||
// do not allow backing out
|
// do not allow backing out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,12 @@
|
|||||||
android:finishOnCloseSystemDialogs="true"
|
android:finishOnCloseSystemDialogs="true"
|
||||||
android:excludeFromRecents="true" />
|
android:excludeFromRecents="true" />
|
||||||
|
|
||||||
|
<activity android:name=".sensorprivacy.SensorUseStartedActivityTest$SensorUseStartedActivityTestable"
|
||||||
|
android:exported="false"
|
||||||
|
android:theme="@style/Theme.SystemUI.Dialog.Alert"
|
||||||
|
android:finishOnCloseSystemDialogs="true"
|
||||||
|
android:excludeFromRecents="true" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.startup.InitializationProvider"
|
android:name="androidx.startup.InitializationProvider"
|
||||||
tools:replace="android:authorities"
|
tools:replace="android:authorities"
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.android.systemui.sensorprivacy
|
||||||
|
|
||||||
|
import android.testing.AndroidTestingRunner
|
||||||
|
import android.testing.TestableLooper
|
||||||
|
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||||
|
import androidx.test.filters.SmallTest
|
||||||
|
import com.android.systemui.SysuiTestCase
|
||||||
|
import com.android.systemui.util.mockito.mock
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RunWith(AndroidTestingRunner::class)
|
||||||
|
@SmallTest
|
||||||
|
@TestableLooper.RunWithLooper
|
||||||
|
class SensorUseStartedActivityTest : SysuiTestCase() {
|
||||||
|
open class SensorUseStartedActivityTestable :
|
||||||
|
SensorUseStartedActivity(
|
||||||
|
sensorPrivacyController = mock(),
|
||||||
|
keyguardStateController = mock(),
|
||||||
|
keyguardDismissUtil = mock(),
|
||||||
|
bgHandler = mock(),
|
||||||
|
)
|
||||||
|
|
||||||
|
@get:Rule val activityRule = ActivityScenarioRule(SensorUseStartedActivityTestable::class.java)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun onBackPressed_doNothing() {
|
||||||
|
activityRule.scenario.onActivity { activity ->
|
||||||
|
assertThat(activity.isFinishing).isFalse()
|
||||||
|
|
||||||
|
activity.onBackPressed()
|
||||||
|
|
||||||
|
assertThat(activity.isFinishing).isFalse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user