Merge "Fix robolectric tests"
diff --git a/res/layout/settings_main_dashboard.xml b/res/layout/settings_main_dashboard.xml
index 7c34803..269bc3c 100644
--- a/res/layout/settings_main_dashboard.xml
+++ b/res/layout/settings_main_dashboard.xml
@@ -32,7 +32,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/search_bar_margin"
- app:cardCornerRadius="@dimen/search_bar_half_height"
+ app:cardCornerRadius="@dimen/search_bar_corner_radius"
app:cardBackgroundColor="?android:attr/colorBackground"
app:cardElevation="2dp">
<Toolbar
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 2f00297..ef4d269 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -121,7 +121,7 @@
<dimen name="search_bar_negative_margin">-8dp</dimen>
<dimen name="search_bar_height">48dp</dimen>
- <dimen name="search_bar_half_height">24dp</dimen>
+ <dimen name="search_bar_corner_radius">2dp</dimen>
<dimen name="search_bar_text_size">16dp</dimen>
<!-- Dimensions for Wifi Assistant Card -->
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index d24dd51..497a485 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -22,4 +22,8 @@
<PreferenceCategory
android:key="connected_device_list"
android:title="@string/connected_device_connected_title"/>
+
+ <PreferenceCategory
+ android:key="saved_device_list"
+ android:title="@string/connected_device_saved_title"/>
</PreferenceScreen>
diff --git a/res/xml/wifi_display_settings.xml b/res/xml/wifi_display_settings.xml
index 2be31d2..7ad214e 100644
--- a/res/xml/wifi_display_settings.xml
+++ b/res/xml/wifi_display_settings.xml
@@ -14,7 +14,9 @@
limitations under the License.
-->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:key="wifi_display_settings_screen"
android:title="@string/wifi_display_settings_title">
</PreferenceScreen>
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
index e053bc9..127730b 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
@@ -149,9 +149,22 @@
}
/**
+ * Return {@code true} if {@code cachedBluetoothDevice} matches this
+ * {@link BluetoothDeviceUpdater} and should stay in the list, otherwise return {@code false}
+ */
+ public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice);
+
+ /**
* Update whether to show {@cde cachedBluetoothDevice} in the list.
*/
- abstract public void update(CachedBluetoothDevice cachedBluetoothDevice);
+ protected void update(CachedBluetoothDevice cachedBluetoothDevice) {
+ if (isFilterMatched(cachedBluetoothDevice)) {
+ // Add the preference if it is new one
+ addPreference(cachedBluetoothDevice);
+ } else {
+ removePreference(cachedBluetoothDevice);
+ }
+ }
/**
* Add the {@link Preference} that represents the {@code cachedDevice}
diff --git a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
index 239e405..deab29f 100644
--- a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
@@ -51,16 +51,8 @@
}
@Override
- public void update(CachedBluetoothDevice cachedDevice) {
+ public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
final BluetoothDevice device = cachedDevice.getDevice();
- final boolean filterMatch =
- device.getBondState() == BluetoothDevice.BOND_BONDED && device.isConnected();
-
- if (filterMatch) {
- // Add the preference if it is new one
- addPreference(cachedDevice);
- } else {
- removePreference(cachedDevice);
- }
+ return device.getBondState() == BluetoothDevice.BOND_BONDED && device.isConnected();
}
}
diff --git a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
new file mode 100644
index 0000000..da7679a
--- /dev/null
+++ b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 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.bluetooth;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+
+/**
+ * Maintain and update saved bluetooth devices(bonded but not connected)
+ */
+public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
+
+ public SavedBluetoothDeviceUpdater(DashboardFragment fragment,
+ DevicePreferenceCallback devicePreferenceCallback) {
+ super(fragment, devicePreferenceCallback);
+ }
+
+ @VisibleForTesting
+ SavedBluetoothDeviceUpdater(DashboardFragment fragment,
+ DevicePreferenceCallback devicePreferenceCallback,
+ LocalBluetoothManager localBluetoothManager) {
+ super(fragment, devicePreferenceCallback, localBluetoothManager);
+ }
+
+ @Override
+ public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
+ if (state == BluetoothAdapter.STATE_CONNECTED) {
+ removePreference(cachedDevice);
+ } else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
+ addPreference(cachedDevice);
+ }
+ }
+
+ @Override
+ public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
+ final BluetoothDevice device = cachedDevice.getDevice();
+ return device.getBondState() == BluetoothDevice.BOND_BONDED && !device.isConnected();
+ }
+}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 14acd89..8b0e568 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -62,9 +62,8 @@
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final Lifecycle lifecycle = getLifecycle();
- final ConnectedDeviceGroupController connectedDeviceGroupController =
- new ConnectedDeviceGroupController(this, lifecycle);
- controllers.add(connectedDeviceGroupController);
+ controllers.add(new ConnectedDeviceGroupController(this, lifecycle));
+ controllers.add(new SavedDeviceGroupController(this, lifecycle));
return controllers;
}
diff --git a/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java b/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java
new file mode 100644
index 0000000..7445047
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 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.connecteddevice;
+
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.bluetooth.BluetoothDeviceUpdater;
+import com.android.settings.bluetooth.SavedBluetoothDeviceUpdater;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+/**
+ * Controller to maintain the {@link PreferenceGroup} for all
+ * saved devices. It uses {@link DevicePreferenceCallback} to add/remove {@link Preference}
+ */
+public class SavedDeviceGroupController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
+ DevicePreferenceCallback {
+
+ private static final String KEY = "saved_device_list";
+
+ @VisibleForTesting
+ PreferenceGroup mPreferenceGroup;
+ private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+
+ public SavedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle) {
+ super(fragment.getContext());
+ init(lifecycle, new SavedBluetoothDeviceUpdater(fragment, SavedDeviceGroupController.this));
+ }
+
+ @VisibleForTesting
+ SavedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle,
+ BluetoothDeviceUpdater bluetoothDeviceUpdater) {
+ super(fragment.getContext());
+ init(lifecycle, bluetoothDeviceUpdater);
+ }
+
+ @Override
+ public void onStart() {
+ mBluetoothDeviceUpdater.registerCallback();
+ }
+
+ @Override
+ public void onStop() {
+ mBluetoothDeviceUpdater.unregisterCallback();
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ mPreferenceGroup = (PreferenceGroup) screen.findPreference(KEY);
+ mPreferenceGroup.setVisible(false);
+ mBluetoothDeviceUpdater.setPrefContext(screen.getContext());
+ mBluetoothDeviceUpdater.forceUpdate();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ public void onDeviceAdded(Preference preference) {
+ if (mPreferenceGroup.getPreferenceCount() == 0) {
+ mPreferenceGroup.setVisible(true);
+ }
+ mPreferenceGroup.addPreference(preference);
+ }
+
+ @Override
+ public void onDeviceRemoved(Preference preference) {
+ mPreferenceGroup.removePreference(preference);
+ if (mPreferenceGroup.getPreferenceCount() == 0) {
+ mPreferenceGroup.setVisible(false);
+ }
+ }
+
+ private void init(Lifecycle lifecycle, BluetoothDeviceUpdater bluetoothDeviceUpdater) {
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModeAutomationSettings.java b/src/com/android/settings/notification/ZenModeAutomationSettings.java
index d096e8c..582fb03 100644
--- a/src/com/android/settings/notification/ZenModeAutomationSettings.java
+++ b/src/com/android/settings/notification/ZenModeAutomationSettings.java
@@ -18,6 +18,7 @@
import android.app.Fragment;
import android.content.Context;
+import android.provider.SearchIndexableResource;
import android.service.notification.ConditionProviderService;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -78,17 +79,30 @@
*/
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- final List<String> keys = super.getNonIndexableKeys(context);
- keys.add(KEY_ADD_RULE);
- keys.add(KEY_AUTOMATIC_RULES);
- return keys;
- }
- @Override
- public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, null, null);
- }
- };
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.zen_mode_automation_settings;
+ result.add(sir);
+ return result;
+ }
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ final List<String> keys = super.getNonIndexableKeys(context);
+ keys.add(KEY_ADD_RULE);
+ keys.add(KEY_AUTOMATIC_RULES);
+ return keys;
+ }
+
+ @Override
+ public List<AbstractPreferenceController> getPreferenceControllers(
+ Context context) {
+ return buildPreferenceControllers(context, null, null);
+ }
+ };
}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
index dfe6786..b58ef86 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
@@ -17,6 +17,7 @@
package com.android.settings.notification;
import android.content.Context;
+import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -65,6 +66,18 @@
*/
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
+
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.zen_mode_behavior_settings;
+ result.add(sir);
+ return result;
+ }
+
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
diff --git a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
index 9eccfdc..069d38b 100644
--- a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
+++ b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
@@ -26,7 +26,6 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
-import android.provider.SearchIndexableResource;
import android.service.notification.ConditionProviderService;
import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.Preference;
@@ -44,15 +43,9 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Indexable;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.core.AbstractPreferenceController;
-import java.util.Arrays;
-import java.util.List;
-
-import java.util.Arrays;
import java.util.List;
public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase
@@ -62,8 +55,6 @@
private static final String KEY_RULE_NAME = "rule_name";
private static final String KEY_ZEN_MODE = "zen_mode";
- private static final String KEY_EVENT_RULE_SETTINGS = "zen_mode_event_rule_settings";
- private static final String KEY_SCHEDULE_RULE_SETTINGS = "zen_mode_schedule_rule_settings";
protected Context mContext;
protected boolean mDisableListeners;
@@ -306,26 +297,4 @@
}
mDisableListeners = false;
}
-
- /**
- * For Search.
- */
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(
- Context context, boolean enabled) {
- final SearchIndexableResource sir = new SearchIndexableResource(context);
- // not indexable
- return Arrays.asList(sir);
- }
-
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- final List<String> keys = super.getNonIndexableKeys(context);
- keys.add(KEY_SCHEDULE_RULE_SETTINGS);
- keys.add(KEY_EVENT_RULE_SETTINGS);
- return keys;
- }
- };
}
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 7512c13..82ab020 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -39,7 +39,6 @@
import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
-import com.android.settings.deviceinfo.Status;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.display.AmbientDisplaySettings;
@@ -69,8 +68,6 @@
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
import com.android.settings.notification.ZenModeBehaviorSettings;
-import com.android.settings.notification.ZenModeEventRuleSettings;
-import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.security.EncryptionAndCredential;
@@ -86,6 +83,7 @@
import com.android.settings.tts.TtsEnginePreferenceFragment;
import com.android.settings.users.UserSettings;
import com.android.settings.wallpaper.WallpaperTypeSettings;
+import com.android.settings.wfd.WifiDisplaySettings;
import com.android.settings.wifi.ConfigureWifiSettings;
import com.android.settings.wifi.WifiSettings;
@@ -169,10 +167,9 @@
addIndex(PowerUsageSummary.class);
addIndex(BatterySaverSettings.class);
addIndex(LockscreenDashboardFragment.class);
+ addIndex(WifiDisplaySettings.class);
addIndex(ZenModeBehaviorSettings.class);
addIndex(ZenModeAutomationSettings.class);
- addIndex(ZenModeEventRuleSettings.class);
- addIndex(ZenModeScheduleRuleSettings.class);
}
private SearchIndexableResources() {
diff --git a/src/com/android/settings/wfd/WifiDisplaySettings.java b/src/com/android/settings/wfd/WifiDisplaySettings.java
index 3fe438f..5707e3e 100755
--- a/src/com/android/settings/wfd/WifiDisplaySettings.java
+++ b/src/com/android/settings/wfd/WifiDisplaySettings.java
@@ -36,7 +36,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
-import android.os.ServiceManager;
+import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.ListPreference;
@@ -63,6 +63,11 @@
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* The Settings screen for WifiDisplay configuration and connection management.
@@ -72,7 +77,7 @@
* on the system. In that case, the enable option will not be shown but other
* remote display routes will continue to be made available.
*/
-public final class WifiDisplaySettings extends SettingsPreferenceFragment {
+public final class WifiDisplaySettings extends SettingsPreferenceFragment implements Indexable {
private static final String TAG = "WifiDisplaySettings";
private static final boolean DEBUG = false;
@@ -823,4 +828,18 @@
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
= (activity, summaryLoader) -> new SummaryProvider(activity, summaryLoader);
+
+ public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.wifi_display_settings;
+ result.add(sir);
+ return result;
+ }
+ };
}
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index 6704fc3..ab1a2af 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -19,4 +19,6 @@
com.android.settings.enterprise.ApplicationListFragment$EnterpriseInstalledPackages
com.android.settings.enterprise.EnterpriseSetDefaultAppsListFragment
com.android.settings.wifi.tether.WifiTetherSettings
-com.android.settings.wifi.SavedAccessPointsWifiSettings
\ No newline at end of file
+com.android.settings.wifi.SavedAccessPointsWifiSettings
+com.android.settings.notification.ZenModeEventRuleSettings
+com.android.settings.notification.ZenModeScheduleRuleSettings
diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable
index 500a582..681e8f6 100644
--- a/tests/robotests/assets/grandfather_not_implementing_indexable
+++ b/tests/robotests/assets/grandfather_not_implementing_indexable
@@ -50,7 +50,6 @@
com.android.settings.applications.AppInfoDashboardFragment
com.android.settings.accessibility.ToggleAccessibilityServicePreferenceFragment
com.android.settings.print.PrintServiceSettingsFragment
-com.android.settings.wfd.WifiDisplaySettings
com.android.settings.deviceinfo.PrivateVolumeSettings
com.android.settings.users.AppRestrictionsFragment
com.android.settings.deviceinfo.PrivateVolumeUnmount
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
index 525f70e..d5abd93 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
@@ -73,8 +73,8 @@
mBluetoothDeviceUpdater = new BluetoothDeviceUpdater(mDashboardFragment,
mDevicePreferenceCallback, null) {
@Override
- public void update(CachedBluetoothDevice cachedBluetoothDevice) {
- // do nothing
+ public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
+ return true;
}
};
mBluetoothDeviceUpdater.setPrefContext(mContext);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
new file mode 100644
index 0000000..d0f367e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 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.bluetooth;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+
+import com.android.settings.TestConfig;
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class SavedBluetoothDeviceUpdaterTest {
+ @Mock
+ private DashboardFragment mDashboardFragment;
+ @Mock
+ private DevicePreferenceCallback mDevicePreferenceCallback;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDevice;
+ @Mock
+ private BluetoothDevice mBluetoothDevice;
+
+ private Context mContext;
+ private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ doReturn(mContext).when(mDashboardFragment).getContext();
+ doReturn(mBluetoothDevice).when(mCachedBluetoothDevice).getDevice();
+
+ mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
+ mDevicePreferenceCallback, null));
+ mBluetoothDeviceUpdater.setPrefContext(mContext);
+ doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
+ doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
+ }
+
+ @Test
+ public void testUpdate_filterMatch_addPreference() {
+ doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
+ doReturn(false).when(mBluetoothDevice).isConnected();
+
+ mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+ verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
+ }
+
+ @Test
+ public void testUpdate_filterNotMatch_removePreference() {
+ doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState();
+ doReturn(true).when(mBluetoothDevice).isConnected();
+
+ mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+ verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
+ }
+
+ @Test
+ public void testOnConnectionStateChanged_deviceConnected_removePreference() {
+ mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothAdapter.STATE_CONNECTED);
+
+ verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
+ }
+
+ @Test
+ public void testOnConnectionStateChanged_deviceDisconnected_addPreference() {
+ mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothAdapter.STATE_DISCONNECTED);
+
+ verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index c9fcf26..99b0945 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -78,7 +78,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowEntityHeaderController.class, ShadowActivityManager.class})
public class AdvancedPowerUsageDetailTest {
private static final String APP_LABEL = "app label";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
index ad5f5b0..5c28a06 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
@@ -66,7 +66,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AppButtonsPreferenceControllerTest {
private static final String PACKAGE_NAME = "com.android.settings";
private static final String RESOURCE_STRING = "string";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
index e010cf3..cb5914f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -39,6 +39,7 @@
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
import org.junit.Before;
@@ -57,10 +58,11 @@
@RunWith(RobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
- SettingsShadowResources.SettingsShadowTheme.class
+ SettingsShadowResources.SettingsShadowTheme.class,
+ ShadowFragment.class
})
public class BackgroundActivityPreferenceControllerTest {
private static final int UID_LOW_SDK = 1234;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
index a163a43..30b3448 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
@@ -41,7 +41,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatteryBroadcastReceiverTest {
private static final String BATTERY_INIT_LEVEL = "100%";
private static final String BATTERY_INIT_STATUS = "Not charging";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
index a57b6ca..04040ac 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
@@ -43,7 +43,7 @@
import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatteryEntryTest {
private static final int APP_UID = 123;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
index 719cc33..e433b3c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
@@ -43,6 +43,7 @@
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -58,9 +59,10 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
+ SettingsShadowResourcesImpl.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowEntityHeaderController.class
})
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
index 0d03512..60d06cd 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
@@ -44,7 +44,8 @@
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O
+ ,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
index b87089a..5029897 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
@@ -42,7 +42,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatteryInfoLoaderTest {
private static final long TEST_TIME_REMAINING = 1000L;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index d82a89b..dd6b709 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -58,7 +58,7 @@
import java.util.concurrent.TimeUnit;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatteryInfoTest {
private static final String STATUS_FULL = "Full";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
index 3a1fad0..fba6a24 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
@@ -39,7 +39,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
// TODO: Consider making the shadow class set global using a robolectric.properties file.
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
index 77e3198..8b8541a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
@@ -45,7 +45,7 @@
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatteryOptimizationPreferenceControllerTest {
private static final String PKG_IN_WHITELIST = "com.pkg.in.whitelist";
private static final String PKG_NOT_IN_WHITELIST = "com.pkg.not.in.whitelist";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
index c75a6a6..eeca72f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
@@ -37,7 +37,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatterySaverControllerTest {
@Mock
private MasterSwitchPreference mBatterySaverPref;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.java
index 259bcd2..944f755 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.java
@@ -33,7 +33,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatterySaverReceiverTest {
@Mock
private BatterySaverReceiver.BatterySaverListener mBatterySaverListener;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java
index 0e32f6b..a7bcf53 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java
@@ -35,7 +35,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatterySaverSettingsTest {
private Context mContext;
private BatterySaverSettings mBatterySaverSettings;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java
index 5f8d7cf..5ba98f2 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java
@@ -36,7 +36,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatteryStatsHelperLoaderTest {
@Mock
private BatteryUtils mBatteryUtils;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index c08b01d..56abf48 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -69,7 +69,7 @@
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BatteryUtilsTest {
// unit that used to converted ms to us
private static final long UNIT = 1000;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java
index dec445d..468c160 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java
@@ -45,7 +45,7 @@
import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
ShadowEventLogWriter.class
})
public class ButtonActionDialogFragmentTest {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
index d87020e..fe3cd29 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
@@ -36,7 +36,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class HighPowerDetailTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java
index 32f6a96..e2f5fad 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java
@@ -38,7 +38,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PowerGaugePreferenceTest {
private static final String SUBTITLE = "Summary";
private static final String CONTENT_DESCRIPTION = "Content description";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 2b5e704..2056262 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -63,7 +63,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PowerUsageAdvancedTest {
private static final int FAKE_UID_1 = 50;
private static final int FAKE_UID_2 = 100;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
index c992d0a..c6040c0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
@@ -59,7 +59,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PowerUsageAnomalyDetailsTest {
private static final String NAME_APP_1 = "app1";
private static final String NAME_APP_2 = "app2";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
index 9e0d4de..df829aa 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
@@ -47,7 +47,7 @@
* Unit tests for {@link PowerUsageBase}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = ShadowDashboardFragment.class)
public class PowerUsageBaseTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index afda69f..6961b60 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -33,7 +33,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PowerUsageFeatureProviderImplTest {
private static final int UID_OTHER = Process.FIRST_APPLICATION_UID + 2;
private static final int UID_CALENDAR = Process.FIRST_APPLICATION_UID + 3;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 4385409..5be2fe6 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -86,7 +86,7 @@
// TODO: Improve this test class so that it starts up the real activity and fragment.
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java
index 46db6b3..4ecd1dd 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java
@@ -39,7 +39,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AnomalyDetectionPolicyTest {
private static final String ANOMALY_DETECTION_CONSTANTS_VALUE =
"anomaly_detection_enabled=true"
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
index 6b3791a..ccce08f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
@@ -49,7 +49,7 @@
import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = ShadowRuntimePermissionPresenter.class)
public class AnomalyDialogFragmentTest {
private static final String PACKAGE_NAME = "com.android.app";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
index 48749d5..dfb7d21 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
@@ -49,7 +49,8 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O
+)
public class AnomalyLoaderTest {
private static final String PACKAGE_NAME = "com.android.settings";
private static final CharSequence DISPLAY_NAME = "Settings";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java
index c0157ae..7061b8a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java
@@ -31,7 +31,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AnomalyPreferenceTest {
@Anomaly.AnomalyType
private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
index 3f48d0a..1114e6a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
@@ -30,6 +30,7 @@
import android.content.Context;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -48,7 +49,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AnomalySummaryPreferenceControllerTest {
@Anomaly.AnomalyType
private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
@@ -56,7 +57,7 @@
private static final String DISPLAY_NAME = "appName";
private static final int UID = 111;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ @Mock
private PreferenceFragment mFragment;
@Mock
private FragmentManager mFragmentManager;
@@ -64,6 +65,9 @@
private FragmentTransaction mFragmentTransaction;
@Mock
private SettingsActivity mSettingsActivity;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
private AnomalySummaryPreferenceController mAnomalySummaryPreferenceController;
private Preference mPreference;
private Context mContext;
@@ -76,11 +80,12 @@
mContext = RuntimeEnvironment.application;
mPreference = new Preference(mContext);
mPreference.setKey(AnomalySummaryPreferenceController.ANOMALY_KEY);
- when(mFragment.getPreferenceScreen().findPreference(any())).thenReturn(mPreference);
+ when(mFragment.getPreferenceScreen()).thenReturn(mPreferenceScreen);
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
when(mFragment.getContext()).thenReturn(mContext);
when(mSettingsActivity.getApplicationContext()).thenReturn(mContext);
+ when(mPreferenceScreen.findPreference(any())).thenReturn(mPreference);
mAnomalyList = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java
index 13a5b31..dae1141 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java
@@ -29,7 +29,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AnomalyTest {
private static int TYPE = Anomaly.AnomalyType.WAKE_LOCK;
private static int UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java
index 38391c9..d37d01e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java
@@ -45,7 +45,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
ShadowKeyValueListParserWrapperImpl.class})
public class AnomalyUtilsTest {
private static final String PACKAGE_NAME_WAKEUP = "com.android.app1";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java
index 8db1a8c..6f3e9b4 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java
@@ -38,7 +38,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AnomalyActionTest {
private static final String PACKAGE_NAME = "com.android.app";
private static final int UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java
index 7e5fc4a..e72039a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java
@@ -40,7 +40,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BackgroundCheckActionTest {
private static final String PACKAGE_NAME = "com.android.app";
private static final int UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java
index 89b1a16..fcb029c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java
@@ -40,7 +40,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ForceStopActionTest {
private static final String PACKAGE_NAME = "com.android.app";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java
index 234dd12..d2b6fcb 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java
@@ -37,7 +37,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows =
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows =
ShadowPermissionChecker.class)
public class LocationCheckActionTest {
private static final String PACKAGE_NAME = "com.android.app";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java
index c06bddd..de7402b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java
@@ -36,7 +36,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class StopAndBackgroundActionTest {
private static final String PACKAGE_NAME = "com.android.app";
private static final int UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
index edf026a..b148ce9 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
@@ -52,7 +52,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BluetoothScanAnomalyDetectorTest {
private static final String TARGET_PACKAGE_NAME = "com.android.app";
private static final int ANOMALY_UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
index d7682ea..0991d89 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
@@ -55,7 +55,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WakeLockAnomalyDetectorTest {
private static final String TARGET_PACKAGE_NAME = "com.android.app";
private static final long ANOMALY_WAKELOCK_TIME_MS = 2 * DateUtils.HOUR_IN_MILLIS;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java
index 13a5ab8..f014f8d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java
@@ -56,7 +56,7 @@
import java.util.Set;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WakeupAlarmAnomalyDetectorTest {
private static final String TARGET_PACKAGE_NAME = "com.android.target";
private static final String ANOMALY_PACKAGE_NAME = "com.android.anomaly";
diff --git a/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java b/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java
index 3c51a90..a8372d9 100644
--- a/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java
+++ b/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java
@@ -16,6 +16,9 @@
package com.android.settings.search;
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import android.provider.SearchIndexableResource;
import android.util.ArraySet;
import android.util.Log;
@@ -23,13 +26,13 @@
import com.android.settings.core.codeinspection.CodeInspector;
import com.android.settings.dashboard.DashboardFragmentSearchIndexProviderInspector;
+import org.robolectric.RuntimeEnvironment;
+
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import static com.google.common.truth.Truth.assertWithMessage;
-
/**
* {@link CodeInspector} to ensure fragments implement search components correctly.
*/
@@ -49,6 +52,9 @@
"Class containing " + DatabaseIndexingManager.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER
+ " must be added to " + SearchIndexableResources.class.getName()
+ " but these are not: \n";
+ private static final String NOT_PROVIDING_VALID_RESOURCE_ERROR =
+ "SearchIndexableProvider must either provide no resource to index, or valid ones. "
+ + "But the followings contain resource with xml id = 0\n";
private final List<String> notImplementingIndexableGrandfatherList;
private final List<String> notImplementingIndexProviderGrandfatherList;
@@ -77,6 +83,7 @@
final Set<String> notImplementingIndexProvider = new ArraySet<>();
final Set<String> notInSearchProviderRegistry = new ArraySet<>();
final Set<String> notSharingPreferenceControllers = new ArraySet<>();
+ final Set<String> notProvidingValidResource = new ArraySet<>();
for (Class clazz : mClasses) {
if (!isConcreteSettingsClass(clazz)) {
@@ -119,6 +126,10 @@
notInSearchProviderRegistry.add(className);
}
}
+ // Search provider must either don't provider resource xml, or provide valid ones.
+ if (!hasValidResourceFromProvider(clazz)) {
+ notProvidingValidResource.add(className);
+ }
}
// Build error messages
@@ -131,6 +142,8 @@
notSharingPreferenceControllers);
final String notInProviderRegistryError =
buildErrorMessage(NOT_IN_INDEXABLE_PROVIDER_REGISTRY, notInSearchProviderRegistry);
+ final String notProvidingValidResourceError = buildErrorMessage(
+ NOT_PROVIDING_VALID_RESOURCE_ERROR, notProvidingValidResource);
assertWithMessage(indexableError)
.that(notImplementingIndexable)
.isEmpty();
@@ -143,6 +156,9 @@
assertWithMessage(notInProviderRegistryError)
.that(notInSearchProviderRegistry)
.isEmpty();
+ assertWithMessage(notProvidingValidResourceError)
+ .that(notProvidingValidResource)
+ .isEmpty();
assertNoObsoleteInGrandfatherList("grandfather_not_implementing_indexable",
notImplementingIndexableGrandfatherList);
assertNoObsoleteInGrandfatherList("grandfather_not_implementing_index_provider",
@@ -168,6 +184,28 @@
}
}
+ private boolean hasValidResourceFromProvider(Class clazz) {
+ try {
+ final Indexable.SearchIndexProvider provider =
+ DatabaseIndexingUtils.getSearchIndexProvider(clazz);
+ final List<SearchIndexableResource> resources = provider.getXmlResourcesToIndex(
+ RuntimeEnvironment.application, true /* enabled */);
+ if (resources == null) {
+ // No resource, that's fine.
+ return true;
+ }
+ for (SearchIndexableResource res : resources) {
+ if (res.xmlResId == 0) {
+ // Invalid resource
+ return false;
+ }
+ }
+ } catch (Exception e) {
+ // Ignore.
+ }
+ return true;
+ }
+
private String buildErrorMessage(String errorSummary, Set<String> errorClasses) {
final StringBuilder error = new StringBuilder(errorSummary);
for (String c : errorClasses) {