Make pref unsearchable for more availibility status.
Bug: 72748524 Test: robotest Change-Id: I12b13ac3503f851857787df98a2d2f599c71b9b7
This commit is contained in:
@@ -187,6 +187,7 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
public final boolean isAvailable() {
|
||||
final int availabilityStatus = getAvailabilityStatus();
|
||||
return (availabilityStatus == AVAILABLE
|
||||
|| availabilityStatus == AVAILABLE_UNSEARCHABLE
|
||||
|| availabilityStatus == DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@@ -230,16 +231,15 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
* Called by SearchIndexProvider#getNonIndexableKeys
|
||||
*/
|
||||
public void updateNonIndexableKeys(List<String> keys) {
|
||||
if (this instanceof AbstractPreferenceController) {
|
||||
if (!isAvailable()) {
|
||||
final String key = getPreferenceKey();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
Log.w(TAG,
|
||||
"Skipping updateNonIndexableKeys due to empty key " + this.toString());
|
||||
return;
|
||||
}
|
||||
keys.add(key);
|
||||
final boolean shouldSuppressFromSearch = !isAvailable()
|
||||
|| getAvailabilityStatus() == AVAILABLE_UNSEARCHABLE;
|
||||
if (shouldSuppressFromSearch) {
|
||||
final String key = getPreferenceKey();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
Log.w(TAG, "Skipping updateNonIndexableKeys due to empty key " + toString());
|
||||
return;
|
||||
}
|
||||
keys.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,6 @@ import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
public class LockdownButtonPreferenceController extends TogglePreferenceController {
|
||||
@@ -36,9 +35,9 @@ public class LockdownButtonPreferenceController extends TogglePreferenceControll
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mLockPatternUtils.isSecure(UserHandle.myUserId())) {
|
||||
return BasePreferenceController.AVAILABLE;
|
||||
return AVAILABLE;
|
||||
} else {
|
||||
return BasePreferenceController.DISABLED_FOR_USER;
|
||||
return DISABLED_FOR_USER;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,9 +27,7 @@ import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
@@ -45,6 +43,8 @@ import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.builders.ListBuilder;
|
||||
|
@@ -16,12 +16,12 @@
|
||||
package com.android.settings.core;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -36,8 +36,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -72,6 +74,13 @@ public class BasePreferenceControllerTest {
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_availableStatusUnSearchable_returnsTrue() {
|
||||
mPreferenceController.setAvailability(AVAILABLE_UNSEARCHABLE);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_availableStatusUnsupportedOnDevice_returnsFalse() {
|
||||
mPreferenceController.setAvailability(UNSUPPORTED_ON_DEVICE);
|
||||
@@ -159,6 +168,36 @@ public class BasePreferenceControllerTest {
|
||||
assertThat(preference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNonIndexableKeys_controllerUnavailable_shouldAddKey() {
|
||||
final List<String> keys = new ArrayList<>();
|
||||
mPreferenceController.setAvailability(UNSUPPORTED_ON_DEVICE);
|
||||
|
||||
mPreferenceController.updateNonIndexableKeys(keys);
|
||||
|
||||
assertThat(keys).containsExactly(mPreferenceController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNonIndexableKeys_controllerUnsearchable_shouldAddKey() {
|
||||
final List<String> keys = new ArrayList<>();
|
||||
mPreferenceController.setAvailability(AVAILABLE_UNSEARCHABLE);
|
||||
|
||||
mPreferenceController.updateNonIndexableKeys(keys);
|
||||
|
||||
assertThat(keys).containsExactly(mPreferenceController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNonIndexableKeys_controllerAvailable_shouldNotAddKey() {
|
||||
final List<String> keys = new ArrayList<>();
|
||||
mPreferenceController.setAvailability(AVAILABLE);
|
||||
|
||||
mPreferenceController.updateNonIndexableKeys(keys);
|
||||
|
||||
assertThat(keys).isEmpty();
|
||||
}
|
||||
|
||||
private class FakeBasePreferenceController extends BasePreferenceController {
|
||||
|
||||
public int mAvailable;
|
||||
|
Reference in New Issue
Block a user