Merge "Add wakelock action in testing app" into oc-mr1-dev
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index fba27fb..be5fbdf 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -75,6 +75,7 @@
private DashboardFeatureProvider mDashboardFeatureProvider;
private SuggestionFeatureProvider mSuggestionFeatureProvider;
private boolean isOnCategoriesChangedCalled;
+ private boolean mOnConditionsChangedCalled;
@Override
public int getMetricsCategory() {
@@ -237,10 +238,21 @@
@Override
public void onConditionsChanged() {
Log.d(TAG, "onConditionsChanged");
- final boolean scrollToTop = mLayoutManager.findFirstCompletelyVisibleItemPosition() <= 1;
- mAdapter.setConditions(mConditionManager.getConditions());
- if (scrollToTop) {
- mDashboard.scrollToPosition(0);
+ // Bypass refreshing the conditions on the first call of onConditionsChanged.
+ // onConditionsChanged is called immediately everytime we start listening to the conditions
+ // change when we gain window focus. Since the conditions are passed to the adapter's
+ // constructor when we create the view, the first handling is not necessary.
+ // But, on the subsequent calls we need to handle it because there might be real changes to
+ // conditions.
+ if (mOnConditionsChangedCalled) {
+ final boolean scrollToTop =
+ mLayoutManager.findFirstCompletelyVisibleItemPosition() <= 1;
+ mAdapter.setConditions(mConditionManager.getConditions());
+ if (scrollToTop) {
+ mDashboard.scrollToPosition(0);
+ }
+ } else {
+ mOnConditionsChangedCalled = true;
}
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index f0457e6..89e5b74 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -176,6 +176,12 @@
// For Search
private static final String DATA_KEY_REFERENCE = "main_toggle_wifi";
+ /**
+ * Tracks whether the user initiated a connection via clicking in order to autoscroll to the
+ * network once connected.
+ */
+ private boolean mClickedConnect;
+
/* End of "used in Wifi Setup context" */
public WifiSettings() {
@@ -894,6 +900,10 @@
mConnectedAccessPointPreferenceCategory.addPreference(pref);
mConnectedAccessPointPreferenceCategory.setVisible(true);
+ if (mClickedConnect) {
+ mClickedConnect = false;
+ scrollToPreference(mConnectedAccessPointPreferenceCategory);
+ }
}
/** Removes all preferences and hide the {@link #mConnectedAccessPointPreferenceCategory}. */
@@ -1039,7 +1049,7 @@
mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_WIFI_CONNECT,
isSavedNetwork);
mWifiManager.connect(config, mConnectListener);
- scrollToPreference(mConnectedAccessPointPreferenceCategory);
+ mClickedConnect = true;
}
protected void connect(final int networkId, boolean isSavedNetwork) {
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
index 967ed24..f3ed57c 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
@@ -36,6 +36,7 @@
import org.robolectric.util.ReflectionHelpers;
import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -90,6 +91,7 @@
public void onConditionChanged_PositionAtTop_ScrollToTop() {
when(mLayoutManager.findFirstCompletelyVisibleItemPosition()).thenReturn(1);
mSummary.onConditionsChanged();
+ mSummary.onConditionsChanged();
verify(mDashboard).scrollToPosition(0);
}
@@ -97,10 +99,24 @@
public void onConditionChanged_PositionNotTop_RemainPosition() {
when(mLayoutManager.findFirstCompletelyVisibleItemPosition()).thenReturn(2);
mSummary.onConditionsChanged();
+ mSummary.onConditionsChanged();
verify(mDashboard, never()).scrollToPosition(0);
}
@Test
+ public void onConditionChanged_firstCall_shouldIgnore() {
+ mSummary.onConditionsChanged();
+ verify(mAdapter, never()).setConditions(any());
+ }
+
+ @Test
+ public void onConditionChanged_secondCall_shouldSetConditionsOnAdapter() {
+ mSummary.onConditionsChanged();
+ mSummary.onConditionsChanged();
+ verify(mAdapter).setConditions(any());
+ }
+
+ @Test
public void onCategoryChanged_noRebuildOnFirstCall() {
doReturn(mock(Activity.class)).when(mSummary).getActivity();
doNothing().when(mSummary).rebuildUI();