Merge "Import translations. DO NOT MERGE"
diff --git a/protos/contextual_card_list.proto b/protos/contextual_card_list.proto
index 3496c8c..5645c87 100644
--- a/protos/contextual_card_list.proto
+++ b/protos/contextual_card_list.proto
@@ -19,6 +19,7 @@
POSSIBLE = 2;
IMPORTANT = 3;
EXCLUSIVE = 4;
+ DEFERRED_SETUP = 5;
}
/** Slice uri of the contextual card */
diff --git a/res/layout/homepage_slice_deferred_setup_tile.xml b/res/layout/homepage_slice_deferred_setup_tile.xml
new file mode 100644
index 0000000..8c83c09
--- /dev/null
+++ b/res/layout/homepage_slice_deferred_setup_tile.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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.
+ -->
+
+<com.google.android.material.card.MaterialCardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/ContextualCardStyle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <ViewFlipper
+ android:id="@+id/view_flipper"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:id="@+id/content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="left"
+ android:orientation="vertical"
+ android:paddingBottom="@dimen/homepage_deferred_setup_card_padding_bottom"
+ android:paddingEnd="@dimen/homepage_card_padding_end"
+ android:paddingStart="@dimen/homepage_card_padding_start"
+ android:paddingTop="@dimen/homepage_deferred_setup_card_padding_top">
+
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="@dimen/homepage_card_icon_size"
+ android:layout_height="@dimen/homepage_card_icon_size"/>
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/homepage_deferred_setup_card_title_margin_top"
+ android:ellipsize="end"
+ android:maxLines="2"
+ android:minLines="1"
+ android:textAppearance="@style/TextAppearance.DeferredSetupCardTitle"/>
+
+ <TextView
+ android:id="@android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/homepage_deferred_setup_card_summary_margin_top"
+ android:ellipsize="end"
+ android:maxLines="2"
+ android:minLines="1"
+ android:textAppearance="@style/TextAppearance.DeferredSetupCardSummary"/>
+
+ <Button
+ android:id="@+id/finish_setup"
+ style="@style/DeferredSetupCardButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/homepage_deferred_setup_card_button_margin_top"
+ android:text="@string/suggestion_button_text"/>
+
+ </LinearLayout>
+
+ <!--dismissal view-->
+ <include layout="@layout/homepage_dismissal_view"/>
+
+ </ViewFlipper>
+</com.google.android.material.card.MaterialCardView>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 087c870..dd06c37 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -333,6 +333,15 @@
<dimen name="homepage_half_card_padding_top">12dp</dimen>
<dimen name="homepage_half_card_padding_bottom">16dp</dimen>
<dimen name="homepage_half_card_title_margin_top">12dp</dimen>
+ <dimen name="homepage_deferred_setup_card_padding_top">16dp</dimen>
+ <dimen name="homepage_deferred_setup_card_padding_bottom">12dp</dimen>
+ <dimen name="homepage_deferred_setup_card_title_margin_top">12dp</dimen>
+ <dimen name="homepage_deferred_setup_card_summary_margin_top">2dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_margin_top">8dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_top">8dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_bottom">8dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_start">24dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_end">24dp</dimen>
<!-- Homepage dismissal cards size and padding -->
<dimen name="homepage_card_dismissal_margin_top">12dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 031c155..1a92f7b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9571,6 +9571,8 @@
<!-- [CHAR_LIMIT=NONE] Developer Settings: Label for the option that turns off all overlays in a given category. -->
<string name="overlay_option_device_default">Device default</string>
+ <!-- [CHAR_LIMIT=NONE] Developer Settings: Toast displayed to the user when an overlay fails to apply. -->
+ <string name="overlay_toast_failed_to_apply">Failed to apply overlay</string>
<!-- [CHAR_LIMIT=60] Label for special access screen -->
<string name="special_access">Special app access</string>
@@ -10144,25 +10146,27 @@
<!-- UI debug setting: ANGLE enabled app has been set [CHAR LIMIT=NONE] -->
<string name="angle_enabled_app_set">ANGLE enabled application: <xliff:g id="app_name" example="com.company.app">%1$s</xliff:g></string>
- <!-- Title for Game Update Package dashboard where developers can configure apps to use GUP or not [CHAR LIMIT=50] -->
- <string name="gup_dashboard_title">Game Update Package Preferences</string>
- <!-- Summary for Game Update Package dashboard [CHAR LIMIT=50] -->
- <string name="gup_dashboard_summary">Modify Game Update Package settings</string>
- <!-- Title for Game Update Package all apps preference [CHAR LIMIT=50] -->
- <string name="gup_all_apps_switch_title">Enable for all apps</string>
- <!-- Title for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_title">Select Graphics Driver</string>
- <!-- The default value for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_default">Default</string>
- <!-- The gup value for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_gup">Game Update Package</string>
- <!-- The system value for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_system">System Graphics Driver</string>
- <!-- All the values for Game Update Package preference [CHAR LIMIT=50] -->
- <string-array name="gup_app_preference_values">
- <item>@string/gup_app_preference_default</item>
- <item>@string/gup_app_preference_gup</item>
- <item>@string/gup_app_preference_system</item>
+ <!-- Title for Game Driver dashboard where developers can configure apps to use game driver or not [CHAR LIMIT=50] -->
+ <string name="game_driver_dashboard_title">Game Driver Preferences</string>
+ <!-- Summary for Game Driver dashboard [CHAR LIMIT=50] -->
+ <string name="game_driver_dashboard_summary">Modify Game Driver settings</string>
+ <!-- Footer text for Game Driver dashboard [CHAR LIMIT=NONE] -->
+ <string name="game_driver_footer_text">When Game Driver is turned on, you can pick to use the updated graphics driver for Apps installed on the device.</string>
+ <!-- Title for Game Driver all apps preference [CHAR LIMIT=50] -->
+ <string name="game_driver_all_apps_preference_title">Enable for all apps</string>
+ <!-- Title for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_title">Select Graphics Driver</string>
+ <!-- The default value for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_default">Default</string>
+ <!-- The game driver value for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_game_driver">Game Driver</string>
+ <!-- The system value for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_system">System Graphics Driver</string>
+ <!-- All the values for Game Driver app preference [CHAR LIMIT=50] -->
+ <string-array name="game_driver_app_preference_values">
+ <item>@string/game_driver_app_preference_default</item>
+ <item>@string/game_driver_app_preference_game_driver</item>
+ <item>@string/game_driver_app_preference_system</item>
</string-array>
<!-- Slices Strings -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 718a712..6d153e1 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -462,4 +462,24 @@
<item name="titleSize">@*android:dimen/text_size_subhead_material</item>
</style>
+ <style name="TextAppearance.DeferredSetupCardTitle">
+ <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
+ <item name="android:textSize">16sp</item>
+ </style>
+
+ <style name="TextAppearance.DeferredSetupCardSummary"
+ parent="@*android:style/TextAppearance.DeviceDefault.Body1">
+ <item name="android:textColor">?android:attr/textColorSecondary</item>
+ </style>
+
+ <style name="DeferredSetupCardButton" parent="android:Widget.DeviceDefault.Button.Colored">
+ <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
+ <item name="android:paddingBottom">@dimen/homepage_deferred_setup_card_button_padding_bottom</item>
+ <item name="android:paddingEnd">@dimen/homepage_deferred_setup_card_button_padding_end</item>
+ <item name="android:paddingStart">@dimen/homepage_deferred_setup_card_button_padding_start</item>
+ <item name="android:paddingTop">@dimen/homepage_deferred_setup_card_button_padding_top</item>
+ <item name="android:textAllCaps">false</item>
+ <item name="android:textSize">14sp</item>
+ </style>
+
</resources>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 6d22a1d..9b43723 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -194,10 +194,10 @@
android:summary="@string/enable_gpu_debug_layers_summary" />
<Preference
- android:key="gup_dashboard"
- android:title="@string/gup_dashboard_title"
- android:summary="@string/gup_dashboard_summary"
- android:fragment="com.android.settings.development.gup.GupDashboard"
+ android:key="game_driver_dashboard"
+ android:title="@string/game_driver_dashboard_title"
+ android:summary="@string/game_driver_dashboard_summary"
+ android:fragment="com.android.settings.development.gamedriver.GameDriverDashboard"
settings:searchable="false" />
</PreferenceCategory>
diff --git a/res/xml/game_driver_settings.xml b/res/xml/game_driver_settings.xml
new file mode 100644
index 0000000..a04724a
--- /dev/null
+++ b/res/xml/game_driver_settings.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2019 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="game_driver_settings"
+ android:title="@string/game_driver_dashboard_title">
+
+ <SwitchPreference
+ android:key="game_driver_all_apps_preference"
+ android:title="@string/game_driver_all_apps_preference_title"
+ settings:controller="com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController">
+ </SwitchPreference>
+
+ <PreferenceCategory
+ android:key="game_driver_category"
+ android:title="@string/game_driver_app_preference_title"
+ settings:controller="com.android.settings.development.gamedriver.GameDriverAppPreferenceController">
+ </PreferenceCategory>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="footer_preference"
+ android:title="@string/game_driver_footer_text"
+ android:selectable="false"
+ settings:controller="com.android.settings.development.gamedriver.GameDriverFooterPreferenceController">
+ </com.android.settingslib.widget.FooterPreference>
+
+</PreferenceScreen>
diff --git a/res/xml/gup_settings.xml b/res/xml/gup_settings.xml
deleted file mode 100644
index 09bca71..0000000
--- a/res/xml/gup_settings.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto"
- android:key="gup_settings"
- android:title="@string/gup_dashboard_title">
-
- <SwitchPreference
- android:key="gup_all_apps_preference"
- android:title="@string/gup_all_apps_switch_title"
- settings:controller="com.android.settings.development.gup.GupEnableForAllAppsPreferenceController">
- </SwitchPreference>
-
- <PreferenceCategory
- android:key="gup_category"
- android:title="@string/gup_app_preference_title"
- settings:controller="com.android.settings.development.gup.GupPreferenceController">
- </PreferenceCategory>
-
-</PreferenceScreen>
diff --git a/src/com/android/settings/development/OverlayCategoryPreferenceController.java b/src/com/android/settings/development/OverlayCategoryPreferenceController.java
index 9db8a2f..0ba9d79 100644
--- a/src/com/android/settings/development/OverlayCategoryPreferenceController.java
+++ b/src/com/android/settings/development/OverlayCategoryPreferenceController.java
@@ -22,9 +22,12 @@
import android.content.om.IOverlayManager;
import android.content.om.OverlayInfo;
import android.content.pm.PackageManager;
+import android.os.AsyncTask;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.TextUtils;
+import android.util.Log;
+import android.widget.Toast;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
@@ -38,6 +41,7 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
+import java.util.Optional;
/**
* Preference controller to allow users to choose an overlay from a list for a given category.
@@ -46,6 +50,7 @@
*/
public class OverlayCategoryPreferenceController extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+ private static final String TAG = "OverlayCategoryPC";
@VisibleForTesting
static final String PACKAGE_DEVICE_DEFAULT = "package_device_default";
private static final String OVERLAY_TARGET_PACKAGE = "android";
@@ -100,12 +105,11 @@
}
private boolean setOverlay(String packageName) {
- String currentPackageName = null;
- for (OverlayInfo o : getOverlayInfos()) {
- if (o.isEnabled()) {
- currentPackageName = o.packageName;
- }
- }
+ final String currentPackageName = getOverlayInfos().stream()
+ .filter(info -> info.isEnabled())
+ .map(info -> info.packageName)
+ .findFirst()
+ .orElse(null);
if (PACKAGE_DEVICE_DEFAULT.equals(packageName) && TextUtils.isEmpty(currentPackageName)
|| TextUtils.equals(packageName, currentPackageName)) {
@@ -113,18 +117,33 @@
return true;
}
- final boolean result;
- try {
- if (PACKAGE_DEVICE_DEFAULT.equals(packageName)) {
- result = mOverlayManager.setEnabled(currentPackageName, false, USER_SYSTEM);
- } else {
- result = mOverlayManager.setEnabledExclusiveInCategory(packageName, USER_SYSTEM);
+ new AsyncTask<Void, Void, Boolean>() {
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ try {
+ if (PACKAGE_DEVICE_DEFAULT.equals(packageName)) {
+ return mOverlayManager.setEnabled(currentPackageName, false, USER_SYSTEM);
+ } else {
+ return mOverlayManager.setEnabledExclusiveInCategory(packageName, USER_SYSTEM);
+ }
+ } catch (RemoteException re) {
+ Log.w(TAG, "Error enabling overlay.", re);
+ return false;
+ }
}
- } catch (RemoteException re) {
- throw re.rethrowFromSystemServer();
- }
- updateState(mPreference);
- return result;
+
+ @Override
+ protected void onPostExecute(Boolean success) {
+ updateState(mPreference);
+ if (!success) {
+ Toast.makeText(
+ mContext, R.string.overlay_toast_failed_to_apply, Toast.LENGTH_LONG)
+ .show();
+ }
+ }
+ }.execute();
+
+ return true; // Assume success; toast on failure.
}
@Override
diff --git a/src/com/android/settings/development/gup/GupPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
similarity index 61%
rename from src/com/android/settings/development/gup/GupPreferenceController.java
rename to src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
index d4cd2f1..3877c45 100644
--- a/src/com/android/settings/development/gup/GupPreferenceController.java
+++ b/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
@@ -14,13 +14,18 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.os.Handler;
+import android.os.Looper;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
@@ -31,6 +36,9 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import java.text.Collator;
@@ -42,62 +50,94 @@
import java.util.List;
import java.util.Set;
-public class GupPreferenceController
- extends BasePreferenceController implements Preference.OnPreferenceChangeListener {
+/**
+ * Controller of all the per App based list preferences.
+ */
+public class GameDriverAppPreferenceController extends BasePreferenceController
+ implements Preference.OnPreferenceChangeListener,
+ GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
private final CharSequence[] mEntryList;
private final String mPreferenceTitle;
private final String mPreferenceDefault;
- private final String mPreferenceGup;
+ private final String mPreferenceGameDriver;
private final String mPreferenceSystem;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
private final List<AppInfo> mAppInfos;
private final Set<String> mDevOptInApps;
private final Set<String> mDevOptOutApps;
- public GupPreferenceController(Context context, String key) {
+ private PreferenceGroup mPreferenceGroup;
+
+ public GameDriverAppPreferenceController(Context context, String key) {
super(context, key);
+ mContext = context;
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+
final Resources resources = context.getResources();
- mEntryList = resources.getStringArray(R.array.gup_app_preference_values);
- mPreferenceTitle = resources.getString(R.string.gup_app_preference_title);
- mPreferenceDefault = resources.getString(R.string.gup_app_preference_default);
- mPreferenceGup = resources.getString(R.string.gup_app_preference_gup);
- mPreferenceSystem = resources.getString(R.string.gup_app_preference_system);
+ mEntryList = resources.getStringArray(R.array.game_driver_app_preference_values);
+ mPreferenceTitle = resources.getString(R.string.game_driver_app_preference_title);
+ mPreferenceDefault = resources.getString(R.string.game_driver_app_preference_default);
+ mPreferenceGameDriver =
+ resources.getString(R.string.game_driver_app_preference_game_driver);
+ mPreferenceSystem = resources.getString(R.string.game_driver_app_preference_system);
// TODO: Move this task to background if there's potential ANR/Jank.
// Update the UI when all the app infos are ready.
mAppInfos = getAppInfos(context);
- final ContentResolver contentResolver = context.getContentResolver();
mDevOptInApps =
- getGlobalSettingsString(contentResolver, Settings.Global.GUP_DEV_OPT_IN_APPS);
+ getGlobalSettingsString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS);
mDevOptOutApps =
- getGlobalSettingsString(contentResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS);
+ getGlobalSettingsString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS);
}
@Override
public int getAvailabilityStatus() {
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
+ && (Settings.Global.getInt(mContentResolver,
+ Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF)
? AVAILABLE
- : DISABLED_DEPENDENT_SETTING;
+ : CONDITIONALLY_UNAVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- final PreferenceGroup preferenceGroup =
- (PreferenceGroup) screen.findPreference(getPreferenceKey());
- if (preferenceGroup == null) {
- return;
- }
+ mPreferenceGroup = (PreferenceGroup) screen.findPreference(getPreferenceKey());
+ final Context context = mPreferenceGroup.getContext();
for (AppInfo appInfo : mAppInfos) {
- preferenceGroup.addPreference(
- createListPreference(appInfo.info.packageName, appInfo.label));
+ mPreferenceGroup.addPreference(
+ createListPreference(context, appInfo.info.packageName, appInfo.label));
}
}
@Override
+ public void onStart() {
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setVisible(isAvailable());
+ }
+
+ @Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final ListPreference listPref = (ListPreference) preference;
final String value = newValue.toString();
@@ -108,7 +148,7 @@
if (value.equals(mPreferenceSystem)) {
mDevOptInApps.remove(packageName);
mDevOptOutApps.add(packageName);
- } else if (value.equals(mPreferenceGup)) {
+ } else if (value.equals(mPreferenceGameDriver)) {
mDevOptInApps.add(packageName);
mDevOptOutApps.remove(packageName);
} else {
@@ -119,15 +159,20 @@
listPref.setSummary(value);
// Push the updated Sets for opt-in and opt-out apps to
- // corresponding Settings.Global.GUP_DEV_OPT_(IN|OUT)_APPS
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.GUP_DEV_OPT_IN_APPS, String.join(",", mDevOptInApps));
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.GUP_DEV_OPT_OUT_APPS, String.join(",", mDevOptOutApps));
+ // corresponding Settings.Global.GAME_DRIVER_OPT_(IN|OUT)_APPS
+ Settings.Global.putString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS,
+ String.join(",", mDevOptInApps));
+ Settings.Global.putString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS,
+ String.join(",", mDevOptOutApps));
return true;
}
+ @Override
+ public void onGameDriverContentChanged() {
+ updateState(mPreferenceGroup);
+ }
+
// AppInfo class to achieve loading the application label only once
class AppInfo {
AppInfo(PackageManager packageManager, ApplicationInfo applicationInfo) {
@@ -176,8 +221,9 @@
};
@VisibleForTesting
- protected ListPreference createListPreference(String packageName, String appName) {
- final ListPreference listPreference = new ListPreference(mContext);
+ protected ListPreference createListPreference(
+ Context context, String packageName, String appName) {
+ final ListPreference listPreference = new ListPreference(context);
listPreference.setKey(packageName);
listPreference.setTitle(appName);
@@ -186,13 +232,13 @@
listPreference.setEntryValues(mEntryList);
// Initialize preference default and summary with the opt in/out choices
- // from Settings.Global.GUP_DEV_OPT_(IN|OUT)_APPS
+ // from Settings.Global.GAME_DRIVER_OPT_(IN|OUT)_APPS
if (mDevOptOutApps.contains(packageName)) {
listPreference.setValue(mPreferenceSystem);
listPreference.setSummary(mPreferenceSystem);
} else if (mDevOptInApps.contains(packageName)) {
- listPreference.setValue(mPreferenceGup);
- listPreference.setSummary(mPreferenceGup);
+ listPreference.setValue(mPreferenceGameDriver);
+ listPreference.setSummary(mPreferenceGameDriver);
} else {
listPreference.setValue(mPreferenceDefault);
listPreference.setSummary(mPreferenceDefault);
diff --git a/src/com/android/settings/development/gamedriver/GameDriverContentObserver.java b/src/com/android/settings/development/gamedriver/GameDriverContentObserver.java
new file mode 100644
index 0000000..e31e046
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverContentObserver.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import android.content.ContentResolver;
+import android.database.ContentObserver;
+import android.os.Handler;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+
+/**
+ * Helper class to observe Game Driver settings global change.
+ */
+public class GameDriverContentObserver extends ContentObserver {
+
+ interface OnGameDriverContentChangedListener {
+ void onGameDriverContentChanged();
+ }
+
+ @VisibleForTesting
+ OnGameDriverContentChangedListener mListener;
+
+ public GameDriverContentObserver(Handler handler, OnGameDriverContentChangedListener listener) {
+ super(handler);
+ mListener = listener;
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ mListener.onGameDriverContentChanged();
+ }
+
+ public void register(ContentResolver contentResolver) {
+ contentResolver.registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_ALL_APPS), false, this);
+ }
+
+ public void unregister(ContentResolver contentResolver) {
+ contentResolver.unregisterContentObserver(this);
+ }
+}
diff --git a/src/com/android/settings/development/gup/GupDashboard.java b/src/com/android/settings/development/gamedriver/GameDriverDashboard.java
similarity index 65%
rename from src/com/android/settings/development/gup/GupDashboard.java
rename to src/com/android/settings/development/gamedriver/GameDriverDashboard.java
index 0ab57e6..db456bd 100644
--- a/src/com/android/settings/development/gup/GupDashboard.java
+++ b/src/com/android/settings/development/gamedriver/GameDriverDashboard.java
@@ -14,29 +14,37 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.os.Bundle;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
+import com.android.settings.widget.SwitchBar;
+import com.android.settings.widget.SwitchBarController;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
+/**
+ * Dashboard for Game Driver preferences.
+ */
@SearchIndexable
-public class GupDashboard extends DashboardFragment {
- private static final String TAG = "GupDashboard";
+public class GameDriverDashboard extends DashboardFragment {
+
+ private static final String TAG = "GameDriverDashboard";
@Override
public int getMetricsCategory() {
- return SettingsEnums.SETTINGS_GUP_DASHBOARD;
+ return SettingsEnums.SETTINGS_GAME_DRIVER_DASHBOARD;
}
@Override
@@ -46,7 +54,7 @@
@Override
protected int getPreferenceScreenResId() {
- return R.xml.gup_settings;
+ return R.xml.game_driver_settings;
}
@Override
@@ -54,6 +62,19 @@
return 0;
}
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ final SettingsActivity activity = (SettingsActivity) getActivity();
+ final SwitchBar switchBar = activity.getSwitchBar();
+ final GameDriverGlobalSwitchBarController switchBarController =
+ new GameDriverGlobalSwitchBarController(
+ activity, new SwitchBarController(switchBar));
+ getSettingsLifecycle().addObserver(switchBarController);
+ switchBar.show();
+ }
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -61,7 +82,7 @@
Context context, boolean enabled) {
final List<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.gup_settings;
+ sir.xmlResId = R.xml.game_driver_settings;
result.add(sir);
return result;
}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java
new file mode 100644
index 0000000..68be526
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
+
+/**
+ * Controller of global switch to enable Game Driver for all Apps.
+ */
+public class GameDriverEnableForAllAppsPreferenceController extends BasePreferenceController
+ implements Preference.OnPreferenceChangeListener,
+ GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ public static final int GAME_DRIVER_DEFAULT = 0;
+ public static final int GAME_DRIVER_ALL_APPS = 1;
+ public static final int GAME_DRIVER_OFF = 2;
+
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
+
+ private SwitchPreference mPreference;
+
+ public GameDriverEnableForAllAppsPreferenceController(Context context, String key) {
+ super(context, key);
+ mContext = context;
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
+ && (Settings.Global.getInt(mContentResolver,
+ Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF)
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onStart() {
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final SwitchPreference switchPreference = (SwitchPreference) preference;
+ switchPreference.setVisible(isAvailable());
+ switchPreference.setChecked(
+ Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ == GAME_DRIVER_ALL_APPS);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Settings.Global.putInt(mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS,
+ (boolean) newValue ? GAME_DRIVER_ALL_APPS : GAME_DRIVER_DEFAULT);
+
+ return true;
+ }
+
+ @Override
+ public void onGameDriverContentChanged() {
+ updateState(mPreference);
+ }
+}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceController.java
new file mode 100644
index 0000000..12156df
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceController.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.widget.FooterPreference;
+
+/**
+ * Controller of footer preference for Game Driver.
+ */
+public class GameDriverFooterPreferenceController extends BasePreferenceController
+ implements GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ private final ContentResolver mContentResolver;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
+
+ private FooterPreference mPreference;
+
+ public GameDriverFooterPreferenceController(Context context) {
+ super(context, FooterPreference.KEY_FOOTER);
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ == GAME_DRIVER_OFF
+ ? AVAILABLE_UNSEARCHABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onStart() {
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setVisible(isAvailable());
+ }
+
+ @Override
+ public void onGameDriverContentChanged() {
+ updateState(mPreference);
+ }
+}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java b/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java
new file mode 100644
index 0000000..125d95b
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.widget.SwitchWidgetController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
+
+/**
+ * Controller of global switch bar used to fully turn off Game Driver.
+ */
+public class GameDriverGlobalSwitchBarController
+ implements SwitchWidgetController.OnSwitchChangeListener,
+ GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
+ @VisibleForTesting
+ SwitchWidgetController mSwitchWidgetController;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
+
+ GameDriverGlobalSwitchBarController(
+ Context context, SwitchWidgetController switchWidgetController) {
+ mContext = context;
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+ mSwitchWidgetController = switchWidgetController;
+ mSwitchWidgetController.setEnabled(
+ DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context));
+ mSwitchWidgetController.setChecked(
+ Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF);
+ mSwitchWidgetController.setListener(this);
+ }
+
+ @Override
+ public void onStart() {
+ mSwitchWidgetController.startListening();
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mSwitchWidgetController.stopListening();
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public boolean onSwitchToggled(boolean isChecked) {
+ if (!isChecked) {
+ Settings.Global.putInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ return true;
+ }
+
+ if (Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_ALL_APPS) {
+ Settings.Global.putInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onGameDriverContentChanged() {
+ mSwitchWidgetController.setChecked(
+ Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF);
+ }
+}
diff --git a/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceController.java b/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceController.java
deleted file mode 100644
index 43a28b6..0000000
--- a/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceController.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2019 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.development.gup;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.core.BasePreferenceController;
-import com.android.settingslib.development.DevelopmentSettingsEnabler;
-
-public class GupEnableForAllAppsPreferenceController
- extends BasePreferenceController implements Preference.OnPreferenceChangeListener {
- public static final int GUP_DEFAULT = 0;
- public static final int GUP_ALL_APPS = 1;
-
- private final ContentResolver mContentResolver;
-
- public GupEnableForAllAppsPreferenceController(Context context, String key) {
- super(context, key);
- mContentResolver = context.getContentResolver();
- }
-
- @Override
- public int getAvailabilityStatus() {
- return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
- ? AVAILABLE
- : DISABLED_DEPENDENT_SETTING;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- final SwitchPreference switchPreference = screen.findPreference(getPreferenceKey());
- if (switchPreference == null) {
- return;
- }
-
- switchPreference.setChecked(Settings.Global.getInt(mContentResolver,
- Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT)
- == GUP_ALL_APPS);
- switchPreference.setOnPreferenceChangeListener(this);
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- // When developer option is present, always overwrite GUP_DEV_ALL_APPS.
- Settings.Global.putInt(mContentResolver, Settings.Global.GUP_DEV_ALL_APPS,
- (boolean) newValue ? GUP_ALL_APPS : GUP_DEFAULT);
-
- return true;
- }
-}
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
index 1f2e89b..e11ce30 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
@@ -80,6 +80,10 @@
LegacySuggestionContextualCardController.class,
LegacySuggestionContextualCardRenderer.class));
add(new ControllerRendererMapping(CardType.SLICE,
+ SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP,
+ SliceContextualCardController.class,
+ SliceContextualCardRenderer.class));
+ add(new ControllerRendererMapping(CardType.SLICE,
SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH,
SliceContextualCardController.class,
SliceContextualCardRenderer.class));
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
index 7a2c2e9..b35a38a 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
@@ -17,6 +17,7 @@
package com.android.settings.homepage.contextualcards;
import static com.android.settings.homepage.contextualcards.ContextualCardLoader.CARD_CONTENT_LOADER_ID;
+import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE;
import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE;
import static java.util.stream.Collectors.groupingBy;
@@ -71,17 +72,15 @@
@VisibleForTesting
final List<ContextualCard> mContextualCards;
+ private final Context mContext;
+ private final ControllerRendererPool mControllerRendererPool;
+ private final Lifecycle mLifecycle;
+ private final List<LifecycleObserver> mLifecycleObservers;
@VisibleForTesting
long mStartTime;
boolean mIsFirstLaunch;
@VisibleForTesting
List<String> mSavedCards;
-
- private final Context mContext;
- private final ControllerRendererPool mControllerRendererPool;
- private final Lifecycle mLifecycle;
- private final List<LifecycleObserver> mLifecycleObservers;
-
private ContextualCardUpdateListener mListener;
public ContextualCardManager(Context context, Lifecycle lifecycle, Bundle savedInstanceState) {
@@ -175,7 +174,7 @@
//replace with the new data
mContextualCards.clear();
final List<ContextualCard> sortedCards = sortCards(allCards);
- mContextualCards.addAll(assignCardWidth(sortedCards));
+ mContextualCards.addAll(getCardsWithViewType(sortedCards));
loadCardControllers();
@@ -228,10 +227,19 @@
}
@VisibleForTesting
- List<ContextualCard> assignCardWidth(List<ContextualCard> cards) {
- final List<ContextualCard> result = new ArrayList<>(cards);
+ List<ContextualCard> getCardsWithViewType(List<ContextualCard> cards) {
+ if (cards.isEmpty()) {
+ return cards;
+ }
+
+ final List<ContextualCard> result = getCardsWithDeferredSetupViewType(cards);
+ return getCardsWithSuggestionViewType(result);
+ }
+
+ private List<ContextualCard> getCardsWithSuggestionViewType(List<ContextualCard> cards) {
// Shows as half cards if 2 suggestion type of cards are next to each other.
// Shows as full card if 1 suggestion type of card lives alone.
+ final List<ContextualCard> result = new ArrayList<>(cards);
for (int index = 1; index < result.size(); index++) {
final ContextualCard previous = result.get(index - 1);
final ContextualCard current = result.get(index);
@@ -247,6 +255,22 @@
return result;
}
+ private List<ContextualCard> getCardsWithDeferredSetupViewType(List<ContextualCard> cards) {
+ // Find the deferred setup card and assign it with proper view type.
+ // Reason: The returned card list will mix deferred setup card and other suggestion cards
+ // after device running 1 days.
+ final List<ContextualCard> result = new ArrayList<>(cards);
+ for (int index = 0; index < result.size(); index++) {
+ final ContextualCard card = cards.get(index);
+ if (card.getCategory() == DEFERRED_SETUP_VALUE) {
+ result.set(index, card.mutate().setViewType(
+ SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP).build());
+ return result;
+ }
+ }
+ return result;
+ }
+
private List<ContextualCard> getCardsToKeep(List<ContextualCard> cards) {
if (mSavedCards != null) {
//screen rotate
diff --git a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
index ca5bbec..016aa32 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
@@ -57,6 +57,7 @@
import com.android.settings.notification.AppNotificationSettings;
import com.android.settings.notification.ChannelNotificationSettings;
import com.android.settings.notification.NotificationBackend;
+import com.android.settings.notification.NotificationBackend.NotificationsSentState;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SliceBroadcastReceiver;
@@ -66,7 +67,6 @@
import com.android.settingslib.applications.ApplicationsState;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -103,21 +103,32 @@
private static final String CHANNEL_ID = "channel_id";
/**
- * TODO(b/119831690): Change to notification count sorting.
- * This is the default sorting from NotificationSettingsBase, will be replaced with notification
- * count sorting mechanism.
+ * Sort notification channel with weekly average sent count by descending.
+ *
+ * Note:
+ * When the sent count of notification channels is the same, follow the sorting mechanism from
+ * {@link com.android.settings.notification.NotificationSettingsBase#mChannelComparator}.
+ * Since slice view only shows displayable notification channels, so those deleted ones are
+ * excluded from the comparison here.
*/
- private static final Comparator<NotificationChannel> mChannelComparator =
+ private static final Comparator<NotificationChannelState> CHANNEL_STATE_COMPARATOR =
(left, right) -> {
- if (TextUtils.equals(left.getId(), NotificationChannel.DEFAULT_CHANNEL_ID)) {
- // Uncategorized/miscellaneous legacy channel goes last
+ final NotificationsSentState leftState = left.getNotificationsSentState();
+ final NotificationsSentState rightState = right.getNotificationsSentState();
+ if (rightState.avgSentWeekly != leftState.avgSentWeekly) {
+ return rightState.avgSentWeekly - leftState.avgSentWeekly;
+ }
+
+ final NotificationChannel leftChannel = left.getNotificationChannel();
+ final NotificationChannel rightChannel = right.getNotificationChannel();
+ if (TextUtils.equals(leftChannel.getId(), NotificationChannel.DEFAULT_CHANNEL_ID)) {
return 1;
- } else if (TextUtils.equals(right.getId(),
+ } else if (TextUtils.equals(rightChannel.getId(),
NotificationChannel.DEFAULT_CHANNEL_ID)) {
return -1;
}
- return left.getId().compareTo(right.getId());
+ return leftChannel.getId().compareTo(rightChannel.getId());
};
private final Context mContext;
@@ -380,9 +391,19 @@
channel -> isChannelEnabled(group, channel, appRow)))
.collect(Collectors.toList());
- // TODO(b/119831690): Sort the channels by notification count.
- Collections.sort(channels, mChannelComparator);
- return channels;
+ // Pack the notification channel with notification sent state for sorting.
+ final List<NotificationChannelState> channelStates = new ArrayList<>();
+ for (NotificationChannel channel : channels) {
+ NotificationsSentState sentState = appRow.sentByChannel.get(channel.getId());
+ if (sentState == null) {
+ sentState = new NotificationsSentState();
+ }
+ channelStates.add(new NotificationChannelState(sentState, channel));
+ }
+
+ // Sort the notification channels with notification sent count by descending.
+ return channelStates.stream().sorted(CHANNEL_STATE_COMPARATOR).map(
+ state -> state.getNotificationChannel()).collect(Collectors.toList());
}
private PackageInfo getMaxSentNotificationsPackage(List<PackageInfo> packageInfoList) {
@@ -471,4 +492,31 @@
return false;
}
-}
\ No newline at end of file
+
+ /**
+ * This class is used to sort notification channels according to notification sent count and
+ * notification id in {@link NotificationChannelSlice#CHANNEL_STATE_COMPARATOR}.
+ *
+ * Include {@link NotificationsSentState#avgSentWeekly} and {@link NotificationChannel#getId()}
+ * to get the number of notifications being sent and notification id.
+ */
+ private static class NotificationChannelState {
+
+ final private NotificationsSentState mNotificationsSentState;
+ final private NotificationChannel mNotificationChannel;
+
+ public NotificationChannelState(NotificationsSentState notificationsSentState,
+ NotificationChannel notificationChannel) {
+ mNotificationsSentState = notificationsSentState;
+ mNotificationChannel = notificationChannel;
+ }
+
+ public NotificationChannel getNotificationChannel() {
+ return mNotificationChannel;
+ }
+
+ public NotificationsSentState getNotificationsSentState() {
+ return mNotificationsSentState;
+ }
+ }
+}
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
index 66e0465..2d40efe 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
@@ -52,6 +52,7 @@
public class SliceContextualCardRenderer implements ContextualCardRenderer, LifecycleObserver {
public static final int VIEW_TYPE_FULL_WIDTH = R.layout.homepage_slice_tile;
public static final int VIEW_TYPE_HALF_WIDTH = R.layout.homepage_slice_half_tile;
+ public static final int VIEW_TYPE_DEFERRED_SETUP = R.layout.homepage_slice_deferred_setup_tile;
private static final String TAG = "SliceCardRenderer";
@@ -64,6 +65,7 @@
private final LifecycleOwner mLifecycleOwner;
private final ControllerRendererPool mControllerRendererPool;
private final Set<ContextualCard> mCardSet;
+ private final SliceDeferredSetupCardRendererHelper mDeferredSetupCardHelper;
private final SliceFullCardRendererHelper mFullCardHelper;
private final SliceHalfCardRendererHelper mHalfCardHelper;
@@ -78,11 +80,14 @@
mLifecycleOwner.getLifecycle().addObserver(this);
mFullCardHelper = new SliceFullCardRendererHelper(context);
mHalfCardHelper = new SliceHalfCardRendererHelper(context);
+ mDeferredSetupCardHelper = new SliceDeferredSetupCardRendererHelper(context);
}
@Override
public RecyclerView.ViewHolder createViewHolder(View view, @LayoutRes int viewType) {
switch (viewType) {
+ case VIEW_TYPE_DEFERRED_SETUP:
+ return mDeferredSetupCardHelper.createViewHolder(view);
case VIEW_TYPE_HALF_WIDTH:
return mHalfCardHelper.createViewHolder(view);
default:
@@ -119,17 +124,25 @@
//TODO(b/120629936): Take this out once blank card issue is fixed.
Log.d(TAG, "Slice callback - uri = " + slice.getUri());
}
- if (holder.getItemViewType() == VIEW_TYPE_HALF_WIDTH) {
- mHalfCardHelper.bindView(holder, card, slice);
- } else {
- mFullCardHelper.bindView(holder, card, slice, mCardSet);
+ switch (holder.getItemViewType()) {
+ case VIEW_TYPE_DEFERRED_SETUP:
+ mDeferredSetupCardHelper.bindView(holder, card, slice);
+ break;
+ case VIEW_TYPE_HALF_WIDTH:
+ mHalfCardHelper.bindView(holder, card, slice);
+ break;
+ default:
+ mFullCardHelper.bindView(holder, card, slice, mCardSet);
}
});
- if (holder.getItemViewType() == VIEW_TYPE_HALF_WIDTH) {
- initDismissalActions(holder, card, R.id.content);
- } else {
- initDismissalActions(holder, card, R.id.slice_view);
+ switch (holder.getItemViewType()) {
+ case VIEW_TYPE_DEFERRED_SETUP:
+ case VIEW_TYPE_HALF_WIDTH:
+ initDismissalActions(holder, card, R.id.content);
+ break;
+ default:
+ initDismissalActions(holder, card, R.id.slice_view);
}
}
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelper.java b/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelper.java
new file mode 100644
index 0000000..d0d51e7
--- /dev/null
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelper.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2019 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.slices;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.slice.Slice;
+import androidx.slice.SliceMetadata;
+import androidx.slice.core.SliceAction;
+import androidx.slice.widget.EventInfo;
+
+import com.android.settings.R;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
+
+/**
+ * Card renderer helper for {@link ContextualCard} built as slice deferred setup card.
+ */
+class SliceDeferredSetupCardRendererHelper {
+ private static final String TAG = "SliceDSCRendererHelper";
+
+ private final Context mContext;
+
+ SliceDeferredSetupCardRendererHelper(Context context) {
+ mContext = context;
+ }
+
+ RecyclerView.ViewHolder createViewHolder(View view) {
+ return new DeferredSetupCardViewHolder(view);
+ }
+
+ void bindView(RecyclerView.ViewHolder holder, ContextualCard card, Slice slice) {
+ final DeferredSetupCardViewHolder view = (DeferredSetupCardViewHolder) holder;
+ final SliceMetadata sliceMetadata = SliceMetadata.from(mContext, slice);
+ final SliceAction primaryAction = sliceMetadata.getPrimaryAction();
+ view.icon.setImageDrawable(primaryAction.getIcon().loadDrawable(mContext));
+ view.title.setText(primaryAction.getTitle());
+ view.summary.setText(sliceMetadata.getSubtitle());
+ view.button.setOnClickListener(v -> {
+ try {
+ primaryAction.getAction().send();
+ } catch (PendingIntent.CanceledException e) {
+ Log.w(TAG, "Failed to start intent " + primaryAction.getTitle());
+ }
+ final ContextualCardFeatureProvider contextualCardFeatureProvider =
+ FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider(mContext);
+ contextualCardFeatureProvider.logContextualCardClick(card, 0 /* row */,
+ EventInfo.ACTION_TYPE_CONTENT);
+ });
+ }
+
+ static class DeferredSetupCardViewHolder extends RecyclerView.ViewHolder {
+ public final LinearLayout content;
+ public final ImageView icon;
+ public final TextView title;
+ public final TextView summary;
+ public final Button button;
+
+ public DeferredSetupCardViewHolder(View itemView) {
+ super(itemView);
+ content = itemView.findViewById(R.id.content);
+ icon = itemView.findViewById(android.R.id.icon);
+ title = itemView.findViewById(android.R.id.title);
+ summary = itemView.findViewById(android.R.id.summary);
+ button = itemView.findViewById(R.id.finish_setup);
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/development/OverlayCategoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/OverlayCategoryPreferenceControllerTest.java
index 3938b89..8a90b20 100644
--- a/tests/robotests/src/com/android/settings/development/OverlayCategoryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/OverlayCategoryPreferenceControllerTest.java
@@ -31,6 +31,8 @@
import android.content.pm.PackageManager;
import android.os.RemoteException;
+import com.android.settings.R;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,6 +40,8 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.shadows.ShadowToast;
import java.util.ArrayList;
import java.util.Arrays;
@@ -105,22 +109,65 @@
mockCurrentOverlays(ONE_DISABLED, TWO_DISABLED);
mController.onPreferenceChange(null, TWO_DISABLED.packageName);
+ ShadowApplication.runBackgroundTasks();
verify(mOverlayManager)
.setEnabledExclusiveInCategory(eq(TWO_DISABLED.packageName), anyInt());
}
@Test
+ public void onPreferenceChange_enable_fails() throws Exception {
+ mockCurrentOverlays(ONE_DISABLED, TWO_DISABLED);
+ when(mOverlayManager.setEnabledExclusiveInCategory(eq(TWO_DISABLED.packageName), anyInt()))
+ .thenReturn(false);
+
+ mController.onPreferenceChange(null, TWO_DISABLED.packageName);
+ ShadowApplication.runBackgroundTasks();
+
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ RuntimeEnvironment.application.getString(R.string.overlay_toast_failed_to_apply));
+ }
+
+ @Test
public void onPreferenceChange_disable() throws Exception {
mockCurrentOverlays(ONE_DISABLED, TWO_ENABLED);
mController.onPreferenceChange(
null, OverlayCategoryPreferenceController.PACKAGE_DEVICE_DEFAULT);
+ ShadowApplication.runBackgroundTasks();
verify(mOverlayManager).setEnabled(eq(TWO_ENABLED.packageName), eq(false), anyInt());
}
@Test
+ public void onPreferenceChange_disable_fails() throws Exception {
+ mockCurrentOverlays(ONE_DISABLED, TWO_ENABLED);
+ when(mOverlayManager.setEnabled(eq(TWO_ENABLED.packageName), eq(false), anyInt()))
+ .thenReturn(false);
+
+ mController.onPreferenceChange(
+ null, OverlayCategoryPreferenceController.PACKAGE_DEVICE_DEFAULT);
+ ShadowApplication.runBackgroundTasks();
+
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ RuntimeEnvironment.application.getString(R.string.overlay_toast_failed_to_apply));
+ }
+
+ @Test
+ public void onPreferenceChange_disable_throws() throws Exception {
+ mockCurrentOverlays(ONE_DISABLED, TWO_ENABLED);
+ when(mOverlayManager.setEnabled(eq(TWO_ENABLED.packageName), eq(false), anyInt()))
+ .thenThrow(new RemoteException());
+
+ mController.onPreferenceChange(
+ null, OverlayCategoryPreferenceController.PACKAGE_DEVICE_DEFAULT);
+ ShadowApplication.runBackgroundTasks();
+
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ RuntimeEnvironment.application.getString(R.string.overlay_toast_failed_to_apply));
+ }
+
+ @Test
public void updateState_enabled() {
mockCurrentOverlays(ONE_DISABLED, TWO_ENABLED);
diff --git a/tests/robotests/src/com/android/settings/development/gup/GupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
similarity index 68%
rename from tests/robotests/src/com/android/settings/development/gup/GupPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
index d5e7a85..f6fa8e0 100644
--- a/tests/robotests/src/com/android/settings/development/gup/GupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
@@ -14,14 +14,17 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
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.ContentResolver;
@@ -49,9 +52,10 @@
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
-public class GupPreferenceControllerTest {
+public class GameDriverAppPreferenceControllerTest {
+
private static final int DEFAULT = 0;
- private static final int GUP = 1;
+ private static final int GAME_DRIVER = 1;
private static final int SYSTEM = 2;
private static final String TEST_APP_NAME = "testApp";
private static final String TEST_PKG_NAME = "testPkg";
@@ -65,12 +69,14 @@
private PackageManager mPackageManager;
@Mock
private PreferenceScreen mScreen;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
private Context mContext;
private PreferenceGroup mGroup;
private PreferenceManager mPreferenceManager;
private ContentResolver mResolver;
- private GupPreferenceController mController;
+ private GameDriverAppPreferenceController mController;
private CharSequence[] mValueList;
private String mDialogTitle;
@@ -79,24 +85,35 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mResolver = mContext.getContentResolver();
- mValueList = mContext.getResources().getStringArray(R.array.gup_app_preference_values);
- mDialogTitle = mContext.getResources().getString(R.string.gup_app_preference_title);
+ mValueList =
+ mContext.getResources().getStringArray(R.array.game_driver_app_preference_values);
+ mDialogTitle = mContext.getResources().getString(R.string.game_driver_app_preference_title);
}
@Test
- public void getAvailability_developmentSettingsEnabled_available() {
+ public void getAvailability_developmentSettingsEnabledAndGameDriverOn_available() {
loadDefaultConfig();
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
- public void getAvailability_developmentSettingsDisabled_disabledDependentSetting() {
+ public void getAvailability_developmentSettingsDisabled_conditionallyUnavailable() {
loadDefaultConfig();
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailability_gameDriverOff_conditionallyUnavailable() {
+ loadDefaultConfig();
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
@@ -111,10 +128,46 @@
}
@Test
+ public void onStart_shouldRegister() {
+ loadDefaultConfig();
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldUnregister() {
+ loadDefaultConfig();
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void updateState_available_visible() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ loadDefaultConfig();
+
+ assertThat(mGroup.isVisible()).isTrue();
+ }
+
+ @Test
+ public void updateState_gameDriverOff_notVisible() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ loadDefaultConfig();
+
+ assertThat(mGroup.isVisible()).isFalse();
+ }
+
+ @Test
public void createPreference_configDefault_shouldSetDefaultAttributes() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
@@ -127,26 +180,26 @@
}
@Test
- public void createPreference_configGup_shouldSetGupAttributes() {
+ public void createPreference_configGAME_DRIVER_shouldSetGameDriverAttributes() {
loadConfig(TEST_PKG_NAME, "");
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
assertThat(preference.getEntries()).isEqualTo(mValueList);
assertThat(preference.getEntryValues()).isEqualTo(mValueList);
- assertThat(preference.getEntry()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getValue()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getSummary()).isEqualTo(mValueList[GUP]);
+ assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
}
@Test
public void createPreference_configSystem_shouldSetSystemAttributes() {
loadConfig("", TEST_PKG_NAME);
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
@@ -162,31 +215,31 @@
public void onPreferenceChange_selectDefault_shouldUpdateAttributesAndSettingsGlobal() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
mController.onPreferenceChange(preference, mValueList[DEFAULT]);
assertThat(preference.getEntry()).isEqualTo(mValueList[DEFAULT]);
assertThat(preference.getValue()).isEqualTo(mValueList[DEFAULT]);
assertThat(preference.getSummary()).isEqualTo(mValueList[DEFAULT]);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
.isEqualTo("");
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
.isEqualTo("");
}
@Test
- public void onPreferenceChange_selectGup_shouldUpdateAttributesAndSettingsGlobal() {
+ public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
- mController.onPreferenceChange(preference, mValueList[GUP]);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
+ mController.onPreferenceChange(preference, mValueList[GAME_DRIVER]);
- assertThat(preference.getEntry()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getValue()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getSummary()).isEqualTo(mValueList[GUP]);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS))
+ assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
.isEqualTo(TEST_PKG_NAME);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
.isEqualTo("");
}
@@ -194,15 +247,15 @@
public void onPreferenceChange_selectSystem_shouldUpdateAttributesAndSettingsGlobal() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
mController.onPreferenceChange(preference, mValueList[SYSTEM]);
assertThat(preference.getEntry()).isEqualTo(mValueList[SYSTEM]);
assertThat(preference.getValue()).isEqualTo(mValueList[SYSTEM]);
assertThat(preference.getSummary()).isEqualTo(mValueList[SYSTEM]);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
.isEqualTo("");
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
.isEqualTo(TEST_PKG_NAME);
}
@@ -224,12 +277,13 @@
private void loadDefaultConfig() { loadConfig("", ""); }
private void loadConfig(String optIn, String optOut) {
- Settings.Global.putString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS, optIn);
- Settings.Global.putString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS, optOut);
+ Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS, optIn);
+ Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut);
- mController = new GupPreferenceController(mContext, "testKey");
+ mController = new GameDriverAppPreferenceController(mContext, "testKey");
mGroup = spy(new PreferenceCategory(mContext));
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
+ when(mGroup.getContext()).thenReturn(mContext);
when(mGroup.getPreferenceManager()).thenReturn(preferenceManager);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mGroup);
mController.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverContentObserverTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverContentObserverTest.java
new file mode 100644
index 0000000..caaf896
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverContentObserverTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.ContentResolver;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverContentObserverTest {
+
+ @Mock
+ private ContentResolver mResolver;
+ @Mock
+ private GameDriverContentObserver.OnGameDriverContentChangedListener mListener;
+
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mGameDriverContentObserver = spy(new GameDriverContentObserver(null, null));
+ }
+
+ @Test
+ public void onChange_shouldCallListener() {
+ mGameDriverContentObserver.mListener = mListener;
+ mGameDriverContentObserver.onChange(true);
+
+ verify(mListener).onGameDriverContentChanged();
+ }
+
+ @Test
+ public void register_shouldRegisterContentObserver() {
+ mGameDriverContentObserver.register(mResolver);
+
+ verify(mResolver).registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_ALL_APPS), false,
+ mGameDriverContentObserver);
+ }
+
+ @Test
+ public void unregister_shouldUnregisterContentObserver() {
+ mGameDriverContentObserver.unregister(mResolver);
+
+ verify(mResolver).unregisterContentObserver(mGameDriverContentObserver);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gup/GupDashboardTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverDashboardTest.java
similarity index 67%
rename from tests/robotests/src/com/android/settings/development/gup/GupDashboardTest.java
rename to tests/robotests/src/com/android/settings/development/gamedriver/GameDriverDashboardTest.java
index 17278ef..f8f8add 100644
--- a/tests/robotests/src/com/android/settings/development/gup/GupDashboardTest.java
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverDashboardTest.java
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
import static com.google.common.truth.Truth.assertThat;
-import com.android.internal.logging.nano.MetricsProto;
+import android.app.settings.SettingsEnums;
+
import com.android.settings.R;
import org.junit.Before;
@@ -27,12 +28,13 @@
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
-public class GupDashboardTest {
- private GupDashboard mDashboard;
+public class GameDriverDashboardTest {
+
+ private GameDriverDashboard mDashboard;
@Before
public void setUp() {
- mDashboard = new GupDashboard();
+ mDashboard = new GameDriverDashboard();
}
@Test
@@ -41,14 +43,13 @@
}
@Test
- public void getMetricesCategory_shouldReturnGupDashboard() {
+ public void getMetricesCategory_shouldReturnGameDriverDashboard() {
assertThat(mDashboard.getMetricsCategory())
- .isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GUP_DASHBOARD);
+ .isEqualTo(SettingsEnums.SETTINGS_GAME_DRIVER_DASHBOARD);
}
@Test
- public void getPreferenceScreen_shouldReturnGupSettings() {
- assertThat(mDashboard.getPreferenceScreenResId())
- .isEqualTo(R.xml.gup_settings);
+ public void getPreferenceScreen_shouldReturnGameDriverSettings() {
+ assertThat(mDashboard.getPreferenceScreenResId()).isEqualTo(R.xml.game_driver_settings);
}
}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
new file mode 100644
index 0000000..094cd21
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverEnableForAllAppsPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private SwitchPreference mPreference;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ private Context mContext;
+ private ContentResolver mResolver;
+ private GameDriverEnableForAllAppsPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mResolver = mContext.getContentResolver();
+ mController = new GameDriverEnableForAllAppsPreferenceController(mContext, "testKey");
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ }
+
+ @Test
+ public void getAvailability_developmentSettingsEnabledAndGameDriverSettingsOn_available() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailability_developmentSettingsDisabled_conditionallyUnavailable() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailability_gameDriverOff_conditionallyUnavailable() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void displayPreference_shouldAddSwitchPreference() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void onStart_shouldRegister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldUnregister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void updateState_availableAndGameDriverDefault_visibleAndUncheck() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController.updateState(mPreference);
+
+ verify(mPreference, atLeastOnce()).setVisible(true);
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void updateState_availableAndGameDriverAllApps_visibleAndCheck() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
+ mController.updateState(mPreference);
+
+ verify(mPreference, atLeastOnce()).setVisible(true);
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void updateState_gameDriverOff_notVisibleAndUncheck() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(false);
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void onPreferenceChange_check_shouldUpdateSettingsGlobal() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController.onPreferenceChange(mPreference, true);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_ALL_APPS);
+ }
+
+ @Test
+ public void onPreferenceChange_uncheck_shouldUpdateSettingsGlobal() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
+ mController.onPreferenceChange(mPreference, false);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_DEFAULT);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceControllerTest.java
new file mode 100644
index 0000000..133791e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceControllerTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+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.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settingslib.widget.FooterPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverFooterPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private FooterPreference mPreference;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ private Context mContext;
+ private ContentResolver mResolver;
+ private GameDriverFooterPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mResolver = mContext.getContentResolver();
+ mController = spy(new GameDriverFooterPreferenceController(mContext));
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void getAvailabilityStatus_gameDriverOff_availableUnsearchable() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_gameDriverDefault_conditionallyUnavailable() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_gameDriverAllApps_conditionallyUnavailable() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void onStart_shouldRegister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldUnregister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void updateState_available_visible() {
+ when(mController.getAvailabilityStatus()).thenReturn(AVAILABLE_UNSEARCHABLE);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(true);
+ }
+
+ @Test
+ public void updateState_unavailable_invisible() {
+ when(mController.getAvailabilityStatus()).thenReturn(CONDITIONALLY_UNAVAILABLE);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(false);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarControllerTest.java
new file mode 100644
index 0000000..f546c36
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarControllerTest.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2019 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.development.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.widget.SwitchBar;
+import com.android.settings.widget.SwitchBarController;
+import com.android.settings.widget.SwitchWidgetController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverGlobalSwitchBarControllerTest {
+
+ @Mock
+ private SwitchBar mSwitchBar;
+ @Mock
+ private SwitchWidgetController mSwitchWidgetController;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ private Context mContext;
+ private ContentResolver mResolver;
+ private GameDriverGlobalSwitchBarController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mResolver = mContext.getContentResolver();
+ }
+
+ @Test
+ public void constructor_gameDriverOn_shouldCheckSwitchBar() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setChecked(true);
+ }
+
+ @Test
+ public void constructor_gameDriverOff_shouldUncheckSwitchBar() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setChecked(false);
+ }
+
+ @Test
+ public void constructor_developmentSettingsEnabled_shouldEnableSwitchBar() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setEnabled(true);
+ }
+
+ @Test
+ public void constructor_developmentSettingsDisabled_shouldDisableSwitchBar() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setEnabled(false);
+ }
+
+ @Test
+ public void onStart_shouldStartListeningAndRegister() {
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.mSwitchWidgetController = mSwitchWidgetController;
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mSwitchWidgetController).startListening();
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldStopListeningAndUnregister() {
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.mSwitchWidgetController = mSwitchWidgetController;
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mSwitchWidgetController).stopListening();
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void onSwitchToggled_checked_shouldTurnOnGameDriver() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.onSwitchToggled(true);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_DEFAULT);
+ }
+
+ @Test
+ public void onSwitchToggled_unchecked_shouldTurnOffGameDriver() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.onSwitchToggled(false);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_OFF);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceControllerTest.java
deleted file mode 100644
index b7aadc3..0000000
--- a/tests/robotests/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceControllerTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2019 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.development.gup;
-
-import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
-import static com.android.settings.development.gup.GupEnableForAllAppsPreferenceController.GUP_ALL_APPS;
-import static com.android.settings.development.gup.GupEnableForAllAppsPreferenceController.GUP_DEFAULT;
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(RobolectricTestRunner.class)
-public class GupEnableForAllAppsPreferenceControllerTest {
- @Mock
- private PreferenceScreen mScreen;
- @Mock
- private SwitchPreference mPreference;
-
- private Context mContext;
- private ContentResolver mResolver;
- private GupEnableForAllAppsPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mResolver = mContext.getContentResolver();
- mController = new GupEnableForAllAppsPreferenceController(mContext, "testKey");
- when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
- }
-
- @Test
- public void getAvailability_developmentSettingsEnabled_available() {
- Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void getAvailability_developmentSettingsDisabled_disabledDependentSetting() {
- Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
- }
-
- @Test
- public void displayPreference_shouldAddSwitchPreference() {
- Settings.Global.putInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT);
- mController.displayPreference(mScreen);
-
- verify(mPreference).setChecked(false);
- }
-
- @Test
- public void onPreferenceChange_check_shouldUpdateSettingsGlobal() {
- Settings.Global.putInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT);
- mController.displayPreference(mScreen);
- mController.onPreferenceChange(mPreference, true);
-
- assertThat(Settings.Global.getInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT))
- .isEqualTo(GUP_ALL_APPS);
- }
-
- @Test
- public void onPreferenceChange_uncheck_shouldUpdateSettingsGlobal() {
- Settings.Global.putInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_ALL_APPS);
- mController.displayPreference(mScreen);
- mController.onPreferenceChange(mPreference, false);
-
- assertThat(Settings.Global.getInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT))
- .isEqualTo(GUP_DEFAULT);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
index 3e6ba6c..1a0539c 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.homepage.contextualcards;
+import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_HALF_WIDTH;
@@ -210,7 +211,7 @@
@Test
- public void assignCardWidth_noSuggestionCards_shouldNotHaveHalfCards() {
+ public void getCardsWithViewType_noSuggestionCards_shouldNotHaveHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -221,7 +222,7 @@
final List<ContextualCard> noSuggestionCards = buildCategoriedCards(getContextualCardList(),
categories);
- final List<ContextualCard> result = mManager.assignCardWidth(noSuggestionCards);
+ final List<ContextualCard> result = mManager.getCardsWithViewType(noSuggestionCards);
assertThat(result).hasSize(5);
for (ContextualCard card : result) {
@@ -230,7 +231,7 @@
}
@Test
- public void assignCardWidth_oneSuggestionCards_shouldNotHaveHalfCards() {
+ public void getCardsWithViewType_oneSuggestionCards_shouldNotHaveHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -241,7 +242,7 @@
final List<ContextualCard> oneSuggestionCards = buildCategoriedCards(
getContextualCardList(), categories);
- final List<ContextualCard> result = mManager.assignCardWidth(oneSuggestionCards);
+ final List<ContextualCard> result = mManager.getCardsWithViewType(oneSuggestionCards);
assertThat(result).hasSize(5);
for (ContextualCard card : result) {
@@ -250,7 +251,7 @@
}
@Test
- public void assignCardWidth_twoConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
+ public void getCardsWithViewType_twoConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -264,7 +265,7 @@
VIEW_TYPE_FULL_WIDTH, VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH,
VIEW_TYPE_FULL_WIDTH);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
twoConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -274,7 +275,7 @@
}
@Test
- public void assignCardWidth_twoNonConsecutiveSuggestionCards_shouldNotHaveHalfCards() {
+ public void getCardsWithViewType_twoNonConsecutiveSuggestionCards_shouldNotHaveHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -285,7 +286,7 @@
final List<ContextualCard> twoNonConsecutiveSuggestionCards = buildCategoriedCards(
getContextualCardList(), categories);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
twoNonConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -295,7 +296,7 @@
}
@Test
- public void assignCardWidth_threeConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
+ public void getCardsWithViewType_threeConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
@@ -309,7 +310,7 @@
VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_FULL_WIDTH,
VIEW_TYPE_FULL_WIDTH);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
threeConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -319,7 +320,7 @@
}
@Test
- public void assignCardWidth_fourConsecutiveSuggestionCards_shouldHaveFourHalfCards() {
+ public void getCardsWithViewType_fourConsecutiveSuggestionCards_shouldHaveFourHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
@@ -333,7 +334,7 @@
VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH,
VIEW_TYPE_HALF_WIDTH);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
fourConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -342,6 +343,55 @@
}
}
+ @Test
+ public void getCardsWithViewType_onlyDeferredSetupCard_shouldHaveDeferredSetupCard() {
+ final List<ContextualCard> oneDeferredSetupCards = getDeferredSetupCardList();
+
+ final List<ContextualCard> result = mManager.getCardsWithViewType(oneDeferredSetupCards);
+
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_DEFERRED_SETUP);
+ }
+
+ @Test
+ public void getCardsWithViewType_hasDeferredSetupCard_shouldHaveDeferredSetupCard() {
+ final List<Integer> categories = Arrays.asList(
+ ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE,
+ ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
+ );
+ final List<ContextualCard> cards = buildCategoriedCards(getContextualCardList(),
+ categories);
+
+ final List<ContextualCard> result = mManager.getCardsWithViewType(cards);
+
+ assertThat(result).hasSize(5);
+ assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_DEFERRED_SETUP);
+ }
+
+ @Test
+ public void getCardsWithViewType_noDeferredSetupCard_shouldNotHaveDeferredSetupCard() {
+ final List<Integer> categories = Arrays.asList(
+ ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
+ ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
+ );
+ final List<ContextualCard> cards = buildCategoriedCards(
+ getContextualCardList(), categories);
+
+ final List<ContextualCard> result = mManager.getCardsWithViewType(cards);
+
+ assertThat(result).hasSize(5);
+ for (int i = 0; i < result.size(); i++) {
+ assertThat(result.get(i).getViewType()).isNotEqualTo(
+ ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE);
+ }
+ }
+
private ContextualCard buildContextualCard(String sliceUri) {
return new ContextualCard.Builder()
.setName(TEST_SLICE_NAME)
@@ -396,4 +446,16 @@
.build());
return cards;
}
+
+ private List<ContextualCard> getDeferredSetupCardList() {
+ final List<ContextualCard> cards = new ArrayList<>();
+ cards.add(new ContextualCard.Builder()
+ .setName("deferred_setup")
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setCategory(ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE)
+ .setSliceUri(new Uri.Builder().appendPath("test_deferred_setup_path").build())
+ .setViewType(VIEW_TYPE_FULL_WIDTH)
+ .build());
+ return cards;
+ }
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java
index f465702..7ec1316 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java
@@ -39,6 +39,7 @@
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
+import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceQuery;
@@ -125,6 +126,34 @@
}
@Test
+ @Config(shadows = ShadowRestrictedLockUtilsInternal.class)
+ public void getSlice_hasSuggestedApp_shouldSortByNotificationSentCount() {
+ addMockPackageToPackageManager(true /* isRecentlyInstalled */,
+ ApplicationInfo.FLAG_INSTALLED);
+ mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */);
+
+ final Slice slice = mNotificationChannelSlice.getSlice();
+
+ // Get all RowBuilders from Slice.
+ final List<SliceItem> rowItems = SliceQuery.findAll(slice, FORMAT_SLICE, HINT_LIST_ITEM,
+ null /* nonHints */);
+
+ // Ensure the total size of rows is equal to the notification channel count with header.
+ assertThat(rowItems).isNotNull();
+ assertThat(rowItems.size()).isEqualTo(CHANNEL_COUNT + 1);
+
+ // Remove the header of slice.
+ rowItems.remove(0);
+
+ // Test the rows of slice are sorted with notification sent count by descending.
+ for (int i = 0; i < rowItems.size(); i++) {
+ // Assert the summary text is the same as expectation.
+ assertThat(getSummaryFromSliceItem(rowItems.get(i))).isEqualTo(
+ mContext.getString(R.string.notifications_sent_weekly, CHANNEL_COUNT - i));
+ }
+ }
+
+ @Test
public void getSlice_noRecentlyInstalledApp_shouldHaveNoSuggestedAppTitle() {
addMockPackageToPackageManager(false /* isRecentlyInstalled */,
ApplicationInfo.FLAG_INSTALLED);
@@ -269,10 +298,31 @@
final Map<String, NotificationBackend.NotificationsSentState> states = new ArrayMap<>();
for (int i = 0; i < channelCount; i++) {
final NotificationsSentState state = new NotificationsSentState();
+ // Set the avgSentWeekly for each channel: channel0 is 1, channel1: 2, channel2: 3.
+ state.avgSentWeekly = i + 1;
state.sentCount = sentCount;
states.put(CHANNEL_NAME_PREFIX + i, state);
}
return states;
}
+
+ private CharSequence getSummaryFromSliceItem(SliceItem rowItem) {
+ if (rowItem == null) {
+ return null;
+ }
+
+ final Slice rowSlice = rowItem.getSlice();
+ if (rowSlice == null) {
+ return null;
+ }
+
+ final List<SliceItem> rowSliceItems = rowSlice.getItems();
+ if (rowSliceItems == null || rowSliceItems.size() < 2) {
+ return null;
+ }
+
+ // Index 0: title; Index 1: summary.
+ return rowSliceItems.get(1).getText();
+ }
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelperTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelperTest.java
new file mode 100644
index 0000000..740a45b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelperTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2019 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.slices;
+
+import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP;
+import static com.android.settings.homepage.contextualcards.slices.SliceDeferredSetupCardRendererHelper.DeferredSetupCardViewHolder;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.net.Uri;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.slice.Slice;
+import androidx.slice.SliceProvider;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
+import androidx.slice.widget.SliceLiveData;
+
+import com.android.settings.R;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.intelligence.ContextualCardProto;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class SliceDeferredSetupCardRendererHelperTest {
+ private static final Uri TEST_SLICE_URI = Uri.parse("content://test/test");
+ private static final CharSequence TITLE = "test_title";
+ private static final CharSequence SUMMARY = "test_summary";
+
+ private Activity mActivity;
+ private SliceDeferredSetupCardRendererHelper mHelper;
+
+ @Before
+ public void setUp() {
+ // Set-up specs for SliceMetadata.
+ SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+ mActivity = Robolectric.buildActivity(Activity.class).create().get();
+ mActivity.setTheme(R.style.Theme_Settings_Home);
+ mHelper = new SliceDeferredSetupCardRendererHelper(mActivity);
+ }
+
+ @Test
+ public void createViewHolder_shouldAlwaysReturnCustomViewHolder() {
+ final RecyclerView.ViewHolder viewHolder = getDeferredSetupCardViewHolder();
+
+ assertThat(viewHolder).isInstanceOf(
+ DeferredSetupCardViewHolder.class);
+ }
+
+ @Test
+ public void bindView_shouldSetTitle() {
+ final RecyclerView.ViewHolder viewHolder = getDeferredSetupCardViewHolder();
+
+ mHelper.bindView(viewHolder, buildContextualCard(), buildSlice());
+
+ assertThat(((DeferredSetupCardViewHolder) viewHolder).title.getText()).isEqualTo(TITLE);
+ }
+
+ @Test
+ public void bindView_shouldSetSummary() {
+ final RecyclerView.ViewHolder viewHolder = getDeferredSetupCardViewHolder();
+
+ mHelper.bindView(viewHolder, buildContextualCard(), buildSlice());
+
+ assertThat(((DeferredSetupCardViewHolder) viewHolder).summary.getText()).isEqualTo(SUMMARY);
+ }
+
+ private RecyclerView.ViewHolder getDeferredSetupCardViewHolder() {
+ final RecyclerView recyclerView = new RecyclerView(mActivity);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ final View view = LayoutInflater.from(mActivity).inflate(VIEW_TYPE_DEFERRED_SETUP,
+ recyclerView, false);
+
+ return mHelper.createViewHolder(view);
+ }
+
+ private ContextualCard buildContextualCard() {
+ return new ContextualCard.Builder()
+ .setName("test_name")
+ .setCategory(ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE)
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setSliceUri(TEST_SLICE_URI)
+ .setViewType(VIEW_TYPE_DEFERRED_SETUP)
+ .build();
+ }
+
+ private Slice buildSlice() {
+ final IconCompat icon = IconCompat.createWithResource(mActivity, R.drawable.empty_icon);
+ final PendingIntent pendingIntent = PendingIntent.getActivity(
+ mActivity,
+ TITLE.hashCode() /* requestCode */,
+ new Intent("test action"),
+ 0 /* flags */);
+ final SliceAction action
+ = SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, TITLE);
+ return new ListBuilder(mActivity, TEST_SLICE_URI, ListBuilder.INFINITY)
+ .addRow(new ListBuilder.RowBuilder()
+ .addEndItem(icon, ListBuilder.ICON_IMAGE)
+ .setTitle(TITLE)
+ .setSubtitle(SUMMARY)
+ .setPrimaryAction(action))
+ .build();
+ }
+}
\ No newline at end of file