Allows for system navigation settings to be added dynamically.

This allows for controller-backed preferences to be added or
overridden via xml.

Similarly, if the controllers cause all of the preferences for
2 or 3 button nav to be unavailable, we hide the settings button.

Bug: 324036308
Test: Manual and unit tests
Flag: NA
Change-Id: I2371f3173076172489966728ac69c8767570cd56
Merged-In: I2371f3173076172489966728ac69c8767570cd56
This commit is contained in:
Andy Wickham
2024-03-08 03:26:35 +00:00
parent 4115a9a278
commit 9aa1c402ae
6 changed files with 133 additions and 5 deletions

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2024 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="fake_title_key"
android:title="screen_title">
<Preference
android:key="key1"
android:title="title"
android:icon="@drawable/ic_android"
android:summary="summary1"
settings:controller="com.android.settings.core.UnavailablePreferenceController"/>
<Preference
android:key="key2"
android:title="title"
android:icon="@drawable/ic_android"
android:summary="summary2"
settings:controller="com.android.settings.core.UnavailablePreferenceController"/>
</PreferenceScreen>

View File

@@ -20,6 +20,8 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.preference.PreferenceManager;
import com.android.settings.R;
import com.android.settings.slices.FakePreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -38,10 +40,12 @@ import java.util.List;
public class PreferenceControllerListHelperTest {
private Context mContext;
private PreferenceManager mPreferenceManager;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mPreferenceManager = new PreferenceManager(mContext);
}
@Test
@@ -68,6 +72,30 @@ public class PreferenceControllerListHelperTest {
assertThat(controllers.get(0)).isInstanceOf(FakePreferenceController.class);
}
@Test
@Config(qualifiers = "mcc999")
public void areAllPreferencesUnavailable_allAvailable() {
// All preferences have controllers indicating they are available.
assertThat(PreferenceControllerListHelper.areAllPreferencesUnavailable(mContext,
mPreferenceManager, R.xml.location_settings)).isFalse();
}
@Test
@Config(qualifiers = "mcc997")
public void areAllPreferencesUnavailable_allUnavailable() {
// All preferences have controllers indicating they are unavailable. (note the qualifier)
assertThat(PreferenceControllerListHelper.areAllPreferencesUnavailable(mContext,
mPreferenceManager, R.xml.location_settings)).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void areAllPreferencesUnavailable_noControllersShouldAssumeAvailable() {
// None of the preferences have controllers, so they are assumed available.
assertThat(PreferenceControllerListHelper.areAllPreferencesUnavailable(mContext,
mPreferenceManager, R.xml.display_settings)).isFalse();
}
@Test
public void filterControllers_noFilter_shouldReturnSameList() {
final List<BasePreferenceController> controllers = new ArrayList<>();

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.core;
import android.content.Context;
public class UnavailablePreferenceController extends BasePreferenceController {
public UnavailablePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return UNSUPPORTED_ON_DEVICE;
}
}