Brings back "Control from locked device" setting.

In ag/20427460, we made ControlsTrivialPrivacyPreferenceController, which controls this setting, be UNSUPPORTED_ON_DEVICE if customizable lock screen quick affordances are enabled.

This wrongly removes this setting from the Settings app and there is no new UI where the user can control that anymore. What this means is that, once users upgrade to an Android build with our feature, they will forever be stuck with whatever they last chose for "Control from locked device".

This CL brings that back but changes the behaviour a bit such that, if
the quick affordances feature is enabled, this setting is never
disabled.

Fix: 260722836
Test: Unit tests added. Manually verified that the setting is visible
and enabled if the feature is enabled, even if the current selection
does not include the Home quick affordance and that if the feature is
off, the setting is visible but disabled if the main setting is off (old
behaviour unchanged).

Change-Id: I2e53123b3b7a2896699aeaa13b0c7d5a1c8a9c92
This commit is contained in:
Alejandro Nijamkin
2022-11-29 12:07:33 -08:00
parent a01a1857ec
commit 8eef47d0cc
2 changed files with 58 additions and 9 deletions

View File

@@ -50,9 +50,11 @@ public class ControlsTrivialPrivacyPreferenceController extends TogglePreference
@Override
public CharSequence getSummary() {
if (getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
if (!CustomizableLockScreenUtils.isFeatureEnabled(mContext)
&& getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
return mContext.getText(R.string.lockscreen_trivial_disabled_controls_summary);
}
return mContext.getText(R.string.lockscreen_trivial_controls_summary);
}
@@ -70,21 +72,22 @@ public class ControlsTrivialPrivacyPreferenceController extends TogglePreference
@Override
public int getAvailabilityStatus() {
if (CustomizableLockScreenUtils.isFeatureEnabled(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return showDeviceControlsSettingsEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
private boolean showDeviceControlsSettingsEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(), DEPENDENCY_SETTING_KEY, 0)
!= 0;
return CustomizableLockScreenUtils.isFeatureEnabled(mContext)
|| Settings.Secure.getInt(
mContext.getContentResolver(), DEPENDENCY_SETTING_KEY, 0) != 0;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (CustomizableLockScreenUtils.isFeatureEnabled(mContext)) {
return;
}
Preference currentPreference = screen.findPreference(getPreferenceKey());
currentPreference.setDependency("lockscreen_privacy_controls_switch");
}

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;
});
}
}