Merge "Removing references to ASEC"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2d2f584..b69cac7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2959,6 +2959,17 @@
android:value="true" />
</activity>
+ <activity android:name=".panel.SettingsPanelActivity"
+ android:label="@string/settings_panel_title"
+ android:theme="@style/Theme.BottomDialog"
+ android:excludeFromRecents="true"
+ android:launchMode="singleTask">
+ <intent-filter>
+ <action android:name="android.settings.SETTINGSPANEL" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
<provider android:name=".slices.SettingsSliceProvider"
android:authorities="com.android.settings.slices;android.settings.slices"
android:exported="true"
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index 0ae001d..1a69b13 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -1177,7 +1177,7 @@
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
- errorLine1=" <color name="homepage_accessibility_background">#5011C1</color>"
+ errorLine1=" <color name="homepage_accessibility_background">#783BE5</color>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
@@ -1209,7 +1209,7 @@
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
- errorLine1=" <color name="homepage_support_background">#26459C</color>"
+ errorLine1=" <color name="homepage_support_background">#3F5FBD</color>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
diff --git a/res/drawable/settings_panel_background.xml b/res/drawable/settings_panel_background.xml
new file mode 100644
index 0000000..36c58e0
--- /dev/null
+++ b/res/drawable/settings_panel_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<inset xmlns:android="http://schemas.android.com/apk/res/android" android:inset="4dp">
+ <shape android:shape="rectangle">
+ <corners android:radius="8dp" />
+ <solid android:color="?android:attr/colorBackground" />
+ </shape>
+</inset>
\ No newline at end of file
diff --git a/res/layout/panel_layout.xml b/res/layout/panel_layout.xml
new file mode 100644
index 0000000..cbdd53f
--- /dev/null
+++ b/res/layout/panel_layout.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License
+ -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/panel_parent_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="24dp"
+ android:paddingRight="24dp"
+ android:paddingBottom="8dp"
+ android:layout_margin="4dp"
+ android:orientation="vertical">
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/settings_panel.xml b/res/layout/settings_panel.xml
new file mode 100644
index 0000000..aec898c
--- /dev/null
+++ b/res/layout/settings_panel.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/main_content"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"/>
\ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 5dfc0b9..f470610 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -121,9 +121,9 @@
<color name="homepage_storage_background">#C14CE6</color>
<color name="homepage_security_background">#0F9D58</color>
<color name="homepage_accounts_background">#F15B8D</color>
- <color name="homepage_accessibility_background">#5011C1</color>
+ <color name="homepage_accessibility_background">#783BE5</color>
<color name="homepage_system_background">#9E9E9E</color>
- <color name="homepage_support_background">#26459C</color>
+ <color name="homepage_support_background">#3F5FBD</color>
<color name="homepage_generic_icon_background">#1A73E8</color>
<color name="homepage_location_background">#2EC7DC</color>
<color name="homepage_about_background">#9FA8DA</color>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 33e8307..9c69bd1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10298,8 +10298,8 @@
<!-- Available networks screen, summary when button disallowed due to permanent automatic mode [CHAR LIMIT=NONE] -->
<string name="manual_mode_disallowed_summary">Unavailable when connected to <xliff:g id="carrier" example="verizon">%1$s</xliff:g></string>
- <!-- Used for EmergencyInfoSlice slice helper class -->
- <string name="emergency_info_contextual_card_summary" translatable="false">Medical info, emergency contacts</string>
+ <!-- Used for EmergencyInfoSlice slice helper class [CHAR LIMIT=NONE]-->
+ <string name="emergency_info_contextual_card_summary">Medical info, emergency contacts</string>
<!-- See more items in contextual homepage [CHAR LIMIT=30]-->
<string name="see_more">See more</string>
@@ -10321,6 +10321,12 @@
<!-- Title for no connected devices in connected device slice. [CHAR LIMIT=NONE] -->
<string name="no_connected_devices">No connected devices</string>
+ <!-- Default title for the settings panel [CHAR LIMIT=NONE] -->
+ <string name="settings_panel_title">Settings Panel</string>
+
+ <!-- Title for the Internet Connectivity dialog (settings panel) with Internet related settings [CHAR LIMIT=50] -->
+ <string name="internet_connectivity_panel_title">Internet Connectivity</string>
+
<!-- UI debug setting: force desktop mode [CHAR LIMIT=50] -->
<string name="force_desktop_mode">Force desktop mode</string>
<!-- UI debug setting: force desktop mode summary [CHAR LIMIT=NONE] -->
diff --git a/res/values/themes.xml b/res/values/themes.xml
index b280482..873216d 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -200,4 +200,8 @@
<item name="cardBackgroundColor">?android:attr/colorBackground</item>
</style>
+ <style name="Theme.BottomDialog" parent="@*android:style/Theme.DeviceDefault.Settings.Dialog">
+ <item name="android:windowBackground">@drawable/settings_panel_background</item>
+ </style>
+
</resources>
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index 8e36e91..c218869 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -64,7 +64,7 @@
settings:useAdminDisabledSummary="true" />
<com.android.settingslib.RestrictedSwitchPreference
- android:key="toggle_airplane"
+ android:key="airplane_mode"
android:title="@string/airplane_mode"
android:icon="@drawable/ic_airplanemode_active"
android:disableDependentsState="true"
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 8ed368c..07f59e2 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -133,15 +133,10 @@
":settings:show_fragment_title_res_package_name";
public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
":settings:show_fragment_title_resid";
- public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
- ":settings:show_fragment_as_shortcut";
public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
":settings:show_fragment_as_subsetting";
- @Deprecated
- public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
-
public static final String META_DATA_KEY_FRAGMENT_CLASS =
"com.android.settings.FRAGMENT_CLASS";
diff --git a/src/com/android/settings/core/SubSettingLauncher.java b/src/com/android/settings/core/SubSettingLauncher.java
index fb730b8..39ecd78 100644
--- a/src/com/android/settings/core/SubSettingLauncher.java
+++ b/src/com/android/settings/core/SubSettingLauncher.java
@@ -84,11 +84,6 @@
return this;
}
- public SubSettingLauncher setIsShortCut(boolean isShortCut) {
- mLaunchRequest.isShortCut = isShortCut;
- return this;
- }
-
public SubSettingLauncher setArguments(Bundle arguments) {
mLaunchRequest.arguments = arguments;
return this;
@@ -159,8 +154,6 @@
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID,
mLaunchRequest.titleResId);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, mLaunchRequest.title);
- intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT,
- mLaunchRequest.isShortCut);
intent.addFlags(mLaunchRequest.flags);
return intent;
}
@@ -195,7 +188,6 @@
int titleResId;
String titleResPackageName;
CharSequence title;
- boolean isShortCut;
int sourceMetricsCategory = -100;
int flags;
Fragment mResultListener;
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
index c723cfd..4c06601 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
@@ -23,7 +23,6 @@
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
-import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
@@ -35,7 +34,6 @@
import androidx.annotation.VisibleForTesting;
import androidx.slice.Slice;
-import com.android.settings.homepage.contextualcards.deviceinfo.BatterySlice;
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
import com.android.settings.wifi.WifiSlice;
import com.android.settingslib.utils.AsyncLoaderCompat;
@@ -52,11 +50,17 @@
private static final String TAG = "ContextualCardLoader";
- private Context mContext;
+ private final ContentObserver mObserver = new ContentObserver(
+ new Handler(Looper.getMainLooper())) {
+ @Override
+ public void onChange(boolean selfChange) {
+ if (isStarted()) {
+ forceLoad();
+ }
+ }
+ };
- public interface CardContentLoaderListener {
- void onFinishCardLoading(List<ContextualCard> contextualCards);
- }
+ private Context mContext;
ContextualCardLoader(Context context) {
super(context);
@@ -86,9 +90,7 @@
public List<ContextualCard> loadInBackground() {
final List<ContextualCard> result = new ArrayList<>();
try (Cursor cursor = getContextualCardsFromProvider()) {
- if (cursor.getCount() == 0) {
- result.addAll(createStaticCards());
- } else {
+ if (cursor.getCount() > 0) {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
final ContextualCard card = new ContextualCard(cursor);
if (card.isCustomCard()) {
@@ -131,24 +133,6 @@
}
@VisibleForTesting
- List<ContextualCard> createStaticCards() {
- final long appVersionCode = getAppVersionCode();
- final String packageName = mContext.getPackageName();
- final double rankingScore = 0.0;
- final List<ContextualCard> result = new ArrayList();
- result.add(new ContextualCard.Builder()
- .setSliceUri(BatterySlice.BATTERY_CARD_URI)
- .setName(BatterySlice.PATH_BATTERY_INFO)
- .setPackageName(packageName)
- .setRankingScore(rankingScore)
- .setAppVersion(appVersionCode)
- .setCardType(ContextualCard.CardType.SLICE)
- .setIsHalfWidth(false)
- .build());
- return result;
- }
-
- @VisibleForTesting
List<ContextualCard> filterEligibleCards(List<ContextualCard> candidates) {
return candidates.stream().filter(card -> isCardEligibleToDisplay(card))
.collect(Collectors.toList());
@@ -191,23 +175,7 @@
.count();
}
- private long getAppVersionCode() {
- try {
- return mContext.getPackageManager().getPackageInfo(mContext.getPackageName(),
- 0 /* flags */).getLongVersionCode();
- } catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, "Invalid package name for context", e);
- }
- return -1L;
+ public interface CardContentLoaderListener {
+ void onFinishCardLoading(List<ContextualCard> contextualCards);
}
-
- private final ContentObserver mObserver = new ContentObserver(
- new Handler(Looper.getMainLooper())) {
- @Override
- public void onChange(boolean selfChange) {
- if (isStarted()) {
- forceLoad();
- }
- }
- };
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
index dabc88c..a4a8419 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
@@ -24,10 +24,14 @@
import com.android.settings.homepage.contextualcards.ContextualCard.CardType;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardController;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardRenderer;
+import com.android.settings.homepage.contextualcards.conditional
+ .ConditionHeaderContextualCardRenderer;
import com.android.settings.homepage.contextualcards.legacysuggestion
.LegacySuggestionContextualCardController;
import com.android.settings.homepage.contextualcards.legacysuggestion
.LegacySuggestionContextualCardRenderer;
+import com.android.settings.homepage.contextualcards.conditional
+ .ConditionFooterContextualCardRenderer;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardController;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer;
@@ -83,6 +87,14 @@
SliceContextualCardRenderer.VIEW_TYPE,
SliceContextualCardController.class,
SliceContextualCardRenderer.class));
+ add(new ControllerRendererMapping(CardType.CONDITIONAL_FOOTER,
+ ConditionFooterContextualCardRenderer.VIEW_TYPE,
+ ConditionContextualCardController.class,
+ ConditionFooterContextualCardRenderer.class));
+ add(new ControllerRendererMapping(CardType.CONDITIONAL_HEADER,
+ ConditionHeaderContextualCardRenderer.VIEW_TYPE,
+ ConditionContextualCardController.class,
+ ConditionHeaderContextualCardRenderer.class));
}};
public static Class<? extends ContextualCardController> getCardControllerClass(
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardsAdapter.java b/src/com/android/settings/homepage/contextualcards/ContextualCardsAdapter.java
index 0a8749d..10bed90 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardsAdapter.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardsAdapter.java
@@ -129,5 +129,7 @@
// Adding items to empty list, should animate.
mRecyclerView.scheduleLayoutAnimation();
}
+
+ //TODO(b/119465242): flickering conditional cards after collapsing/expanding
}
}
diff --git a/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java b/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
index 931bfb7..992d4c9 100644
--- a/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
+++ b/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
@@ -26,10 +26,14 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardController;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardRenderer;
+import com.android.settings.homepage.contextualcards.conditional
+ .ConditionHeaderContextualCardRenderer;
import com.android.settings.homepage.contextualcards.legacysuggestion
.LegacySuggestionContextualCardController;
import com.android.settings.homepage.contextualcards.legacysuggestion
.LegacySuggestionContextualCardRenderer;
+import com.android.settings.homepage.contextualcards.conditional
+ .ConditionFooterContextualCardRenderer;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardController;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer;
@@ -131,6 +135,12 @@
} else if (LegacySuggestionContextualCardRenderer.class == clz) {
return new LegacySuggestionContextualCardRenderer(context,
this /* controllerRendererPool */);
+ } else if (ConditionFooterContextualCardRenderer.class == clz) {
+ return new ConditionFooterContextualCardRenderer(context,
+ this /*controllerRendererPool*/);
+ } else if (ConditionHeaderContextualCardRenderer.class == clz) {
+ return new ConditionHeaderContextualCardRenderer(context,
+ this /*controllerRendererPool*/);
}
return null;
}
diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
index db3fddc..5ff3e90 100644
--- a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
+++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
@@ -20,7 +20,6 @@
import android.annotation.Nullable;
-import com.android.settings.homepage.contextualcards.deviceinfo.BatterySlice;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
@@ -44,12 +43,6 @@
.setCardName(KEY_WIFI)
.setCardCategory(ContextualCard.Category.IMPORTANT)
.build();
- final ContextualCard batteryInfoCard =
- ContextualCard.newBuilder()
- .setSliceUri(BatterySlice.BATTERY_CARD_URI.toString())
- .setCardName(BatterySlice.PATH_BATTERY_INFO)
- .setCardCategory(ContextualCard.Category.DEFAULT)
- .build();
final ContextualCard connectedDeviceCard =
ContextualCard.newBuilder()
.setSliceUri(ConnectedDeviceSlice.CONNECTED_DEVICE_URI.toString())
@@ -70,7 +63,6 @@
.build();
final ContextualCardList cards = ContextualCardList.newBuilder()
.addCard(wifiCard)
- .addCard(batteryInfoCard)
.addCard(connectedDeviceCard)
.addCard(lowStorageCard)
.addCard(batteryFixCard)
@@ -78,4 +70,4 @@
return cards;
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java
index 4eb4c6b..02854c2 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardController.java
@@ -19,6 +19,8 @@
import android.content.Context;
import android.util.ArrayMap;
+import androidx.annotation.VisibleForTesting;
+
import com.android.settings.homepage.contextualcards.ContextualCard;
import com.android.settings.homepage.contextualcards.ContextualCardController;
import com.android.settings.homepage.contextualcards.ContextualCardUpdateListener;
@@ -26,8 +28,11 @@
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* This controller triggers the loading of conditional cards and monitors state changes to
@@ -35,8 +40,12 @@
*/
public class ConditionContextualCardController implements ContextualCardController,
ConditionListener, LifecycleObserver, OnStart, OnStop {
+ public static final int EXPANDING_THRESHOLD = 2;
+ private static final double UNSUPPORTED_RANKING = -99999.0;
private static final String TAG = "ConditionCtxCardCtrl";
+ private static final String CONDITION_FOOTER = "condition_footer";
+ private static final String CONDITION_HEADER = "condition_header";
private final Context mContext;
private final ConditionManager mConditionManager;
@@ -93,20 +102,102 @@
@Override
public void onConditionsChanged() {
+ if (mListener == null) {
+ return;
+ }
final List<ContextualCard> conditionCards = mConditionManager.getDisplayableCards();
+ final Map<Integer, List<ContextualCard>> conditionalCards =
+ buildConditionalCardsWithFooterOrHeader(conditionCards);
+ mListener.onContextualCardUpdated(conditionalCards);
- final boolean isOddNumber = conditionCards.size() % 2 == 1;
+ }
+
+ /**
+ * According to conditional cards, build a map that includes conditional cards, header card and
+ * footer card.
+ *
+ * Rules:
+ * - The last one of conditional cards will be displayed as a full-width card if the size of
+ * conditional cards is odd number. The rest will be displayed as a half-width card.
+ * - By default conditional cards will be collapsed if there are more than TWO cards.
+ *
+ * For examples:
+ * - Only one conditional card: Returns a map that contains a full-width conditional card,
+ * no header card and no footer card.
+ * <p>Map{(CONDITIONAL, conditionCards), (CONDITIONAL_FOOTER, EMPTY_LIST), (CONDITIONAL_HEADER,
+ * EMPTY_LIST)}</p>
+ * - Two conditional cards: Returns a map that contains two half-width conditional cards,
+ * no header card and no footer card.
+ * <p>Map{(CONDITIONAL, conditionCards), (CONDITIONAL_FOOTER, EMPTY_LIST), (CONDITIONAL_HEADER,
+ * EMPTY_LIST)}</p>
+ * - Three conditional cards or above: By default, returns a map that contains no conditional
+ * card, one header card and no footer card. If conditional cards are expanded, will returns a
+ * map that contains three conditional cards, no header card and one footer card.
+ * If expanding conditional cards:
+ * <p>Map{(CONDITIONAL, conditionCards), (CONDITIONAL_FOOTER, footerCards), (CONDITIONAL_HEADER,
+ * EMPTY_LIST)}</p>
+ * If collapsing conditional cards:
+ * <p>Map{(CONDITIONAL, EMPTY_LIST), (CONDITIONAL_FOOTER, EMPTY_LIST), (CONDITIONAL_HEADER,
+ * headerCards)}</p>
+ *
+ * @param conditionCards A list of conditional cards that are from {@link
+ * ConditionManager#getDisplayableCards}
+ * @return A map contained three types of lists
+ */
+ @VisibleForTesting
+ Map<Integer, List<ContextualCard>> buildConditionalCardsWithFooterOrHeader(
+ List<ContextualCard> conditionCards) {
+ final Map<Integer, List<ContextualCard>> conditionalCards = new ArrayMap<>();
+ conditionalCards.put(ContextualCard.CardType.CONDITIONAL,
+ getExpandedConditionalCards(conditionCards));
+ conditionalCards.put(ContextualCard.CardType.CONDITIONAL_FOOTER,
+ getConditionalFooterCard(conditionCards));
+ conditionalCards.put(ContextualCard.CardType.CONDITIONAL_HEADER,
+ getConditionalHeaderCard(conditionCards));
+ return conditionalCards;
+ }
+
+ private List<ContextualCard> getExpandedConditionalCards(List<ContextualCard> conditionCards) {
+ if (conditionCards.isEmpty() || (conditionCards.size() > EXPANDING_THRESHOLD
+ && !mIsExpanded)) {
+ return Collections.EMPTY_LIST;
+ }
+ final List<ContextualCard> expandedCards = conditionCards.stream().collect(
+ Collectors.toList());
+ final boolean isOddNumber = expandedCards.size() % 2 == 1;
if (isOddNumber) {
- final int lastIndex = conditionCards.size() - 1;
- final ConditionalContextualCard card = (ConditionalContextualCard) conditionCards
- .get(lastIndex);
- conditionCards.set(lastIndex, card.mutate().setIsHalfWidth(false).build());
+ final int lastIndex = expandedCards.size() - 1;
+ final ConditionalContextualCard card =
+ (ConditionalContextualCard) expandedCards.get(lastIndex);
+ expandedCards.set(lastIndex, card.mutate().setIsHalfWidth(false).build());
}
+ return expandedCards;
+ }
- if (mListener != null) {
- final Map<Integer, List<ContextualCard>> conditionalCards = new ArrayMap<>();
- conditionalCards.put(ContextualCard.CardType.CONDITIONAL, conditionCards);
- mListener.onContextualCardUpdated(conditionalCards);
+ private List<ContextualCard> getConditionalFooterCard(List<ContextualCard> conditionCards) {
+ if (!conditionCards.isEmpty() && mIsExpanded
+ && conditionCards.size() > EXPANDING_THRESHOLD) {
+ final List<ContextualCard> footerCards = new ArrayList<>();
+ footerCards.add(new ConditionFooterContextualCard.Builder()
+ .setName(CONDITION_FOOTER)
+ .setRankingScore(UNSUPPORTED_RANKING)
+ .build());
+ return footerCards;
}
+ return Collections.EMPTY_LIST;
+ }
+
+ private List<ContextualCard> getConditionalHeaderCard(List<ContextualCard> conditionCards) {
+ if (!conditionCards.isEmpty() && !mIsExpanded
+ && conditionCards.size() > EXPANDING_THRESHOLD) {
+ final List<ContextualCard> headerCards = new ArrayList<>();
+ headerCards.add(new ConditionHeaderContextualCard.Builder()
+ .setConditionalCards(conditionCards)
+ .setName(CONDITION_HEADER)
+ .setRankingScore(UNSUPPORTED_RANKING)
+ .build());
+ return headerCards;
+ }
+ return Collections.EMPTY_LIST;
}
}
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCard.java b/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCard.java
index f1a0fed..b72f9f7 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCard.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCard.java
@@ -16,9 +16,12 @@
package com.android.settings.homepage.contextualcards.conditional;
+import android.text.TextUtils;
+
import com.android.settings.homepage.contextualcards.ContextualCard;
import java.util.List;
+import java.util.Objects;
/**
* Data class representing a condition header {@link ContextualCard}.
@@ -44,6 +47,25 @@
return mConditionalCards;
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), mConditionalCards);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof ConditionHeaderContextualCard)) {
+ return false;
+ }
+ final ConditionHeaderContextualCard that = (ConditionHeaderContextualCard) obj;
+
+ return TextUtils.equals(getName(), that.getName()) && mConditionalCards.equals(
+ that.mConditionalCards);
+ }
+
public static class Builder extends ContextualCard.Builder {
private List<ContextualCard> mConditionalCards;
diff --git a/src/com/android/settings/network/AirplaneModePreferenceController.java b/src/com/android/settings/network/AirplaneModePreferenceController.java
index 80cca2c..1c4e351 100644
--- a/src/com/android/settings/network/AirplaneModePreferenceController.java
+++ b/src/com/android/settings/network/AirplaneModePreferenceController.java
@@ -93,7 +93,7 @@
@Override
public boolean isSliceable() {
- return TextUtils.equals(getPreferenceKey(), "toggle_airplane");
+ return true;
}
@Override
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index 38d48c8..02468b8 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -29,6 +29,7 @@
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
+import com.android.settings.panel.PanelFeatureProvider;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.slices.SlicesFeatureProvider;
@@ -105,6 +106,8 @@
public abstract AccountFeatureProvider getAccountFeatureProvider();
+ public abstract PanelFeatureProvider getPanelFeatureProvider();
+
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index f74043f..8d6d4b6 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -42,6 +42,8 @@
import com.android.settings.gestures.AssistGestureFeatureProviderImpl;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
+import com.android.settings.panel.PanelFeatureProvider;
+import com.android.settings.panel.PanelFeatureProviderImpl;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.search.SearchFeatureProviderImpl;
import com.android.settings.security.SecurityFeatureProvider;
@@ -72,6 +74,7 @@
private UserFeatureProvider mUserFeatureProvider;
private SlicesFeatureProvider mSlicesFeatureProvider;
private AccountFeatureProvider mAccountFeatureProvider;
+ private PanelFeatureProvider mPanelFeatureProvider;
@Override
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -209,4 +212,12 @@
}
return mAccountFeatureProvider;
}
+
+ @Override
+ public PanelFeatureProvider getPanelFeatureProvider() {
+ if (mPanelFeatureProvider == null) {
+ mPanelFeatureProvider = new PanelFeatureProviderImpl();
+ }
+ return mPanelFeatureProvider;
+ }
}
diff --git a/src/com/android/settings/panel/InternetConnectivityPanel.java b/src/com/android/settings/panel/InternetConnectivityPanel.java
new file mode 100644
index 0000000..b6fe53b
--- /dev/null
+++ b/src/com/android/settings/panel/InternetConnectivityPanel.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.panel;
+
+import androidx.annotation.VisibleForTesting;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.provider.SettingsSlicesContract;
+
+import com.android.settings.R;
+import com.android.settings.wifi.WifiSlice;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents the Internet Connectivity Panel.
+ *
+ * <p>
+ * Displays Wifi (full Slice) and Airplane mode.
+ * </p>
+ */
+public class InternetConnectivityPanel implements PanelContent {
+
+ @VisibleForTesting
+ static final Uri AIRPLANE_URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SettingsSlicesContract.AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath(SettingsSlicesContract.KEY_AIRPLANE_MODE)
+ .build();
+
+ private final Context mContext;
+
+ public static InternetConnectivityPanel create(Context context) {
+ return new InternetConnectivityPanel(context);
+ }
+
+ private InternetConnectivityPanel(Context context) {
+ mContext = context.getApplicationContext();
+ }
+
+ @Override
+ public String getTitle() {
+ return (String) mContext.getText(R.string.internet_connectivity_panel_title);
+ }
+
+ @Override
+ public List<Uri> getSlices() {
+ final List<Uri> uris = new ArrayList<>();
+ uris.add(WifiSlice.WIFI_URI);
+ uris.add(AIRPLANE_URI);
+ return uris;
+ }
+
+ @Override
+ public Intent getSeeMoreIntent() {
+ return null;
+ }
+}
diff --git a/src/com/android/settings/panel/PanelContent.java b/src/com/android/settings/panel/PanelContent.java
new file mode 100644
index 0000000..bd84c2f
--- /dev/null
+++ b/src/com/android/settings/panel/PanelContent.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.panel;
+
+import android.content.Intent;
+import android.net.Uri;
+
+import java.util.List;
+
+/**
+ * Represents the data class needed to create a Settings Panel. See {@link PanelFragment}.
+ */
+public interface PanelContent {
+
+ /**
+ * @return a string for the title of the Panel.
+ */
+ CharSequence getTitle();
+
+ /**
+ * @return an ordered list of the Slices to be displayed in the Panel. The first item in the
+ * list is shown on top of the Panel.
+ */
+ List<Uri> getSlices();
+
+
+ /**
+ * @return an {@link Intent} to the full content in Settings that is summarized by the Panel.
+ *
+ * <p>
+ * For example, for the connectivity panel you would intent to the Network & Internet page.
+ * </p>
+ */
+ Intent getSeeMoreIntent();
+}
diff --git a/src/com/android/settings/panel/PanelFeatureProvider.java b/src/com/android/settings/panel/PanelFeatureProvider.java
new file mode 100644
index 0000000..7d6c558
--- /dev/null
+++ b/src/com/android/settings/panel/PanelFeatureProvider.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.panel;
+
+import android.content.Context;
+
+public interface PanelFeatureProvider {
+
+ /**
+ * Returns {@link PanelContent} as specified by the {@param panelType}.
+ */
+ PanelContent getPanel(Context context, String panelType);
+}
diff --git a/src/com/android/settings/panel/PanelFeatureProviderImpl.java b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
new file mode 100644
index 0000000..2e84078
--- /dev/null
+++ b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.panel;
+
+import android.content.Context;
+
+public class PanelFeatureProviderImpl implements PanelFeatureProvider {
+
+ @Override
+ public PanelContent getPanel(Context context, String panelType) {
+ switch (panelType) {
+ case SettingsPanelActivity.PANEL_TYPE_WIFI:
+ return InternetConnectivityPanel.create(context);
+ }
+
+ throw new IllegalStateException("No matching panel for: " + panelType);
+ }
+}
diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java
new file mode 100644
index 0000000..bbdaec3
--- /dev/null
+++ b/src/com/android/settings/panel/PanelFragment.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.panel;
+
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import android.widget.LinearLayout;
+
+import androidx.lifecycle.LiveData;
+import androidx.slice.Slice;
+import androidx.slice.widget.SliceLiveData;
+import androidx.slice.widget.SliceView;
+
+import com.android.settings.R;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+
+import com.android.settings.overlay.FeatureFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PanelFragment extends Fragment {
+
+ private static final String TAG = "PanelFragment";
+
+ private List<SliceView> mSliceViewList;
+ private List<LiveData<Slice>> mSliceDataList;
+ private LinearLayout mPanelLayout;
+
+ public PanelFragment() {
+ mSliceViewList = new ArrayList<>();
+ mSliceDataList = new ArrayList<>();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ final FragmentActivity activity = getActivity();
+ final View view = inflater.inflate(R.layout.panel_layout, container, false);
+
+ mPanelLayout = view.findViewById(R.id.panel_parent_layout);
+ final Bundle arguments = getArguments();
+
+ final String panelType = arguments.getString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT);
+
+ final PanelContent panel = FeatureFactory.getFactory(activity)
+ .getPanelFeatureProvider()
+ .getPanel(activity, panelType);
+
+ activity.setTitle(panel.getTitle());
+
+
+ for (Uri uri : panel.getSlices()) {
+ final SliceView sliceView = new SliceView(activity);
+ mPanelLayout.addView(sliceView);
+ final LiveData<Slice> liveData = SliceLiveData.fromUri(activity, uri);
+ liveData.observe(this /* lifecycleOwner */, sliceView);
+
+ mSliceDataList.add(liveData);
+ mSliceViewList.add(sliceView);
+ }
+
+ return view;
+ }
+}
diff --git a/src/com/android/settings/panel/SettingsPanelActivity.java b/src/com/android/settings/panel/SettingsPanelActivity.java
new file mode 100644
index 0000000..db1f60d
--- /dev/null
+++ b/src/com/android/settings/panel/SettingsPanelActivity.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.panel;
+
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.Bundle;
+
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.Window;
+import android.view.WindowManager;
+
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+
+import com.android.settings.R;
+
+/**
+ * Dialog Activity to host Settings Slices.
+ *
+ * TODO link to action / framework API
+ */
+public class SettingsPanelActivity extends FragmentActivity {
+
+ private final String TAG = "panel_activity";
+
+ /**
+ * Key specifying which Panel the app is requesting.
+ */
+ public static final String KEY_PANEL_TYPE_ARGUMENT = "PANEL_TYPE_ARGUMENT";
+
+
+ // TODO (b/117804442) move to framework
+ public static final String EXTRA_PANEL_TYPE = "com.android.settings.panel.extra";
+
+ // TODO (b/117804442) move to framework
+ public static final String PANEL_TYPE_WIFI = "wifi_panel";
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final ComponentName callingActivityName = getCallingActivity();
+
+ if (callingActivityName == null) {
+ Log.e(TAG, "Must start with startActivityForResult. Closing.");
+ finish();
+ return;
+ }
+
+ final Intent callingIntent = getIntent();
+ if (callingIntent == null) {
+ Log.e(TAG, "Null intent, closing Panel Activity");
+ finish();
+ return;
+ }
+
+ final String typeExtra = callingIntent.getStringExtra(EXTRA_PANEL_TYPE);
+ if (TextUtils.isEmpty(typeExtra)) {
+ Log.e(TAG, "No intent passed, closing Panel Activity");
+ return;
+ }
+
+ setContentView(R.layout.settings_panel);
+
+ // Move the window to the bottom of screen, and make it take up the entire screen width.
+ final Window window = getWindow();
+ window.setGravity(Gravity.BOTTOM);
+ window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
+ WindowManager.LayoutParams.WRAP_CONTENT);
+
+
+ final Bundle bundle = new Bundle();
+ bundle.putString(KEY_PANEL_TYPE_ARGUMENT, typeExtra);
+
+ final PanelFragment panelFragment = new PanelFragment();
+ panelFragment.setArguments(bundle);
+
+ final FragmentManager fragmentManager = getSupportFragmentManager();
+ final Fragment fragment = fragmentManager.findFragmentById(R.id.main_content);
+ if (fragment == null) {
+ fragmentManager.beginTransaction().add(R.id.main_content, panelFragment).commit();
+ }
+ }
+}
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index 14a918e..cbb3593 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -19,8 +19,7 @@
import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD;
import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD;
-import static com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment
- .RESULT_FINISHED;
+import static com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment.RESULT_FINISHED;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Activity;
@@ -77,12 +76,6 @@
public Intent getIntent() {
Intent modIntent = new Intent(super.getIntent());
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getFragmentClass().getName());
-
- String action = modIntent.getAction();
- if (ACTION_SET_NEW_PASSWORD.equals(action)
- || ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(action)) {
- modIntent.putExtra(EXTRA_HIDE_DRAWER, true);
- }
return modIntent;
}
@@ -154,7 +147,6 @@
private FingerprintManager mFingerprintManager;
private FaceManager mFaceManager;
private int mUserId;
- private boolean mHideDrawer = false;
private ManagedLockPasswordProvider mManagedPasswordProvider;
private boolean mIsSetNewPassword = false;
private UserManager mUserManager;
@@ -194,7 +186,6 @@
mUserPassword = getActivity().getIntent().getStringExtra(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
}
- mHideDrawer = getActivity().getIntent().getBooleanExtra(EXTRA_HIDE_DRAWER, false);
mHasChallenge = getActivity().getIntent().getBooleanExtra(
ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false);
@@ -345,7 +336,6 @@
mForFingerprint);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE,
mForFace);
- intent.putExtra(EXTRA_HIDE_DRAWER, mHideDrawer);
startActivityForResult(
intent,
mIsSetNewPassword && mHasChallenge
@@ -748,9 +738,6 @@
} else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
intent = getLockPatternIntent();
}
- if (intent != null) {
- intent.putExtra(EXTRA_HIDE_DRAWER, mHideDrawer);
- }
return intent;
}
diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java
index cd04193..1ef95da 100644
--- a/src/com/android/settings/password/ChooseLockPassword.java
+++ b/src/com/android/settings/password/ChooseLockPassword.java
@@ -190,7 +190,6 @@
private int mPasswordMinNonLetter = 0;
private int mPasswordMinLengthToFulfillAllPolicies = 0;
protected int mUserId;
- private boolean mHideDrawer = false;
private byte[] mPasswordHistoryHashFactor;
/**
* Password requirements that we need to verify.
@@ -375,7 +374,6 @@
mForFace = intent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false);
processPasswordRequirements(intent);
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
- mHideDrawer = getActivity().getIntent().getBooleanExtra(EXTRA_HIDE_DRAWER, false);
if (intent.getBooleanExtra(
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT, false)) {
@@ -975,7 +973,6 @@
if (!wasSecureBefore) {
Intent intent = getRedactionInterstitialIntent(getActivity());
if (intent != null) {
- intent.putExtra(EXTRA_HIDE_DRAWER, mHideDrawer);
startActivity(intent);
}
}
diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java
index 4e4730f..0d06ed8 100644
--- a/src/com/android/settings/password/ChooseLockPattern.java
+++ b/src/com/android/settings/password/ChooseLockPattern.java
@@ -196,7 +196,6 @@
private TextView mFooterLeftButton;
private TextView mFooterRightButton;
protected List<LockPatternView.Cell> mChosenPattern = null;
- private boolean mHideDrawer = false;
private ColorStateList mDefaultHeaderColorList;
// ScrollView that contains title and header, only exist in land mode
@@ -464,7 +463,6 @@
w.start(mChooseLockSettingsHelper.utils(), required,
false, 0, LockPatternUtils.stringToPattern(current), current, mUserId);
}
- mHideDrawer = getActivity().getIntent().getBooleanExtra(EXTRA_HIDE_DRAWER, false);
mForFingerprint = intent.getBooleanExtra(
ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
mForFace = intent.getBooleanExtra(
@@ -808,7 +806,6 @@
if (!wasSecureBefore) {
Intent intent = getRedactionInterstitialIntent(getActivity());
if (intent != null) {
- intent.putExtra(EXTRA_HIDE_DRAWER, mHideDrawer);
startActivity(intent);
}
}
diff --git a/src/com/android/settings/password/ChooseLockSettingsHelper.java b/src/com/android/settings/password/ChooseLockSettingsHelper.java
index d5182b3..938dec4 100644
--- a/src/com/android/settings/password/ChooseLockSettingsHelper.java
+++ b/src/com/android/settings/password/ChooseLockSettingsHelper.java
@@ -391,8 +391,6 @@
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_RETURN_CREDENTIALS, returnCredentials);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, hasChallenge);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
- // we should never have a drawer when confirming device credentials.
- intent.putExtra(SettingsActivity.EXTRA_HIDE_DRAWER, true);
intent.putExtra(Intent.EXTRA_USER_ID, userId);
intent.putExtra(KeyguardManager.EXTRA_ALTERNATE_BUTTON_LABEL, alternateButton);
if (extras != null) {
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index fa669bb..952fc8b 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -427,7 +427,7 @@
try {
sliceData = mSlicesDatabaseAccessor.getSliceDataFromUri(uri);
} catch (IllegalStateException e) {
- Log.d(TAG, "Could not create slicedata for uri: " + uri);
+ Log.d(TAG, "Could not create slicedata for uri: " + uri, e);
return;
}
diff --git a/src/com/android/settings/slices/SlicesFeatureProviderImpl.java b/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
index 39d385e..508eb1c 100644
--- a/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
+++ b/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.android.settings.slices;
import android.content.Context;
diff --git a/tests/robotests/assets/grandfather_not_implementing_instrumentable b/tests/robotests/assets/grandfather_not_implementing_instrumentable
index 625d9ff..04ef0ef 100644
--- a/tests/robotests/assets/grandfather_not_implementing_instrumentable
+++ b/tests/robotests/assets/grandfather_not_implementing_instrumentable
@@ -6,4 +6,5 @@
com.android.settings.RestrictedListPreference$RestrictedListPreferenceDialogFragment
com.android.settings.password.ConfirmDeviceCredentialBaseFragment$LastTryDialog
com.android.settings.password.CredentialCheckResultTracker
-com.android.settings.dashboard.profileselector.ProfileSelectDialog
\ No newline at end of file
+com.android.settings.dashboard.profileselector.ProfileSelectDialog
+com.android.settings.panel.PanelFragment
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardLoaderTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardLoaderTest.java
index f9eda49..e8cb674 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardLoaderTest.java
@@ -40,7 +40,6 @@
import org.robolectric.shadows.ShadowContentResolver;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -61,17 +60,6 @@
}
@Test
- public void createStaticCards_shouldContainCorrectCards() {
- final Uri batteryInfo = BatterySlice.BATTERY_CARD_URI;
- final List<Uri> expectedUris = Arrays.asList(batteryInfo);
-
- final List<Uri> actualCardUris = mContextualCardLoader.createStaticCards().stream().map(
- ContextualCard::getSliceUri).collect(Collectors.toList());
-
- assertThat(actualCardUris).containsExactlyElementsIn(expectedUris);
- }
-
- @Test
public void isCardEligibleToDisplay_customCard_returnTrue() {
final ContextualCard customCard = new ContextualCard.Builder()
.setName("custom_card")
@@ -224,4 +212,4 @@
.build());
return cards;
}
-}
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardControllerTest.java
index ab82a54..688e94c 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardControllerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardControllerTest.java
@@ -16,6 +16,8 @@
package com.android.settings.homepage.contextualcards.conditional;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -25,6 +27,7 @@
import android.content.Context;
import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ContextualCard.CardType;
import com.android.settings.homepage.contextualcards.ContextualCardUpdateListener;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -38,6 +41,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
@RunWith(SettingsRobolectricTestRunner.class)
public class ConditionContextualCardControllerTest {
@@ -95,4 +99,81 @@
verify(mListener, never()).onContextualCardUpdated(any());
}
+
+ @Test
+ public void getConditionalCards_hasEmptyConditionCards_shouldReturnThreeEmptyList() {
+ final Map<Integer, List<ContextualCard>> conditionalCards =
+ mController.buildConditionalCardsWithFooterOrHeader(generateConditionCards(0));
+
+ assertThat(conditionalCards).hasSize(3);
+ for (@CardType int cardType : conditionalCards.keySet()) {
+ assertThat(conditionalCards.get(cardType)).isEmpty();
+ }
+ }
+
+ @Test
+ public void getConditionalCards_hasOneConditionCard_shouldGetOneFullWidthCard() {
+ final Map<Integer, List<ContextualCard>> conditionalCards =
+ mController.buildConditionalCardsWithFooterOrHeader(generateConditionCards(1));
+
+ assertThat(conditionalCards).hasSize(3);
+ assertThat(conditionalCards.get(CardType.CONDITIONAL)).hasSize(1);
+ assertThat(conditionalCards.get(CardType.CONDITIONAL).get(0).isHalfWidth()).isFalse();
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_HEADER)).isEmpty();
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_FOOTER)).isEmpty();
+ }
+
+ @Test
+ public void getConditionalCards_hasTwoConditionCards_shouldGetTwoHalfWidthCards() {
+ final Map<Integer, List<ContextualCard>> conditionalCards =
+ mController.buildConditionalCardsWithFooterOrHeader(generateConditionCards(2));
+
+ assertThat(conditionalCards).hasSize(3);
+ assertThat(conditionalCards.get(CardType.CONDITIONAL)).hasSize(2);
+ for (ContextualCard card : conditionalCards.get(CardType.CONDITIONAL)) {
+ assertThat(card.isHalfWidth()).isTrue();
+ }
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_HEADER)).isEmpty();
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_FOOTER)).isEmpty();
+ }
+
+ @Test
+ public void getConditionalCards_hasThreeCardsAndExpanded_shouldGetThreeCardsWithFooter() {
+ mController.setIsExpanded(true);
+ final Map<Integer, List<ContextualCard>> conditionalCards =
+ mController.buildConditionalCardsWithFooterOrHeader(generateConditionCards(3));
+
+ assertThat(conditionalCards).hasSize(3);
+ assertThat(conditionalCards.get(CardType.CONDITIONAL)).hasSize(3);
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_HEADER)).isEmpty();
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_FOOTER)).isNotEmpty();
+ }
+
+ @Test
+ public void getConditionalCards_hasThreeCardsAndCollapsed_shouldGetOneConditionalHeader() {
+ mController.setIsExpanded(false);
+ final Map<Integer, List<ContextualCard>> conditionalCards =
+ mController.buildConditionalCardsWithFooterOrHeader(generateConditionCards(3));
+
+ assertThat(conditionalCards).hasSize(3);
+ assertThat(conditionalCards.get(CardType.CONDITIONAL)).isEmpty();
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_HEADER)).isNotEmpty();
+ assertThat(conditionalCards.get(CardType.CONDITIONAL_FOOTER)).isEmpty();
+ }
+
+ private List<ContextualCard> generateConditionCards(int numberOfCondition) {
+ final List<ContextualCard> conditionCards = new ArrayList<>();
+ for (int i = 0; i < numberOfCondition; i++) {
+ conditionCards.add(new ConditionalContextualCard.Builder()
+ .setConditionId(123 + i)
+ .setMetricsConstant(1)
+ .setActionText("test_action" + i)
+ .setName("test_name" + i)
+ .setTitleText("test_title" + i)
+ .setSummaryText("test_summary" + i)
+ .setIsHalfWidth(true)
+ .build());
+ }
+ return conditionCards;
+ }
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionFooterContextualCardRendererTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionFooterContextualCardRendererTest.java
new file mode 100644
index 0000000..524a690
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionFooterContextualCardRendererTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.homepage.contextualcards.conditional;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ControllerRendererPool;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ConditionFooterContextualCardRendererTest {
+
+ @Mock
+ private ControllerRendererPool mControllerRendererPool;
+ @Mock
+ private ConditionContextualCardController mController;
+ private Context mContext;
+ private ConditionFooterContextualCardRenderer mRenderer;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mRenderer = new ConditionFooterContextualCardRenderer(mContext, mControllerRendererPool);
+ }
+
+ @Test
+ public void bindView_shouldSetClickListener() {
+ final int viewType = mRenderer.getViewType(false /* isHalfWidth */);
+ final RecyclerView recyclerView = new RecyclerView(mContext);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+ final View view = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
+ final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(view);
+ when(mControllerRendererPool.getController(mContext,
+ ContextualCard.CardType.CONDITIONAL_FOOTER)).thenReturn(mController);
+
+ mRenderer.bindView(viewHolder, generateConditionFooterContextualCard());
+
+ assertThat(viewHolder.itemView).isNotNull();
+ assertThat(viewHolder.itemView.hasOnClickListeners()).isTrue();
+ }
+
+ @Test
+ public void bindView_clickView_shouldSetTrueToIsConditionExpanded() {
+ final int viewType = mRenderer.getViewType(false /* isHalfWidth */);
+ final RecyclerView recyclerView = new RecyclerView(mContext);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+ final View view = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
+ final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(view);
+ when(mControllerRendererPool.getController(mContext,
+ ContextualCard.CardType.CONDITIONAL_FOOTER)).thenReturn(mController);
+
+ mRenderer.bindView(viewHolder, generateConditionFooterContextualCard());
+
+ assertThat(viewHolder.itemView).isNotNull();
+ viewHolder.itemView.performClick();
+
+ verify(mController).setIsExpanded(false);
+ verify(mController).onConditionsChanged();
+ }
+
+ private ContextualCard generateConditionFooterContextualCard() {
+ return new ConditionFooterContextualCard.Builder()
+ .setName("test_condition_footer")
+ .setRankingScore(-9999.0)
+ .build();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionFooterContextualCardTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionFooterContextualCardTest.java
new file mode 100644
index 0000000..783ae9f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionFooterContextualCardTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.homepage.contextualcards.conditional;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ConditionFooterContextualCardTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void newInstance_changeCardType_shouldCrash() {
+ new ConditionFooterContextualCard.Builder()
+ .setCardType(ContextualCard.CardType.LEGACY_SUGGESTION)
+ .build();
+ }
+
+ @Test
+ public void getCardType_shouldAlwaysBeConditionalFooter() {
+ assertThat(new ConditionFooterContextualCard.Builder().build().getCardType())
+ .isEqualTo(ContextualCard.CardType.CONDITIONAL_FOOTER);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCardRendererTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCardRendererTest.java
new file mode 100644
index 0000000..dbe5544
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCardRendererTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.homepage.contextualcards.conditional;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ControllerRendererPool;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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 java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ConditionHeaderContextualCardRendererTest {
+
+ @Mock
+ private ControllerRendererPool mControllerRendererPool;
+ @Mock
+ private ConditionContextualCardController mController;
+ private Context mContext;
+ private ConditionHeaderContextualCardRenderer mRenderer;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mRenderer = new ConditionHeaderContextualCardRenderer(mContext, mControllerRendererPool);
+ }
+
+ @Test
+ public void bindView_shouldSetClickListener() {
+ final int viewType = mRenderer.getViewType(false /* isHalfWidth */);
+ final RecyclerView recyclerView = new RecyclerView(mContext);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+ final View view = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
+ final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(view);
+ when(mControllerRendererPool.getController(mContext,
+ ContextualCard.CardType.CONDITIONAL_HEADER)).thenReturn(mController);
+
+ mRenderer.bindView(viewHolder, generateConditionHeaderContextualCard());
+
+ assertThat(viewHolder.itemView).isNotNull();
+ assertThat(viewHolder.itemView.hasOnClickListeners()).isTrue();
+ }
+
+ @Test
+ public void bindView_clickView_shouldSetTrueToIsConditionExpanded() {
+ final int viewType = mRenderer.getViewType(false /* isHalfWidth */);
+ final RecyclerView recyclerView = new RecyclerView(mContext);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+ final View view = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
+ final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(view);
+ when(mControllerRendererPool.getController(mContext,
+ ContextualCard.CardType.CONDITIONAL_HEADER)).thenReturn(mController);
+
+ mRenderer.bindView(viewHolder, generateConditionHeaderContextualCard());
+
+ assertThat(viewHolder.itemView).isNotNull();
+ viewHolder.itemView.performClick();
+
+ verify(mController).setIsExpanded(true);
+ verify(mController).onConditionsChanged();
+ }
+
+ private ContextualCard generateConditionHeaderContextualCard() {
+ return new ConditionHeaderContextualCard.Builder()
+ .setConditionalCards(generateConditionCards(3))
+ .setName("test_condition_header")
+ .setRankingScore(-9999.0)
+ .build();
+ }
+
+ private List<ContextualCard> generateConditionCards(int numberOfCondition) {
+ final List<ContextualCard> conditionCards = new ArrayList<>();
+ for (int i = 0; i < numberOfCondition; i++) {
+ conditionCards.add(new ConditionalContextualCard.Builder()
+ .setConditionId(123 + i)
+ .setMetricsConstant(1)
+ .setActionText("test_action" + i)
+ .setName("test_name" + i)
+ .setTitleText("test_title" + i)
+ .setSummaryText("test_summary" + i)
+ .setIsHalfWidth(true)
+ .build());
+ }
+ return conditionCards;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCardTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCardTest.java
new file mode 100644
index 0000000..767adad
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/ConditionHeaderContextualCardTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.homepage.contextualcards.conditional;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ConditionHeaderContextualCardTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void newInstance_changeCardType_shouldCrash() {
+ new ConditionHeaderContextualCard.Builder()
+ .setCardType(ContextualCard.CardType.LEGACY_SUGGESTION)
+ .build();
+ }
+
+ @Test
+ public void getCardType_shouldAlwaysBeConditionalHeader() {
+ assertThat(new ConditionHeaderContextualCard.Builder().build().getCardType())
+ .isEqualTo(ContextualCard.CardType.CONDITIONAL_HEADER);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
index 91a545c..46d177f 100644
--- a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
@@ -187,11 +187,4 @@
new AirplaneModePreferenceController(mContext,"toggle_airplane");
assertThat(controller.isSliceable()).isTrue();
}
-
- @Test
- public void isSliceableIncorrectKey_returnsFalse() {
- final AirplaneModePreferenceController controller =
- new AirplaneModePreferenceController(mContext, "bad_key");
- assertThat(controller.isSliceable()).isFalse();
- }
}
diff --git a/tests/robotests/src/com/android/settings/panel/InternetConnectivityPanelTest.java b/tests/robotests/src/com/android/settings/panel/InternetConnectivityPanelTest.java
new file mode 100644
index 0000000..3e210f5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/panel/InternetConnectivityPanelTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.panel;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.net.Uri;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.wifi.WifiSlice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+
+public class InternetConnectivityPanelTest {
+
+ private InternetConnectivityPanel mPanel;
+
+ @Before
+ public void setUp() {
+ mPanel = InternetConnectivityPanel.create(RuntimeEnvironment.application);
+ }
+
+ @Test
+ public void getSlices_containsNecessarySlices() {
+ final List<Uri> uris = mPanel.getSlices();
+
+ assertThat(uris).containsExactly(WifiSlice.WIFI_URI,
+ InternetConnectivityPanel.AIRPLANE_URI);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/panel/PanelFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
new file mode 100644
index 0000000..050fd0c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.panel;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class PanelFeatureProviderImplTest {
+
+ private Context mContext;
+ private PanelFeatureProviderImpl mProvider;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mProvider = new PanelFeatureProviderImpl();
+ }
+
+ @Test
+ public void getPanel_internetConnectivityKey_returnsCorrectPanel() {
+ final PanelContent panel = mProvider.getPanel(mContext,
+ SettingsPanelActivity.PANEL_TYPE_WIFI);
+
+ assertThat(panel).isInstanceOf(InternetConnectivityPanel.class);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index 24db829..e14ef1f 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -33,6 +33,7 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.overlay.SurveyFeatureProvider;
+import com.android.settings.panel.PanelFeatureProvider;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.slices.SlicesFeatureProvider;
@@ -61,6 +62,7 @@
public final UserFeatureProvider userFeatureProvider;
public final AssistGestureFeatureProvider assistGestureFeatureProvider;
public final AccountFeatureProvider mAccountFeatureProvider;
+ public final PanelFeatureProvider mPanelFeatureProvider;
public SlicesFeatureProvider slicesFeatureProvider;
public SearchFeatureProvider searchFeatureProvider;
@@ -102,6 +104,7 @@
assistGestureFeatureProvider = mock(AssistGestureFeatureProvider.class);
slicesFeatureProvider = mock(SlicesFeatureProvider.class);
mAccountFeatureProvider = mock(AccountFeatureProvider.class);
+ mPanelFeatureProvider = mock(PanelFeatureProvider.class);
}
@Override
@@ -183,4 +186,9 @@
public AccountFeatureProvider getAccountFeatureProvider() {
return mAccountFeatureProvider;
}
+
+ @Override
+ public PanelFeatureProvider getPanelFeatureProvider() {
+ return mPanelFeatureProvider;
+ }
}