Merge "Set toggle state for profile group" into sc-dev am: 405fac1ca0
am: 4f253570f8
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15362614 Change-Id: I6f832b9d5e67acd4351a6bf045f57b8b370637e1
This commit is contained in:
@@ -59,7 +59,8 @@ public abstract class SensorToggleController extends TogglePreferenceController
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mSensorPrivacyManagerHelper.setSensorBlocked(SETTINGS, getSensor(), !isChecked);
|
||||
mSensorPrivacyManagerHelper.setSensorBlockedForProfileGroup(SETTINGS, getSensor(),
|
||||
!isChecked);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -172,6 +172,27 @@ public class SensorPrivacyManagerHelper {
|
||||
mSensorPrivacyManager.setSensorPrivacy(source, sensor, blocked, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sensor privacy for the current profile group.
|
||||
* @param source The source with which sensor privacy is toggled.
|
||||
* @param sensor The sensor to set for
|
||||
* @param blocked The state to set to
|
||||
*/
|
||||
public void setSensorBlockedForProfileGroup(int source, int sensor, boolean blocked) {
|
||||
mSensorPrivacyManager.setSensorPrivacyForProfileGroup(source, sensor, blocked);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sensor privacy for the given user's profile group.
|
||||
* @param source The source with which sensor privacy is toggled.
|
||||
* @param sensor The sensor to set for
|
||||
* @param blocked The state to set to
|
||||
*/
|
||||
public void setSensorBlockedForProfileGroup(int source, int sensor, boolean blocked,
|
||||
int userId) {
|
||||
mSensorPrivacyManager.setSensorPrivacyForProfileGroup(source, sensor, blocked, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener for the state of the current user. If the current user changes and the state
|
||||
* of the new user is different, a callback will be received.
|
||||
|
@@ -33,6 +33,8 @@ import android.content.Context;
|
||||
import android.hardware.SensorPrivacyManager;
|
||||
import android.hardware.SensorPrivacyManager.OnSensorPrivacyChangedListener;
|
||||
import android.util.ArraySet;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseBooleanArray;
|
||||
|
||||
import com.android.settings.utils.SensorPrivacyManagerHelper;
|
||||
|
||||
@@ -54,10 +56,10 @@ public class SensorToggleControllerTest {
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SensorPrivacyManager mSensorPrivacyManager;
|
||||
private boolean mMicState;
|
||||
private boolean mCamState;
|
||||
private Set<OnSensorPrivacyChangedListener> mMicListeners;
|
||||
private Set<OnSensorPrivacyChangedListener> mCamListeners;
|
||||
private SparseBooleanArray mMicState;
|
||||
private SparseBooleanArray mCamState;
|
||||
private SparseArray<Set<OnSensorPrivacyChangedListener>> mMicListeners;
|
||||
private SparseArray<Set<OnSensorPrivacyChangedListener>> mCamListeners;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -73,39 +75,85 @@ public class SensorToggleControllerTest {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
mMicState = false;
|
||||
mCamState = false;
|
||||
mMicListeners = new ArraySet<>();
|
||||
mCamListeners = new ArraySet<>();
|
||||
mMicState = new SparseBooleanArray();
|
||||
mCamState = new SparseBooleanArray();
|
||||
mMicState.put(0, false);
|
||||
mCamState.put(0, false);
|
||||
mMicState.put(10, false);
|
||||
mCamState.put(10, false);
|
||||
mMicListeners = new SparseArray<>();
|
||||
mCamListeners = new SparseArray<>();
|
||||
mMicListeners.put(0, new ArraySet<>());
|
||||
mMicListeners.put(10, new ArraySet<>());
|
||||
mCamListeners.put(0, new ArraySet<>());
|
||||
mCamListeners.put(10, new ArraySet<>());
|
||||
|
||||
doReturn(0).when(mContext).getUserId();
|
||||
doReturn(mSensorPrivacyManager).when(mContext)
|
||||
.getSystemService(SensorPrivacyManager.class);
|
||||
|
||||
doAnswer(invocation -> mMicState)
|
||||
doAnswer(invocation -> mMicState.get(0))
|
||||
.when(mSensorPrivacyManager).isSensorPrivacyEnabled(eq(MICROPHONE));
|
||||
doAnswer(invocation -> mCamState)
|
||||
doAnswer(invocation -> mCamState.get(0))
|
||||
.when(mSensorPrivacyManager).isSensorPrivacyEnabled(eq(CAMERA));
|
||||
doAnswer(invocation -> mMicState.get(invocation.getArgument(1)))
|
||||
.when(mSensorPrivacyManager).isSensorPrivacyEnabled(eq(MICROPHONE), anyInt());
|
||||
doAnswer(invocation -> mCamState.get(invocation.getArgument(1)))
|
||||
.when(mSensorPrivacyManager).isSensorPrivacyEnabled(eq(CAMERA), anyInt());
|
||||
|
||||
doAnswer(invocation -> {
|
||||
mMicState = invocation.getArgument(1);
|
||||
for (OnSensorPrivacyChangedListener listener : mMicListeners) {
|
||||
listener.onSensorPrivacyChanged(MICROPHONE, mMicState);
|
||||
mMicState.put(0, invocation.getArgument(2));
|
||||
mMicState.put(10, invocation.getArgument(2));
|
||||
for (OnSensorPrivacyChangedListener listener : mMicListeners.get(0)) {
|
||||
listener.onSensorPrivacyChanged(MICROPHONE, mMicState.get(0));
|
||||
}
|
||||
return null;
|
||||
}).when(mSensorPrivacyManager).setSensorPrivacy(anyInt(), eq(MICROPHONE), anyBoolean());
|
||||
doAnswer(invocation -> {
|
||||
mCamState = invocation.getArgument(1);
|
||||
for (OnSensorPrivacyChangedListener listener : mMicListeners) {
|
||||
listener.onSensorPrivacyChanged(CAMERA, mMicState);
|
||||
mCamState.put(0, invocation.getArgument(2));
|
||||
mCamState.put(10, invocation.getArgument(2));
|
||||
for (OnSensorPrivacyChangedListener listener : mMicListeners.get(0)) {
|
||||
listener.onSensorPrivacyChanged(CAMERA, mMicState.get(0));
|
||||
}
|
||||
return null;
|
||||
}).when(mSensorPrivacyManager).setSensorPrivacy(anyInt(), eq(CAMERA), anyBoolean());
|
||||
|
||||
doAnswer(invocation -> mMicListeners.add(invocation.getArgument(1)))
|
||||
doAnswer(invocation -> {
|
||||
mMicState.put(0, invocation.getArgument(2));
|
||||
mMicState.put(10, invocation.getArgument(2));
|
||||
for (OnSensorPrivacyChangedListener listener : mMicListeners.get(0)) {
|
||||
listener.onSensorPrivacyChanged(MICROPHONE, mMicState.get(0));
|
||||
}
|
||||
for (OnSensorPrivacyChangedListener listener : mMicListeners.get(10)) {
|
||||
listener.onSensorPrivacyChanged(MICROPHONE, mMicState.get(10));
|
||||
}
|
||||
return null;
|
||||
}).when(mSensorPrivacyManager)
|
||||
.setSensorPrivacyForProfileGroup(anyInt(), eq(MICROPHONE), anyBoolean());
|
||||
doAnswer(invocation -> {
|
||||
mCamState.put(0, invocation.getArgument(2));
|
||||
mCamState.put(10, invocation.getArgument(2));
|
||||
for (OnSensorPrivacyChangedListener listener : mCamListeners.get(0)) {
|
||||
listener.onSensorPrivacyChanged(CAMERA, mCamState.get(0));
|
||||
}
|
||||
for (OnSensorPrivacyChangedListener listener : mCamListeners.get(10)) {
|
||||
listener.onSensorPrivacyChanged(CAMERA, mCamState.get(10));
|
||||
}
|
||||
return null;
|
||||
}).when(mSensorPrivacyManager)
|
||||
.setSensorPrivacyForProfileGroup(anyInt(), eq(CAMERA), anyBoolean());
|
||||
|
||||
doAnswer(invocation -> mMicListeners.get(0).add(invocation.getArgument(1)))
|
||||
.when(mSensorPrivacyManager).addSensorPrivacyListener(eq(MICROPHONE), any());
|
||||
doAnswer(invocation -> mCamListeners.add(invocation.getArgument(1)))
|
||||
doAnswer(invocation -> mCamListeners.get(0).add(invocation.getArgument(1)))
|
||||
.when(mSensorPrivacyManager).addSensorPrivacyListener(eq(CAMERA), any());
|
||||
|
||||
doAnswer(invocation -> mMicListeners.get(invocation.getArgument(2))
|
||||
.add(invocation.getArgument(1))).when(mSensorPrivacyManager)
|
||||
.addSensorPrivacyListener(eq(MICROPHONE), anyInt(), any());
|
||||
doAnswer(invocation -> mCamListeners.get(invocation.getArgument(2))
|
||||
.add(invocation.getArgument(1))).when(mSensorPrivacyManager)
|
||||
.addSensorPrivacyListener(eq(CAMERA), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,7 +191,7 @@ public class SensorToggleControllerTest {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, MICROPHONE, false);
|
||||
MicToggleController micToggleController = new MicToggleController(mContext, "mic_toggle");
|
||||
micToggleController.setChecked(false);
|
||||
assertTrue(mMicState);
|
||||
assertTrue(mMicState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,7 +199,23 @@ public class SensorToggleControllerTest {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, MICROPHONE, true);
|
||||
MicToggleController micToggleController = new MicToggleController(mContext, "mic_toggle");
|
||||
micToggleController.setChecked(true);
|
||||
assertFalse(mMicState);
|
||||
assertFalse(mMicState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMicrophoneSensorPrivacyEnabledForProfileUser_uncheckMicToggle_returnTrue() {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, MICROPHONE, false);
|
||||
MicToggleController micToggleController = new MicToggleController(mContext, "mic_toggle");
|
||||
micToggleController.setChecked(false);
|
||||
assertTrue(mMicState.get(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMicrophoneSensorPrivacyEnabledProfileUser_checkMicToggle_returnFalse() {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, MICROPHONE, true);
|
||||
MicToggleController micToggleController = new MicToggleController(mContext, "mic_toggle");
|
||||
micToggleController.setChecked(true);
|
||||
assertFalse(mMicState.get(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,20 +253,38 @@ public class SensorToggleControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCameraSensorPrivacyEnabled_uncheckMicToggle_returnTrue() {
|
||||
public void isCameraSensorPrivacyEnabled_uncheckCanToggle_returnTrue() {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, CAMERA, false);
|
||||
CameraToggleController camToggleController =
|
||||
new CameraToggleController(mContext, "cam_toggle");
|
||||
camToggleController.setChecked(false);
|
||||
assertTrue(mCamState);
|
||||
assertTrue(mCamState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCameraSensorPrivacyEnabled_checkMicToggle_returnFalse() {
|
||||
public void isCameraSensorPrivacyEnabled_checkCamToggle_returnFalse() {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, CAMERA, true);
|
||||
CameraToggleController camToggleController =
|
||||
new CameraToggleController(mContext, "cam_toggle");
|
||||
camToggleController.setChecked(true);
|
||||
assertFalse(mCamState);
|
||||
assertFalse(mCamState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCameraSensorPrivacyEnabledForProfileUser_uncheckCamToggle_returnTrue() {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, CAMERA, false);
|
||||
CameraToggleController camToggleController =
|
||||
new CameraToggleController(mContext, "cam_toggle");
|
||||
camToggleController.setChecked(false);
|
||||
assertTrue(mCamState.get(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCameraSensorPrivacyEnabledProfileUser_checkCamToggle_returnFalse() {
|
||||
mSensorPrivacyManager.setSensorPrivacy(OTHER, CAMERA, true);
|
||||
CameraToggleController camToggleController =
|
||||
new CameraToggleController(mContext, "cam_toggle");
|
||||
camToggleController.setChecked(true);
|
||||
assertFalse(mCamState.get(10));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user