Merge "Call releaseSession() when "stop casting" button click" into rvc-dev
diff --git a/res/layout/app_preferred_settings.xml b/res/layout/app_preferred_settings.xml
index 1f3b497..b3343f5 100644
--- a/res/layout/app_preferred_settings.xml
+++ b/res/layout/app_preferred_settings.xml
@@ -35,6 +35,7 @@
android:layout_marginStart="-4dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/clear_activities" />
+ android:text="@string/clear_activities"
+ style="@style/ActionPrimaryButton" />
</LinearLayout>
diff --git a/res/layout/zen_rule_name.xml b/res/layout/zen_rule_name.xml
index 90b4fbe..afa97ac 100755
--- a/res/layout/zen_rule_name.xml
+++ b/res/layout/zen_rule_name.xml
@@ -21,7 +21,7 @@
<EditText
android:id="@+id/zen_mode_rule_name"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
+ android:layout_height="48dp"
android:singleLine="true"
android:inputType="textCapSentences"
android:hint="@string/zen_mode_rule_name_hint"
diff --git a/res/values/config.xml b/res/values/config.xml
index 2373b25..64d9ab7 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -201,6 +201,9 @@
<!-- Whether or not TopLevelSettings should force rounded icon for injected tiles -->
<bool name="config_force_rounded_icon_TopLevelSettings">true</bool>
+ <!-- Whether dismissal timestamp should be kept before deletion -->
+ <bool name="config_keep_contextual_card_dismissal_timestamp">false</bool>
+
<!-- Settings intelligence package name -->
<string name="config_settingsintelligence_package_name" translatable="false">
com.android.settings.intelligence
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 024569b..ef6b818 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -394,8 +394,6 @@
<!-- Maximum height for SliceView, override on slices/view/src/main/res/values/dimens.xml -->
<!-- A single Row Slice height is 60dp -->
<dimen name="abc_slice_large_height">1200dp</dimen>
- <!-- Min height of slice row view, override on slices/view/src/main/res/values/dimens.xml -->
- <dimen name="abc_slice_row_min_height">@dimen/abc_slice_row_max_height</dimen>
<!-- System navigation settings illustration height -->
<dimen name="system_navigation_illustration_height">320dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index aa37f06..9b80808 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -144,6 +144,8 @@
<string name="bluetooth_lock_voice_dialing_summary">
Prevent use of the bluetooth dialer when the screen is locked
</string>
+ <!-- Bluetooth settings screen, heading above the list of nearby bluetooth devices. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_devices">Bluetooth devices</string>
<!-- Bluetooth settings screen, title for the current bluetooth name setting -->
<string name="bluetooth_device_name">Device name</string>
<!-- Bluetooth settings screen, image description for device details button. This opens the screen to rename, unpair, etc. a single device. -->
@@ -2029,8 +2031,10 @@
<string name="wifi_ip_settings">IP settings</string>
<!-- Label for the spinner to show Wifi MAC randomization [CHAR LIMIT=25] -->
<string name="wifi_privacy_settings">Privacy</string>
- <!-- Label for the subscription detail preference. [CHAR LIMIT=32] -->
- <string name="wifi_subscription_detail">Subscription details</string>
+ <!-- Label for the subscription preference. [CHAR LIMIT=32] -->
+ <string name="wifi_subscription">Subscription</string>
+ <!-- Summary text for the subscription preference. [CHAR LIMIT=NONE] -->
+ <string name="wifi_subscription_summary">View or change subscription</string>
<!-- Summary for Wifi MAC randomization option when it is ephemeral network [CHAR LIMIT=50] -->
<string name="wifi_privacy_settings_ephemeral_summary">Randomized MAC</string>
<!-- Title for the fragment to add a device into the wifi network [CHAR LIMIT=50] -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 85b25e4..dee8176 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -590,6 +590,7 @@
<style name="TextAppearance.Tab" parent="@android:style/TextAppearance.DeviceDefault.Medium">
<item name="android:textAllCaps">false</item>
+ <item name="android:textSize">14sp</item>
<item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
</style>
diff --git a/res/xml/battery_saver_settings.xml b/res/xml/battery_saver_settings.xml
index 6009f6a..29b82ef 100644
--- a/res/xml/battery_saver_settings.xml
+++ b/res/xml/battery_saver_settings.xml
@@ -45,7 +45,7 @@
<com.android.settingslib.widget.FooterPreference
android:key="battery_saver_footer_preference"
- android:selectable="false"
+ android:selectable="true"
android:title="@*android:string/battery_saver_description"
settings:allowDividerAbove="true"
settings:searchable="false"/>
diff --git a/res/xml/installed_app_launch_settings.xml b/res/xml/installed_app_launch_settings.xml
index 6cf1955..b777949 100644
--- a/res/xml/installed_app_launch_settings.xml
+++ b/res/xml/installed_app_launch_settings.xml
@@ -38,7 +38,8 @@
android:title="@string/app_launch_other_defaults_title">
<com.android.settings.applications.ClearDefaultsPreference
- android:key="app_launch_clear_defaults"/>
+ android:key="app_launch_clear_defaults"
+ android:selectable="false"/>
</PreferenceCategory>
diff --git a/res/xml/wifi_network_details_fragment2.xml b/res/xml/wifi_network_details_fragment2.xml
index 156b744..30a7f67 100644
--- a/res/xml/wifi_network_details_fragment2.xml
+++ b/res/xml/wifi_network_details_fragment2.xml
@@ -69,6 +69,12 @@
android:entries="@array/wifi_privacy_entries"
android:entryValues="@array/wifi_privacy_values"/>
+ <Preference
+ android:key="subscription_detail"
+ android:title="@string/wifi_subscription"
+ android:summary="@string/wifi_subscription_summary"
+ settings:allowDividerAbove="true"/>
+
<SwitchPreference
android:key="auto_connect"
android:title="@string/wifi_auto_connect_title"
@@ -139,9 +145,4 @@
settings:enableCopying="true"/>
</PreferenceCategory>
- <Preference
- android:key="subscription_detail"
- android:title="@string/wifi_subscription_detail"
- settings:allowDividerAbove="true"/>
-
</PreferenceScreen>
diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java
index 8da6fbb..76fb3ff 100644
--- a/src/com/android/settings/accessibility/AccessibilityUtil.java
+++ b/src/com/android/settings/accessibility/AccessibilityUtil.java
@@ -21,9 +21,11 @@
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName;
import android.content.Context;
+import android.content.res.Resources;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.TypedValue;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.IntDef;
@@ -350,4 +352,32 @@
"Unsupported userShortcutType " + shortcutType);
}
}
+
+ /**
+ * Gets the width of the screen.
+ *
+ * @param context the current context.
+ * @return the width of the screen in terms of pixels.
+ */
+ public static int getScreenWidthPixels(Context context) {
+ final Resources resources = context.getResources();
+ final int screenWidthDp = resources.getConfiguration().screenWidthDp;
+
+ return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, screenWidthDp,
+ resources.getDisplayMetrics()));
+ }
+
+ /**
+ * Gets the height of the screen.
+ *
+ * @param context the current context.
+ * @return the height of the screen in terms of pixels.
+ */
+ public static int getScreenHeightPixels(Context context) {
+ final Resources resources = context.getResources();
+ final int screenHeightDp = resources.getConfiguration().screenHeightDp;
+
+ return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, screenHeightDp,
+ resources.getDisplayMetrics()));
+ }
}
diff --git a/src/com/android/settings/accessibility/AnimatedImagePreference.java b/src/com/android/settings/accessibility/AnimatedImagePreference.java
index 1609a3c..61e439f 100644
--- a/src/com/android/settings/accessibility/AnimatedImagePreference.java
+++ b/src/com/android/settings/accessibility/AnimatedImagePreference.java
@@ -34,6 +34,7 @@
public class AnimatedImagePreference extends Preference {
private Uri mImageUri;
+ private int mMaxHeight = -1;
AnimatedImagePreference(Context context) {
super(context);
@@ -45,20 +46,26 @@
super.onBindViewHolder(holder);
final ImageView imageView = holder.itemView.findViewById(R.id.animated_img);
- if (imageView != null && mImageUri != null) {
+ if (imageView == null) {
+ return;
+ }
+
+ if (mImageUri != null) {
imageView.setImageURI(mImageUri);
final Drawable drawable = imageView.getDrawable();
- if (drawable != null) {
- if (drawable instanceof AnimatedImageDrawable) {
- ((AnimatedImageDrawable) drawable).start();
- }
+ if (drawable instanceof AnimatedImageDrawable) {
+ ((AnimatedImageDrawable) drawable).start();
}
}
+
+ if (mMaxHeight > -1) {
+ imageView.setMaxWidth(mMaxHeight);
+ }
}
/**
- * Set image uri to display image in {@link ImageView}
+ * Sets image uri to display image in {@link ImageView}
*
* @param imageUri the Uri of an image
*/
@@ -68,4 +75,16 @@
notifyChanged();
}
}
+
+ /**
+ * Sets the maximum height of the view.
+ *
+ * @param maxHeight the maximum height of ImageView in terms of pixels.
+ */
+ public void setMaxHeight(int maxHeight) {
+ if (maxHeight != mMaxHeight) {
+ mMaxHeight = maxHeight;
+ notifyChanged();
+ }
+ }
}
diff --git a/src/com/android/settings/accessibility/HtmlTextPreference.java b/src/com/android/settings/accessibility/HtmlTextPreference.java
index fcf4725..4c528a3 100644
--- a/src/com/android/settings/accessibility/HtmlTextPreference.java
+++ b/src/com/android/settings/accessibility/HtmlTextPreference.java
@@ -23,9 +23,6 @@
import androidx.preference.PreferenceViewHolder;
-import java.util.List;
-import java.util.regex.Pattern;
-
/**
* A custom {@link android.widget.TextView} preference that shows html text with a custom tag
* filter.
@@ -35,7 +32,6 @@
private int mFlag = Html.FROM_HTML_MODE_COMPACT;
private Html.ImageGetter mImageGetter;
private Html.TagHandler mTagHandler;
- private List<String> mUnsupportedTagList;
HtmlTextPreference(Context context) {
super(context);
@@ -47,8 +43,8 @@
final TextView summaryView = holder.itemView.findViewById(android.R.id.summary);
if (summaryView != null && !TextUtils.isEmpty(getSummary())) {
- final String filteredText = getFilteredText(getSummary().toString());
- summaryView.setText(Html.fromHtml(filteredText, mFlag, mImageGetter, mTagHandler));
+ summaryView.setText(
+ Html.fromHtml(getSummary().toString(), mFlag, mImageGetter, mTagHandler));
}
}
@@ -87,39 +83,4 @@
notifyChanged();
}
}
-
- /**
- * Sets unsupported tag list, the text will be filtered though this list in advanced.
- *
- * @param unsupportedTagList the list of unsupported tags
- */
- public void setUnsupportedTagList(List<String> unsupportedTagList) {
- if (unsupportedTagList != null && !unsupportedTagList.equals(mUnsupportedTagList)) {
- mUnsupportedTagList = unsupportedTagList;
- notifyChanged();
- }
- }
-
- private String getFilteredText(String text) {
- if (mUnsupportedTagList == null) {
- return text;
- }
-
- int i = 1;
- for (String tag : mUnsupportedTagList) {
- if (!TextUtils.isEmpty(text)) {
- final String index = String.valueOf(i++);
- final String targetStart1 = "(?i)<" + tag + " ";
- final String targetStart2 = "(?i)<" + tag + ">";
- final String replacementStart1 = "<unsupportedtag" + index + " ";
- final String replacementStart2 = "<unsupportedtag" + index + ">";
- final String targetEnd = "(?i)</" + tag + ">";
- final String replacementEnd = "</unsupportedtag" + index + ">";
- text = Pattern.compile(targetStart1).matcher(text).replaceAll(replacementStart1);
- text = Pattern.compile(targetStart2).matcher(text).replaceAll(replacementStart2);
- text = Pattern.compile(targetEnd).matcher(text).replaceAll(replacementEnd);
- }
- }
- return text;
- }
}
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 19a0f2b..838a758 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -16,6 +16,9 @@
package com.android.settings.accessibility;
+import static com.android.settings.accessibility.AccessibilityUtil.getScreenHeightPixels;
+import static com.android.settings.accessibility.AccessibilityUtil.getScreenWidthPixels;
+
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
@@ -80,7 +83,6 @@
protected CharSequence mPackageName;
protected Uri mImageUri;
protected CharSequence mHtmlDescription;
- private static final String ANCHOR_TAG = "a";
private static final String DRAWABLE_FOLDER = "drawable";
protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
protected static final String KEY_GENERAL_CATEGORY = "general_categories";
@@ -94,9 +96,8 @@
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
- // For html description of accessibility service, third party developer must follow the rule,
- // such as <img src="R.drawable.fileName"/>, a11y settings will get third party resources
- // by this.
+ // For html description of accessibility service, must follow the rule, such as
+ // <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully.
private static final String IMG_PREFIX = "R.drawable.";
private ImageView mImageGetterCacheView;
@@ -147,10 +148,12 @@
PreferenceScreen preferenceScreen = getPreferenceScreen();
if (mImageUri != null) {
+ final int screenHalfHeight = getScreenHeightPixels(getPrefContext()) / /* half */ 2;
final AnimatedImagePreference animatedImagePreference = new AnimatedImagePreference(
getPrefContext());
animatedImagePreference.setImageUri(mImageUri);
animatedImagePreference.setSelectable(false);
+ animatedImagePreference.setMaxHeight(screenHalfHeight);
preferenceScreen.addPreference(animatedImagePreference);
}
@@ -195,14 +198,9 @@
introductionCategory.setTitle(title);
preferenceScreen.addPreference(introductionCategory);
- // For accessibility service, avoid malicious links made by third party developer.
- final List<String> unsupportedTagList = new ArrayList<>();
- unsupportedTagList.add(ANCHOR_TAG);
-
final HtmlTextPreference htmlTextPreference = new HtmlTextPreference(getPrefContext());
htmlTextPreference.setSummary(mHtmlDescription);
htmlTextPreference.setImageGetter(mImageGetter);
- htmlTextPreference.setUnsupportedTagList(unsupportedTagList);
htmlTextPreference.setSelectable(false);
introductionCategory.addPreference(htmlTextPreference);
}
@@ -383,14 +381,24 @@
mImageGetterCacheView.setAdjustViewBounds(true);
mImageGetterCacheView.setImageURI(imageUri);
- final Drawable drawable = mImageGetterCacheView.getDrawable().mutate();
- if (drawable != null) {
- drawable.setBounds(/* left= */0, /* top= */0, drawable.getIntrinsicWidth(),
- drawable.getIntrinsicHeight());
+ if (mImageGetterCacheView.getDrawable() == null) {
+ return null;
}
+ final Drawable drawable =
+ mImageGetterCacheView.getDrawable().mutate().getConstantState().newDrawable();
mImageGetterCacheView.setImageURI(null);
- mImageGetterCacheView.setImageDrawable(null);
+ final int imageWidth = drawable.getIntrinsicWidth();
+ final int imageHeight = drawable.getIntrinsicHeight();
+ final int screenHalfHeight = getScreenHeightPixels(getPrefContext()) / /* half */ 2;
+ if ((imageWidth > getScreenWidthPixels(getPrefContext()))
+ || (imageHeight > screenHalfHeight)) {
+ return null;
+ }
+
+ drawable.setBounds(/* left= */0, /* top= */0, drawable.getIntrinsicWidth(),
+ drawable.getIntrinsicHeight());
+
return drawable;
}
diff --git a/src/com/android/settings/applications/appinfo/InstantAppDomainsPreferenceController.java b/src/com/android/settings/applications/appinfo/InstantAppDomainsPreferenceController.java
index cbb805f..34c67f1 100644
--- a/src/com/android/settings/applications/appinfo/InstantAppDomainsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/InstantAppDomainsPreferenceController.java
@@ -38,7 +38,8 @@
@Override
public int getAvailabilityStatus() {
- return AppUtils.isInstant(mParent.getPackageInfo().applicationInfo)
+ return mParent.getPackageInfo() != null
+ && AppUtils.isInstant(mParent.getPackageInfo().applicationInfo)
? AVAILABLE : DISABLED_FOR_USER;
}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
index 2ee77d9..2048be0 100644
--- a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
@@ -118,7 +118,8 @@
mDialog.setText(ID_PRL_VERSION_VALUE, getCdmaPrlVersion());
- if (mSubscriptionInfo != null && isCdmaLteEnabled()) {
+ if ((mSubscriptionInfo != null && isCdmaLteEnabled()) ||
+ (mSubscriptionInfo == null && isSimPresent(mSlotId))) {
// Show IMEI for LTE device
mDialog.setText(ID_IMEI_VALUE,
getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
@@ -149,6 +150,15 @@
return mTelephonyManager.isGlobalModeEnabled();
}
+ boolean isSimPresent(int slotId) {
+ final int simState = mTelephonyManager.getSimState(slotId);
+ if ((simState != TelephonyManager.SIM_STATE_ABSENT) &&
+ (simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
+ return true;
+ }
+ return false;
+ }
+
@VisibleForTesting
String getMeid() {
return mTelephonyManager.getMeid(mSlotId);
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
index d7e07d9..30ba084 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
@@ -152,7 +152,11 @@
private final BroadcastReceiver mAreaInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- updateAreaInfoText();
+ if (CellBroadcastIntents.ACTION_AREA_INFO_UPDATED.equals(intent.getAction())
+ && intent.getIntExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)
+ == mSlotIndex) {
+ updateAreaInfoText();
+ }
}
};
@@ -337,8 +341,7 @@
if (cellBroadcastService == null) return;
try {
mDialog.setText(OPERATOR_INFO_VALUE_ID,
- cellBroadcastService.getCellBroadcastAreaInfo(
- SimStatusDialogController.this.mSlotIndex));
+ cellBroadcastService.getCellBroadcastAreaInfo(mSlotIndex));
} catch (RemoteException e) {
Log.d(TAG, "Can't get area info. e=" + e);
diff --git a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
index 8faae30..9f5b49e 100644
--- a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
+++ b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
@@ -39,13 +39,13 @@
@Override
public boolean isChecked() {
- return hasSufficientPermission(mContext.getPackageManager()) && Settings.System.getInt(
+ return hasSufficientPermission(mContext.getPackageManager()) && Settings.Secure.getInt(
mContext.getContentResolver(), SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
}
@Override
public boolean setChecked(boolean isChecked) {
- Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
+ Settings.Secure.putInt(mContext.getContentResolver(), SYSTEM_KEY,
isChecked ? 1 : DEFAULT_VALUE);
return true;
}
diff --git a/src/com/android/settings/homepage/contextualcards/CardContentProvider.java b/src/com/android/settings/homepage/contextualcards/CardContentProvider.java
index 9627eb0..75ec651 100644
--- a/src/com/android/settings/homepage/contextualcards/CardContentProvider.java
+++ b/src/com/android/settings/homepage/contextualcards/CardContentProvider.java
@@ -26,12 +26,16 @@
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
+import android.util.ArrayMap;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
+import com.android.settings.R;
import com.android.settingslib.utils.ThreadUtils;
+import java.util.Map;
+
/**
* Provider stores and manages user interaction feedback for homepage contextual cards.
*/
@@ -40,10 +44,10 @@
public static final String CARD_AUTHORITY = "com.android.settings.homepage.CardContentProvider";
public static final Uri REFRESH_CARD_URI = new Uri.Builder()
- .scheme(ContentResolver.SCHEME_CONTENT)
- .authority(CardContentProvider.CARD_AUTHORITY)
- .appendPath(CardDatabaseHelper.CARD_TABLE)
- .build();
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(CardContentProvider.CARD_AUTHORITY)
+ .appendPath(CardDatabaseHelper.CARD_TABLE)
+ .build();
public static final Uri DELETE_CARD_URI = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
@@ -81,6 +85,9 @@
final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
int numInserted = 0;
final SQLiteDatabase database = mDBHelper.getWritableDatabase();
+ final boolean keepDismissalTimestampBeforeDeletion = getContext().getResources()
+ .getBoolean(R.bool.config_keep_contextual_card_dismissal_timestamp);
+ final Map<String, Long> dismissedTimeMap = new ArrayMap<>();
try {
maybeEnableStrictMode();
@@ -88,9 +95,42 @@
final String table = getTableFromMatch(uri);
database.beginTransaction();
- // Here deletion first is avoiding redundant insertion. According to cl/215350754
+ if (keepDismissalTimestampBeforeDeletion) {
+ // Query the existing db and get dismissal info.
+ final String[] columns = new String[]{CardDatabaseHelper.CardColumns.NAME,
+ CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP};
+ final String selection =
+ CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP + " IS NOT NULL";
+ try (Cursor cursor = database.query(table, columns, selection,
+ null/* selectionArgs */, null /* groupBy */,
+ null /* having */, null /* orderBy */)) {
+ // Save them to a Map
+ for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
+ final String cardName = cursor.getString(cursor.getColumnIndex(
+ CardDatabaseHelper.CardColumns.NAME));
+ final long timestamp = cursor.getLong(cursor.getColumnIndex(
+ CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP));
+ dismissedTimeMap.put(cardName, timestamp);
+ }
+ }
+ }
+
+ // Here delete data first to avoid redundant insertion. According to cl/215350754
database.delete(table, null /* whereClause */, null /* whereArgs */);
+
for (ContentValues value : values) {
+ if (keepDismissalTimestampBeforeDeletion) {
+ // Replace dismissedTimestamp in each value if there is an old one.
+ final String cardName =
+ value.get(CardDatabaseHelper.CardColumns.NAME).toString();
+ if (dismissedTimeMap.containsKey(cardName)) {
+ // Replace the value of dismissedTimestamp
+ value.put(CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP,
+ dismissedTimeMap.get(cardName));
+ Log.d(TAG, "Replace dismissed time: " + cardName);
+ }
+ }
+
long ret = database.insert(table, null /* nullColumnHack */, value);
if (ret != -1L) {
numInserted++;
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
index 3d75962..53782e5 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
@@ -16,14 +16,14 @@
package com.android.settings.homepage.contextualcards.slices;
-import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
-
import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
@@ -77,8 +77,6 @@
private static final String TAG = "BluetoothDevicesSlice";
- private static int sToggledState;
-
private final Context mContext;
public BluetoothDevicesSlice(Context context) {
@@ -103,37 +101,26 @@
final IconCompat icon = IconCompat.createWithResource(mContext,
com.android.internal.R.drawable.ic_settings_bluetooth);
- final CharSequence title = mContext.getText(R.string.bluetooth_settings_title);
+ final CharSequence title = mContext.getText(R.string.bluetooth_devices);
final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, 0,
getIntent(), 0);
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon,
ListBuilder.ICON_IMAGE, title);
+ final SliceAction pairNewDeviceAction = getPairNewDeviceAction();
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
.setAccentColor(COLOR_NOT_TINTED)
+ .addAction(pairNewDeviceAction)
.setHeader(new ListBuilder.HeaderBuilder()
.setTitle(title)
.setPrimaryAction(primarySliceAction));
- // Only show a toggle when Bluetooth is off and not turning on.
- if ((!isBluetoothEnabled(btAdapter) && sToggledState != BluetoothAdapter.STATE_TURNING_ON)
- || sToggledState == BluetoothAdapter.STATE_TURNING_OFF) {
- sToggledState = 0;
- final PendingIntent toggleAction = getBroadcastIntent(mContext);
- final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction,
- null /* actionTitle */, false /* isChecked */);
- return listBuilder
- .addAction(toggleSliceAction)
- .build();
+ // Only show a header when Bluetooth is off.
+ if (!isBluetoothEnabled(btAdapter)) {
+ return listBuilder.build();
}
- sToggledState = 0;
// Get row builders by Bluetooth devices.
final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder();
- if (rows.isEmpty()) {
- return listBuilder
- .addRow(getPairNewDeviceRow())
- .build();
- }
// Get displayable device count.
final int deviceCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT);
@@ -161,20 +148,6 @@
@Override
public void onNotifyChange(Intent intent) {
- final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
- final boolean currentState = isBluetoothEnabled(btAdapter);
- final boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, currentState);
- if (newState != currentState) {
- if (newState) {
- sToggledState = BluetoothAdapter.STATE_TURNING_ON;
- btAdapter.enable();
- } else {
- sToggledState = BluetoothAdapter.STATE_TURNING_OFF;
- btAdapter.disable();
- }
- mContext.getContentResolver().notifyChange(getUri(), null);
- }
-
// Activate available media device.
final int bluetoothDeviceHashCode = intent.getIntExtra(BLUETOOTH_DEVICE_HASH_CODE, -1);
for (CachedBluetoothDevice cachedBluetoothDevice : getConnectedBluetoothDevices()) {
@@ -250,8 +223,11 @@
return Utils.createIconWithDrawable(drawable);
}
- private ListBuilder.RowBuilder getPairNewDeviceRow() {
- final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp);
+ private SliceAction getPairNewDeviceAction() {
+ final Drawable d = mContext.getDrawable(R.drawable.ic_add_24dp);
+ d.setColorFilter(new PorterDuffColorFilter(Utils.getColorAccentDefaultColor(mContext),
+ PorterDuff.Mode.SRC_IN));
+ final IconCompat icon = Utils.createIconWithDrawable(d);
final String title = mContext.getString(R.string.bluetooth_pairing_pref_title);
final Intent intent = new SubSettingLauncher(mContext)
.setDestination(BluetoothPairingDetail.class.getName())
@@ -260,11 +236,7 @@
.toIntent();
final PendingIntent pi = PendingIntent.getActivity(mContext, intent.hashCode(), intent,
0 /* flags */);
- final SliceAction action = SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE,
- title);
- return new ListBuilder.RowBuilder()
- .setTitleItem(action)
- .setTitle(title);
+ return SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE, title);
}
private List<ListBuilder.RowBuilder> getBluetoothRowBuilder() {
diff --git a/src/com/android/settings/media/MediaOutputIndicatorSlice.java b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
index 17d7cee..de2f85f 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorSlice.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
@@ -24,6 +24,7 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
+import android.media.session.MediaController;
import android.net.Uri;
import android.util.Log;
@@ -36,6 +37,8 @@
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.slices.CustomSliceable;
+import com.android.settings.slices.SliceBackgroundWorker;
+import com.android.settings.slices.SliceBroadcastReceiver;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -52,6 +55,7 @@
private Context mContext;
private LocalBluetoothManager mLocalBluetoothManager;
private LocalBluetoothProfileManager mProfileManager;
+ private MediaOutputIndicatorWorker mWorker;
public MediaOutputIndicatorSlice(Context context) {
mContext = context;
@@ -66,22 +70,18 @@
@Override
public Slice getSlice() {
if (!isVisible()) {
- return new ListBuilder(mContext, MEDIA_OUTPUT_INDICATOR_SLICE_URI, ListBuilder.INFINITY)
+ return new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
.setIsError(true)
.build();
}
final IconCompat icon = IconCompat.createWithResource(mContext,
com.android.internal.R.drawable.ic_settings_bluetooth);
final CharSequence title = mContext.getText(R.string.media_output_title);
- final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext,
- 0 /* requestCode */, getMediaOutputSliceIntent(), 0 /* flags */);
final SliceAction primarySliceAction = SliceAction.createDeeplink(
- primaryActionIntent, icon, ListBuilder.ICON_IMAGE, title);
+ getBroadcastIntent(), icon, ListBuilder.ICON_IMAGE, title);
@ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
// To set an empty icon to indent the row
- final ListBuilder listBuilder = new ListBuilder(mContext,
- MEDIA_OUTPUT_INDICATOR_SLICE_URI,
- ListBuilder.INFINITY)
+ final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
.setAccentColor(color)
.addRow(new ListBuilder.RowBuilder()
.setTitle(title)
@@ -96,11 +96,11 @@
return IconCompat.createWithBitmap(bitmap);
}
- private Intent getMediaOutputSliceIntent() {
- final Intent intent = new Intent()
- .setAction(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- return intent;
+ private PendingIntent getBroadcastIntent() {
+ final Intent intent = new Intent(getUri().toString());
+ intent.setClass(mContext, SliceBroadcastReceiver.class);
+ return PendingIntent.getBroadcast(mContext, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
@@ -120,6 +120,28 @@
return MediaOutputIndicatorWorker.class;
}
+ @Override
+ public void onNotifyChange(Intent i) {
+ final MediaController mediaController = getWorker().getActiveLocalMediaController();
+ final Intent intent = new Intent()
+ .setAction(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ if (mediaController != null) {
+ intent.putExtra(MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN,
+ mediaController.getSessionToken());
+ intent.putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME,
+ mediaController.getPackageName());
+ }
+ mContext.startActivity(intent);
+ }
+
+ private MediaOutputIndicatorWorker getWorker() {
+ if (mWorker == null) {
+ mWorker = SliceBackgroundWorker.getInstance(getUri());
+ }
+ return mWorker;
+ }
+
private boolean isVisible() {
// To decide Slice's visibility.
// Return true if
diff --git a/src/com/android/settings/media/MediaOutputIndicatorWorker.java b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
index 6498dd6..4ceeade 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorWorker.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
@@ -24,18 +24,21 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
+import android.media.session.MediaController;
+import android.media.session.MediaSessionManager;
+import android.media.session.PlaybackState;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
+import androidx.annotation.Nullable;
+
import com.android.settings.bluetooth.Utils;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import java.io.IOException;
-
/**
* Listener for background change from {@code BluetoothCallback} to update media output indicator.
*/
@@ -100,6 +103,27 @@
notifySliceChange();
}
+ @Nullable
+ MediaController getActiveLocalMediaController() {
+ final MediaSessionManager mMediaSessionManager = mContext.getSystemService(
+ MediaSessionManager.class);
+
+ for (MediaController controller : mMediaSessionManager.getActiveSessions(null)) {
+ final MediaController.PlaybackInfo pi = controller.getPlaybackInfo();
+ if (pi == null) {
+ return null;
+ }
+ final PlaybackState playbackState = controller.getPlaybackState();
+ if (playbackState == null) {
+ return null;
+ }
+ if (pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL
+ && playbackState.getState() == PlaybackState.STATE_PLAYING) {
+ return controller;
+ }
+ }
+ return null;
+ }
private class DevicesChangedBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
diff --git a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
index 5ef9246..766e4aa 100644
--- a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
@@ -62,7 +62,7 @@
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
- if (mChannel == null) {
+ if (mChannel == null || !KEY.equals(preference.getKey())) {
return false;
}
mChannel.setDemoted(false);
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index 9f8a07f..fbbda21 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -236,39 +236,44 @@
};
private final NotificationListenerService mListener = new NotificationListenerService() {
+ private RecyclerView mDismissedRv;
+ private RecyclerView mSnoozedRv;
@Override
public void onListenerConnected() {
StatusBarNotification[] snoozed = getSnoozedNotifications();
+ mSnoozedRv = mSnoozeView.findViewById(R.id.notification_list);
+ LinearLayoutManager lm = new LinearLayoutManager(NotificationHistoryActivity.this);
+ mSnoozedRv.setLayoutManager(lm);
+ mSnoozedRv.setAdapter(
+ new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
+ DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
+ mSnoozedRv.getContext(), lm.getOrientation());
+ mSnoozedRv.addItemDecoration(dividerItemDecoration);
+ mSnoozedRv.setNestedScrollingEnabled(false);
+
if (snoozed == null || snoozed.length == 0) {
mSnoozeView.setVisibility(View.GONE);
} else {
- RecyclerView rv = mSnoozeView.findViewById(R.id.notification_list);
- LinearLayoutManager lm = new LinearLayoutManager(NotificationHistoryActivity.this);
- rv.setLayoutManager(lm);
- rv.setAdapter(new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
- DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
- rv.getContext(), lm.getOrientation());
- rv.addItemDecoration(dividerItemDecoration);
- rv.setNestedScrollingEnabled(false);
-
- ((NotificationSbnAdapter) rv.getAdapter()).onRebuildComplete(
+ ((NotificationSbnAdapter) mSnoozedRv.getAdapter()).onRebuildComplete(
new ArrayList<>(Arrays.asList(snoozed)));
}
try {
StatusBarNotification[] dismissed = mNm.getHistoricalNotifications(
NotificationHistoryActivity.this.getPackageName(), 6, false);
- RecyclerView rv = mDismissView.findViewById(R.id.notification_list);
- LinearLayoutManager lm = new LinearLayoutManager(NotificationHistoryActivity.this);
- rv.setLayoutManager(lm);
- rv.setAdapter(new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
- DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
- rv.getContext(), lm.getOrientation());
- rv.addItemDecoration(dividerItemDecoration);
- rv.setNestedScrollingEnabled(false);
+ mDismissedRv = mDismissView.findViewById(R.id.notification_list);
+ LinearLayoutManager dismissLm =
+ new LinearLayoutManager(NotificationHistoryActivity.this);
+ mDismissedRv.setLayoutManager(dismissLm);
+ mDismissedRv.setAdapter(
+ new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
+ DividerItemDecoration dismissDivider = new DividerItemDecoration(
+ mDismissedRv.getContext(), dismissLm.getOrientation());
+ mDismissedRv.addItemDecoration(dismissDivider);
+ mDismissedRv.setNestedScrollingEnabled(false);
- ((NotificationSbnAdapter) rv.getAdapter()).onRebuildComplete(
+ ((NotificationSbnAdapter) mDismissedRv.getAdapter()).onRebuildComplete(
new ArrayList<>(Arrays.asList(dismissed)));
mDismissView.setVisibility(View.VISIBLE);
} catch (Exception e) {
@@ -276,5 +281,22 @@
mDismissView.setVisibility(View.GONE);
}
}
+
+ @Override
+ public void onNotificationPosted(StatusBarNotification sbn) {
+ // making lint happy
+ }
+
+ @Override
+ public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap,
+ int reason) {
+ if (reason == REASON_SNOOZED) {
+ ((NotificationSbnAdapter) mSnoozedRv.getAdapter()).addSbn(sbn);
+ mSnoozeView.setVisibility(View.VISIBLE);
+ } else {
+ ((NotificationSbnAdapter) mDismissedRv.getAdapter()).addSbn(sbn);
+ mDismissView.setVisibility(View.VISIBLE);
+ }
+ }
};
}
diff --git a/src/com/android/settings/notification/history/NotificationSbnAdapter.java b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
index f1dcf47..f7a747b 100644
--- a/src/com/android/settings/notification/history/NotificationSbnAdapter.java
+++ b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
@@ -108,6 +108,14 @@
notifyDataSetChanged();
}
+ public void addSbn(StatusBarNotification sbn) {
+ if (sbn.isGroup() && sbn.getNotification().isGroupSummary()) {
+ return;
+ }
+ mValues.add(0, sbn);
+ notifyDataSetChanged();
+ }
+
private @NonNull CharSequence loadPackageName(String pkg) {
try {
ApplicationInfo info = mPm.getApplicationInfo(pkg,
diff --git a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
index 05c7b4e..7a5677f 100644
--- a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
+++ b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
@@ -349,7 +349,7 @@
* If specified is passpoint network, need to check with the existing passpoint
* networks.
*/
- final PasspointConfiguration passpointConfig = suggestion.getPasspointConfiguration();
+ final PasspointConfiguration passpointConfig = suggestion.getPasspointConfig();
if (passpointConfig != null) {
foundInSavedList = isSavedPasspointConfiguration(passpointConfig);
displayedName = passpointConfig.getHomeSp().getFriendlyName();
@@ -600,7 +600,7 @@
*/
private void saveNetwork(int index) {
final PasspointConfiguration passpointConfig =
- mUiToRequestedList.get(index).mWifiNetworkSuggestion.getPasspointConfiguration();
+ mUiToRequestedList.get(index).mWifiNetworkSuggestion.getPasspointConfig();
if (passpointConfig != null) {
// Save passpoint, if no IllegalArgumentException, then treat it as success.
try {
diff --git a/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java b/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java
index f1c24c3..fc7b5ce 100644
--- a/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java
@@ -51,11 +51,8 @@
@Override
public int getAvailabilityStatus() {
- if (!WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mWifiEntry)
- || mWifiEntry.canManageSubscription()) {
- return CONDITIONALLY_UNAVAILABLE;
- }
- return AVAILABLE;
+ return WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mWifiEntry) ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index c12f8d3..803b828 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -145,7 +145,6 @@
static final String KEY_IPV6_CATEGORY = "ipv6_category";
@VisibleForTesting
static final String KEY_IPV6_ADDRESSES_PREF = "ipv6_addresses";
- static final String KEY_IP_DETAILS_CATEGORY = "ip_details_category";
private final WifiEntry mWifiEntry;
private final ConnectivityManager mConnectivityManager;
@@ -165,7 +164,6 @@
private ActionButtonsPreference mButtonsPref;
private EntityHeaderController mEntityHeaderController;
private Preference mSignalStrengthPref;
- private PreferenceCategory mIpDetailsCategory;
private Preference mTxLinkSpeedPref;
private Preference mRxLinkSpeedPref;
private Preference mFrequencyPref;
@@ -196,9 +194,7 @@
mLinkProperties = lp;
refreshEntityHeader();
refreshButtons();
- if (!mWifiEntry.canManageSubscription()) {
- refreshIpLayerInfo();
- }
+ refreshIpLayerInfo();
}
}
@@ -238,9 +234,7 @@
}
mNetworkCapabilities = nc;
refreshButtons();
- if (!mWifiEntry.canManageSubscription()) {
- refreshIpLayerInfo();
- }
+ refreshIpLayerInfo();
}
}
@@ -335,7 +329,6 @@
updateCaptivePortalButton();
mSignalStrengthPref = screen.findPreference(KEY_SIGNAL_STRENGTH_PREF);
- mIpDetailsCategory = screen.findPreference(KEY_IP_DETAILS_CATEGORY);
mTxLinkSpeedPref = screen.findPreference(KEY_TX_LINK_SPEED);
mRxLinkSpeedPref = screen.findPreference(KEY_RX_LINK_SPEED);
mFrequencyPref = screen.findPreference(KEY_FREQUENCY_PREF);
@@ -351,13 +344,6 @@
mIpv6Category = screen.findPreference(KEY_IPV6_CATEGORY);
mIpv6AddressPref = screen.findPreference(KEY_IPV6_ADDRESSES_PREF);
- if (mWifiEntry.canManageSubscription()) {
- mIpDetailsCategory.setVisible(false);
- mIpv6Category.setVisible(false);
- mSignalStrengthPref.setVisible(false);
- mFrequencyPref.setVisible(false);
- mSecurityPref.setVisible(false);
- }
mSecurityPref.setSummary(mWifiEntry.getSecurityString(false /* concise */));
}
@@ -505,16 +491,10 @@
// refresh header
refreshEntityHeader();
- refreshEntityHeaderIcon();
+
// refresh Buttons
refreshButtons();
- // When support manage subscription, there won't have any detail information, so don't
- // need to update those detail UIs.
- if (mWifiEntry.canManageSubscription()) {
- return;
- }
-
// Update Connection Header icon and Signal Strength Preference
refreshRssiViews();
// Frequency Pref
@@ -531,11 +511,7 @@
refreshMacAddress();
}
- private void refreshEntityHeaderIcon() {
- if (mEntityHeaderController == null) {
- return;
- }
-
+ private void refreshRssiViews() {
int signalLevel = mWifiEntry.getLevel();
// Disappears signal view if not in range. e.g. for saved networks.
@@ -550,23 +526,13 @@
}
mRssiSignalLevel = signalLevel;
Drawable wifiIcon = mIconInjector.getIcon(mRssiSignalLevel);
- mEntityHeaderController
- .setIcon(redrawIconForHeader(wifiIcon)).done(mFragment.getActivity(),
- true /* rebind */);
- }
- private void refreshRssiViews() {
- int signalLevel = mWifiEntry.getLevel();
-
- // Disappears signal view if not in range. e.g. for saved networks.
- if (signalLevel == WifiEntry.WIFI_LEVEL_UNREACHABLE) {
- mSignalStrengthPref.setVisible(false);
- mRssiSignalLevel = -1;
- return;
+ if (mEntityHeaderController != null) {
+ mEntityHeaderController
+ .setIcon(redrawIconForHeader(wifiIcon)).done(mFragment.getActivity(),
+ true /* rebind */);
}
- mRssiSignalLevel = signalLevel;
- Drawable wifiIcon = mIconInjector.getIcon(mRssiSignalLevel);
Drawable wifiIconDark = wifiIcon.getConstantState().newDrawable().mutate();
wifiIconDark.setTintList(Utils.getColorAttr(mContext, android.R.attr.colorControlNormal));
mSignalStrengthPref.setIcon(wifiIconDark);
diff --git a/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
index df205a3..b4909e2 100644
--- a/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
@@ -55,7 +55,7 @@
@Override
public int getAvailabilityStatus() {
- return mWifiEntry.canManageSubscription() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
+ return AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
index a11cadf..07bd5a4 100644
--- a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
+++ b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
@@ -115,10 +115,6 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- if (mNetworkDetailsTracker.getWifiEntry().canManageSubscription()) {
- return;
- }
-
MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
diff --git a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
index 479848c..b87b05d 100644
--- a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
@@ -55,11 +55,8 @@
@Override
public int getAvailabilityStatus() {
- if (!mWifiManager.isConnectedMacRandomizationSupported()
- || mWifiEntry.canManageSubscription()) {
- return CONDITIONALLY_UNAVAILABLE;
- }
- return AVAILABLE;
+ return mWifiManager.isConnectedMacRandomizationSupported()
+ ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java
index 7c93327..2598fb3 100644
--- a/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java
@@ -41,11 +41,7 @@
@Override
public int getAvailabilityStatus() {
- if (mWifiEntry.canManageSubscription()) {
- return AVAILABLE;
- }
-
- return CONDITIONALLY_UNAVAILABLE;
+ return mWifiEntry.canManageSubscription() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index dc638a5..c7173bc 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -72,6 +72,8 @@
<!-- Whether or not extra preview panels should be used for screen zoom setting. -->
<bool name="config_enable_extra_screen_zoom_preview">false</bool>
+ <!-- Whether dismissal timestamp should be kept before deletion -->
+ <bool name="config_keep_contextual_card_dismissal_timestamp">true</bool>
<!-- List of a11y components on the device allowed to be enabled by Settings Slices -->
<string-array name="config_settings_slices_accessibility_components" translatable="false">
diff --git a/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java
index 5ac5bad..63c7da1 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java
@@ -23,7 +23,6 @@
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
@@ -36,9 +35,6 @@
import org.robolectric.RuntimeEnvironment;
import org.xml.sax.XMLReader;
-import java.util.ArrayList;
-import java.util.List;
-
/** Tests for {@link HtmlTextPreference} */
@RunWith(RobolectricTestRunner.class)
public final class HtmlTextPreferenceTest {
@@ -65,21 +61,13 @@
}
@Test
- public void testUnsupportedTagList_keepRealContentWithoutTag() {
- final List<String> testUnsupportedTagList = new ArrayList<>();
- testUnsupportedTagList.add("testTag");
+ public void testTagHandler() {
final String testStr = "<testTag>Real description</testTag>";
- final String expectedStr = "Real description";
- final String expectedTag = "unsupportedtag1";
- mHtmlTextPreference.setUnsupportedTagList(testUnsupportedTagList);
mHtmlTextPreference.setSummary(testStr);
mHtmlTextPreference.setTagHandler(mTagHandler);
mHtmlTextPreference.onBindViewHolder(mPreferenceViewHolder);
- final TextView summaryView = mPreferenceViewHolder.itemView.findViewById(
- android.R.id.summary);
- assertThat(summaryView.getText().toString()).isEqualTo(expectedStr);
- assertThat(mHandledTag).isEqualTo(expectedTag);
+ assertThat(mHandledTag).isEqualTo("testTag");
}
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
index 7ad8d63..2fb2a3d 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
@@ -142,6 +142,37 @@
verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
}
+
+ @Test
+ public void populateImeiInfo_cdmaSimPresent_shouldSetImeiInfoAndSetAllCdmaSetting() {
+ ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
+ when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
+ when(mTelephonyManager.getSimState(anyInt())).thenReturn(
+ TelephonyManager.SIM_STATE_PRESENT);
+
+ mController.populateImeiInfo();
+
+ verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
+ verify(mDialog).setText(ID_MIN_NUMBER_VALUE, "");
+ verify(mDialog).setText(ID_PRL_VERSION_VALUE, "");
+ verify(mDialog).setText(eq(ID_IMEI_VALUE), any());
+ verify(mDialog).setText(eq(ID_IMEI_SV_VALUE), any());
+ }
+
+ @Test
+ public void populateImeiInfo_cdmaSimABSENT_shouldSetImeiInfoAndSetAllCdmaSetting() {
+ ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
+ when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
+ when(mTelephonyManager.getSimState(anyInt())).thenReturn(TelephonyManager.SIM_STATE_ABSENT);
+
+ mController.populateImeiInfo();
+
+ verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
+ verify(mDialog).setText(ID_MIN_NUMBER_VALUE, "");
+ verify(mDialog).setText(ID_PRL_VERSION_VALUE, "");
+ verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
+ }
+
@Test
public void populateImeiInfo_gsmSimDisabled_shouldSetImeiAndRemoveCdmaSettings() {
ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/CardContentProviderTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/CardContentProviderTest.java
index d13c97c..32af5d8 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/CardContentProviderTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/CardContentProviderTest.java
@@ -38,6 +38,7 @@
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@@ -86,6 +87,25 @@
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void bulkInsert_keepDismissalTimestamp_shouldHaveTimestamp() {
+ mResolver.bulkInsert(mUri, generateTwoRowsWithDismissTimestamp());
+
+ mResolver.bulkInsert(mUri, generateTwoRows());
+
+ assertThat(queryDismissedTimestamp()).isEqualTo(10001L);
+ }
+
+ @Test
+ public void bulkInsert_notKeepDismissalTimestamp_shouldNotHaveTimestamp() {
+ mResolver.bulkInsert(mUri, generateTwoRowsWithDismissTimestamp());
+
+ mResolver.bulkInsert(mUri, generateTwoRows());
+
+ assertThat(queryDismissedTimestamp()).isEqualTo(0L);
+ }
+
+ @Test
public void cardData_query() {
mResolver.insert(mUri, generateOneRow());
final int count = getRowCount();
@@ -198,10 +218,40 @@
return twoRows;
}
+ private ContentValues[] generateTwoRowsWithDismissTimestamp() {
+ final ContentValues[] twoRows = new ContentValues[2];
+ twoRows[0] = generateOneRow();
+
+ final ContentValues values = new ContentValues();
+ values.put(CardDatabaseHelper.CardColumns.NAME, "toggle_airplane");
+ values.put(CardDatabaseHelper.CardColumns.TYPE, 1);
+ values.put(CardDatabaseHelper.CardColumns.SCORE, 0.95);
+ values.put(CardDatabaseHelper.CardColumns.SLICE_URI,
+ "content://com.android.settings.slices/action/toggle_airplane");
+ values.put(CardDatabaseHelper.CardColumns.CATEGORY, 2);
+ values.put(CardDatabaseHelper.CardColumns.PACKAGE_NAME, "com.android.settings");
+ values.put(CardDatabaseHelper.CardColumns.APP_VERSION, 10001);
+ values.put(CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP, 10001L);
+ twoRows[1] = values;
+
+ return twoRows;
+ }
+
private int getRowCount() {
final Cursor cr = mResolver.query(mUri, null, null, null);
final int count = cr.getCount();
cr.close();
return count;
}
+
+ private long queryDismissedTimestamp() {
+ final String[] columns = {CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP};
+ final String selection = CardDatabaseHelper.CardColumns.NAME + "=?";
+ final String[] selectionArgs = {"toggle_airplane"};
+ final Cursor cr = mResolver.query(mUri, columns, selection, selectionArgs, null);
+ cr.moveToFirst();
+ final long dismissedTimestamp = cr.getLong(0);
+ cr.close();
+ return dismissedTimestamp;
+ }
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
index 0eda973..cec3bee 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
@@ -16,7 +16,6 @@
package com.android.settings.homepage.contextualcards.slices;
-import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static android.app.slice.Slice.HINT_LIST_ITEM;
import static android.app.slice.SliceItem.FORMAT_SLICE;
@@ -38,7 +37,6 @@
import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
-import androidx.slice.core.SliceAction;
import androidx.slice.core.SliceQuery;
import androidx.slice.widget.SliceLiveData;
@@ -117,70 +115,11 @@
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
- public void getSlice_bluetoothOff_shouldHaveToggle() {
- final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
- adapter.setState(BluetoothAdapter.STATE_OFF);
-
+ public void getSlice_hasBluetoothHardware_shouldHaveBluetoothDevicesTitleAndPairNewDevice() {
final Slice slice = mBluetoothDevicesSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
- assertTitleAndIcon(metadata);
- final List<SliceAction> toggles = metadata.getToggles();
- assertThat(toggles).hasSize(1);
- }
-
- @Test
- @Config(shadows = ShadowBluetoothAdapter.class)
- public void getSlice_bluetoothOn_shouldNotHaveToggle() {
- final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
- adapter.setState(BluetoothAdapter.STATE_ON);
-
- final Slice slice = mBluetoothDevicesSlice.getSlice();
-
- final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
- assertTitleAndIcon(metadata);
- final List<SliceAction> toggles = metadata.getToggles();
- assertThat(toggles).isEmpty();
- }
-
- @Test
- @Config(shadows = ShadowBluetoothAdapter.class)
- public void getSlice_bluetoothTurningOff_shouldHaveToggle() {
- final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
- adapter.setState(BluetoothAdapter.STATE_ON);
- final Intent intent = new Intent().putExtra(EXTRA_TOGGLE_STATE, false);
-
- mBluetoothDevicesSlice.onNotifyChange(intent);
- final Slice slice = mBluetoothDevicesSlice.getSlice();
-
- final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
- final List<SliceAction> toggles = metadata.getToggles();
- assertThat(toggles).hasSize(1);
- }
-
- @Test
- @Config(shadows = ShadowBluetoothAdapter.class)
- public void getSlice_bluetoothTurningOn_shouldHaveToggle() {
- final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
- adapter.setState(BluetoothAdapter.STATE_OFF);
- final Intent intent = new Intent().putExtra(EXTRA_TOGGLE_STATE, true);
-
- mBluetoothDevicesSlice.onNotifyChange(intent);
- final Slice slice = mBluetoothDevicesSlice.getSlice();
-
- final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
- final List<SliceAction> toggles = metadata.getToggles();
- assertThat(toggles).isEmpty();
- }
-
- @Test
- @Config(shadows = ShadowBluetoothAdapter.class)
- public void getSlice_noBluetoothDevice_shouldHavePairNewDeviceRow() {
- final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
- adapter.setState(BluetoothAdapter.STATE_ON);
- doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
-
- final Slice slice = mBluetoothDevicesSlice.getSlice();
+ assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_devices));
final List<SliceItem> sliceItems = slice.getItems();
SliceTester.assertAnySliceItemContainsTitle(sliceItems, mContext.getString(
@@ -189,21 +128,6 @@
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
- public void getSlice_hasBluetoothDevices_shouldNotHavePairNewDeviceRow() {
- final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
- adapter.setState(BluetoothAdapter.STATE_ON);
- mockBluetoothDeviceList(1);
- doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
-
- final Slice slice = mBluetoothDevicesSlice.getSlice();
-
- final List<SliceItem> sliceItems = slice.getItems();
- SliceTester.assertNoSliceItemContainsTitle(sliceItems, mContext.getString(
- R.string.bluetooth_pairing_pref_title));
- }
-
- @Test
- @Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_hasBluetoothDevices_shouldMatchBluetoothMockTitle() {
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
adapter.setState(BluetoothAdapter.STATE_ON);
@@ -280,16 +204,6 @@
}
}
- private void assertTitleAndIcon(SliceMetadata metadata) {
- assertThat(metadata.getTitle()).isEqualTo(mContext.getString(
- R.string.bluetooth_settings_title));
-
- final SliceAction primaryAction = metadata.getPrimaryAction();
- final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
- com.android.internal.R.drawable.ic_settings_bluetooth);
- assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
- }
-
@Implements(BluetoothAdapter.class)
public static class ShadowNoBluetoothAdapter extends ShadowBluetoothAdapter {
@Implementation
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
index 3b5e828..fa926df 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
@@ -17,16 +17,25 @@
package com.android.settings.media;
+import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
+import android.content.Intent;
import android.media.AudioManager;
+import android.media.session.MediaController;
+import android.media.session.MediaSession;
+import android.net.Uri;
+import android.text.TextUtils;
import androidx.slice.Slice;
import androidx.slice.SliceMetadata;
@@ -34,33 +43,42 @@
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
+import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
+import com.android.settingslib.media.MediaOutputSliceConstants;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowBluetoothUtils.class})
+@Config(shadows = {ShadowBluetoothUtils.class,
+ MediaOutputIndicatorSliceTest.ShadowSliceBackgroundWorker.class})
public class MediaOutputIndicatorSliceTest {
private static final String TEST_A2DP_DEVICE_NAME = "Test_A2DP_BT_Device_NAME";
private static final String TEST_HAP_DEVICE_NAME = "Test_HAP_BT_Device_NAME";
private static final String TEST_A2DP_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
private static final String TEST_HAP_DEVICE_ADDRESS = "00:B2:B2:B2:B2:B2";
+ private static final String TEST_PACKAGE_NAME = "com.test";
+
+ private static MediaOutputIndicatorWorker sMediaOutputIndicatorWorker;
@Mock
private A2dpProfile mA2dpProfile;
@@ -70,6 +88,8 @@
private LocalBluetoothManager mLocalBluetoothManager;
@Mock
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
+ @Mock
+ private MediaController mMediaController;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mA2dpDevice;
@@ -79,6 +99,7 @@
private List<BluetoothDevice> mDevicesList;
private MediaOutputIndicatorSlice mMediaOutputIndicatorSlice;
private AudioManager mAudioManager;
+ private MediaSession.Token mToken;
@Before
public void setUp() throws Exception {
@@ -86,9 +107,11 @@
mContext = spy(RuntimeEnvironment.application);
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
+ sMediaOutputIndicatorWorker = spy(new MediaOutputIndicatorWorker(mContext,
+ MEDIA_OUTPUT_INDICATOR_SLICE_URI));
+ mToken = new MediaSession.Token(null);
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
-
// Setup Bluetooth environment
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
mBluetoothManager = new BluetoothManager(mContext);
@@ -196,4 +219,45 @@
final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
assertThat(metadata.isErrorSlice()).isTrue();
}
+
+ @Test
+ public void onNotifyChange_withActiveLocalMedia_verifyIntentExtra() {
+ when(mMediaController.getSessionToken()).thenReturn(mToken);
+ when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
+ doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
+ .getActiveLocalMediaController();
+
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ mMediaOutputIndicatorSlice.onNotifyChange(new Intent());
+ verify(mContext).startActivity(intentCaptor.capture());
+
+ assertThat(TextUtils.equals(TEST_PACKAGE_NAME, intentCaptor.getValue().getStringExtra(
+ MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue();
+ assertThat(mToken == intentCaptor.getValue().getExtras().getParcelable(
+ MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN)).isTrue();
+ }
+
+ @Test
+ public void onNotifyChange_withoutActiveLocalMedia_verifyIntentExtra() {
+ doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
+ .getActiveLocalMediaController();
+
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ mMediaOutputIndicatorSlice.onNotifyChange(new Intent());
+ verify(mContext).startActivity(intentCaptor.capture());
+
+ assertThat(TextUtils.isEmpty(intentCaptor.getValue().getStringExtra(
+ MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue();
+ assertThat(intentCaptor.getValue().getExtras().getParcelable(
+ MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN) == null).isTrue();
+ }
+
+ @Implements(SliceBackgroundWorker.class)
+ public static class ShadowSliceBackgroundWorker {
+
+ @Implementation
+ public static SliceBackgroundWorker getInstance(Uri uri) {
+ return sMediaOutputIndicatorWorker;
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
index 78658fd..b6231a3 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
@@ -16,6 +16,8 @@
package com.android.settings.media;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -28,7 +30,12 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.media.AudioAttributes;
import android.media.AudioManager;
+import android.media.VolumeProvider;
+import android.media.session.MediaController;
+import android.media.session.MediaSessionManager;
+import android.media.session.PlaybackState;
import android.net.Uri;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
@@ -45,6 +52,9 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+import java.util.List;
+
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothUtils.class})
public class MediaOutputIndicatorWorkerTest {
@@ -54,10 +64,18 @@
private BluetoothEventManager mBluetoothEventManager;
@Mock
private LocalBluetoothManager mLocalBluetoothManager;
+ @Mock
+ private MediaSessionManager mMediaSessionManager;
+ @Mock
+ private MediaController mMediaController;
+
private Context mContext;
- private MediaOutputIndicatorWorker mMediaDeviceUpdateWorker;
+ private MediaOutputIndicatorWorker mMediaOutputIndicatorWorker;
private ShadowApplication mShadowApplication;
private ContentResolver mResolver;
+ private List<MediaController> mMediaControllers = new ArrayList<>();
+ private PlaybackState mPlaybackState;
+ private MediaController.PlaybackInfo mPlaybackInfo;
@Before
public void setUp() {
@@ -66,7 +84,10 @@
mContext = spy(RuntimeEnvironment.application);
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
- mMediaDeviceUpdateWorker = new MediaOutputIndicatorWorker(mContext, URI);
+ mMediaOutputIndicatorWorker = new MediaOutputIndicatorWorker(mContext, URI);
+ when(mContext.getSystemService(MediaSessionManager.class)).thenReturn(mMediaSessionManager);
+ mMediaControllers.add(mMediaController);
+ when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers);
mResolver = mock(ContentResolver.class);
doReturn(mResolver).when(mContext).getContentResolver();
@@ -74,22 +95,22 @@
@Test
public void onSlicePinned_registerCallback() {
- mMediaDeviceUpdateWorker.onSlicePinned();
- verify(mBluetoothEventManager).registerCallback(mMediaDeviceUpdateWorker);
+ mMediaOutputIndicatorWorker.onSlicePinned();
+ verify(mBluetoothEventManager).registerCallback(mMediaOutputIndicatorWorker);
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
}
@Test
public void onSliceUnpinned_unRegisterCallback() {
- mMediaDeviceUpdateWorker.onSlicePinned();
- mMediaDeviceUpdateWorker.onSliceUnpinned();
- verify(mBluetoothEventManager).unregisterCallback(mMediaDeviceUpdateWorker);
+ mMediaOutputIndicatorWorker.onSlicePinned();
+ mMediaOutputIndicatorWorker.onSliceUnpinned();
+ verify(mBluetoothEventManager).unregisterCallback(mMediaOutputIndicatorWorker);
verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
}
@Test
public void onReceive_shouldNotifyChange() {
- mMediaDeviceUpdateWorker.onSlicePinned();
+ mMediaOutputIndicatorWorker.onSlicePinned();
final Intent intent = new Intent(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
for (BroadcastReceiver receiver : mShadowApplication.getReceiversForIntent(intent)) {
@@ -98,4 +119,62 @@
verify(mResolver).notifyChange(URI, null);
}
+
+ @Test
+ public void getActiveLocalMediaController_localMediaPlaying_returnController() {
+ mPlaybackInfo = new MediaController.PlaybackInfo(
+ MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
+ VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+ 100,
+ 10,
+ new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+ null);
+ mPlaybackState = new PlaybackState.Builder()
+ .setState(PlaybackState.STATE_PLAYING, 0, 1)
+ .build();
+
+ when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+ when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+ assertThat(mMediaOutputIndicatorWorker.getActiveLocalMediaController()).isEqualTo(
+ mMediaController);
+ }
+
+ @Test
+ public void getActiveLocalMediaController_remoteMediaPlaying_returnNull() {
+ mPlaybackInfo = new MediaController.PlaybackInfo(
+ MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE,
+ VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+ 100,
+ 10,
+ new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+ null);
+ mPlaybackState = new PlaybackState.Builder()
+ .setState(PlaybackState.STATE_PLAYING, 0, 1)
+ .build();
+
+ when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+ when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+ assertThat(mMediaOutputIndicatorWorker.getActiveLocalMediaController()).isNull();
+ }
+
+ @Test
+ public void getActiveLocalMediaController_localMediaStopped_returnNull() {
+ mPlaybackInfo = new MediaController.PlaybackInfo(
+ MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
+ VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+ 100,
+ 10,
+ new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+ null);
+ mPlaybackState = new PlaybackState.Builder()
+ .setState(PlaybackState.STATE_STOPPED, 0, 1)
+ .build();
+
+ when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+ when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+ assertThat(mMediaOutputIndicatorWorker.getActiveLocalMediaController()).isNull();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
index 725be3d..9b60c97 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
@@ -20,9 +20,11 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -122,4 +124,20 @@
verify(mFragment).getActivity();
}
+
+ @Test
+ public void testHandlePreferenceClick_wrongKey() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ channel.setConversationId("a", "a");
+ channel.setDemoted(true);
+ mController.onResume(appRow, channel, null, null, null, null);
+
+ Preference pref = mock(Preference.class);
+ when(pref.getKey()).thenReturn("wrong");
+ assertFalse(mController.handlePreferenceTreeClick(pref));
+
+ verify(mBackend, never()).updateChannel(eq(null), anyInt(), any());
+ verify(mFragment, never()).getActivity();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/SliceTester.java b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
index 03a7146..6fb2c49 100644
--- a/tests/robotests/src/com/android/settings/testutils/SliceTester.java
+++ b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
@@ -243,16 +243,6 @@
}
/**
- * Assert no slice item contains title.
- *
- * @param sliceItems All slice items of a Slice.
- * @param title Title for asserting.
- */
- public static void assertNoSliceItemContainsTitle(List<SliceItem> sliceItems, String title) {
- assertThat(hasText(sliceItems, title, HINT_TITLE)).isFalse();
- }
-
- /**
* Assert any slice item contains subtitle.
*
* @param sliceItems All slice items of a Slice.