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:
@@ -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");
|
||||
}
|
||||
|
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user