Merge "Fix search non-indexable update"
This commit is contained in:
committed by
Android (Google) Code Review
commit
26ea60a231
@@ -67,14 +67,20 @@ public class PreferenceControllerListHelper {
|
|||||||
try {
|
try {
|
||||||
controller = BasePreferenceController.createInstance(context, controllerName);
|
controller = BasePreferenceController.createInstance(context, controllerName);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
|
Log.d(TAG, "Could not find Context-only controller for pref: " + controllerName);
|
||||||
final String key = metadata.getString(METADATA_KEY);
|
final String key = metadata.getString(METADATA_KEY);
|
||||||
if (TextUtils.isEmpty(key)) {
|
if (TextUtils.isEmpty(key)) {
|
||||||
Log.w(TAG, "Controller requires key but it's not defined in xml: "
|
Log.w(TAG, "Controller requires key but it's not defined in xml: "
|
||||||
+ controllerName);
|
+ controllerName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Could not find Context-only controller for pref: " + key);
|
try {
|
||||||
controller = BasePreferenceController.createInstance(context, controllerName, key);
|
controller = BasePreferenceController.createInstance(context, controllerName,
|
||||||
|
key);
|
||||||
|
} catch (IllegalStateException e2) {
|
||||||
|
Log.w(TAG, "Cannot instantiate controller from reflection: " + controllerName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
controllers.add(controller);
|
controllers.add(controller);
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
@@ -119,7 +120,8 @@ public class BatterySaverController extends TogglePreferenceController
|
|||||||
mBatterySaverPref.setSummary(getSummary());
|
mBatterySaverPref.setSummary(getSummary());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ContentObserver mObserver = new ContentObserver(new Handler()) {
|
private final ContentObserver mObserver = new ContentObserver(
|
||||||
|
new Handler(Looper.getMainLooper())) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange) {
|
public void onChange(boolean selfChange) {
|
||||||
updateSummary();
|
updateSummary();
|
||||||
|
@@ -25,7 +25,6 @@ import android.os.BatteryStats;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
@@ -33,17 +32,14 @@ import android.view.Menu;
|
|||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.View.OnLongClickListener;
|
import android.view.View.OnLongClickListener;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Settings.HighPowerApplicationsActivity;
|
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.applications.LayoutPreference;
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
import com.android.settings.display.BatteryPercentagePreferenceController;
|
import com.android.settings.display.BatteryPercentagePreferenceController;
|
||||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||||
@@ -56,7 +52,6 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
|||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
import com.android.settingslib.utils.PowerUtil;
|
import com.android.settingslib.utils.PowerUtil;
|
||||||
import com.android.settingslib.utils.StringUtil;
|
import com.android.settingslib.utils.StringUtil;
|
||||||
|
|
||||||
@@ -242,11 +237,7 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
|||||||
KEY_BATTERY_TIP, (SettingsActivity) getActivity(), this /* fragment */, this /*
|
KEY_BATTERY_TIP, (SettingsActivity) getActivity(), this /* fragment */, this /*
|
||||||
BatteryTipListener */);
|
BatteryTipListener */);
|
||||||
controllers.add(mBatteryTipPreferenceController);
|
controllers.add(mBatteryTipPreferenceController);
|
||||||
BatterySaverController batterySaverController = new BatterySaverController(context);
|
|
||||||
controllers.add(batterySaverController);
|
|
||||||
controllers.add(new BatteryPercentagePreferenceController(context));
|
controllers.add(new BatteryPercentagePreferenceController(context));
|
||||||
|
|
||||||
lifecycle.addObserver(batterySaverController);
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -78,8 +78,10 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
|||||||
((BasePreferenceController) controller).updateNonIndexableKeys(
|
((BasePreferenceController) controller).updateNonIndexableKeys(
|
||||||
nonIndexableKeys);
|
nonIndexableKeys);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException(controller.getClass().getName()
|
Log.e(TAG, controller.getClass().getName()
|
||||||
+ " must implement " + PreferenceControllerMixin.class.getName());
|
+ " must implement " + PreferenceControllerMixin.class.getName()
|
||||||
|
+ " treating the key non-indexable");
|
||||||
|
nonIndexableKeys.add(controller.getPreferenceKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nonIndexableKeys;
|
return nonIndexableKeys;
|
||||||
|
31
tests/robotests/res/xml-mcc998/location_settings.xml
Normal file
31
tests/robotests/res/xml-mcc998/location_settings.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2018 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"
|
||||||
|
settings:controller="com.android.settings.slices.FakePreferenceController">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="key"
|
||||||
|
android:title="title"
|
||||||
|
android:icon="@drawable/ic_android"
|
||||||
|
android:summary="summary"
|
||||||
|
settings:controller="com.android.settings.core.BadPreferenceController"/>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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 BadPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
public BadPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
throw new IllegalArgumentException("error");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
@@ -59,6 +59,17 @@ public class PreferenceControllerListHelperTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc998")
|
||||||
|
public void getControllers_partialFailure_shouldReturnTheRest() {
|
||||||
|
final List<BasePreferenceController> controllers =
|
||||||
|
PreferenceControllerListHelper.getPreferenceControllersFromXml(mContext,
|
||||||
|
R.xml.location_settings);
|
||||||
|
|
||||||
|
assertThat(controllers).hasSize(1);
|
||||||
|
assertThat(controllers.get(0)).isInstanceOf(FakePreferenceController.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterControllers_noFilter_shouldReturnSameList() {
|
public void filterControllers_noFilter_shouldReturnSameList() {
|
||||||
final List<BasePreferenceController> controllers = new ArrayList<>();
|
final List<BasePreferenceController> controllers = new ArrayList<>();
|
||||||
|
Reference in New Issue
Block a user