Merge "Brings back "Control from locked device" setting." into tm-qpr-dev am: d81ae0a645 am: 2a557b75fe

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/20590947

Change-Id: Iefe3c423fae6c6eb720b1b816af196736089067f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ale Nijamkin
2022-12-02 03:27:05 +00:00
committed by Automerger Merge Worker
2 changed files with 58 additions and 9 deletions

View File

@@ -21,10 +21,14 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.provider.Settings;
import androidx.preference.Preference;
@@ -40,6 +44,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
@@ -62,9 +67,11 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = ApplicationProvider.getApplicationContext();
mContext = spy(ApplicationProvider.getApplicationContext());
mContentResolver = spy(mContext.getContentResolver());
when(mContext.getContentResolver()).thenReturn(mContentResolver);
mContentResolver = mContext.getContentResolver();
setCustomizableLockScreenQuickAffordancesEnabled(false);
mController = new ControlsTrivialPrivacyPreferenceController(mContext, TEST_KEY);
}
@@ -130,6 +137,18 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
verify(mPreference, atLeastOnce()).setSummary(mController.getSummary());
}
@Test
public void updateStateWithCustomizableLockScreenQuickAffordancesEnabled() {
setCustomizableLockScreenQuickAffordancesEnabled(true);
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
mController.updateState(mPreference);
verify(mPreference).setEnabled(true);
verify(mPreference, atLeastOnce()).setSummary(
mContext.getString(R.string.lockscreen_trivial_controls_summary));
}
@Test
public void getAvailabilityStatusWithoutDeviceControls() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
@@ -138,6 +157,15 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
@Test
public void getAvailabilityStatusWithCustomizableLockScreenQuickAffordancesEnabled() {
setCustomizableLockScreenQuickAffordancesEnabled(true);
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatusWithDeviceControls() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 1);
@@ -154,4 +182,22 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
mController.displayPreference(mPreferenceScreen);
verify(mPreference).setDependency(anyString());
}
private void setCustomizableLockScreenQuickAffordancesEnabled(boolean isEnabled) {
when(
mContentResolver.query(
CustomizableLockScreenUtils.FLAGS_URI, null, null, null))
.thenAnswer((Answer<Cursor>) invocation -> {
final MatrixCursor cursor = new MatrixCursor(
new String[] {
CustomizableLockScreenUtils.NAME,
CustomizableLockScreenUtils.VALUE
});
cursor.addRow(
new Object[] {
CustomizableLockScreenUtils.ENABLED_FLAG, isEnabled ? 1 : 0
});
return cursor;
});
}
}