Merge "Show all system apps to hub teamfood, remove location indicator" into sc-dev

This commit is contained in:
Nate Myren
2021-03-12 23:35:53 +00:00
committed by Android (Google) Code Review
11 changed files with 47 additions and 153 deletions

View File

@@ -111,8 +111,7 @@ public class PermissionUsageHelper {
private static boolean shouldShowLocationIndicator() { private static boolean shouldShowLocationIndicator() {
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
PROPERTY_LOCATION_INDICATORS_ENABLED, false) PROPERTY_LOCATION_INDICATORS_ENABLED, false);
|| shouldShowPermissionsHub();
} }
private static long getRecentThreshold(Long now) { private static long getRecentThreshold(Long now) {
@@ -326,10 +325,10 @@ public class PermissionUsageHelper {
} }
if (packageName.equals(SYSTEM_PKG) if (packageName.equals(SYSTEM_PKG)
|| (!isUserSensitive(packageName, user, op) || (!shouldShowPermissionsHub()
&& !isUserSensitive(packageName, user, op)
&& !isLocationProvider(packageName, user) && !isLocationProvider(packageName, user)
&& !isAppPredictor(packageName, user)) && !isSpeechRecognizerUsage(op, packageName))) {
&& !isSpeechRecognizerUsage(op, packageName)) {
continue; continue;
} }

View File

@@ -20,7 +20,6 @@ import static android.hardware.SensorPrivacyManager.Sensors.CAMERA;
import static android.hardware.SensorPrivacyManager.Sensors.MICROPHONE; import static android.hardware.SensorPrivacyManager.Sensors.MICROPHONE;
import static android.media.AudioManager.ACTION_MICROPHONE_MUTE_CHANGED; import static android.media.AudioManager.ACTION_MICROPHONE_MUTE_CHANGED;
import android.Manifest;
import android.app.AppOpsManager; import android.app.AppOpsManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@@ -43,6 +42,7 @@ import androidx.annotation.WorkerThread;
import com.android.internal.R; import com.android.internal.R;
import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.systemui.Dumpable; import com.android.systemui.Dumpable;
import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.SysUISingleton;
@@ -370,13 +370,9 @@ public class AppOpsControllerImpl extends BroadcastReceiver implements AppOpsCon
} }
// TODO ntmyren: remove after teamfood is finished // TODO ntmyren: remove after teamfood is finished
private boolean shouldShowAppPredictor(String pkgName) { private boolean showSystemApps() {
if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "permissions_hub_2_enabled", return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
false)) { SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED, false);
return false;
}
return mPackageManager.checkPermission(Manifest.permission.MANAGE_APP_PREDICTIONS, pkgName)
== PackageManager.PERMISSION_GRANTED;
} }
/** /**
@@ -399,8 +395,8 @@ public class AppOpsControllerImpl extends BroadcastReceiver implements AppOpsCon
return true; return true;
} }
// TODO ntmyren: Replace this with more robust check if this moves beyond teamfood // TODO ntmyren: Replace this with more robust check if this moves beyond teamfood
if ((appOpCode == AppOpsManager.OP_CAMERA && isLocationProvider(packageName)) if (((showSystemApps() && !packageName.equals("android"))
|| shouldShowAppPredictor(packageName) || appOpCode == AppOpsManager.OP_CAMERA && isLocationProvider(packageName))
|| isSpeechRecognizerUsage(appOpCode, packageName)) { || isSpeechRecognizerUsage(appOpCode, packageName)) {
return true; return true;
} }

View File

@@ -214,9 +214,7 @@ class PrivacyDialogController(
private fun filterType(type: PrivacyType?): PrivacyType? { private fun filterType(type: PrivacyType?): PrivacyType? {
return type?.let { return type?.let {
if (privacyItemController.allIndicatorsAvailable) { if ((it == PrivacyType.TYPE_CAMERA || it == PrivacyType.TYPE_MICROPHONE) &&
it
} else if ((it == PrivacyType.TYPE_CAMERA || it == PrivacyType.TYPE_MICROPHONE) &&
privacyItemController.micCameraAvailable) { privacyItemController.micCameraAvailable) {
it it
} else if (it == PrivacyType.TYPE_LOCATION && privacyItemController.locationAvailable) { } else if (it == PrivacyType.TYPE_LOCATION && privacyItemController.locationAvailable) {

View File

@@ -68,8 +68,6 @@ class PrivacyItemController @Inject constructor(
addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE) addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)
} }
const val TAG = "PrivacyItemController" const val TAG = "PrivacyItemController"
private const val ALL_INDICATORS =
SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED
private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED
private const val LOCATION = SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_ENABLED private const val LOCATION = SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_ENABLED
private const val DEFAULT_ALL_INDICATORS = false private const val DEFAULT_ALL_INDICATORS = false
@@ -83,11 +81,6 @@ class PrivacyItemController @Inject constructor(
@Synchronized get() = field.toList() // Returns a shallow copy of the list @Synchronized get() = field.toList() // Returns a shallow copy of the list
@Synchronized set @Synchronized set
private fun isAllIndicatorsEnabled(): Boolean {
return deviceConfigProxy.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
ALL_INDICATORS, DEFAULT_ALL_INDICATORS)
}
private fun isMicCameraEnabled(): Boolean { private fun isMicCameraEnabled(): Boolean {
return deviceConfigProxy.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, return deviceConfigProxy.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
MIC_CAMERA, DEFAULT_MIC_CAMERA) MIC_CAMERA, DEFAULT_MIC_CAMERA)
@@ -120,34 +113,29 @@ class PrivacyItemController @Inject constructor(
uiExecutor.execute(notifyChanges) uiExecutor.execute(notifyChanges)
} }
var allIndicatorsAvailable = isAllIndicatorsEnabled()
private set
var micCameraAvailable = isMicCameraEnabled() var micCameraAvailable = isMicCameraEnabled()
private set private set
var locationAvailable = isLocationEnabled() var locationAvailable = isLocationEnabled()
var allIndicatorsAvailable = micCameraAvailable && locationAvailable
private val devicePropertiesChangedListener = private val devicePropertiesChangedListener =
object : DeviceConfig.OnPropertiesChangedListener { object : DeviceConfig.OnPropertiesChangedListener {
override fun onPropertiesChanged(properties: DeviceConfig.Properties) { override fun onPropertiesChanged(properties: DeviceConfig.Properties) {
if (DeviceConfig.NAMESPACE_PRIVACY.equals(properties.getNamespace()) && if (DeviceConfig.NAMESPACE_PRIVACY.equals(properties.getNamespace()) &&
(properties.keyset.contains(ALL_INDICATORS) || (properties.keyset.contains(MIC_CAMERA) ||
properties.keyset.contains(MIC_CAMERA) ||
properties.keyset.contains(LOCATION))) { properties.keyset.contains(LOCATION))) {
// Running on the ui executor so can iterate on callbacks // Running on the ui executor so can iterate on callbacks
if (properties.keyset.contains(ALL_INDICATORS)) {
allIndicatorsAvailable = properties.getBoolean(ALL_INDICATORS,
DEFAULT_ALL_INDICATORS)
callbacks.forEach { it.get()?.onFlagAllChanged(allIndicatorsAvailable) }
}
if (properties.keyset.contains(MIC_CAMERA)) { if (properties.keyset.contains(MIC_CAMERA)) {
micCameraAvailable = properties.getBoolean(MIC_CAMERA, DEFAULT_MIC_CAMERA) micCameraAvailable = properties.getBoolean(MIC_CAMERA, DEFAULT_MIC_CAMERA)
allIndicatorsAvailable = micCameraAvailable && locationAvailable
callbacks.forEach { it.get()?.onFlagMicCameraChanged(micCameraAvailable) } callbacks.forEach { it.get()?.onFlagMicCameraChanged(micCameraAvailable) }
} }
if (properties.keyset.contains(LOCATION)) { if (properties.keyset.contains(LOCATION)) {
locationAvailable = properties.getBoolean(LOCATION, DEFAULT_LOCATION) locationAvailable = properties.getBoolean(LOCATION, DEFAULT_LOCATION)
allIndicatorsAvailable = micCameraAvailable && locationAvailable
callbacks.forEach { it.get()?.onFlagLocationChanged(locationAvailable) } callbacks.forEach { it.get()?.onFlagLocationChanged(locationAvailable) }
} }
internalUiExecutor.updateListeningState() internalUiExecutor.updateListeningState()
@@ -163,8 +151,7 @@ class PrivacyItemController @Inject constructor(
active: Boolean active: Boolean
) { ) {
// Check if we care about this code right now // Check if we care about this code right now
if (!allIndicatorsAvailable && if (code in OPS_LOCATION && !locationAvailable) {
(code in OPS_LOCATION && !locationAvailable)) {
return return
} }
val userId = UserHandle.getUserId(uid) val userId = UserHandle.getUserId(uid)
@@ -231,7 +218,7 @@ class PrivacyItemController @Inject constructor(
*/ */
private fun setListeningState() { private fun setListeningState() {
val listen = !callbacks.isEmpty() and val listen = !callbacks.isEmpty() and
(allIndicatorsAvailable || micCameraAvailable || locationAvailable) (micCameraAvailable || locationAvailable)
if (listening == listen) return if (listening == listen) return
listening = listen listening = listen
if (listening) { if (listening) {
@@ -338,7 +325,7 @@ class PrivacyItemController @Inject constructor(
AppOpsManager.OP_RECORD_AUDIO -> PrivacyType.TYPE_MICROPHONE AppOpsManager.OP_RECORD_AUDIO -> PrivacyType.TYPE_MICROPHONE
else -> return null else -> return null
} }
if (type == PrivacyType.TYPE_LOCATION && (!allIndicatorsAvailable && !locationAvailable)) { if (type == PrivacyType.TYPE_LOCATION && !locationAvailable) {
return null return null
} }
val app = PrivacyApplication(appOpItem.packageName, appOpItem.uid) val app = PrivacyApplication(appOpItem.packageName, appOpItem.uid)

View File

@@ -88,7 +88,6 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
private boolean mViewAndWindowAdded; private boolean mViewAndWindowAdded;
private ObjectAnimator mAnimator; private ObjectAnimator mAnimator;
private boolean mAllIndicatorsFlagEnabled;
private boolean mMicCameraIndicatorFlagEnabled; private boolean mMicCameraIndicatorFlagEnabled;
private boolean mLocationIndicatorEnabled; private boolean mLocationIndicatorEnabled;
private List<PrivacyItem> mPrivacyItems; private List<PrivacyItem> mPrivacyItems;
@@ -111,12 +110,10 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
mIconMarginStart = Math.round(res.getDimension(R.dimen.privacy_chip_icon_margin)); mIconMarginStart = Math.round(res.getDimension(R.dimen.privacy_chip_icon_margin));
mIconSize = res.getDimensionPixelSize(R.dimen.privacy_chip_icon_size); mIconSize = res.getDimensionPixelSize(R.dimen.privacy_chip_icon_size);
mAllIndicatorsFlagEnabled = privacyItemController.getAllIndicatorsAvailable();
mMicCameraIndicatorFlagEnabled = privacyItemController.getMicCameraAvailable(); mMicCameraIndicatorFlagEnabled = privacyItemController.getMicCameraAvailable();
mLocationIndicatorEnabled = privacyItemController.getLocationAvailable(); mLocationIndicatorEnabled = privacyItemController.getLocationAvailable();
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "allIndicators: " + mAllIndicatorsFlagEnabled);
Log.d(TAG, "micCameraIndicators: " + mMicCameraIndicatorFlagEnabled); Log.d(TAG, "micCameraIndicators: " + mMicCameraIndicatorFlagEnabled);
Log.d(TAG, "locationIndicators: " + mLocationIndicatorEnabled); Log.d(TAG, "locationIndicators: " + mLocationIndicatorEnabled);
} }
@@ -134,12 +131,6 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
updateUI(); updateUI();
} }
@Override
public void onFlagAllChanged(boolean flag) {
if (DEBUG) Log.d(TAG, "all indicators enabled: " + flag);
mAllIndicatorsFlagEnabled = flag;
}
@Override @Override
public void onFlagMicCameraChanged(boolean flag) { public void onFlagMicCameraChanged(boolean flag) {
if (DEBUG) Log.d(TAG, "mic/camera indicators enabled: " + flag); if (DEBUG) Log.d(TAG, "mic/camera indicators enabled: " + flag);
@@ -155,8 +146,8 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
private void updateUI() { private void updateUI() {
if (DEBUG) Log.d(TAG, mPrivacyItems.size() + " privacy items"); if (DEBUG) Log.d(TAG, mPrivacyItems.size() + " privacy items");
if ((mMicCameraIndicatorFlagEnabled || mAllIndicatorsFlagEnabled if ((mMicCameraIndicatorFlagEnabled || mLocationIndicatorEnabled)
|| mLocationIndicatorEnabled) && !mPrivacyItems.isEmpty()) { && !mPrivacyItems.isEmpty()) {
if (mState == STATE_NOT_SHOWN || mState == STATE_DISAPPEARING) { if (mState == STATE_NOT_SHOWN || mState == STATE_DISAPPEARING) {
showIndicator(); showIndicator();
} else { } else {

View File

@@ -97,7 +97,6 @@ class QuickStatusBarHeaderController extends ViewController<QuickStatusBarHeader
private boolean mListening; private boolean mListening;
private AlarmClockInfo mNextAlarm; private AlarmClockInfo mNextAlarm;
private boolean mAllIndicatorsEnabled;
private boolean mMicCameraIndicatorsEnabled; private boolean mMicCameraIndicatorsEnabled;
private boolean mLocationIndicatorsEnabled; private boolean mLocationIndicatorsEnabled;
private boolean mPrivacyChipLogged; private boolean mPrivacyChipLogged;
@@ -150,14 +149,6 @@ class QuickStatusBarHeaderController extends ViewController<QuickStatusBarHeader
setChipVisibility(!privacyItems.isEmpty()); setChipVisibility(!privacyItems.isEmpty());
} }
@Override
public void onFlagAllChanged(boolean flag) {
if (mAllIndicatorsEnabled != flag) {
mAllIndicatorsEnabled = flag;
update();
}
}
@Override @Override
public void onFlagMicCameraChanged(boolean flag) { public void onFlagMicCameraChanged(boolean flag) {
if (mMicCameraIndicatorsEnabled != flag) { if (mMicCameraIndicatorsEnabled != flag) {
@@ -270,7 +261,6 @@ class QuickStatusBarHeaderController extends ViewController<QuickStatusBarHeader
mRingerContainer.setOnClickListener(mOnClickListener); mRingerContainer.setOnClickListener(mOnClickListener);
mPrivacyChip.setOnClickListener(mOnClickListener); mPrivacyChip.setOnClickListener(mOnClickListener);
mAllIndicatorsEnabled = mPrivacyItemController.getAllIndicatorsAvailable();
mMicCameraIndicatorsEnabled = mPrivacyItemController.getMicCameraAvailable(); mMicCameraIndicatorsEnabled = mPrivacyItemController.getMicCameraAvailable();
mLocationIndicatorsEnabled = mPrivacyItemController.getLocationAvailable(); mLocationIndicatorsEnabled = mPrivacyItemController.getLocationAvailable();
@@ -321,7 +311,6 @@ class QuickStatusBarHeaderController extends ViewController<QuickStatusBarHeader
mNextAlarmController.addCallback(mNextAlarmChangeCallback); mNextAlarmController.addCallback(mNextAlarmChangeCallback);
mLifecycle.setCurrentState(Lifecycle.State.RESUMED); mLifecycle.setCurrentState(Lifecycle.State.RESUMED);
// Get the most up to date info // Get the most up to date info
mAllIndicatorsEnabled = mPrivacyItemController.getAllIndicatorsAvailable();
mMicCameraIndicatorsEnabled = mPrivacyItemController.getMicCameraAvailable(); mMicCameraIndicatorsEnabled = mPrivacyItemController.getMicCameraAvailable();
mLocationIndicatorsEnabled = mPrivacyItemController.getLocationAvailable(); mLocationIndicatorsEnabled = mPrivacyItemController.getLocationAvailable();
mPrivacyItemController.addCallback(mPICCallback); mPrivacyItemController.addCallback(mPICCallback);
@@ -353,13 +342,13 @@ class QuickStatusBarHeaderController extends ViewController<QuickStatusBarHeader
private List<String> getIgnoredIconSlots() { private List<String> getIgnoredIconSlots() {
ArrayList<String> ignored = new ArrayList<>(); ArrayList<String> ignored = new ArrayList<>();
if (getChipEnabled()) { if (getChipEnabled()) {
if (mAllIndicatorsEnabled || mMicCameraIndicatorsEnabled) { if (mMicCameraIndicatorsEnabled) {
ignored.add(mView.getResources().getString( ignored.add(mView.getResources().getString(
com.android.internal.R.string.status_bar_camera)); com.android.internal.R.string.status_bar_camera));
ignored.add(mView.getResources().getString( ignored.add(mView.getResources().getString(
com.android.internal.R.string.status_bar_microphone)); com.android.internal.R.string.status_bar_microphone));
} }
if (mAllIndicatorsEnabled || mLocationIndicatorsEnabled) { if (mLocationIndicatorsEnabled) {
ignored.add(mView.getResources().getString( ignored.add(mView.getResources().getString(
com.android.internal.R.string.status_bar_location)); com.android.internal.R.string.status_bar_location));
} }
@@ -368,7 +357,7 @@ class QuickStatusBarHeaderController extends ViewController<QuickStatusBarHeader
} }
private boolean getChipEnabled() { private boolean getChipEnabled() {
return mMicCameraIndicatorsEnabled || mLocationIndicatorsEnabled || mAllIndicatorsEnabled; return mMicCameraIndicatorsEnabled || mLocationIndicatorsEnabled;
} }
private boolean isZenOverridingRinger() { private boolean isZenOverridingRinger() {

View File

@@ -675,8 +675,7 @@ public class PhoneStatusBarPolicy
mIconController.setIconVisibility(mSlotCamera, showCamera); mIconController.setIconVisibility(mSlotCamera, showCamera);
mIconController.setIconVisibility(mSlotMicrophone, showMicrophone); mIconController.setIconVisibility(mSlotMicrophone, showMicrophone);
if (mPrivacyItemController.getAllIndicatorsAvailable() if (mPrivacyItemController.getLocationAvailable()) {
|| mPrivacyItemController.getLocationAvailable()) {
mIconController.setIconVisibility(mSlotLocation, showLocation); mIconController.setIconVisibility(mSlotLocation, showLocation);
} }
mPrivacyLogger.logStatusBarIconsVisible(showCamera, showMicrophone, showLocation); mPrivacyLogger.logStatusBarIconsVisible(showCamera, showMicrophone, showLocation);
@@ -684,8 +683,7 @@ public class PhoneStatusBarPolicy
@Override @Override
public void onLocationActiveChanged(boolean active) { public void onLocationActiveChanged(boolean active) {
if (!mPrivacyItemController.getAllIndicatorsAvailable() if (!mPrivacyItemController.getLocationAvailable()) {
&& !mPrivacyItemController.getLocationAvailable()) {
updateLocationFromController(); updateLocationFromController();
} }
} }

View File

@@ -395,9 +395,8 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
`when`(permissionManager.indicatorAppOpUsageData).thenReturn( `when`(permissionManager.indicatorAppOpUsageData).thenReturn(
listOf(usage_camera, usage_location, usage_microphone) listOf(usage_camera, usage_location, usage_microphone)
) )
`when`(privacyItemController.micCameraAvailable).thenReturn(false) `when`(privacyItemController.micCameraAvailable).thenReturn(true)
`when`(privacyItemController.locationAvailable).thenReturn(false) `when`(privacyItemController.locationAvailable).thenReturn(true)
`when`(privacyItemController.allIndicatorsAvailable).thenReturn(true)
controller.showDialog(context) controller.showDialog(context)
exhaustExecutors() exhaustExecutors()
@@ -422,7 +421,6 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
) )
`when`(privacyItemController.micCameraAvailable).thenReturn(false) `when`(privacyItemController.micCameraAvailable).thenReturn(false)
`when`(privacyItemController.locationAvailable).thenReturn(false) `when`(privacyItemController.locationAvailable).thenReturn(false)
`when`(privacyItemController.allIndicatorsAvailable).thenReturn(false)
controller.showDialog(context) controller.showDialog(context)
exhaustExecutors() exhaustExecutors()
@@ -525,7 +523,6 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
`when`(privacyItemController.locationAvailable).thenReturn(true) `when`(privacyItemController.locationAvailable).thenReturn(true)
`when`(privacyItemController.micCameraAvailable).thenReturn(true) `when`(privacyItemController.micCameraAvailable).thenReturn(true)
`when`(privacyItemController.allIndicatorsAvailable).thenReturn(false)
`when`(userTracker.userProfiles).thenReturn(listOf( `when`(userTracker.userProfiles).thenReturn(listOf(
UserInfo(USER_ID, "", 0), UserInfo(USER_ID, "", 0),

View File

@@ -37,7 +37,6 @@ import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor import org.mockito.ArgumentCaptor
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.anyBoolean
import org.mockito.Mockito.atLeastOnce import org.mockito.Mockito.atLeastOnce
import org.mockito.Mockito.never import org.mockito.Mockito.never
import org.mockito.Mockito.verify import org.mockito.Mockito.verify
@@ -51,8 +50,6 @@ class PrivacyItemControllerFlagsTest : SysuiTestCase() {
fun <T> eq(value: T): T = Mockito.eq(value) ?: value fun <T> eq(value: T): T = Mockito.eq(value) ?: value
fun <T> any(): T = Mockito.any<T>() fun <T> any(): T = Mockito.any<T>()
private const val ALL_INDICATORS =
SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED
private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED
private const val LOCATION = SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_ENABLED private const val LOCATION = SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_ENABLED
} }
@@ -95,11 +92,6 @@ class PrivacyItemControllerFlagsTest : SysuiTestCase() {
executor.runAllReady() executor.runAllReady()
} }
@Test
fun testNotListeningAllByDefault() {
assertFalse(privacyItemController.allIndicatorsAvailable)
}
@Test @Test
fun testMicCameraListeningByDefault() { fun testMicCameraListeningByDefault() {
assertTrue(privacyItemController.micCameraAvailable) assertTrue(privacyItemController.micCameraAvailable)
@@ -111,10 +103,8 @@ class PrivacyItemControllerFlagsTest : SysuiTestCase() {
executor.runAllReady() executor.runAllReady()
verify(callback).onFlagMicCameraChanged(false) verify(callback).onFlagMicCameraChanged(false)
verify(callback, never()).onFlagAllChanged(anyBoolean())
assertFalse(privacyItemController.micCameraAvailable) assertFalse(privacyItemController.micCameraAvailable)
assertFalse(privacyItemController.allIndicatorsAvailable)
} }
@Test @Test
@@ -126,27 +116,16 @@ class PrivacyItemControllerFlagsTest : SysuiTestCase() {
assertTrue(privacyItemController.locationAvailable) assertTrue(privacyItemController.locationAvailable)
} }
@Test
fun testAllChanged() {
changeAll(true)
executor.runAllReady()
verify(callback).onFlagAllChanged(true)
verify(callback, never()).onFlagMicCameraChanged(anyBoolean())
assertTrue(privacyItemController.allIndicatorsAvailable)
}
@Test @Test
fun testBothChanged() { fun testBothChanged() {
changeAll(true) changeAll(true)
changeMicCamera(false) changeMicCamera(false)
executor.runAllReady() executor.runAllReady()
verify(callback, atLeastOnce()).onFlagAllChanged(true) verify(callback, atLeastOnce()).onFlagLocationChanged(true)
verify(callback, atLeastOnce()).onFlagMicCameraChanged(false) verify(callback, atLeastOnce()).onFlagMicCameraChanged(false)
assertTrue(privacyItemController.allIndicatorsAvailable) assertTrue(privacyItemController.locationAvailable)
assertFalse(privacyItemController.micCameraAvailable) assertFalse(privacyItemController.micCameraAvailable)
} }
@@ -185,28 +164,6 @@ class PrivacyItemControllerFlagsTest : SysuiTestCase() {
verify(appOpsController).removeCallback(any(), any()) verify(appOpsController).removeCallback(any(), any())
} }
@Test
fun testSomeListening_stillListening() {
// Mic and camera are true by default
changeAll(true)
executor.runAllReady()
changeAll(false)
executor.runAllReady()
verify(appOpsController, never()).removeCallback(any(), any())
}
@Test
fun testAllDeleted_micCameraFalse_stopListening() {
changeMicCamera(false)
changeAll(true)
executor.runAllReady()
changeAll(null)
executor.runAllReady()
verify(appOpsController).removeCallback(any(), any())
}
@Test @Test
fun testMicDeleted_stillListening() { fun testMicDeleted_stillListening() {
changeMicCamera(true) changeMicCamera(true)
@@ -219,7 +176,10 @@ class PrivacyItemControllerFlagsTest : SysuiTestCase() {
private fun changeMicCamera(value: Boolean?) = changeProperty(MIC_CAMERA, value) private fun changeMicCamera(value: Boolean?) = changeProperty(MIC_CAMERA, value)
private fun changeLocation(value: Boolean?) = changeProperty(LOCATION, value) private fun changeLocation(value: Boolean?) = changeProperty(LOCATION, value)
private fun changeAll(value: Boolean?) = changeProperty(ALL_INDICATORS, value) private fun changeAll(value: Boolean?) {
changeMicCamera(value)
changeLocation(value)
}
private fun changeProperty(name: String, value: Boolean?) { private fun changeProperty(name: String, value: Boolean?) {
deviceConfigProxy.setProperty( deviceConfigProxy.setProperty(

View File

@@ -43,7 +43,6 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertThat import org.junit.Assert.assertThat
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor import org.mockito.ArgumentCaptor
@@ -72,8 +71,8 @@ class PrivacyItemControllerTest : SysuiTestCase() {
val TEST_UID = CURRENT_USER_ID * UserHandle.PER_USER_RANGE val TEST_UID = CURRENT_USER_ID * UserHandle.PER_USER_RANGE
const val TEST_PACKAGE_NAME = "test" const val TEST_PACKAGE_NAME = "test"
private const val ALL_INDICATORS = private const val LOCATION_INDICATOR =
SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_ENABLED
private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED
fun <T> capture(argumentCaptor: ArgumentCaptor<T>): T = argumentCaptor.capture() fun <T> capture(argumentCaptor: ArgumentCaptor<T>): T = argumentCaptor.capture()
fun <T> eq(value: T): T = Mockito.eq(value) ?: value fun <T> eq(value: T): T = Mockito.eq(value) ?: value
@@ -119,7 +118,8 @@ class PrivacyItemControllerTest : SysuiTestCase() {
deviceConfigProxy = DeviceConfigProxyFake() deviceConfigProxy = DeviceConfigProxyFake()
// Listen to everything by default // Listen to everything by default
changeAll(true) changeMicCamera(true)
changeLocation(true)
`when`(userTracker.userProfiles).thenReturn(listOf(UserInfo(CURRENT_USER_ID, "", 0))) `when`(userTracker.userProfiles).thenReturn(listOf(UserInfo(CURRENT_USER_ID, "", 0)))
@@ -259,9 +259,8 @@ class PrivacyItemControllerTest : SysuiTestCase() {
} }
@Test @Test
@Ignore // TODO(b/168209929)
fun testNotListeningWhenIndicatorsDisabled() { fun testNotListeningWhenIndicatorsDisabled() {
changeAll(false) changeLocation(false)
changeMicCamera(false) changeMicCamera(false)
privacyItemController.addCallback(callback) privacyItemController.addCallback(callback)
executor.runAllReady() executor.runAllReady()
@@ -271,7 +270,7 @@ class PrivacyItemControllerTest : SysuiTestCase() {
@Test @Test
fun testNotSendingLocationWhenOnlyMicCamera() { fun testNotSendingLocationWhenOnlyMicCamera() {
changeAll(false) changeLocation(false)
changeMicCamera(true) changeMicCamera(true)
executor.runAllReady() executor.runAllReady()
@@ -294,7 +293,7 @@ class PrivacyItemControllerTest : SysuiTestCase() {
.`when`(appOpsController).getActiveAppOpsForUser(anyInt()) .`when`(appOpsController).getActiveAppOpsForUser(anyInt())
privacyItemController.addCallback(callback) privacyItemController.addCallback(callback)
changeAll(false) changeLocation(false)
changeMicCamera(true) changeMicCamera(true)
executor.runAllReady() executor.runAllReady()
reset(callback) // Clean callback reset(callback) // Clean callback
@@ -521,7 +520,7 @@ class PrivacyItemControllerTest : SysuiTestCase() {
} }
private fun changeMicCamera(value: Boolean?) = changeProperty(MIC_CAMERA, value) private fun changeMicCamera(value: Boolean?) = changeProperty(MIC_CAMERA, value)
private fun changeAll(value: Boolean?) = changeProperty(ALL_INDICATORS, value) private fun changeLocation(value: Boolean?) = changeProperty(LOCATION_INDICATOR, value)
private fun changeProperty(name: String, value: Boolean?) { private fun changeProperty(name: String, value: Boolean?) {
deviceConfigProxy.setProperty( deviceConfigProxy.setProperty(

View File

@@ -148,7 +148,7 @@ class QuickStatusBarHeaderControllerTest : SysuiTestCase() {
@Test @Test
fun testIgnoredSlotsOnAttached_noIndicators() { fun testIgnoredSlotsOnAttached_noIndicators() {
setPrivacyController(false, false, false) setPrivacyController(micCamera = false, location = false)
controller.init() controller.init()
@@ -160,7 +160,7 @@ class QuickStatusBarHeaderControllerTest : SysuiTestCase() {
@Test @Test
fun testIgnoredSlotsOnAttached_onlyMicCamera() { fun testIgnoredSlotsOnAttached_onlyMicCamera() {
setPrivacyController(false, true, false) setPrivacyController(micCamera = true, location = false)
controller.init() controller.init()
@@ -177,7 +177,7 @@ class QuickStatusBarHeaderControllerTest : SysuiTestCase() {
@Test @Test
fun testIgnoredSlotsOnAttached_onlyLocation() { fun testIgnoredSlotsOnAttached_onlyLocation() {
setPrivacyController(false, false, true) setPrivacyController(micCamera = false, location = true)
controller.init() controller.init()
@@ -192,26 +192,7 @@ class QuickStatusBarHeaderControllerTest : SysuiTestCase() {
@Test @Test
fun testIgnoredSlotsOnAttached_locationMicCamera() { fun testIgnoredSlotsOnAttached_locationMicCamera() {
setPrivacyController(false, true, true) setPrivacyController(micCamera = true, location = true)
controller.init()
val captor = argumentCaptor<List<String>>()
verify(iconContainer).setIgnoredSlots(capture(captor))
val cameraString = mContext.resources.getString(
com.android.internal.R.string.status_bar_camera)
val micString = mContext.resources.getString(
com.android.internal.R.string.status_bar_microphone)
val locationString = mContext.resources.getString(
com.android.internal.R.string.status_bar_location)
assertThat(captor.value).containsExactly(cameraString, micString, locationString)
}
@Test
fun testIgnoredSlotsOnAttached_all() {
setPrivacyController(true, false, false)
controller.init() controller.init()
@@ -248,8 +229,7 @@ class QuickStatusBarHeaderControllerTest : SysuiTestCase() {
`when`(view.findViewById<Clock>(R.id.clock)).thenReturn(clock) `when`(view.findViewById<Clock>(R.id.clock)).thenReturn(clock)
} }
private fun setPrivacyController(all: Boolean, micCamera: Boolean, location: Boolean) { private fun setPrivacyController(micCamera: Boolean, location: Boolean) {
`when`(privacyItemController.allIndicatorsAvailable).thenReturn(all)
`when`(privacyItemController.micCameraAvailable).thenReturn(micCamera) `when`(privacyItemController.micCameraAvailable).thenReturn(micCamera)
`when`(privacyItemController.locationAvailable).thenReturn(location) `when`(privacyItemController.locationAvailable).thenReturn(location)
} }