Merge "Update strings for anomaly dialog" into oc-dr1-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 173d7eb..485a233 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3011,7 +3011,8 @@
android:value="com.android.settings.deletionhelper.AutomaticStorageManagerSettings" />
</activity>
- <activity android:name="Settings$LegacySupportActivity">
+ <activity android:name="Settings$LegacySupportActivity"
+ android:label="@string/page_tab_title_support">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.dashboard.SupportFragment"/>
</activity>
diff --git a/res/layout/condition_card.xml b/res/layout/condition_card.xml
deleted file mode 100644
index 4edd0f2..0000000
--- a/res/layout/condition_card.xml
+++ /dev/null
@@ -1,128 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 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.
--->
-
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:clipChildren="false"
- android:clipToPadding="false">
- <LinearLayout
- android:id="@+id/content"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:background="?android:attr/colorAccent"
- android:elevation="2dp"
- android:clickable="true"
- android:focusable="true">
-
- <LinearLayout
- android:id="@+id/collapsed_group"
- android:layout_width="match_parent"
- android:layout_height="56dp"
- android:background="?android:attr/selectableItemBackground"
- android:orientation="horizontal"
- android:gravity="center">
-
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="24dp"
- android:layout_height="wrap_content"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="32dp"
- android:tint="?android:attr/textColorPrimaryInverse" />
-
- <TextView
- android:id="@android:id/title"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:textColor="?android:attr/textColorPrimaryInverse" />
-
- <ImageView
- android:id="@+id/expand_indicator"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:padding="16dp"
- android:tint="?android:attr/textColorPrimaryInverse"/>
-
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/detail_group"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingStart="72dp"
- android:visibility="gone"
- android:orientation="vertical">
-
- <!-- TODO: Don't set alpha here, and do proper themeing that
- handles night mode -->
- <TextView
- android:id="@android:id/summary"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:paddingBottom="16dp"
- android:textAppearance="?android:attr/textAppearanceListItemSecondary"
- android:alpha=".7"
- android:textColor="?android:attr/textColorPrimaryInverse" />
-
- <!-- TODO: Better background -->
- <View
- android:id="@+id/divider"
- android:layout_width="match_parent"
- android:layout_height=".25dp"
- android:background="@android:color/white" />
-
- <com.android.internal.widget.ButtonBarLayout
- android:id="@+id/buttonBar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dp"
- android:paddingBottom="8dp"
- style="?android:attr/buttonBarStyle"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
-
- <Button
- android:id="@+id/first_action"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:paddingStart="0dp"
- android:alpha=".8"
- android:textAlignment="viewStart"
- android:textColor="?android:attr/textColorPrimaryInverse"
- style="?android:attr/buttonBarButtonStyle" />
-
- <Button
- android:id="@+id/second_action"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:alpha=".8"
- android:textAlignment="viewStart"
- android:textColor="?android:attr/textColorPrimaryInverse"
- style="?android:attr/buttonBarButtonStyle" />
-
- </com.android.internal.widget.ButtonBarLayout>
-
- </LinearLayout>
-
- </LinearLayout>
-</FrameLayout>
diff --git a/res/layout/suggestion_header.xml b/res/layout/suggestion_header.xml
deleted file mode 100644
index 2268636..0000000
--- a/res/layout/suggestion_header.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 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.
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="@dimen/dashboard_category_height"
- android:clickable="true"
- android:focusable="true"
- android:background="@drawable/selectable_card_grey"
- android:gravity="center_vertical"
- android:paddingTop="4dp">
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="@dimen/dashboard_tile_image_size"
- android:layout_height="@dimen/dashboard_tile_image_size"
- android:layout_marginStart="@dimen/dashboard_tile_image_margin"
- android:layout_marginEnd="@dimen/dashboard_tile_image_margin"
- android:src="@drawable/ic_expand_more"/>
- <TextView
- android:id="@android:id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textAppearance="@style/TextAppearance.SuggestionTitle"
- android:textColor="?android:attr/colorAccent"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal"/>
- <TextView
- android:id="@android:id/summary"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="end"
- android:paddingEnd="18dp"
- android:textAppearance="@style/TextAppearance.SuggestionTitle"
- android:textColor="?android:attr/colorAccent"/>
-</LinearLayout>
diff --git a/res/layout/suggestion_tile.xml b/res/layout/suggestion_tile.xml
deleted file mode 100644
index cabbafd..0000000
--- a/res/layout/suggestion_tile.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/selectable_card_grey"
- android:clickable="true"
- android:focusable="true"
- android:gravity="center_vertical"
- android:minHeight="@dimen/dashboard_tile_minimum_height">
-
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="@dimen/dashboard_tile_image_size"
- android:layout_height="@dimen/dashboard_tile_image_size"
- android:layout_marginStart="@dimen/dashboard_tile_image_margin"
- android:layout_marginEnd="@dimen/dashboard_tile_image_margin"
- android:scaleType="centerInside"/>
-
- <RelativeLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1">
-
- <TextView android:id="@android:id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textAppearance="@style/TextAppearance.TileTitle"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal"/>
-
- <TextView android:id="@android:id/summary"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@android:id/title"
- android:layout_alignStart="@android:id/title"
- android:textAppearance="@style/TextAppearance.Small"
- android:textColor="?android:attr/textColorSecondary"/>
-
- </RelativeLayout>
-
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/suggestion_tile_card.xml b/res/layout/suggestion_tile_card.xml
index 6f94914..fd19b80 100644
--- a/res/layout/suggestion_tile_card.xml
+++ b/res/layout/suggestion_tile_card.xml
@@ -18,9 +18,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_margin="8dp"
- android:background="@drawable/selectable_card"
+ android:background="@android:color/white"
android:clickable="true"
- android:elevation="2dp"
android:focusable="true"
android:minHeight="@dimen/dashboard_tile_minimum_height" />
diff --git a/res/xml/account_type_settings.xml b/res/xml/account_type_settings.xml
index 0ba961f..7f57ed0 100644
--- a/res/xml/account_type_settings.xml
+++ b/res/xml/account_type_settings.xml
@@ -39,6 +39,7 @@
android:key="remove_account"
android:layout="@layout/remove_account_button"
android:order="1000"
- android:selectable="false"/>
+ android:selectable="false"
+ settings:allowDividerAbove="true"/>
</PreferenceScreen>
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 9ce4c4a..c7f349e 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -127,6 +127,7 @@
public List<String> getNonIndexableKeys(Context context) {
List<String> keys = super.getNonIndexableKeys(context);
keys.add(KEY_DISPLAY_SIZE);
+ keys.add(WallpaperPreferenceController.KEY_WALLPAPER);
return keys;
}
diff --git a/src/com/android/settings/EncryptionInterstitial.java b/src/com/android/settings/EncryptionInterstitial.java
index c352bf0..f0115b8 100644
--- a/src/com/android/settings/EncryptionInterstitial.java
+++ b/src/com/android/settings/EncryptionInterstitial.java
@@ -24,6 +24,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@@ -57,6 +58,12 @@
}
@Override
+ protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
+ resid = SetupWizardUtils.getTheme(getIntent());
+ super.onApplyThemeResource(theme, resid, first);
+ }
+
+ @Override
protected boolean isValidFragment(String fragmentName) {
return EncryptionInterstitialFragment.class.getName().equals(fragmentName);
}
diff --git a/src/com/android/settings/SetupEncryptionInterstitial.java b/src/com/android/settings/SetupEncryptionInterstitial.java
index 4f30cc0..989cc2b 100644
--- a/src/com/android/settings/SetupEncryptionInterstitial.java
+++ b/src/com/android/settings/SetupEncryptionInterstitial.java
@@ -18,7 +18,6 @@
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.os.Bundle;
import android.widget.LinearLayout;
@@ -55,12 +54,6 @@
}
@Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
- @Override
protected void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
diff --git a/src/com/android/settings/SetupRedactionInterstitial.java b/src/com/android/settings/SetupRedactionInterstitial.java
index 321040e..ac1db15 100644
--- a/src/com/android/settings/SetupRedactionInterstitial.java
+++ b/src/com/android/settings/SetupRedactionInterstitial.java
@@ -60,12 +60,6 @@
return SetupRedactionInterstitialFragment.class.getName().equals(fragmentName);
}
- @Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
public static class SetupRedactionInterstitialFragment extends RedactionInterstitialFragment {
// Setup wizard specific UI customizations can be done here
diff --git a/src/com/android/settings/accounts/AccountSyncPreferenceController.java b/src/com/android/settings/accounts/AccountSyncPreferenceController.java
index 0b095f7..2eee579 100644
--- a/src/com/android/settings/accounts/AccountSyncPreferenceController.java
+++ b/src/com/android/settings/accounts/AccountSyncPreferenceController.java
@@ -19,23 +19,31 @@
import static android.content.Intent.EXTRA_USER;
import android.accounts.Account;
+import android.content.ContentResolver;
import android.content.Context;
+import android.content.SyncAdapterType;
import android.os.Bundle;
import android.os.UserHandle;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
+import com.android.settingslib.accounts.AuthenticatorHelper;
-public class AccountSyncPreferenceController extends PreferenceController {
+public class AccountSyncPreferenceController extends PreferenceController
+ implements AuthenticatorHelper.OnAccountsUpdateListener {
private static final String TAG = "AccountSyncController";
private static final String KEY_ACCOUNT_SYNC = "account_sync";
private Account mAccount;
private UserHandle mUserHandle;
+ private AuthenticatorHelper mAuthenticatorHelper;
+ private Preference mPreference;
public AccountSyncPreferenceController(Context context) {
super(context);
@@ -65,8 +73,61 @@
return KEY_ACCOUNT_SYNC;
}
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ updateSummary(preference);
+ }
+
+ @Override
+ public void onAccountsUpdate(UserHandle userHandle) {
+ updateSummary(mPreference);
+ }
+
public void init(Account account, UserHandle userHandle) {
mAccount = account;
mUserHandle = userHandle;
+ mAuthenticatorHelper = new AuthenticatorHelper(mContext, mUserHandle, this);
+ }
+
+ @VisibleForTesting
+ void updateSummary(Preference preference) {
+ final int userId = mUserHandle.getIdentifier();
+ final SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(userId);
+ int total = 0;
+ int enabled = 0;
+ if (syncAdapters != null) {
+ for (int i = 0, n = syncAdapters.length; i < n; i++) {
+ final SyncAdapterType sa = syncAdapters[i];
+ if (!sa.accountType.equals(mAccount.type) || !sa.isUserVisible()) {
+ continue;
+ }
+ final int syncState =
+ ContentResolver.getIsSyncableAsUser(mAccount, sa.authority, userId);
+ if (syncState > 0) {
+ total++;
+ final boolean syncEnabled = ContentResolver.getSyncAutomaticallyAsUser(
+ mAccount, sa.authority, userId);
+ final boolean oneTimeSyncMode =
+ !ContentResolver.getMasterSyncAutomaticallyAsUser(userId);
+ if (oneTimeSyncMode || syncEnabled) {
+ enabled++;
+ }
+ }
+ }
+ }
+ if (enabled == 0) {
+ preference.setSummary(R.string.account_sync_summary_all_off);
+ } else if (enabled == total) {
+ preference.setSummary(R.string.account_sync_summary_all_on);
+ } else {
+ preference.setSummary(
+ mContext.getString(R.string.account_sync_summary_some_on, enabled, total));
+ }
}
}
diff --git a/src/com/android/settings/applications/LayoutPreference.java b/src/com/android/settings/applications/LayoutPreference.java
index 6ae0772..f2bd183 100644
--- a/src/com/android/settings/applications/LayoutPreference.java
+++ b/src/com/android/settings/applications/LayoutPreference.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.VisibleForTesting;
+import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
@@ -33,19 +34,30 @@
public class LayoutPreference extends Preference {
private final View.OnClickListener mClickListener = v -> performClick(v);
+ private boolean mAllowDividerAbove;
+ private boolean mAllowDividerBelow;
@VisibleForTesting
View mRootView;
public LayoutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- final TypedArray a = context.obtainStyledAttributes(
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Preference);
+ mAllowDividerAbove = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerAbove,
+ R.styleable.Preference_allowDividerAbove, false);
+ mAllowDividerBelow = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerBelow,
+ R.styleable.Preference_allowDividerBelow, false);
+ a.recycle();
+
+ a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.Preference, 0, 0);
int layoutResource = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
0);
if (layoutResource == 0) {
throw new IllegalArgumentException("LayoutPreference requires a layout to be defined");
}
+ a.recycle();
+
// Need to create view now so that findViewById can be called immediately.
final View view = LayoutInflater.from(getContext())
.inflate(layoutResource, null, false);
@@ -78,6 +90,8 @@
final boolean selectable = isSelectable();
holder.itemView.setFocusable(selectable);
holder.itemView.setClickable(selectable);
+ holder.setDividerAllowedAbove(mAllowDividerAbove);
+ holder.setDividerAllowedBelow(mAllowDividerBelow);
FrameLayout layout = (FrameLayout) holder.itemView;
layout.removeAllViews();
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index abbd683..35d7c28 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -15,7 +15,6 @@
*/
package com.android.settings.dashboard;
-import android.annotation.ColorInt;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
@@ -40,12 +39,10 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.R.id;
-import com.android.settings.SettingsActivity;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.dashboard.DashboardData.SuggestionConditionHeaderData;
import com.android.settings.dashboard.conditional.Condition;
import com.android.settings.dashboard.conditional.ConditionAdapter;
-import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
@@ -63,7 +60,6 @@
public static final String TAG = "DashboardAdapter";
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
private static final String STATE_CATEGORY_LIST = "category_list";
- private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
private static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
@@ -77,7 +73,6 @@
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
private final ArrayList<String> mSuggestionsShownLogged;
private boolean mFirstFrameDrawn;
- private boolean mCombineSuggestionAndCondition;
private RecyclerView mRecyclerView;
private SuggestionParser mSuggestionParser;
private SuggestionAdapter mSuggestionAdapter;
@@ -99,46 +94,20 @@
@Override
public void onClick(View v) {
- if (mCombineSuggestionAndCondition) {
- Condition condition = (Condition) v.getTag();
- //TODO: get rid of setTag/getTag
- mMetricsFeatureProvider.action(mContext,
+ Condition condition = (Condition) v.getTag();
+ //TODO: get rid of setTag/getTag
+ mMetricsFeatureProvider.action(mContext,
MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
condition.getMetricsConstant());
- condition.onPrimaryClick();
- } else {
- Condition expandedCondition = mDashboardData.getExpandedCondition();
-
- //TODO: get rid of setTag/getTag
- if (v.getTag() == expandedCondition) {
- mMetricsFeatureProvider.action(mContext,
- MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
- expandedCondition.getMetricsConstant());
- expandedCondition.onPrimaryClick();
- } else {
- expandedCondition = (Condition) v.getTag();
- mMetricsFeatureProvider.action(mContext,
- MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
- expandedCondition.getMetricsConstant());
-
- updateExpandedCondition(expandedCondition);
- }
- }
+ condition.onPrimaryClick();
}
};
- @Deprecated
- public DashboardAdapter(Context context, Bundle savedInstanceState,
- List<Condition> conditions) {
- this(context, savedInstanceState, conditions, null, null);
- }
-
public DashboardAdapter(Context context, Bundle savedInstanceState,
List<Condition> conditions, SuggestionParser suggestionParser,
SuggestionDismissController.Callback callback) {
List<Tile> suggestions = null;
List<DashboardCategory> categories = null;
- int suggestionMode = DashboardData.SUGGESTION_MODE_DEFAULT;
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
mContext = context;
@@ -146,7 +115,6 @@
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(context);
mSuggestionFeatureProvider = factory.getSuggestionFeatureProvider(context);
- mCombineSuggestionAndCondition = mDashboardFeatureProvider.combineSuggestionAndCondition();
mCache = new IconCache(context);
mSuggestionParser = suggestionParser;
mCallback = callback;
@@ -158,8 +126,6 @@
categories = savedInstanceState.getParcelableArrayList(STATE_CATEGORY_LIST);
suggestionConditionMode = savedInstanceState.getInt(
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
- suggestionMode = savedInstanceState.getInt(
- STATE_SUGGESTION_MODE, DashboardData.SUGGESTION_MODE_DEFAULT);
mSuggestionsShownLogged = savedInstanceState.getStringArrayList(
STATE_SUGGESTIONS_SHOWN_LOGGED);
} else {
@@ -170,8 +136,6 @@
.setConditions(conditions)
.setSuggestions(suggestions)
.setCategories(categories)
- .setSuggestionMode(suggestionMode)
- .setCombineSuggestionAndCondition(mCombineSuggestionAndCondition)
.setSuggestionConditionMode(suggestionConditionMode)
.build();
}
@@ -213,24 +177,12 @@
.build();
notifyDashboardDataChanged(prevData);
List<Tile> shownSuggestions = null;
- if (mCombineSuggestionAndCondition) {
- final int mode = mDashboardData.getSuggestionConditionMode();
- if (mode == DashboardData.HEADER_MODE_DEFAULT) {
- shownSuggestions = suggestions.subList(0,
+ final int mode = mDashboardData.getSuggestionConditionMode();
+ if (mode == DashboardData.HEADER_MODE_DEFAULT) {
+ shownSuggestions = suggestions.subList(0,
Math.min(suggestions.size(), DashboardData.DEFAULT_SUGGESTION_COUNT));
- } else if (mode != DashboardData.HEADER_MODE_COLLAPSED) {
- shownSuggestions = suggestions;
- }
- } else {
- switch (mDashboardData.getSuggestionMode()) {
- case DashboardData.SUGGESTION_MODE_DEFAULT:
- shownSuggestions = suggestions.subList(0,
- Math.min(suggestions.size(), DashboardData.DEFAULT_SUGGESTION_COUNT));
- break;
- case DashboardData.SUGGESTION_MODE_EXPANDED:
- shownSuggestions = suggestions;
- break;
- }
+ } else if (mode != DashboardData.HEADER_MODE_COLLAPSED) {
+ shownSuggestions = suggestions;
}
if (shownSuggestions != null) {
for (Tile suggestion : shownSuggestions) {
@@ -255,16 +207,9 @@
public void setConditions(List<Condition> conditions) {
final DashboardData prevData = mDashboardData;
Log.d(TAG, "adapter setConditions called");
- if (mCombineSuggestionAndCondition) {
- mDashboardData = new DashboardData.Builder(prevData)
+ mDashboardData = new DashboardData.Builder(prevData)
.setConditions(conditions)
.build();
- } else {
- mDashboardData = new DashboardData.Builder(prevData)
- .setConditions(conditions)
- .setExpandedCondition(null)
- .build();
- }
notifyDashboardDataChanged(prevData);
}
@@ -317,44 +262,6 @@
holder.itemView.setTag(tile);
holder.itemView.setOnClickListener(mTileClickListener);
break;
- case R.layout.suggestion_header:
- onBindSuggestionHeader(holder, (DashboardData.SuggestionHeaderData)
- mDashboardData.getItemEntityByPosition(position));
- break;
- case R.layout.suggestion_tile:
- case R.layout.suggestion_tile_card:
- final Tile suggestion = (Tile) mDashboardData.getItemEntityByPosition(position);
- final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
- mContext, suggestion);
- // This is for cases when a suggestion is dismissed and the next one comes to view
- if (!mSuggestionsShownLogged.contains(suggestionId)) {
- mMetricsFeatureProvider.action(
- mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, suggestionId);
- mSuggestionsShownLogged.add(suggestionId);
- }
- onBindTile(holder, suggestion);
- View clickHandler = holder.itemView;
- // If a view with @android:id/primary is defined, use that as the click handler
- // instead.
- final View primaryAction = holder.itemView.findViewById(android.R.id.primary);
- if (primaryAction != null) {
- clickHandler = primaryAction;
- // set the item view to disabled to remove any touch effects
- holder.itemView.setEnabled(false);
- }
- clickHandler.setOnClickListener(v -> {
- mMetricsFeatureProvider.action(mContext,
- MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId);
- ((SettingsActivity) mContext).startSuggestion(suggestion.intent);
- });
- break;
- case R.layout.condition_card:
- final boolean isExpanded = mDashboardData.getItemEntityByPosition(position)
- == mDashboardData.getExpandedCondition();
- ConditionAdapterUtils.bindViews(
- (Condition) mDashboardData.getItemEntityByPosition(position),
- holder, isExpanded, mConditionClickListener, v -> onExpandClick(v));
- break;
case R.layout.suggestion_condition_container:
onBindConditionAndSuggestion(
(SuggestionAndConditionContainerHolder) holder, position);
@@ -434,34 +341,12 @@
mSuggestionsShownLogged.clear();
}
- // condition card is always expanded in new suggestion/condition UI.
- // TODO: Remove when completely move to new suggestion/condition UI
- @Deprecated
- public void onExpandClick(View v) {
- Condition expandedCondition = mDashboardData.getExpandedCondition();
- if (v.getTag() == expandedCondition) {
- mMetricsFeatureProvider.action(mContext,
- MetricsEvent.ACTION_SETTINGS_CONDITION_COLLAPSE,
- expandedCondition.getMetricsConstant());
- expandedCondition = null;
- } else {
- expandedCondition = (Condition) v.getTag();
- mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
- expandedCondition.getMetricsConstant());
- }
-
- updateExpandedCondition(expandedCondition);
- }
-
public Object getItem(long itemId) {
return mDashboardData.getItemEntityById(itemId);
}
public Tile getSuggestion(int position) {
- if (mCombineSuggestionAndCondition) {
- return mSuggestionAdapter.getSuggestion(position);
- }
- return (Tile) getItem(getItemId(position));
+ return mSuggestionAdapter.getSuggestion(position);
}
@VisibleForTesting
@@ -476,56 +361,6 @@
}
}
- private void updateExpandedCondition(Condition condition) {
- final DashboardData prevData = mDashboardData;
- mDashboardData = new DashboardData.Builder(prevData)
- .setExpandedCondition(condition)
- .build();
- notifyDashboardDataChanged(prevData);
- }
-
- @VisibleForTesting
- void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
- .SuggestionHeaderData data) {
- final boolean moreSuggestions = data.hasMoreSuggestions;
- final int undisplayedSuggestionCount = data.undisplayedSuggestionCount;
-
- holder.icon.setImageResource(moreSuggestions ? R.drawable.ic_expand_more
- : R.drawable.ic_expand_less);
- holder.title.setText(mContext.getString(R.string.suggestions_title, data.suggestionSize));
- String summaryContentDescription;
- if (moreSuggestions) {
- summaryContentDescription = mContext.getResources().getQuantityString(
- R.plurals.settings_suggestion_header_summary_hidden_items,
- undisplayedSuggestionCount, undisplayedSuggestionCount);
- } else {
- summaryContentDescription = mContext.getString(R.string.condition_expand_hide);
- }
- holder.summary.setContentDescription(summaryContentDescription);
-
- if (undisplayedSuggestionCount == 0) {
- holder.summary.setText(null);
- } else {
- holder.summary.setText(
- mContext.getString(R.string.suggestions_summary, undisplayedSuggestionCount));
- }
- holder.itemView.setOnClickListener(v -> {
- final int suggestionMode;
- if (moreSuggestions) {
- suggestionMode = DashboardData.SUGGESTION_MODE_EXPANDED;
- logSuggestions();
- } else {
- suggestionMode = DashboardData.SUGGESTION_MODE_COLLAPSED;
- }
-
- DashboardData prevData = mDashboardData;
- mDashboardData = new DashboardData.Builder(prevData)
- .setSuggestionMode(suggestionMode)
- .build();
- notifyDashboardDataChanged(prevData);
- });
- }
-
private void logSuggestions() {
for (Tile suggestion : mDashboardData.getSuggestions()) {
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
@@ -550,7 +385,8 @@
holder.itemView.setOnClickListener(null);
}
- private void onBindSuggestionConditionHeader(final SuggestionAndConditionHeaderHolder holder,
+ @VisibleForTesting
+ void onBindSuggestionConditionHeader(final SuggestionAndConditionHeaderHolder holder,
SuggestionConditionHeaderData data) {
final int curMode = mDashboardData.getSuggestionConditionMode();
final int nextMode = data.hiddenSuggestionCount > 0 && data.conditionCount > 0
@@ -632,24 +468,23 @@
@VisibleForTesting
void onBindConditionAndSuggestion(final SuggestionAndConditionContainerHolder holder,
int position) {
- RecyclerView.Adapter<DashboardItemHolder> adapter;
// If there is suggestions to show, it will be at position 1
// position 0 is suggestion header.
if (position == (SUGGESTION_CONDITION_HEADER_POSITION + 1)
&& mDashboardData.getSuggestions() != null) {
mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
mDashboardData.getItemEntityByPosition(position), mSuggestionsShownLogged);
- adapter = mSuggestionAdapter;
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
holder.data, mSuggestionParser, mCallback);
+ holder.data.setAdapter(mSuggestionAdapter);
} else {
- ConditionAdapterUtils.addDismiss(holder.data);
- adapter = new ConditionAdapter(mContext,
+ ConditionAdapter adapter = new ConditionAdapter(mContext,
(List<Condition>) mDashboardData.getItemEntityByPosition(position),
mDashboardData.getSuggestionConditionMode());
+ adapter.addDismissHandling(holder.data);
+ holder.data.setAdapter(adapter);
}
holder.data.setLayoutManager(new LinearLayoutManager(mContext));
- holder.data.setAdapter(adapter);
}
private void onBindTile(DashboardItemHolder holder, Tile tile) {
@@ -682,7 +517,6 @@
if (categories != null) {
outState.putParcelableArrayList(STATE_CATEGORY_LIST, new ArrayList<>(categories));
}
- outState.putInt(STATE_SUGGESTION_MODE, mDashboardData.getSuggestionMode());
outState.putStringArrayList(STATE_SUGGESTIONS_SHOWN_LOGGED, mSuggestionsShownLogged);
outState.putInt(STATE_SUGGESTION_CONDITION_MODE,
mDashboardData.getSuggestionConditionMode());
diff --git a/src/com/android/settings/dashboard/DashboardData.java b/src/com/android/settings/dashboard/DashboardData.java
index 6f776b2..7528fb5 100644
--- a/src/com/android/settings/dashboard/DashboardData.java
+++ b/src/com/android/settings/dashboard/DashboardData.java
@@ -17,8 +17,6 @@
import android.annotation.IntDef;
import android.graphics.drawable.Icon;
-import android.support.annotation.Nullable;
-import android.support.annotation.VisibleForTesting;
import android.support.v7.util.DiffUtil;
import android.text.TextUtils;
@@ -31,7 +29,6 @@
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
/**
* Description about data list used in the DashboardAdapter. In the data list each item can be
@@ -40,13 +37,6 @@
* ItemsData has inner class Item, which represents the Item in data list.
*/
public class DashboardData {
- @Deprecated
- public static final int SUGGESTION_MODE_DEFAULT = 0;
- @Deprecated
- public static final int SUGGESTION_MODE_COLLAPSED = 1;
- @Deprecated
- public static final int SUGGESTION_MODE_EXPANDED = 2;
-
public static final int HEADER_MODE_DEFAULT = 0;
public static final int HEADER_MODE_SUGGESTION_EXPANDED = 1;
public static final int HEADER_MODE_FULLY_EXPANDED = 2;
@@ -62,29 +52,20 @@
// id namespace for different type of items.
private static final int NS_SPACER = 0;
private static final int NS_ITEMS = 2000;
- private static final int NS_CONDITION = 3000;
- private static final int NS_SUGGESTION_CONDITION = 4000;
+ private static final int NS_SUGGESTION_CONDITION = 3000;
private final List<Item> mItems;
private final List<DashboardCategory> mCategories;
private final List<Condition> mConditions;
private final List<Tile> mSuggestions;
- @Deprecated
- private final int mSuggestionMode;
- @Deprecated
- private final Condition mExpandedCondition;
private final @HeaderMode int mSuggestionConditionMode;
private int mId;
- private boolean mCombineSuggestionAndCondition;
private DashboardData(Builder builder) {
mCategories = builder.mCategories;
mConditions = builder.mConditions;
mSuggestions = builder.mSuggestions;
- mSuggestionMode = builder.mSuggestionMode;
- mExpandedCondition = builder.mExpandedCondition;
mSuggestionConditionMode = builder.mSuggestionConditionMode;
- mCombineSuggestionAndCondition = builder.mCombineSuggestionAndCondition;
mItems = new ArrayList<>();
mId = 0;
@@ -133,19 +114,10 @@
return mSuggestions;
}
- public int getSuggestionMode() {
- return mSuggestionMode;
- }
-
public int getSuggestionConditionMode() {
return mSuggestionConditionMode;
}
- @Deprecated
- public Condition getExpandedCondition() {
- return mExpandedCondition;
- }
-
/**
* Find the position of the object in mItems list, using the equals method to compare
*
@@ -192,10 +164,10 @@
/**
* Get the count of suggestions to display
*
- * The displayable count mainly depends on the {@link #mSuggestionMode}
+ * The displayable count mainly depends on the {@link #mSuggestionConditionMode}
* and the size of suggestions list.
*
- * When in default mode, displayable count couldn't larger than
+ * When in default mode, displayable count couldn't be larger than
* {@link #DEFAULT_SUGGESTION_COUNT}.
*
* When in expanded mode, display all the suggestions.
@@ -204,33 +176,19 @@
*/
public int getDisplayableSuggestionCount() {
final int suggestionSize = sizeOf(mSuggestions);
- if (mCombineSuggestionAndCondition) {
- if (mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
- return 0;
- }
- if (mSuggestionConditionMode == HEADER_MODE_DEFAULT) {
- return Math.min(DEFAULT_SUGGESTION_COUNT, suggestionSize);
- }
- return suggestionSize;
+ if (mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
+ return 0;
}
- if (mSuggestionMode == SUGGESTION_MODE_DEFAULT) {
+ if (mSuggestionConditionMode == HEADER_MODE_DEFAULT) {
return Math.min(DEFAULT_SUGGESTION_COUNT, suggestionSize);
}
- if (mSuggestionMode == SUGGESTION_MODE_EXPANDED) {
- return suggestionSize;
- }
- return 0;
+ return suggestionSize;
}
public boolean hasMoreSuggestions() {
- if (mCombineSuggestionAndCondition) {
- return mSuggestionConditionMode == HEADER_MODE_COLLAPSED && mSuggestions.size() > 0
+ return mSuggestionConditionMode == HEADER_MODE_COLLAPSED && mSuggestions.size() > 0
|| mSuggestionConditionMode == HEADER_MODE_DEFAULT
- && mSuggestions.size() > DEFAULT_SUGGESTION_COUNT;
- }
- return mSuggestionMode == SUGGESTION_MODE_COLLAPSED
- || (mSuggestionMode == SUGGESTION_MODE_DEFAULT
- && mSuggestions.size() > DEFAULT_SUGGESTION_COUNT);
+ && mSuggestions.size() > DEFAULT_SUGGESTION_COUNT;
}
private void resetCount() {
@@ -251,105 +209,62 @@
*/
private void countItem(Object object, int type, boolean add, int nameSpace) {
if (add) {
- if (mCombineSuggestionAndCondition) {
- mItems.add(new Item(object, type, mId + nameSpace));
- } else {
- mItems.add(new Item(object, type, mId + nameSpace, object == mExpandedCondition));
- }
- }
- mId++;
- }
-
- /**
- * A special count item method for just suggestions. Id is calculated using suggestion hash
- * instead of the position of suggestion in list. This is a more stable id than countItem.
- */
- private void countSuggestion(Tile tile, boolean add) {
- if (add) {
- mItems.add(new Item(
- tile,
- tile.remoteViews != null
- ? R.layout.suggestion_tile_card
- : R.layout.suggestion_tile,
- Objects.hash(tile.title),
- false));
+ mItems.add(new Item(object, type, mId + nameSpace));
}
mId++;
}
/**
* Build the mItems list using mConditions, mSuggestions, mCategories data
- * and mIsShowingAll, mSuggestionMode flag.
+ * and mIsShowingAll, mSuggestionConditionMode flag.
*/
private void buildItemsData() {
final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
- if (!mCombineSuggestionAndCondition) {
- boolean hasConditions = false;
- for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
- boolean shouldShow = mConditions.get(i).shouldShow();
- hasConditions |= shouldShow;
- countItem(mConditions.get(i), R.layout.condition_card, shouldShow, NS_CONDITION);
- }
+ final List<Condition> conditions = getConditionsToShow(mConditions);
+ final boolean hasConditions = sizeOf(conditions) > 0;
- resetCount();
- countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions, NS_SPACER);
- countItem(buildSuggestionHeaderData(), R.layout.suggestion_header, hasSuggestions,
- NS_SPACER);
-
- resetCount();
- if (mSuggestions != null) {
- int maxSuggestions = getDisplayableSuggestionCount();
- for (int i = 0; i < mSuggestions.size(); i++) {
- countSuggestion(mSuggestions.get(i), i < maxSuggestions);
- }
- }
- } else {
- final List<Condition> conditions = getConditionsToShow(mConditions);
- final boolean hasConditions = sizeOf(conditions) > 0;
-
- final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
- final int hiddenSuggestion =
+ final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
+ final int hiddenSuggestion =
hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
- resetCount();
+ resetCount();
/* Top suggestion/condition header. This will be present when there is any suggestion or
* condition to show, except in the case that there is only conditions to show and the
* mode is fully expanded. */
- countItem(new SuggestionConditionHeaderData(conditions, hiddenSuggestion),
+ countItem(new SuggestionConditionHeaderData(conditions, hiddenSuggestion),
R.layout.suggestion_condition_header, hasSuggestions
- || hasConditions && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED,
+ || hasConditions && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED,
NS_SUGGESTION_CONDITION);
/* Suggestion container. This is the card view that contains the list of suggestions.
* This will be added whenever the suggestion list is not empty */
- countItem(suggestions, R.layout.suggestion_condition_container, sizeOf(suggestions) > 0,
+ countItem(suggestions, R.layout.suggestion_condition_container, sizeOf(suggestions) > 0,
NS_SUGGESTION_CONDITION);
/* Second suggestion/condition header. This will be added when there is at least one
* suggestion or condition that is not currently displayed, and the user can expand the
* section to view more items. */
- countItem(new SuggestionConditionHeaderData(conditions, hiddenSuggestion),
+ countItem(new SuggestionConditionHeaderData(conditions, hiddenSuggestion),
R.layout.suggestion_condition_header,
mSuggestionConditionMode != HEADER_MODE_COLLAPSED
- && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED
- && (hiddenSuggestion > 0
+ && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED
+ && (hiddenSuggestion > 0
|| hasConditions && hasSuggestions),
NS_SUGGESTION_CONDITION);
/* Condition container. This is the card view that contains the list of conditions.
* This will be added whenever the condition list is not empty */
- countItem(conditions, R.layout.suggestion_condition_container,
+ countItem(conditions, R.layout.suggestion_condition_container,
hasConditions && mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED,
NS_SUGGESTION_CONDITION);
/* Suggestion/condition footer. This will be present when the section is fully expanded
* or when there is no conditions and no hidden suggestions */
- countItem(null, R.layout.suggestion_condition_footer,
+ countItem(null, R.layout.suggestion_condition_footer,
(hasConditions || hasSuggestions) &&
- mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED
- || hasSuggestions && !hasConditions && hiddenSuggestion == 0,
+ mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED
+ || hasSuggestions && !hasConditions && hiddenSuggestion == 0,
NS_SUGGESTION_CONDITION);
- }
resetCount();
for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
@@ -367,21 +282,6 @@
return list == null ? 0 : list.size();
}
- private SuggestionHeaderData buildSuggestionHeaderData() {
- SuggestionHeaderData data;
- if (mSuggestions == null) {
- data = new SuggestionHeaderData();
- } else {
- final boolean hasMoreSuggestions = hasMoreSuggestions();
- final int suggestionSize = mSuggestions.size();
- final int undisplayedSuggestionCount = suggestionSize - getDisplayableSuggestionCount();
- data = new SuggestionHeaderData(hasMoreSuggestions, suggestionSize,
- undisplayedSuggestionCount);
- }
-
- return data;
- }
-
private List<Condition> getConditionsToShow(List<Condition> conditions) {
if (conditions == null) {
return null;
@@ -411,20 +311,14 @@
/**
* Builder used to build the ItemsData
* <p>
- * {@link #mExpandedCondition}, {@link #mSuggestionConditionMode} and {@link #mSuggestionMode}
- * have default value while others are not.
+ * {@link #mSuggestionConditionMode} have default value while others are not.
*/
public static class Builder {
- @Deprecated
- private int mSuggestionMode = SUGGESTION_MODE_DEFAULT;
- @Deprecated
- private Condition mExpandedCondition = null;
private @HeaderMode int mSuggestionConditionMode = HEADER_MODE_DEFAULT;
private List<DashboardCategory> mCategories;
private List<Condition> mConditions;
private List<Tile> mSuggestions;
- private boolean mCombineSuggestionAndCondition;
public Builder() {
}
@@ -433,10 +327,7 @@
mCategories = dashboardData.mCategories;
mConditions = dashboardData.mConditions;
mSuggestions = dashboardData.mSuggestions;
- mSuggestionMode = dashboardData.mSuggestionMode;
- mExpandedCondition = dashboardData.mExpandedCondition;
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
- mCombineSuggestionAndCondition = dashboardData.mCombineSuggestionAndCondition;
}
public Builder setCategories(List<DashboardCategory> categories) {
@@ -454,27 +345,11 @@
return this;
}
- public Builder setSuggestionMode(int suggestionMode) {
- this.mSuggestionMode = suggestionMode;
- return this;
- }
-
- @Deprecated
- public Builder setExpandedCondition(Condition expandedCondition) {
- this.mExpandedCondition = expandedCondition;
- return this;
- }
-
public Builder setSuggestionConditionMode(@HeaderMode int mode) {
this.mSuggestionConditionMode = mode;
return this;
}
- public Builder setCombineSuggestionAndCondition(boolean combine) {
- this.mCombineSuggestionAndCondition = combine;
- return this;
- }
-
public DashboardData build() {
return new DashboardData(this);
}
@@ -513,16 +388,6 @@
return mOldItems.get(oldItemPosition).equals(mNewItems.get(newItemPosition));
}
- // not needed in combined UI
- @Deprecated
- @Nullable
- @Override
- public Object getChangePayload(int oldItemPosition, int newItemPosition) {
- if (mOldItems.get(oldItemPosition).type == Item.TYPE_CONDITION_CARD) {
- return "condition"; // return anything but null to mark the payload
- }
- return null;
- }
}
/**
@@ -532,24 +397,17 @@
// valid types in field type
private static final int TYPE_DASHBOARD_CATEGORY = R.layout.dashboard_category;
private static final int TYPE_DASHBOARD_TILE = R.layout.dashboard_tile;
- @Deprecated
- private static final int TYPE_SUGGESTION_HEADER = R.layout.suggestion_header;
- @Deprecated
- private static final int TYPE_SUGGESTION_TILE = R.layout.suggestion_tile;
private static final int TYPE_SUGGESTION_CONDITION_CONTAINER =
R.layout.suggestion_condition_container;
private static final int TYPE_SUGGESTION_CONDITION_HEADER =
R.layout.suggestion_condition_header;
- @Deprecated
- private static final int TYPE_CONDITION_CARD = R.layout.condition_card;
private static final int TYPE_SUGGESTION_CONDITION_FOOTER =
R.layout.suggestion_condition_footer;
private static final int TYPE_DASHBOARD_SPACER = R.layout.dashboard_spacer;
- @IntDef({TYPE_DASHBOARD_CATEGORY, TYPE_DASHBOARD_TILE, TYPE_SUGGESTION_HEADER,
- TYPE_SUGGESTION_TILE, TYPE_SUGGESTION_CONDITION_CONTAINER,
- TYPE_SUGGESTION_CONDITION_HEADER, TYPE_CONDITION_CARD,
- TYPE_SUGGESTION_CONDITION_FOOTER, TYPE_DASHBOARD_SPACER})
+ @IntDef({TYPE_DASHBOARD_CATEGORY, TYPE_DASHBOARD_TILE, TYPE_SUGGESTION_CONDITION_CONTAINER,
+ TYPE_SUGGESTION_CONDITION_HEADER, TYPE_SUGGESTION_CONDITION_FOOTER,
+ TYPE_DASHBOARD_SPACER})
@Retention(RetentionPolicy.SOURCE)
public @interface ItemTypes{}
@@ -571,23 +429,10 @@
*/
public final int id;
- /**
- * To store whether the condition is expanded, useless when {@link #type} is not
- * {@link #TYPE_CONDITION_CARD}
- */
- @Deprecated
- public final boolean conditionExpanded;
-
- @Deprecated
- public Item(Object entity, @ItemTypes int type, int id, boolean conditionExpanded) {
+ public Item(Object entity, @ItemTypes int type, int id) {
this.entity = entity;
this.type = type;
this.id = id;
- this.conditionExpanded = conditionExpanded;
- }
-
- public Item(Object entity, @ItemTypes int type, int id) {
- this(entity, type, id, false);
}
/**
@@ -622,12 +467,6 @@
// Only check title and summary for dashboard tile
return TextUtils.equals(localTile.title, targetTile.title)
&& TextUtils.equals(localTile.summary, targetTile.summary);
- case TYPE_CONDITION_CARD:
- // First check conditionExpanded for quick return
- if (conditionExpanded != targetItem.conditionExpanded) {
- return false;
- }
- // After that, go to default to do final check
default:
return entity == null ? targetItem.entity == null
: entity.equals(targetItem.entity);
@@ -636,46 +475,6 @@
}
/**
- * This class contains the data needed to build the header. The data can also be
- * used to check the diff in DiffUtil.Callback
- */
- public static class SuggestionHeaderData {
- public final boolean hasMoreSuggestions;
- public final int suggestionSize;
- public final int undisplayedSuggestionCount;
-
- public SuggestionHeaderData(boolean moreSuggestions, int suggestionSize, int
- undisplayedSuggestionCount) {
- this.hasMoreSuggestions = moreSuggestions;
- this.suggestionSize = suggestionSize;
- this.undisplayedSuggestionCount = undisplayedSuggestionCount;
- }
-
- public SuggestionHeaderData() {
- hasMoreSuggestions = false;
- suggestionSize = 0;
- undisplayedSuggestionCount = 0;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (!(obj instanceof SuggestionHeaderData)) {
- return false;
- }
-
- SuggestionHeaderData targetData = (SuggestionHeaderData) obj;
-
- return hasMoreSuggestions == targetData.hasMoreSuggestions
- && suggestionSize == targetData.suggestionSize
- && undisplayedSuggestionCount == targetData.undisplayedSuggestionCount;
- }
- }
-
- /**
* This class contains the data needed to build the suggestion/condition header. The data can
* also be used to check the diff in DiffUtil.Callback
*/
diff --git a/src/com/android/settings/dashboard/DashboardDecorator.java b/src/com/android/settings/dashboard/DashboardDecorator.java
index 9bcf39d..6466c0b 100644
--- a/src/com/android/settings/dashboard/DashboardDecorator.java
+++ b/src/com/android/settings/dashboard/DashboardDecorator.java
@@ -43,19 +43,14 @@
for (int i = 1; i < childCount; i++) {
final View child = parent.getChildAt(i);
final ViewHolder holder = parent.getChildViewHolder(child);
- if (holder.getItemViewType() == R.layout.dashboard_category) {
- if (parent.getChildViewHolder(parent.getChildAt(i - 1)).getItemViewType()
- != R.layout.dashboard_tile) {
- continue;
- }
- } else if (holder.getItemViewType() != R.layout.condition_card) {
- continue;
+ if (holder.getItemViewType() == R.layout.dashboard_category
+ && parent.getChildViewHolder(parent.getChildAt(i - 1)).getItemViewType()
+ == R.layout.dashboard_tile) {
+ int top = getChildTop(child);
+ mDivider.setBounds(child.getLeft(), top, child.getRight(),
+ top + mDivider.getIntrinsicHeight());
+ mDivider.draw(c);
}
-
- int top = getChildTop(child);
- mDivider.setBounds(child.getLeft(), top, child.getRight(),
- top + mDivider.getIntrinsicHeight());
- mDivider.draw(c);
}
}
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProvider.java b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
index 939a5d6..15608a2 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProvider.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
@@ -95,9 +95,4 @@
*/
void openTileIntent(Activity activity, Tile tile);
- /**
- * Whether or not we should use new UI that combines the settings suggestions and conditions.
- */
- boolean combineSuggestionAndCondition();
-
}
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index dcae322..88cf666 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -206,11 +206,6 @@
launchIntentOrSelectProfile(activity, tile, intent, MetricsEvent.DASHBOARD_SUMMARY);
}
- @Override
- public boolean combineSuggestionAndCondition() {
- return false;
- }
-
private void launchIntentOrSelectProfile(Activity activity, Tile tile, Intent intent,
int sourceMetricCategory) {
if (!isIntentResolvable(intent)) {
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index 9d2cc0d..809b83d 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -32,7 +32,6 @@
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.dashboard.conditional.Condition;
-import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
import com.android.settings.dashboard.conditional.ConditionManager;
import com.android.settings.dashboard.conditional.ConditionManager.ConditionListener;
import com.android.settings.dashboard.conditional.FocusRecyclerView;
@@ -75,7 +74,6 @@
private DashboardFeatureProvider mDashboardFeatureProvider;
private SuggestionFeatureProvider mSuggestionFeatureProvider;
private boolean isOnCategoriesChangedCalled;
- private SuggestionDismissController mSuggestionDismissHandler;
@Override
public int getMetricsCategory() {
@@ -198,11 +196,6 @@
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
mSuggestionParser, this /* SuggestionDismissController.Callback */);
mDashboard.setAdapter(mAdapter);
- if (!mDashboardFeatureProvider.combineSuggestionAndCondition()) {
- mSuggestionDismissHandler = new SuggestionDismissController(
- getContext(), mDashboard, mSuggestionParser, this);
- ConditionAdapterUtils.addDismiss(mDashboard);
- }
mDashboard.setItemAnimator(new DashboardItemAnimator());
mSummaryLoader.setSummaryConsumer(mAdapter);
if (DEBUG_TIMING) {
diff --git a/src/com/android/settings/dashboard/conditional/ConditionAdapter.java b/src/com/android/settings/dashboard/conditional/ConditionAdapter.java
index 5827d14..4a7422f 100644
--- a/src/com/android/settings/dashboard/conditional/ConditionAdapter.java
+++ b/src/com/android/settings/dashboard/conditional/ConditionAdapter.java
@@ -17,16 +17,23 @@
import android.content.Context;
import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.helper.ItemTouchHelper;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.dashboard.DashboardAdapter;
import com.android.settings.dashboard.DashboardAdapter.DashboardItemHolder;
import com.android.settings.dashboard.DashboardData;
import com.android.settings.dashboard.DashboardData.HeaderMode;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.WirelessUtils;
+
import java.util.List;
import java.util.Objects;
@@ -77,8 +84,7 @@
@Override
public void onBindViewHolder(DashboardItemHolder holder, int position) {
- // TODO: merge methods from ConditionAdapterUtils into this class
- ConditionAdapterUtils.bindViews(mConditions.get(position), holder,
+ bindViews(mConditions.get(position), holder,
position == mConditions.size() - 1, mConditionClickListener);
}
@@ -100,4 +106,78 @@
return 0;
}
+ public void addDismissHandling(final RecyclerView recyclerView) {
+ ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0,
+ ItemTouchHelper.START | ItemTouchHelper.END) {
+ @Override
+ public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
+ RecyclerView.ViewHolder target) {
+ return true;
+ }
+
+ @Override
+ public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
+ return viewHolder.getItemViewType() == R.layout.condition_tile_new_ui
+ ? super.getSwipeDirs(recyclerView, viewHolder) : 0;
+ }
+
+ @Override
+ public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
+ Object item = getItem(viewHolder.getItemId());
+ ((Condition) item).silence();
+ }
+ };
+ ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
+ itemTouchHelper.attachToRecyclerView(recyclerView);
+ }
+
+ private void bindViews(final Condition condition,
+ DashboardAdapter.DashboardItemHolder view, boolean isLastItem,
+ View.OnClickListener onClickListener) {
+ if (condition instanceof AirplaneModeCondition) {
+ Log.d(TAG, "Airplane mode condition has been bound with "
+ + "isActive=" + condition.isActive() + ". Airplane mode is currently " +
+ WirelessUtils.isAirplaneModeOn(condition.mManager.getContext()));
+ }
+ View card = view.itemView.findViewById(R.id.content);
+ card.setTag(condition);
+ card.setOnClickListener(onClickListener);
+ view.icon.setImageIcon(condition.getIcon());
+ view.title.setText(condition.getTitle());
+
+ CharSequence[] actions = condition.getActions();
+ final boolean hasButtons = actions.length > 0;
+ setViewVisibility(view.itemView, R.id.buttonBar, hasButtons);
+
+ view.summary.setText(condition.getSummary());
+ for (int i = 0; i < 2; i++) {
+ Button button = (Button) view.itemView.findViewById(i == 0
+ ? R.id.first_action : R.id.second_action);
+ if (actions.length > i) {
+ button.setVisibility(View.VISIBLE);
+ button.setText(actions[i]);
+ final int index = i;
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Context context = v.getContext();
+ FeatureFactory.getFactory(context).getMetricsFeatureProvider()
+ .action(context, MetricsEvent.ACTION_SETTINGS_CONDITION_BUTTON,
+ condition.getMetricsConstant());
+ condition.onActionClick(index);
+ }
+ });
+ } else {
+ button.setVisibility(View.GONE);
+ }
+ }
+ setViewVisibility(view.itemView, R.id.divider, !isLastItem);
+ }
+
+ private void setViewVisibility(View containerView, int viewId, boolean visible) {
+ View view = containerView.findViewById(viewId);
+ if (view != null) {
+ view.setVisibility(visible ? View.VISIBLE : View.GONE);
+ }
+ }
}
diff --git a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java b/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
deleted file mode 100644
index 0e25723..0000000
--- a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (C) 2015 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.dashboard.conditional;
-
-import android.content.Context;
-import android.support.v7.widget.RecyclerView;
-import android.support.v7.widget.helper.ItemTouchHelper;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.ImageView;
-
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
-import com.android.settings.dashboard.DashboardAdapter;
-import com.android.settings.overlay.FeatureFactory;
-import com.android.settingslib.WirelessUtils;
-
-public class ConditionAdapterUtils {
- private static final String TAG = "ConditionAdapterUtils";
-
- public static void addDismiss(final RecyclerView recyclerView) {
- ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0,
- ItemTouchHelper.START | ItemTouchHelper.END) {
- @Override
- public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
- RecyclerView.ViewHolder target) {
- return true;
- }
-
- @Override
- public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
- return viewHolder.getItemViewType() == R.layout.condition_card
- || viewHolder.getItemViewType() == R.layout.condition_tile_new_ui
- ? super.getSwipeDirs(recyclerView, viewHolder) : 0;
- }
-
- @Override
- public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
- Object item;
- if (viewHolder.getItemViewType() == R.layout.condition_card) {
- DashboardAdapter adapter = (DashboardAdapter) recyclerView.getAdapter();
- item = adapter.getItem(viewHolder.getItemId());
- } else {
- ConditionAdapter adapter = (ConditionAdapter) recyclerView.getAdapter();
- item = adapter.getItem(viewHolder.getItemId());
- }
- ((Condition) item).silence();
- }
- };
- ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
- itemTouchHelper.attachToRecyclerView(recyclerView);
- }
-
- @Deprecated
- public static void bindViews(final Condition condition,
- DashboardAdapter.DashboardItemHolder view, boolean isExpanded,
- View.OnClickListener onClickListener, View.OnClickListener onExpandListener) {
- if (condition instanceof AirplaneModeCondition) {
- Log.d(TAG, "Airplane mode condition has been bound with "
- + "isActive=" + condition.isActive() + ". Airplane mode is currently " +
- WirelessUtils.isAirplaneModeOn(condition.mManager.getContext()));
- }
- View card = view.itemView.findViewById(R.id.content);
- card.setTag(condition);
- card.setOnClickListener(onClickListener);
- view.icon.setImageIcon(condition.getIcon());
- view.title.setText(condition.getTitle());
- final View collapsedGroup = view.itemView.findViewById(R.id.collapsed_group);
- collapsedGroup.setTag(condition);
- final ImageView expand = (ImageView) view.itemView.findViewById(R.id.expand_indicator);
- expand.setImageResource(isExpanded ? R.drawable.ic_expand_less : R.drawable.ic_expand_more);
- expand.setContentDescription(expand.getContext().getString(isExpanded
- ? R.string.condition_expand_hide : R.string.condition_expand_show));
- collapsedGroup.setOnClickListener(onExpandListener);
-
- View detailGroup = view.itemView.findViewById(R.id.detail_group);
- CharSequence[] actions = condition.getActions();
- if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
- if (isExpanded) {
- final boolean hasButtons = actions.length > 0;
- setViewVisibility(detailGroup, R.id.divider, hasButtons);
- setViewVisibility(detailGroup, R.id.buttonBar, hasButtons);
-
- detailGroup.setVisibility(View.VISIBLE);
- } else {
- detailGroup.setVisibility(View.GONE);
- }
- }
-
- if (isExpanded) {
- view.summary.setText(condition.getSummary());
- for (int i = 0; i < 2; i++) {
- Button button = (Button) detailGroup.findViewById(i == 0
- ? R.id.first_action : R.id.second_action);
- if (actions.length > i) {
- button.setVisibility(View.VISIBLE);
- button.setText(actions[i]);
- final int index = i;
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Context context = v.getContext();
- FeatureFactory.getFactory(context).getMetricsFeatureProvider()
- .action(context, MetricsEvent.ACTION_SETTINGS_CONDITION_BUTTON,
- condition.getMetricsConstant());
- condition.onActionClick(index);
- }
- });
- } else {
- button.setVisibility(View.GONE);
- }
- }
- }
- }
-
- public static void bindViews(final Condition condition,
- DashboardAdapter.DashboardItemHolder view, boolean isLastItem,
- View.OnClickListener onClickListener) {
- if (condition instanceof AirplaneModeCondition) {
- Log.d(TAG, "Airplane mode condition has been bound with "
- + "isActive=" + condition.isActive() + ". Airplane mode is currently " +
- WirelessUtils.isAirplaneModeOn(condition.mManager.getContext()));
- }
- View card = view.itemView.findViewById(R.id.content);
- card.setTag(condition);
- card.setOnClickListener(onClickListener);
- view.icon.setImageIcon(condition.getIcon());
- view.title.setText(condition.getTitle());
-
- CharSequence[] actions = condition.getActions();
- final boolean hasButtons = actions.length > 0;
- setViewVisibility(view.itemView, R.id.buttonBar, hasButtons);
-
- view.summary.setText(condition.getSummary());
- for (int i = 0; i < 2; i++) {
- Button button = (Button) view.itemView.findViewById(i == 0
- ? R.id.first_action : R.id.second_action);
- if (actions.length > i) {
- button.setVisibility(View.VISIBLE);
- button.setText(actions[i]);
- final int index = i;
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Context context = v.getContext();
- FeatureFactory.getFactory(context).getMetricsFeatureProvider()
- .action(context, MetricsEvent.ACTION_SETTINGS_CONDITION_BUTTON,
- condition.getMetricsConstant());
- condition.onActionClick(index);
- }
- });
- } else {
- button.setVisibility(View.GONE);
- }
- }
- setViewVisibility(view.itemView, R.id.divider, !isLastItem);
- }
-
- private static void setViewVisibility(View containerView, int viewId, boolean visible) {
- View view = containerView.findViewById(viewId);
- if (view != null) {
- view.setVisibility(visible ? View.VISIBLE : View.GONE);
- }
- }
-}
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
index 3335950..3a6582f 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
@@ -23,7 +23,6 @@
import android.view.ViewGroup;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.R.layout;
import com.android.settings.SettingsActivity;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.dashboard.DashboardAdapter.DashboardItemHolder;
@@ -114,7 +113,10 @@
@Override
public int getItemViewType(int position) {
- return layout.suggestion_tile_new_ui;
+ Tile suggestion = getSuggestion(position);
+ return suggestion.remoteViews != null
+ ? R.layout.suggestion_tile_card
+ : R.layout.suggestion_tile_new_ui;
}
@Override
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionDismissController.java b/src/com/android/settings/dashboard/suggestions/SuggestionDismissController.java
index f0a65f6..618b6df 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionDismissController.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionDismissController.java
@@ -66,8 +66,7 @@
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
final int layoutId = viewHolder.getItemViewType();
- if (layoutId == R.layout.suggestion_tile
- || layoutId == R.layout.suggestion_tile_new_ui
+ if (layoutId == R.layout.suggestion_tile_new_ui
|| layoutId == R.layout.suggestion_tile_card) {
// Only return swipe direction for suggestion tiles. All other types are not swipeable.
return super.getSwipeDirs(recyclerView, viewHolder);
diff --git a/src/com/android/settings/display/WallpaperPreferenceController.java b/src/com/android/settings/display/WallpaperPreferenceController.java
index aa29afc..eb91052 100644
--- a/src/com/android/settings/display/WallpaperPreferenceController.java
+++ b/src/com/android/settings/display/WallpaperPreferenceController.java
@@ -25,7 +25,7 @@
public class WallpaperPreferenceController extends PreferenceController {
- private static final String KEY_WALLPAPER = "wallpaper";
+ public static final String KEY_WALLPAPER = "wallpaper";
public WallpaperPreferenceController(Context context) {
super(context);
diff --git a/src/com/android/settings/fingerprint/FingerprintEnrollBase.java b/src/com/android/settings/fingerprint/FingerprintEnrollBase.java
index df7bf3c..7c34f2d 100644
--- a/src/com/android/settings/fingerprint/FingerprintEnrollBase.java
+++ b/src/com/android/settings/fingerprint/FingerprintEnrollBase.java
@@ -18,6 +18,7 @@
import android.annotation.Nullable;
import android.content.Intent;
+import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.os.UserHandle;
@@ -27,6 +28,7 @@
import android.widget.TextView;
import com.android.settings.R;
+import com.android.settings.SetupWizardUtils;
import com.android.settings.core.InstrumentedActivity;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.setupwizardlib.GlifLayout;
@@ -57,6 +59,12 @@
}
@Override
+ protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
+ resid = SetupWizardUtils.getTheme(getIntent());
+ super.onApplyThemeResource(theme, resid, first);
+ }
+
+ @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
diff --git a/src/com/android/settings/fingerprint/SetupFingerprintEnrollEnrolling.java b/src/com/android/settings/fingerprint/SetupFingerprintEnrollEnrolling.java
index 5d0152c..fbbf033 100644
--- a/src/com/android/settings/fingerprint/SetupFingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/fingerprint/SetupFingerprintEnrollEnrolling.java
@@ -17,7 +17,6 @@
package com.android.settings.fingerprint;
import android.content.Intent;
-import android.content.res.Resources;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.SetupWizardUtils;
@@ -32,12 +31,6 @@
}
@Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
- @Override
public int getMetricsCategory() {
return MetricsEvent.FINGERPRINT_ENROLLING_SETUP;
}
diff --git a/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensor.java b/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensor.java
index d7a4a73..f62b701 100644
--- a/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensor.java
+++ b/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensor.java
@@ -17,7 +17,6 @@
package com.android.settings.fingerprint;
import android.content.Intent;
-import android.content.res.Resources;
import android.os.UserHandle;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -44,12 +43,6 @@
}
@Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
- @Override
public int getMetricsCategory() {
return MetricsEvent.FINGERPRINT_FIND_SENSOR_SETUP;
}
diff --git a/src/com/android/settings/fingerprint/SetupFingerprintEnrollFinish.java b/src/com/android/settings/fingerprint/SetupFingerprintEnrollFinish.java
index 02f6cb8..e81203f 100644
--- a/src/com/android/settings/fingerprint/SetupFingerprintEnrollFinish.java
+++ b/src/com/android/settings/fingerprint/SetupFingerprintEnrollFinish.java
@@ -17,7 +17,6 @@
package com.android.settings.fingerprint;
import android.content.Intent;
-import android.content.res.Resources;
import android.os.UserHandle;
import android.widget.Button;
@@ -40,12 +39,6 @@
}
@Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
- @Override
protected void initViews() {
super.initViews();
Button nextButton = findViewById(R.id.next_button);
diff --git a/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java b/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java
index e668812..8f93bca 100644
--- a/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java
+++ b/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java
@@ -19,7 +19,6 @@
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
-import android.content.res.Resources;
import android.os.UserHandle;
import android.widget.Button;
import android.widget.TextView;
@@ -53,12 +52,6 @@
}
@Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
- @Override
protected void initViews() {
super.initViews();
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 17c0cd7..7dc7800 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -331,8 +331,8 @@
long getForegroundActivityTotalTimeMs(BatteryStats.Uid uid, long rawRealtimeMs) {
final BatteryStats.Timer timer = uid.getForegroundActivityTimer();
if (timer != null) {
- return convertUsToMs(
- timer.getTotalTimeLocked(rawRealtimeMs, BatteryStats.STATS_SINCE_CHARGED));
+ return convertUsToMs(timer.getTotalTimeLocked(convertMsToUs(rawRealtimeMs),
+ BatteryStats.STATS_SINCE_CHARGED));
}
return 0;
diff --git a/src/com/android/settings/fuelgauge/anomaly/action/AnomalyAction.java b/src/com/android/settings/fuelgauge/anomaly/action/AnomalyAction.java
index 3344eb6..87212e7 100644
--- a/src/com/android/settings/fuelgauge/anomaly/action/AnomalyAction.java
+++ b/src/com/android/settings/fuelgauge/anomaly/action/AnomalyAction.java
@@ -16,26 +16,47 @@
package com.android.settings.fuelgauge.anomaly.action;
+import android.content.Context;
+import android.util.Pair;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.fuelgauge.anomaly.Anomaly;
+import com.android.settings.overlay.FeatureFactory;
/**
- * Interface for anomaly action, which is triggered if we need to handle the anomaly
+ * Abstract class for anomaly action, which is triggered if we need to handle the anomaly
*/
-public interface AnomalyAction {
+public abstract class AnomalyAction {
+ protected Context mContext;
+ protected int mActionMetricKey;
+
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+
+ public AnomalyAction(Context context) {
+ mContext = context;
+ mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
+ }
+
/**
* handle the action when user clicks positive button
- * @param anomaly about the app that we need to handle
- * @param metricsKey key for the page that invokes the action
*
+ * @param anomaly about the app that we need to handle
+ * @param contextMetricsKey key for the page that invokes the action
* @see com.android.internal.logging.nano.MetricsProto
*/
- void handlePositiveAction(Anomaly anomaly, int metricsKey);
+ public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
+ mMetricsFeatureProvider.action(mContext, mActionMetricKey, anomaly.packageName,
+ Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, contextMetricsKey));
+ }
/**
* Check whether the action is active for {@code anomaly}
+ *
* @param anomaly about the app that we need to handle
* @return {@code true} if action is active, otherwise return {@code false}
*/
- boolean isActionActive(Anomaly anomaly);
- int getActionType();
+ public abstract boolean isActionActive(Anomaly anomaly);
+
+ public abstract int getActionType();
}
diff --git a/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckAction.java b/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckAction.java
index 16fd0df..799bddc 100644
--- a/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckAction.java
+++ b/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckAction.java
@@ -19,28 +19,26 @@
import android.app.AppOpsManager;
import android.content.Context;
-import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.fuelgauge.anomaly.Anomaly;
-import com.android.settings.overlay.FeatureFactory;
/**
* Background check action for anomaly app, which means to stop app running in the background
*/
-public class BackgroundCheckAction implements AnomalyAction {
+public class BackgroundCheckAction extends AnomalyAction {
- private Context mContext;
- private MetricsFeatureProvider mMetricsFeatureProvider;
private AppOpsManager mAppOpsManager;
public BackgroundCheckAction(Context context) {
- mContext = context;
- mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
+ super(context);
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
+ mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_BACKGROUND_CHECK;
}
@Override
- public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
- // TODO(b/37681923): add metric log here if possible
+ public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
+ super.handlePositiveAction(anomaly, contextMetricsKey);
+
mAppOpsManager.setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, anomaly.uid, anomaly.packageName,
AppOpsManager.MODE_IGNORED);
}
diff --git a/src/com/android/settings/fuelgauge/anomaly/action/ForceStopAction.java b/src/com/android/settings/fuelgauge/anomaly/action/ForceStopAction.java
index 557b2a9..fb7306a 100644
--- a/src/com/android/settings/fuelgauge/anomaly/action/ForceStopAction.java
+++ b/src/com/android/settings/fuelgauge/anomaly/action/ForceStopAction.java
@@ -21,43 +21,32 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;
-import android.util.Pair;
import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.fuelgauge.anomaly.Anomaly;
-import com.android.settings.overlay.FeatureFactory;
-
-import java.util.List;
/**
* Force stop action for anomaly app, which means to stop the app which causes anomaly
*/
-public class ForceStopAction implements AnomalyAction {
+public class ForceStopAction extends AnomalyAction {
private static final String TAG = "ForceStopAction";
- private Context mContext;
- private MetricsFeatureProvider mMetricsFeatureProvider;
private ActivityManager mActivityManager;
private PackageManager mPackageManager;
public ForceStopAction(Context context) {
- mContext = context;
- mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
+ super(context);
mActivityManager = (ActivityManager) context.getSystemService(
Context.ACTIVITY_SERVICE);
mPackageManager = context.getPackageManager();
+ mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_FORCE_STOP;
}
@Override
- public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
- final String packageName = anomaly.packageName;
- // force stop the package
- mMetricsFeatureProvider.action(mContext,
- MetricsProto.MetricsEvent.ACTION_APP_FORCE_STOP, packageName,
- Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, metricsKey));
+ public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
+ super.handlePositiveAction(anomaly, contextMetricsKey);
- mActivityManager.forceStopPackage(packageName);
+ mActivityManager.forceStopPackage(anomaly.packageName);
}
@Override
diff --git a/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java b/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java
index 4205b6e..6779828 100644
--- a/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java
+++ b/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java
@@ -20,28 +20,28 @@
import android.content.pm.permission.RuntimePermissionPresenter;
import android.support.v4.content.PermissionChecker;
-import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.fuelgauge.anomaly.Anomaly;
-import com.android.settings.overlay.FeatureFactory;
/**
* Location action for anomaly app, which means to turn off location permission for this app
*/
-public class LocationCheckAction implements AnomalyAction {
+public class LocationCheckAction extends AnomalyAction {
private static final String TAG = "LocationCheckAction";
private static final String LOCATION_PERMISSION = "android.permission-group.LOCATION";
- private final Context mContext;
private final RuntimePermissionPresenter mRuntimePermissionPresenter;
public LocationCheckAction(Context context) {
- mContext = context;
+ super(context);
mRuntimePermissionPresenter = RuntimePermissionPresenter.getInstance(context);
+ mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_LOCATION_CHECK;
}
@Override
- public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
+ public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
+ super.handlePositiveAction(anomaly, contextMetricsKey);
mRuntimePermissionPresenter.revokeRuntimePermission(anomaly.packageName,
LOCATION_PERMISSION);
}
diff --git a/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetector.java b/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetector.java
index aadfa0c..55686e0 100644
--- a/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetector.java
+++ b/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetector.java
@@ -70,11 +70,12 @@
String targetPackageName) {
final List<BatterySipper> batterySippers = batteryStatsHelper.getUsageList();
final List<Anomaly> anomalies = new ArrayList<>();
- final long totalRunningHours = mBatteryUtils.calculateRunningTimeBasedOnStatsType(
- batteryStatsHelper, BatteryStats.STATS_SINCE_CHARGED) / DateUtils.HOUR_IN_MILLIS;
+ final double totalRunningHours = mBatteryUtils.calculateRunningTimeBasedOnStatsType(
+ batteryStatsHelper, BatteryStats.STATS_SINCE_CHARGED)
+ / (double) DateUtils.HOUR_IN_MILLIS;
final int targetUid = mBatteryUtils.getPackageUid(targetPackageName);
- if (totalRunningHours != 0) {
+ if (totalRunningHours >= 1) {
for (int i = 0, size = batterySippers.size(); i < size; i++) {
final BatterySipper sipper = batterySippers.get(i);
final BatteryStats.Uid uid = sipper.uidObj;
diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java
index b269062..93c14c7 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.content.Intent;
+import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.Settings;
@@ -41,6 +42,7 @@
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.SetupRedactionInterstitial;
+import com.android.settings.SetupWizardUtils;
import com.android.settings.Utils;
import com.android.settingslib.RestrictedLockUtils;
@@ -54,6 +56,12 @@
}
@Override
+ protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
+ resid = SetupWizardUtils.getTheme(getIntent());
+ super.onApplyThemeResource(theme, resid, first);
+ }
+
+ @Override
protected boolean isValidFragment(String fragmentName) {
return RedactionInterstitialFragment.class.getName().equals(fragmentName);
}
diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java
index 2f359d1..b646360 100644
--- a/src/com/android/settings/password/ChooseLockPassword.java
+++ b/src/com/android/settings/password/ChooseLockPassword.java
@@ -28,6 +28,7 @@
import android.app.admin.PasswordMetrics;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Resources.Theme;
import android.graphics.Insets;
import android.os.Bundle;
import android.os.Handler;
@@ -61,6 +62,7 @@
import com.android.settings.EncryptionInterstitial;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
+import com.android.settings.SetupWizardUtils;
import com.android.settings.Utils;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.notification.RedactionInterstitial;
@@ -88,6 +90,12 @@
return modIntent;
}
+ @Override
+ protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
+ resid = SetupWizardUtils.getTheme(getIntent());
+ super.onApplyThemeResource(theme, resid, first);
+ }
+
public static class IntentBuilder {
private final Intent mIntent;
diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java
index 51c1569..d1964b4 100644
--- a/src/com/android/settings/password/ChooseLockPattern.java
+++ b/src/com/android/settings/password/ChooseLockPattern.java
@@ -20,6 +20,7 @@
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Resources.Theme;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
@@ -40,6 +41,7 @@
import com.android.settings.EncryptionInterstitial;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
+import com.android.settings.SetupWizardUtils;
import com.android.settings.Utils;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.notification.RedactionInterstitial;
@@ -80,6 +82,12 @@
return modIntent;
}
+ @Override
+ protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
+ resid = SetupWizardUtils.getTheme(getIntent());
+ super.onApplyThemeResource(theme, resid, first);
+ }
+
public static class IntentBuilder {
private final Intent mIntent;
diff --git a/src/com/android/settings/password/SetupChooseLockPassword.java b/src/com/android/settings/password/SetupChooseLockPassword.java
index b8ded5e..f23ab6d 100644
--- a/src/com/android/settings/password/SetupChooseLockPassword.java
+++ b/src/com/android/settings/password/SetupChooseLockPassword.java
@@ -20,7 +20,6 @@
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@@ -30,7 +29,6 @@
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.SetupRedactionInterstitial;
-import com.android.settings.SetupWizardUtils;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
import com.android.setupwizardlib.util.WizardManagerHelper;
@@ -69,12 +67,6 @@
layout.setFitsSystemWindows(false);
}
- @Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment
implements OnLockTypeSelectedListener {
diff --git a/src/com/android/settings/password/SetupChooseLockPattern.java b/src/com/android/settings/password/SetupChooseLockPattern.java
index 7cb5afb..b1e3d0d 100644
--- a/src/com/android/settings/password/SetupChooseLockPattern.java
+++ b/src/com/android/settings/password/SetupChooseLockPattern.java
@@ -19,10 +19,8 @@
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import com.android.settings.SetupRedactionInterstitial;
-import com.android.settings.SetupWizardUtils;
/**
* Setup Wizard's version of ChooseLockPattern screen. It inherits the logic and basic structure
@@ -48,12 +46,6 @@
return SetupChooseLockPatternFragment.class;
}
- @Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
- resid = SetupWizardUtils.getTheme(getIntent());
- super.onApplyThemeResource(theme, resid, first);
- }
-
public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment {
@Override
diff --git a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
index afbb0b4..90c5888 100644
--- a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
+++ b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
@@ -45,7 +45,7 @@
finish();
}
- @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ @VisibleForTesting
void startFallbackSuggestion() {
// fall back to default wallpaper picker
Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(), null, null, 0,
diff --git a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
index bef4777..1ca8ac7 100644
--- a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
+++ b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
@@ -90,8 +90,13 @@
final List<ResolveInfo> rList = pm.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
- // Add indexable data for each of the matching activities
+ // Add indexable data for package that is in config_wallpaper_picker_package
+ final String wallpaperPickerPackage =
+ context.getString(R.string.config_wallpaper_picker_package);
for (ResolveInfo info : rList) {
+ if (!wallpaperPickerPackage.equals(info.activityInfo.packageName)) {
+ continue;
+ }
CharSequence label = info.loadLabel(pm);
if (label == null) label = info.activityInfo.packageName;
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 3cfb17d..761c4ff 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -749,10 +749,7 @@
AccessPoint accessPoint = accessPoints.get(index);
// Ignore access points that are out of range.
if (accessPoint.isReachable()) {
- String key = accessPoint.getBssid();
- if (TextUtils.isEmpty(key)) {
- key = accessPoint.getSsidStr();
- }
+ String key = generateKey(accessPoint);
hasAvailableAccessPoints = true;
LongPressAccessPointPreference pref =
(LongPressAccessPointPreference) getCachedPreference(key);
@@ -794,6 +791,18 @@
}
}
+ private String generateKey(AccessPoint accessPoint) {
+ StringBuilder key = new StringBuilder();
+ String bssid = accessPoint.getBssid();
+ if (TextUtils.isEmpty(bssid)) {
+ key.append(accessPoint.getSsidStr());
+ } else {
+ key.append(bssid);
+ }
+ key.append(',').append(accessPoint.getSecurity());
+ return key.toString();
+ }
+
@NonNull
private LongPressAccessPointPreference createLongPressActionPointPreference(
AccessPoint accessPoint) {
@@ -1006,6 +1015,7 @@
mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_WIFI_CONNECT,
isSavedNetwork);
mWifiManager.connect(config, mConnectListener);
+ scrollToPreference(mConnectedAccessPointPreferenceCategory);
}
protected void connect(final int networkId, boolean isSavedNetwork) {
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
index edb5d89..5fbd3a7 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
@@ -16,11 +16,17 @@
package com.android.settings.accounts;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
+
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.when;
import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AuthenticatorDescription;
import android.content.Context;
import android.content.Intent;
+import android.content.SyncAdapterType;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
@@ -28,29 +34,58 @@
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.ShadowAccountManager;
+import com.android.settings.testutils.shadow.ShadowContentResolver;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+ shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public class AccountSyncPreferenceControllerTest {
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private AccountManager mAccountManager;
+
+ private Context mContext;
+ private AccountSyncPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication application = ShadowApplication.getInstance();
+ application.setSystemService(Context.ACCOUNT_SERVICE, mAccountManager);
+ mContext = application.getApplicationContext();
+
+ when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(
+ new AuthenticatorDescription[0]);
+ when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
+
+ mPreference = new Preference(mContext);
+ mPreference.setKey("account_sync");
+
+ mController = new AccountSyncPreferenceController(mContext);
+ mController.init(new Account("acct1", "type1"), new UserHandle(3));
+ }
+
+ @After
+ public void tearDown() {
+ ShadowContentResolver.reset();
+ }
+
@Test
public void handlePreferenceTreeClick_shouldStartFragment() {
- final ShadowApplication application = ShadowApplication.getInstance();
- final Context context = application.getApplicationContext();
- final Preference preference = new Preference(context);
- preference.setKey("account_sync");
+ mController.handlePreferenceTreeClick(mPreference);
- final AccountSyncPreferenceController controller =
- new AccountSyncPreferenceController(context);
- controller.init(new Account("acct1", "type1"), mock(UserHandle.class));
- controller.handlePreferenceTreeClick(preference);
-
- final Intent nextActivity = application.getNextStartedActivity();
+ final Intent nextActivity = ShadowApplication.getInstance().getNextStartedActivity();
assertThat(nextActivity.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
.isEqualTo(AccountSyncSettings.class.getName());
@@ -58,4 +93,93 @@
.isEqualTo(R.string.account_sync_title);
}
+ @Test
+ public void updateSummary_adapterInvisible_shouldNotCount() {
+ SyncAdapterType syncAdapterType = new SyncAdapterType("authority" /* authority */,
+ "type1" /* accountType */, false /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType[] syncAdapters = {syncAdapterType};
+ ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getString(R.string.account_sync_summary_all_off));
+ }
+
+ @Test
+ public void updateSummary_notSameAccountType_shouldNotCount() {
+ SyncAdapterType syncAdapterType = new SyncAdapterType("authority" /* authority */,
+ "type5" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType[] syncAdapters = {syncAdapterType};
+ ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getString(R.string.account_sync_summary_all_off));
+ }
+
+ @Test
+ public void updateSummary_notSyncable_shouldNotCount() {
+ SyncAdapterType syncAdapterType = new SyncAdapterType("authority" /* authority */,
+ "type1" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType[] syncAdapters = {syncAdapterType};
+ ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
+ ShadowContentResolver.setSyncable("authority", 0);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getString(R.string.account_sync_summary_all_off));
+ }
+
+ @Test
+ public void updateSummary_syncDisabled_shouldNotCount() {
+ SyncAdapterType syncAdapterType = new SyncAdapterType("authority" /* authority */,
+ "type1" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType[] syncAdapters = {syncAdapterType};
+ ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
+ ShadowContentResolver.setSyncAutomatically("authority", false);
+ ShadowContentResolver.setMasterSyncAutomatically(3, true);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getString(R.string.account_sync_summary_all_off));
+ }
+
+ @Test
+ public void updateSummary_syncEnabled_shouldCount() {
+ SyncAdapterType syncAdapterType = new SyncAdapterType("authority" /* authority */,
+ "type1" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType[] syncAdapters = {syncAdapterType};
+ ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getString(R.string.account_sync_summary_all_on));
+ }
+
+ @Test
+ public void updateSummary_multipleSyncAdapters_shouldSetSummary() {
+ SyncAdapterType syncAdapterType1 = new SyncAdapterType("authority1" /* authority */,
+ "type1" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType syncAdapterType2 = new SyncAdapterType("authority2" /* authority */,
+ "type1" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType syncAdapterType3 = new SyncAdapterType("authority3" /* authority */,
+ "type1" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType syncAdapterType4 = new SyncAdapterType("authority4" /* authority */,
+ "type1" /* accountType */, true /* userVisible */, true /* supportsUploading */);
+ SyncAdapterType[] syncAdapters =
+ {syncAdapterType1, syncAdapterType2, syncAdapterType3, syncAdapterType4};
+ ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
+
+ ShadowContentResolver.setSyncAutomatically("authority4", false);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getString(R.string.account_sync_summary_some_on, 3, 4));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/conditional/ConditionAdapterUtilsTest.java b/tests/robotests/src/com/android/settings/conditional/ConditionAdapterUtilsTest.java
deleted file mode 100644
index 83883b2..0000000
--- a/tests/robotests/src/com/android/settings/conditional/ConditionAdapterUtilsTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2016 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.conditional;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.LinearLayout;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.dashboard.DashboardAdapter;
-import com.android.settings.dashboard.conditional.Condition;
-import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
-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;
-import com.android.settings.R;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
-
-// Not needed in new UI as the view is always expanded
-@Deprecated
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class ConditionAdapterUtilsTest{
- @Mock
- private Condition mCondition;
- private DashboardAdapter.DashboardItemHolder mViewHolder;
- private Context mContext;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- final CharSequence[] actions = new CharSequence[2];
- when(mCondition.getActions()).thenReturn(actions);
-
- final View view = LayoutInflater.from(mContext).inflate(R.layout.condition_card, new
- LinearLayout(mContext), true);
- mViewHolder = new DashboardAdapter.DashboardItemHolder(view);
- }
-
- @Test
- public void testBindView_isExpanded_returnVisible() {
- ConditionAdapterUtils.bindViews(mCondition, mViewHolder, true, null, null);
- assertThat(mViewHolder.itemView.findViewById(R.id.detail_group).getVisibility())
- .isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void testBindView_isNotExpanded_returnGone() {
- ConditionAdapterUtils.bindViews(mCondition, mViewHolder, false, null, null);
- assertThat(mViewHolder.itemView.findViewById(R.id.detail_group).getVisibility())
- .isEqualTo(View.GONE);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index 66706cc..55bc4ca 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -38,15 +38,10 @@
import android.graphics.drawable.Icon;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
-import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.FrameLayout;
import android.widget.LinearLayout;
-import android.widget.RemoteViews;
-import android.widget.TextView;
+import android.widget.RelativeLayout;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -71,7 +66,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.Collections;
@@ -101,8 +95,8 @@
private ArgumentCaptor<String> mActionPackageCaptor = ArgumentCaptor.forClass(String.class);
private FakeFeatureFactory mFactory;
private DashboardAdapter mDashboardAdapter;
- private DashboardAdapter.DashboardItemHolder mSuggestionHolder;
- private DashboardData.SuggestionHeaderData mSuggestionHeaderData;
+ private DashboardAdapter.SuggestionAndConditionHeaderHolder mSuggestionHolder;
+ private DashboardData.SuggestionConditionHeaderData mSuggestionHeaderData;
@Before
public void setUp() {
@@ -121,8 +115,10 @@
when(mResources.getQuantityString(any(int.class), any(int.class), any()))
.thenReturn("");
- mDashboardAdapter = new DashboardAdapter(mContext, null, null);
- mSuggestionHeaderData = new DashboardData.SuggestionHeaderData(true, 1, 0);
+ List<Condition> conditions = new ArrayList<>();
+ conditions.add(mCondition);
+ mDashboardAdapter = new DashboardAdapter(mContext, null, conditions, null, null);
+ mSuggestionHeaderData = new DashboardData.SuggestionConditionHeaderData(conditions, 1);
when(mView.getTag()).thenReturn(mCondition);
}
@@ -161,8 +157,7 @@
@Test
public void testSuggestionsLogs_Expanded() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
verify(mFactory.metricsFeatureProvider, times(3)).action(
any(Context.class), mActionCategoryCaptor.capture(),
@@ -180,8 +175,7 @@
@Test
public void testSuggestionsLogs_ExpandedAndPaused() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
verify(mFactory.metricsFeatureProvider, times(6)).action(
@@ -204,8 +198,7 @@
public void testSuggestionsLogs_ExpandedAfterPause() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
mDashboardAdapter.onPause();
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
verify(mFactory.metricsFeatureProvider, times(7)).action(
any(Context.class), mActionCategoryCaptor.capture(),
@@ -229,8 +222,7 @@
public void testSuggestionsLogs_ExpandedAfterPauseAndPausedAgain() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
mDashboardAdapter.onPause();
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
verify(mFactory.metricsFeatureProvider, times(10)).action(
@@ -257,8 +249,7 @@
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShown() {
setupSuggestions(makeSuggestions("pkg1"));
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
verify(mFactory.metricsFeatureProvider, times(1)).action(
any(Context.class), mActionCategoryCaptor.capture(),
@@ -274,8 +265,7 @@
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAndPaused() {
setupSuggestions(makeSuggestions("pkg1"));
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
verify(mFactory.metricsFeatureProvider, times(2)).action(
@@ -294,8 +284,7 @@
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPause() {
setupSuggestions(makeSuggestions("pkg1"));
mDashboardAdapter.onPause();
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
verify(mFactory.metricsFeatureProvider, times(3)).action(
any(Context.class), mActionCategoryCaptor.capture(),
@@ -314,8 +303,7 @@
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPauseAndPausedAgain() {
setupSuggestions(makeSuggestions("pkg1"));
mDashboardAdapter.onPause();
- mDashboardAdapter.onBindSuggestionHeader(
- mSuggestionHolder, mSuggestionHeaderData);
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
verify(mFactory.metricsFeatureProvider, times(4)).action(
@@ -333,81 +321,9 @@
}
@Test
- public void testBindViewHolder_inflateRemoteView() {
- List<Tile> packages = makeSuggestions("pkg1");
- RemoteViews remoteViews = mock(RemoteViews.class);
- TextView textView = new TextView(RuntimeEnvironment.application);
- doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
- packages.get(0).remoteViews = remoteViews;
- mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
- mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
- new FrameLayout(RuntimeEnvironment.application),
- R.layout.suggestion_tile_card);
-
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
- assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
- mSuggestionHolder.itemView.performClick();
-
- verify(mContext).startSuggestion(any(Intent.class));
- }
-
- @Test
- public void testBindViewHolder_primaryViewHandlesClick() {
- Context context =
- new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
-
- List<Tile> packages = makeSuggestions("pkg1");
- RemoteViews remoteViews = mock(RemoteViews.class);
- FrameLayout layout = new FrameLayout(context);
- Button primary = new Button(context);
- primary.setId(android.R.id.primary);
- layout.addView(primary);
- doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
- packages.get(0).remoteViews = remoteViews;
- mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
- mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
- new FrameLayout(context),
- R.layout.suggestion_tile_card);
-
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
-
- mSuggestionHolder.itemView.performClick();
- assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
- verify(mContext, never()).startSuggestion(any(Intent.class));
-
- primary.performClick();
-
- verify(mContext).startSuggestion(any(Intent.class));
- }
-
- @Test
- public void testBindViewHolder_viewsClearedOnRebind() {
- Context context =
- new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
-
- List<Tile> packages = makeSuggestions("pkg1");
- RemoteViews remoteViews = mock(RemoteViews.class);
- FrameLayout layout = new FrameLayout(context);
- Button primary = new Button(context);
- primary.setId(android.R.id.primary);
- layout.addView(primary);
- doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
- packages.get(0).remoteViews = remoteViews;
- mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
- mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
- new FrameLayout(context),
- R.layout.suggestion_tile_card);
-
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
-
- ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
- assertThat(itemView.getChildCount()).isEqualTo(1);
- }
-
- @Test
- public void testSuggestionDismissed_notOnlySuggestion_doNothing() {
- final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, null));
+ public void testSuggestioDismissed_notOnlySuggestion_doNothing() {
+ final DashboardAdapter adapter =
+ spy(new DashboardAdapter(mContext, null, null, null, null));
adapter.setCategoriesAndSuggestions(
new ArrayList<>(), makeSuggestions("pkg1", "pkg2", "pkg3"));
final DashboardData dashboardData = adapter.mDashboardData;
@@ -420,8 +336,9 @@
}
@Test
- public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
- DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, null));
+ public void testSuggestioDismissed_onlySuggestion_updateDashboardData() {
+ DashboardAdapter adapter =
+ spy(new DashboardAdapter(mContext, null, null, null, null));
adapter.setCategoriesAndSuggestions(new ArrayList<>(), makeSuggestions("pkg1"));
final DashboardData dashboardData = adapter.mDashboardData;
reset(adapter); // clear interactions tracking
@@ -450,8 +367,7 @@
@Test
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
- when(mFactory.dashboardFeatureProvider.combineSuggestionAndCondition()).thenReturn(true);
- mDashboardAdapter = new DashboardAdapter(mContext, null, null);
+ mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
final List<Tile> suggestions = makeSuggestions("pkg1");
final List<DashboardCategory> categories = new ArrayList<>();
final DashboardCategory category = mock(DashboardCategory.class);
@@ -489,8 +405,9 @@
private void setupSuggestions(List<Tile> suggestions) {
mDashboardAdapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
- mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
- new FrameLayout(RuntimeEnvironment.application),
- mDashboardAdapter.getItemViewType(1));
+ final Context context = RuntimeEnvironment.application;
+ mSuggestionHolder = new DashboardAdapter.SuggestionAndConditionHeaderHolder(
+ LayoutInflater.from(context).inflate(
+ R.layout.suggestion_condition_header, new RelativeLayout(context), true));
}
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
index 8c6a828..3b8672e 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
@@ -94,7 +94,6 @@
.setCategories(categories)
.setSuggestions(suggestions)
.setSuggestionConditionMode(DashboardData.HEADER_MODE_FULLY_EXPANDED)
- .setCombineSuggestionAndCondition(true)
.build();
mDashboardDataWithTwoConditions = new DashboardData.Builder()
@@ -102,7 +101,6 @@
.setCategories(categories)
.setSuggestions(suggestions)
.setSuggestionConditionMode(DashboardData.HEADER_MODE_FULLY_EXPANDED)
- .setCombineSuggestionAndCondition(true)
.build();
mDashboardDataWithNoItems = new DashboardData.Builder()
@@ -127,9 +125,7 @@
.isEqualTo(expectedSize);
for (int i = 0; i < expectedSize; i++) {
final Object item = mDashboardDataWithOneConditions.getItemEntityByPosition(i);
- if (item instanceof DashboardData.SuggestionHeaderData
- || item instanceof List) {
- // SuggestionHeaderData is created inside when build, we can only use isEqualTo
+ if (item instanceof List) {
assertThat(item).isEqualTo(expectedObjects[i]);
} else if (item instanceof DashboardData.SuggestionConditionHeaderData) {
DashboardData.SuggestionConditionHeaderData i1 =
diff --git a/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java
index 688f078..f0412d6 100644
--- a/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java
@@ -38,7 +38,6 @@
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
index a29ac93..c9e3815 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
@@ -15,16 +15,26 @@
*/
package com.android.settings.dashboard.suggestions;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.graphics.drawable.Icon;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.ContextThemeWrapper;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.FrameLayout;
import android.widget.LinearLayout;
+import android.widget.RemoteViews;
+import android.widget.TextView;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.DashboardAdapter;
+import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.Tile;
import java.util.ArrayList;
@@ -33,15 +43,20 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -51,9 +66,12 @@
private Tile mSuggestion1;
@Mock
private Tile mSuggestion2;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private SettingsActivity mActivity;
private Context mContext;
private SuggestionAdapter mSuggestionAdapter;
+ private DashboardAdapter.DashboardItemHolder mSuggestionHolder;
private List<Tile> mOneSuggestion;
private List<Tile> mTwoSuggestions;
@@ -61,6 +79,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
+ FakeFeatureFactory.setupForTest(mActivity);
+
mSuggestion1.title = "Test Suggestion 1";
mSuggestion1.icon = mock(Icon.class);
mSuggestion2.title = "Test Suggestion 2";
@@ -92,13 +112,96 @@
public void onBindViewHolder_shouldSetListener() {
final View view = spy(LayoutInflater.from(mContext).inflate(
R.layout.suggestion_tile_new_ui, new LinearLayout(mContext), true));
- final DashboardAdapter.DashboardItemHolder viewHolder =
- new DashboardAdapter.DashboardItemHolder(view);
+ mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion, new ArrayList<>());
- mSuggestionAdapter.onBindViewHolder(viewHolder, 0);
+ mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
verify(view).setOnClickListener(any(View.OnClickListener.class));
}
+ @Test
+ public void onBindViewHolder_shouldInflateRemoteView() {
+ List<Tile> packages = makeSuggestions("pkg1");
+ RemoteViews remoteViews = mock(RemoteViews.class);
+ TextView textView = new TextView(RuntimeEnvironment.application);
+ doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
+ packages.get(0).remoteViews = remoteViews;
+ setupSuggestions(mActivity, packages);
+
+ mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
+
+ assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
+ mSuggestionHolder.itemView.performClick();
+
+ verify(mActivity).startSuggestion(any(Intent.class));
+ }
+
+ @Test
+ public void onBindViewHolder_primaryViewShouldHandleClick() {
+ Context context =
+ new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
+
+ List<Tile> packages = makeSuggestions("pkg1");
+ RemoteViews remoteViews = mock(RemoteViews.class);
+ FrameLayout layout = new FrameLayout(context);
+ Button primary = new Button(context);
+ primary.setId(android.R.id.primary);
+ layout.addView(primary);
+ doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
+ packages.get(0).remoteViews = remoteViews;
+ setupSuggestions(mActivity, packages);
+
+ mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
+ mSuggestionHolder.itemView.performClick();
+
+ assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
+ verify(mActivity, never()).startSuggestion(any(Intent.class));
+
+ primary.performClick();
+
+ verify(mActivity).startSuggestion(any(Intent.class));
+ }
+
+ @Test
+ public void onBindViewHolder_viewsShouldClearOnRebind() {
+ Context context =
+ new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
+
+ List<Tile> packages = makeSuggestions("pkg1");
+ RemoteViews remoteViews = mock(RemoteViews.class);
+ FrameLayout layout = new FrameLayout(context);
+ Button primary = new Button(context);
+ primary.setId(android.R.id.primary);
+ layout.addView(primary);
+ doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
+ packages.get(0).remoteViews = remoteViews;
+ setupSuggestions(mActivity, packages);
+
+ mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
+ mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
+
+ ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
+ assertThat(itemView.getChildCount()).isEqualTo(1);
+ }
+
+ private void setupSuggestions(Context context, List<Tile> suggestions) {
+ mSuggestionAdapter = new SuggestionAdapter(context, suggestions, new ArrayList<>());
+ mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
+ new FrameLayout(RuntimeEnvironment.application),
+ mSuggestionAdapter.getItemViewType(0));
+ }
+
+ private List<Tile> makeSuggestions(String... pkgNames) {
+ final List<Tile> suggestions = new ArrayList<>();
+ for (String pkgName : pkgNames) {
+ Tile suggestion = new Tile();
+ suggestion.intent = new Intent("action");
+ suggestion.intent.setComponent(new ComponentName(pkgName, "cls"));
+ suggestions.add(suggestion);
+ suggestion.icon = mock(Icon.class);
+ }
+ return suggestions;
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
index c20e5c4..025e600 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
@@ -80,7 +80,7 @@
@Test
public void getSwipeDirs_isSuggestionTile_shouldReturnDirection() {
final RecyclerView.ViewHolder vh = mock(RecyclerView.ViewHolder.class);
- when(vh.getItemViewType()).thenReturn(R.layout.suggestion_tile);
+ when(vh.getItemViewType()).thenReturn(R.layout.suggestion_tile_new_ui);
assertThat(mController.getSwipeDirs(mRecyclerView, vh))
.isEqualTo(ItemTouchHelper.START | ItemTouchHelper.END);
@@ -98,7 +98,7 @@
@Test
public void getSwipeDirs_isNotSuggestionTile_shouldReturn0() {
final RecyclerView.ViewHolder vh = mock(RecyclerView.ViewHolder.class);
- when(vh.getItemViewType()).thenReturn(R.layout.condition_card);
+ when(vh.getItemViewType()).thenReturn(R.layout.condition_tile_new_ui);
assertThat(mController.getSwipeDirs(mRecyclerView, vh))
.isEqualTo(0);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index ff6e52a..151463a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.os.BatteryStats;
import android.os.Process;
+import android.os.SystemClock;
import android.text.format.DateUtils;
import com.android.internal.os.BatterySipper;
@@ -369,11 +370,12 @@
@Test
public void testGetForegroundActivityTotalTimeMs_returnMilliseconds() {
+ final long rawRealtimeMs = SystemClock.elapsedRealtime();
doReturn(mTimer).when(mUid).getForegroundActivityTimer();
- doReturn(TIME_SINCE_LAST_FULL_CHARGE_US).when(mTimer).getTotalTimeLocked(anyLong(),
- anyInt());
+ doReturn(TIME_SINCE_LAST_FULL_CHARGE_US).when(mTimer)
+ .getTotalTimeLocked(rawRealtimeMs * 1000, BatteryStats.STATS_SINCE_CHARGED);
- assertThat(mBatteryUtils.getForegroundActivityTotalTimeMs(mUid, 0)).isEqualTo(
+ assertThat(mBatteryUtils.getForegroundActivityTotalTimeMs(mUid, rawRealtimeMs)).isEqualTo(
TIME_SINCE_LAST_FULL_CHARGE_MS);
}
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
new file mode 100644
index 0000000..8db1a8c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.fuelgauge.anomaly.action;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+import android.app.AppOpsManager;
+import android.content.Context;
+import android.util.Pair;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.TestConfig;
+import com.android.settings.fuelgauge.anomaly.Anomaly;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AnomalyActionTest {
+ private static final String PACKAGE_NAME = "com.android.app";
+ private static final int UID = 111;
+ private static final int ACTION_KEY = 2;
+ private static final int METRIC_KEY = 3;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private AppOpsManager mAppOpsManagerr;
+ private Anomaly mAnomaly;
+ private TestAnomalyAction mTestAnomalyAction;
+ private FakeFeatureFactory mFeatureFactory;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ FakeFeatureFactory.setupForTest(mContext);
+ mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ doReturn(mAppOpsManagerr).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
+
+ mAnomaly = new Anomaly.Builder()
+ .setUid(UID)
+ .setPackageName(PACKAGE_NAME)
+ .build();
+ mTestAnomalyAction = new TestAnomalyAction(mContext);
+ }
+
+ @Test
+ public void testHandlePositiveAction_logAction() {
+ mTestAnomalyAction.handlePositiveAction(mAnomaly, METRIC_KEY);
+
+ verify(mFeatureFactory.metricsFeatureProvider).action(mContext, ACTION_KEY, PACKAGE_NAME,
+ Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, METRIC_KEY));
+ }
+
+ /**
+ * Test class for {@link AnomalyAction}
+ */
+ public class TestAnomalyAction extends AnomalyAction {
+ public TestAnomalyAction(Context context) {
+ super(context);
+ mActionMetricKey = ACTION_KEY;
+ }
+
+ @Override
+ public boolean isActionActive(Anomaly anomaly) {
+ return false;
+ }
+
+ @Override
+ public int getActionType() {
+ return 0;
+ }
+ }
+}
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 21b2e54..e7c2664 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
@@ -59,9 +59,10 @@
private static final int ANOMALY_UID = 111;
private static final int NORMAL_UID = 222;
private static final int TARGET_UID = 333;
- private static final long RUNNING_TIME_MS = 2 * DateUtils.HOUR_IN_MILLIS;
+ private static final long RUNNING_TIME_MS =
+ 1 * DateUtils.HOUR_IN_MILLIS + 10 * DateUtils.MINUTE_IN_MILLIS;
private static final int ANOMALY_WAKEUP_COUNT = 500;
- private static final int NORMAL_WAKEUP_COUNT = 50;
+ private static final int NORMAL_WAKEUP_COUNT = 61;
@Mock
private BatteryStatsHelper mBatteryStatsHelper;
@Mock
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowContentResolver.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowContentResolver.java
index 36f170a..2e346a2 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowContentResolver.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowContentResolver.java
@@ -16,6 +16,7 @@
package com.android.settings.testutils.shadow;
+import android.accounts.Account;
import android.content.ContentResolver;
import android.content.SyncAdapterType;
@@ -28,12 +29,20 @@
import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
+import java.util.HashMap;
+import java.util.Map;
+
@Implements(ContentResolver.class)
public class ShadowContentResolver {
+ private static SyncAdapterType[] sSyncAdapterTypes = new SyncAdapterType[0];
+ private static Map<String, Integer> sSyncable = new HashMap<>();
+ private static Map<String, Boolean> sSyncAutomatically = new HashMap<>();
+ private static Map<Integer, Boolean> sMasterSyncAutomatically = new HashMap<>();
+
@Implementation
public static SyncAdapterType[] getSyncAdapterTypesAsUser(int userId) {
- return new SyncAdapterType[0];
+ return sSyncAdapterTypes;
}
@Implementation
@@ -44,4 +53,44 @@
.add(SearchIndexablesContract.NonIndexableKey.COLUMN_KEY_VALUE, "");
return cursor;
}
+
+ @Implementation
+ public static int getIsSyncableAsUser(Account account, String authority, int userId) {
+ return sSyncable.containsKey(authority) ? sSyncable.get(authority) : 1;
+ }
+
+ @Implementation
+ public static boolean getSyncAutomaticallyAsUser(Account account, String authority,
+ int userId) {
+ return sSyncAutomatically.containsKey(authority) ? sSyncAutomatically.get(authority) : true;
+ }
+
+ @Implementation
+ public static boolean getMasterSyncAutomaticallyAsUser(int userId) {
+ return sMasterSyncAutomatically.containsKey(userId)
+ ? sMasterSyncAutomatically.get(userId) : true;
+ }
+
+ public static void setSyncAdapterTypes(SyncAdapterType[] syncAdapterTypes) {
+ sSyncAdapterTypes = syncAdapterTypes;
+ }
+
+ public static void setSyncable(String authority, int syncable) {
+ sSyncable.put(authority, syncable);
+ }
+
+ public static void setSyncAutomatically(String authority, boolean syncAutomatically) {
+ sSyncAutomatically.put(authority, syncAutomatically);
+ }
+
+ public static void setMasterSyncAutomatically(int userId, boolean syncAutomatically) {
+ sMasterSyncAutomatically.put(userId, syncAutomatically);
+ }
+
+ public static void reset() {
+ sSyncable.clear();
+ sSyncAutomatically.clear();
+ sMasterSyncAutomatically.clear();
+ sSyncAdapterTypes = new SyncAdapterType[0];
+ }
}
diff --git a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
index 640c884..a85d591 100644
--- a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
+++ b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
@@ -15,6 +15,24 @@
*/
package com.android.settings.wifi;
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE;
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+import static org.mockito.Mockito.atMost;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
@@ -31,6 +49,7 @@
import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settingslib.wifi.AccessPoint;
+import com.android.settingslib.wifi.TestAccessPointBuilder;
import com.android.settingslib.wifi.WifiTracker;
import com.android.settingslib.wifi.WifiTracker.WifiListener;
import com.android.settingslib.wifi.WifiTrackerFactory;
@@ -46,25 +65,6 @@
import java.util.List;
-import static android.support.test.InstrumentationRegistry.getInstrumentation;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.startsWith;
-
-import static org.mockito.Mockito.atMost;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(AndroidJUnit4.class)
public class WifiSettingsUiTest {
@@ -242,4 +242,34 @@
getInstrumentation().callActivityOnStart(activity);
verify(mWifiTracker, atMost(1)).forceUpdate();
}
+
+ @Test
+ public void changingSecurityStateOnApShouldNotCauseMultipleListItems() {
+ setWifiState(WifiManager.WIFI_STATE_ENABLED);
+ TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext)
+ .setSsid(TEST_SSID).setSecurity(AccessPoint.SECURITY_NONE);
+ AccessPoint open = builder.build();
+
+ builder.setSecurity(AccessPoint.SECURITY_EAP);
+ AccessPoint eap = builder.build();
+
+ builder.setSecurity(AccessPoint.SECURITY_WEP);
+ AccessPoint wep = builder.build();
+
+ // Return a different security state each time getAccessPoints is invoked
+ when(mWifiTracker.getAccessPoints())
+ .thenReturn(Lists.newArrayList(open, eap))
+ .thenReturn(Lists.newArrayList(eap))
+ .thenReturn(Lists.newArrayList(wep));
+
+ launchActivity();
+
+ onView(withText(TEST_SSID)).check(matches(isDisplayed()));
+
+ mWifiListener.onAccessPointsChanged();
+ onView(withText(TEST_SSID)).check(matches(isDisplayed()));
+
+ mWifiListener.onAccessPointsChanged();
+ onView(withText(TEST_SSID)).check(matches(isDisplayed()));
+ }
}