Merge "Update Secure NFC API definitions"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 29f69b8..48b1333 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -100,6 +100,7 @@
<uses-permission android:name="android.permission.USE_RESERVED_DISK" />
<uses-permission android:name="android.permission.MANAGE_SCOPED_ACCESS_DIRECTORY_PERMISSIONS" />
<uses-permission android:name="android.permission.CAMERA" />
+ <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<application android:label="@string/settings_label"
android:icon="@drawable/ic_launcher_settings"
diff --git a/res/layout/homepage_condition_full_tile.xml b/res/layout/homepage_condition_full_tile.xml
index 3d261ca..e90a0cb 100644
--- a/res/layout/homepage_condition_full_tile.xml
+++ b/res/layout/homepage_condition_full_tile.xml
@@ -30,7 +30,7 @@
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:paddingStart="@dimen/homepage_card_padding_start"
+ android:paddingStart="@dimen/homepage_card_icon_padding_start"
android:paddingEnd="@dimen/homepage_full_card_padding_end"
android:paddingTop="@dimen/homepage_condition_full_card_padding_top"
android:paddingBottom="@dimen/homepage_condition_full_card_padding_bottom"
diff --git a/res/layout/homepage_condition_half_tile.xml b/res/layout/homepage_condition_half_tile.xml
index 308b3a6..1086f2d 100644
--- a/res/layout/homepage_condition_half_tile.xml
+++ b/res/layout/homepage_condition_half_tile.xml
@@ -31,7 +31,6 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:paddingStart="@dimen/homepage_card_padding_start"
android:paddingEnd="@dimen/homepage_card_padding_end"
android:orientation="vertical">
@@ -39,6 +38,7 @@
android:id="@android:id/icon"
android:layout_width="@dimen/homepage_card_icon_size"
android:layout_height="@dimen/homepage_card_icon_size"
+ android:layout_marginStart="@dimen/homepage_card_icon_padding_start"
android:tint="?android:attr/colorAccent"/>
<TextView
@@ -47,6 +47,7 @@
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
+ android:layout_marginStart="@dimen/homepage_card_text_padding_start"
android:layout_marginTop="@dimen/homepage_condition_half_card_title_margin_top"
android:layout_marginBottom="@dimen/homepage_condition_card_title_margin_bottom"
android:textAppearance="@style/TextAppearance.ConditionCardTitle"/>
@@ -57,6 +58,7 @@
android:layout_height="wrap_content"
android:lines="2"
android:ellipsize="end"
+ android:layout_marginStart="@dimen/homepage_card_text_padding_start"
android:layout_marginBottom="@dimen/homepage_condition_half_card_summary_margin_bottom"
android:textAppearance="@style/TextAppearance.ConditionCardSummary"/>
diff --git a/res/layout/homepage_slice_deferred_setup_tile.xml b/res/layout/homepage_slice_deferred_setup_tile.xml
index 73199d4..ed096b0 100644
--- a/res/layout/homepage_slice_deferred_setup_tile.xml
+++ b/res/layout/homepage_slice_deferred_setup_tile.xml
@@ -21,59 +21,52 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <ViewFlipper
- android:id="@+id/view_flipper"
+ <LinearLayout
+ android:id="@+id/content"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:gravity="left"
+ android:orientation="vertical"
+ android:paddingEnd="@dimen/homepage_card_padding_end"
+ android:paddingTop="@dimen/homepage_deferred_setup_card_padding_top"
+ android:paddingBottom="@dimen/homepage_deferred_setup_card_padding_bottom">
- <LinearLayout
- android:id="@+id/content"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="left"
- android:orientation="vertical"
- android:paddingStart="@dimen/homepage_card_padding_start"
- android:paddingEnd="@dimen/homepage_card_padding_end"
- android:paddingTop="@dimen/homepage_deferred_setup_card_padding_top"
- android:paddingBottom="@dimen/homepage_deferred_setup_card_padding_bottom">
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="@dimen/homepage_card_icon_size"
+ android:layout_height="@dimen/homepage_card_icon_size"
+ android:layout_marginStart="@dimen/homepage_card_icon_padding_start"/>
- <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_marginStart="@dimen/homepage_card_text_padding_start"
+ 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/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_marginStart="@dimen/homepage_card_text_padding_start"
+ 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"/>
- <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_marginStart="@dimen/homepage_card_text_padding_start"
+ android:layout_marginTop="@dimen/homepage_deferred_setup_card_button_margin_top"
+ android:text="@string/suggestion_button_text"/>
- <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>
+ </LinearLayout>
</com.google.android.material.card.MaterialCardView>
\ No newline at end of file
diff --git a/res/layout/homepage_slice_half_tile.xml b/res/layout/homepage_slice_half_tile.xml
index fc99561..8b6d415 100644
--- a/res/layout/homepage_slice_half_tile.xml
+++ b/res/layout/homepage_slice_half_tile.xml
@@ -30,7 +30,6 @@
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:paddingStart="@dimen/homepage_card_padding_start"
android:paddingEnd="@dimen/homepage_card_padding_end"
android:paddingTop="@dimen/homepage_half_card_padding_top"
android:paddingBottom="@dimen/homepage_half_card_padding_bottom"
@@ -39,7 +38,8 @@
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/homepage_card_icon_size"
- android:layout_height="@dimen/homepage_card_icon_size"/>
+ android:layout_height="@dimen/homepage_card_icon_size"
+ android:layout_marginStart="@dimen/homepage_card_icon_padding_start"/>
<TextView
android:id="@android:id/title"
@@ -48,6 +48,7 @@
android:maxLines="2"
android:minLines="1"
android:ellipsize="end"
+ android:layout_marginStart="@dimen/homepage_card_text_padding_start"
android:layout_marginTop="@dimen/homepage_half_card_title_margin_top"
android:textAppearance="@style/TextAppearance.ConditionCardTitle"/>
diff --git a/res/layout/search_bar.xml b/res/layout/search_bar.xml
index 64ddb6d..dbd61df 100644
--- a/res/layout/search_bar.xml
+++ b/res/layout/search_bar.xml
@@ -27,6 +27,7 @@
android:id="@+id/search_action_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/search_bar_height"
+ android:layout_marginStart="-2dp"
android:background="?android:attr/selectableItemBackground"
android:contentInsetStartWithNavigation="@dimen/search_bar_content_inset"
android:navigationIcon="@drawable/ic_homepage_search">
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 03e40aa..6a03582 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1268,7 +1268,7 @@
<item>NV</item>
</string-array>
<!-- Values for CDMA subscription-->
- <string-array name="cdma_subscription_values">
+ <string-array name="cdma_subscription_values" translatable="false">
<item>"0"</item>
<item>"1"</item>
</string-array>
@@ -1351,7 +1351,7 @@
<item>LTE / GSM / UMTS</item>
</string-array>
- <string-array name="preferred_network_mode_values_world_mode">
+ <string-array name="preferred_network_mode_values_world_mode" translatable="false">
<item>"10"</item>
<item>"8"</item>
<item>"9"</item>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 4ac0db8..aeeb403 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -331,7 +331,8 @@
<dimen name="homepage_card_icon_size">24dp</dimen>
<dimen name="homepage_card_vertical_margin">8dp</dimen>
<dimen name="homepage_card_side_margin">4dp</dimen>
- <dimen name="homepage_card_padding_start">16dp</dimen>
+ <dimen name="homepage_card_icon_padding_start">14dp</dimen>
+ <dimen name="homepage_card_text_padding_start">16dp</dimen>
<dimen name="homepage_card_padding_end">16dp</dimen>
<dimen name="homepage_full_card_padding_end">12dp</dimen>
<dimen name="homepage_half_card_padding_top">12dp</dimen>
@@ -369,13 +370,13 @@
<dimen name="homepage_condition_half_card_padding_top">12dp</dimen>
<dimen name="homepage_condition_half_card_title_margin_top">12dp</dimen>
<dimen name="homepage_condition_half_card_summary_margin_bottom">12dp</dimen>
- <dimen name="homepage_condition_full_card_padding_start">12dp</dimen>
+ <dimen name="homepage_condition_full_card_padding_start">24dp</dimen>
<dimen name="homepage_condition_full_card_padding_end">16dp</dimen>
<dimen name="homepage_condition_full_card_padding_top">12dp</dimen>
<dimen name="homepage_condition_full_card_padding_bottom">12dp</dimen>
<dimen name="homepage_condition_header_padding_top">10dp</dimen>
<dimen name="homepage_condition_header_padding_bottom">10dp</dimen>
- <dimen name="homepage_condition_header_icons_margin_start">16dp</dimen>
+ <dimen name="homepage_condition_header_icons_margin_start">14dp</dimen>
<dimen name="homepage_condition_header_indicator_padding_top">4dp</dimen>
<dimen name="homepage_condition_header_indicator_padding_start">16dp</dimen>
<dimen name="homepage_condition_header_indicator_padding_end">16dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0d6eaeb..1bbeb63 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2489,7 +2489,7 @@
<item>Mobile</item>
<item>Wi-Fi only</item>
</string-array>
- <string-array name="wifi_calling_mode_values">
+ <string-array name="wifi_calling_mode_values" translatable="false">
<item>"2"</item>
<item>"1"</item>
<item>"0"</item>
@@ -2502,7 +2502,7 @@
<item>Wi-Fi</item>
<item>Mobile</item>
</string-array>
- <string-array name="wifi_calling_mode_values_without_wifi_only">
+ <string-array name="wifi_calling_mode_values_without_wifi_only" translatable="false">
<item>"2"</item>
<item>"1"</item>
</string-array>
@@ -7001,7 +7001,7 @@
<!-- Title for setting tile leading to Apps & Notification settings [CHAR LIMIT=40]-->
<string name="app_and_notification_dashboard_title">Apps & notifications</string>
<!-- Summary for Apps & Notification settings, explaining a few important settings under it [CHAR LIMIT=NONE]-->
- <string name="app_and_notification_dashboard_summary">Permissions, default apps</string>
+ <string name="app_and_notification_dashboard_summary">Assistant, recent apps, default apps</string>
<!-- Toast shown when an app in the work profile attempts to open notification settings. The apps in the work profile cannot access notification settings. [CHAR LIMIT=NONE] -->
<string name="notification_settings_work_profile">Notification access is not available for apps in the work profile.</string>
<!-- Title for setting tile leading to account settings [CHAR LIMIT=40]-->
@@ -7193,6 +7193,9 @@
<!-- Sound: Title for the option managing media volume. [CHAR LIMIT=30] -->
<string name="media_volume_option_title">Media volume</string>
+ <!-- Sound: Title for the option managing remote media volume. [CHAR LIMIT=30] -->
+ <string name="remote_media_volume_option_title">Cast volume</string>
+
<!-- Sound: Title for the option managing call volume. [CHAR LIMIT=30] -->
<string name="call_volume_option_title">Call volume</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index a778f76..92a4098 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -303,6 +303,11 @@
<item name="android:textSize">16sp</item>
</style>
+ <style name="TextAppearance.DialogMessage"
+ parent="@*android:style/TextAppearance.DeviceDefault.Body1">
+ <item name="android:textSize">16sp</item>
+ </style>
+
<style name="SuggestionCardText">
<item name="android:textAlignment">viewStart</item>
</style>
@@ -443,7 +448,7 @@
<style name="ConditionFullCardBorderlessButton"
parent="@style/ConditionCardBorderlessButton">
<item name="android:textAlignment">viewStart</item>
- <item name="android:paddingStart">50dp</item>
+ <item name="android:paddingStart">62dp</item>
<item name="android:paddingEnd">50dp</item>
</style>
@@ -479,8 +484,8 @@
</style>
<style name="SliceViewStyle">
- <!-- 4dp start padding for the start icon -->
- <item name="android:paddingStart">4dp</item>
+ <!-- 2dp start padding for the start icon -->
+ <item name="android:paddingStart">2dp</item>
<!-- End margin of content without end items is 24dp.
android:paddingEnd = 24 - 16(contentEndPadding) -->
@@ -492,8 +497,8 @@
<style name="SliceRowStyle">
<item name="titleItemEndPadding">0dp</item>
- <!-- Padding between content and the start icon is 12dp. -->
- <item name="contentStartPadding">12dp</item>
+ <!-- Padding between content and the start icon is 14dp. -->
+ <item name="contentStartPadding">14dp</item>
<!-- Padding between content and end items is 16dp. -->
<item name="contentEndPadding">16dp</item>
@@ -503,9 +508,9 @@
<item name="endItemEndPadding">8dp</item>
<!-- Both side margins of bottom divider are 12dp.
- bottomDividerStartPadding = 12 - 4(android:paddingStart)
+ bottomDividerStartPadding = 12 - 2(android:paddingStart)
bottomDividerEndPadding = 12 - 8(android:paddingEnd) -->
- <item name="bottomDividerStartPadding">8dp</item>
+ <item name="bottomDividerStartPadding">10dp</item>
<item name="bottomDividerEndPadding">4dp</item>
<item name="actionDividerHeight">32dp</item>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 991e376..a8ae506 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -128,8 +128,11 @@
<!-- Redefine the ActionBar style for contentInsetStart -->
<item name="android:actionBarStyle">@style/Widget.ActionBar</item>
- <!-- copied from Theme.DeviceDefault.Light.Dialog.Alert -->
+ <!-- copied from Theme.DeviceDefault.Dialog.Alert -->
<item name="dialogCornerRadius">@*android:dimen/config_dialogCornerRadius</item>
+ <item name="android:windowTitleStyle">@*android:style/DialogWindowTitle.DeviceDefault</item>
+ <item name="android:textAppearanceMedium">@style/TextAppearance.DialogMessage</item>
+ <item name="buttonBarButtonStyle">@*android:style/Widget.DeviceDefault.Button.ButtonBar.AlertDialog</item>
</style>
<style name="Theme.ConfirmDeviceCredentials" parent="Theme.SubSettings">
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index ee8613d..81a0453 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -22,6 +22,15 @@
settings:keywords="@string/keywords_sounds"
settings:initialExpandedChildrenCount="9">
+ <!-- Remote volume -->
+ <com.android.settings.notification.RemoteVolumeSeekBarPreference
+ android:key="remote_volume"
+ android:icon="@drawable/ic_volume_remote"
+ android:title="@string/remote_media_volume_option_title"
+ android:order="-185"
+ settings:allowDynamicSummaryInSlice="true"
+ settings:controller="com.android.settings.notification.RemoteVolumePreferenceController"/>
+
<!-- Media volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="media_volume"
diff --git a/src/com/android/settings/RestrictedListPreference.java b/src/com/android/settings/RestrictedListPreference.java
index 2e9ec14..bd3cd17 100644
--- a/src/com/android/settings/RestrictedListPreference.java
+++ b/src/com/android/settings/RestrictedListPreference.java
@@ -157,8 +157,8 @@
return null;
}
- protected ListAdapter createListAdapter() {
- return new RestrictedArrayAdapter(getContext(), getEntries(),
+ protected ListAdapter createListAdapter(Context context) {
+ return new RestrictedArrayAdapter(context, getEntries(),
getSelectedValuePos());
}
@@ -172,10 +172,9 @@
@Override
protected void onPrepareDialogBuilder(Builder builder,
DialogInterface.OnClickListener listener) {
- builder.setAdapter(createListAdapter(), listener);
+ builder.setAdapter(createListAdapter(builder.getContext()), listener);
}
-
public class RestrictedArrayAdapter extends ArrayAdapter<CharSequence> {
private final int mSelectedIndex;
public RestrictedArrayAdapter(Context context, CharSequence[] objects, int selectedIndex) {
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
index 48e9f1e..b9170a9 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
@@ -139,6 +139,8 @@
switch (holder.getItemViewType()) {
case VIEW_TYPE_DEFERRED_SETUP:
+ // Deferred setup is never dismissible.
+ break;
case VIEW_TYPE_HALF_WIDTH:
initDismissalActions(holder, card, R.id.content);
break;
diff --git a/src/com/android/settings/notification/NotificationAssistantPicker.java b/src/com/android/settings/notification/NotificationAssistantPicker.java
index 7720e6f..868e0a9 100644
--- a/src/com/android/settings/notification/NotificationAssistantPicker.java
+++ b/src/com/android/settings/notification/NotificationAssistantPicker.java
@@ -20,12 +20,15 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageItemInfo;
+import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.graphics.drawable.Drawable;
+import android.os.RemoteException;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.service.notification.NotificationAssistantService;
import android.text.TextUtils;
+import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
@@ -114,8 +117,12 @@
List<CandidateInfo> list = new ArrayList<>();
services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
for (ServiceInfo service : services) {
- final ComponentName cn = new ComponentName(service.packageName, service.name);
- list.add(new DefaultAppInfo(mContext, mPm, mUserId, cn));
+ if (mContext.getPackageManager().checkPermission(
+ android.Manifest.permission.REQUEST_NOTIFICATION_ASSISTANT_SERVICE,
+ service.packageName) == PackageManager.PERMISSION_GRANTED) {
+ final ComponentName cn = new ComponentName(service.packageName, service.name);
+ list.add(new DefaultAppInfo(mContext, mPm, mUserId, cn));
+ }
}
list.add(new CandidateNone(mContext));
mCandidateInfos = list;
diff --git a/src/com/android/settings/notification/NotificationLockscreenPreference.java b/src/com/android/settings/notification/NotificationLockscreenPreference.java
index 8c04e16..b236014 100644
--- a/src/com/android/settings/notification/NotificationLockscreenPreference.java
+++ b/src/com/android/settings/notification/NotificationLockscreenPreference.java
@@ -27,7 +27,6 @@
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
-import android.widget.ListAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AlertDialog;
@@ -78,7 +77,8 @@
DialogInterface.OnClickListener innerListener) {
mListener = new Listener(innerListener);
- builder.setSingleChoiceItems(createListAdapter(), getSelectedValuePos(), mListener);
+ builder.setSingleChoiceItems(createListAdapter(builder.getContext()), getSelectedValuePos(),
+ mListener);
mShowRemoteInput = getEntryValues().length == 3;
mAllowRemoteInput = Settings.Secure.getInt(getContext().getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, 0) != 0;
@@ -117,11 +117,6 @@
}
@Override
- protected ListAdapter createListAdapter() {
- return new RestrictedArrayAdapter(getContext(), getEntries(), -1);
- }
-
- @Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
Settings.Secure.putInt(getContext().getContentResolver(),
diff --git a/src/com/android/settings/notification/RemoteVolumePreferenceController.java b/src/com/android/settings/notification/RemoteVolumePreferenceController.java
new file mode 100644
index 0000000..0ad307e
--- /dev/null
+++ b/src/com/android/settings/notification/RemoteVolumePreferenceController.java
@@ -0,0 +1,261 @@
+/*
+ * 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.notification;
+
+import android.content.Context;
+import android.media.session.MediaController;
+import android.media.session.MediaSession;
+import android.media.session.MediaSessionManager;
+import android.net.Uri;
+import android.os.Looper;
+import android.text.TextUtils;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.slices.SliceBackgroundWorker;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.volume.MediaSessions;
+
+import java.io.IOException;
+import java.util.List;
+
+public class RemoteVolumePreferenceController extends
+ VolumeSeekBarPreferenceController {
+
+ private static final String KEY_REMOTE_VOLUME = "remote_volume";
+ @VisibleForTesting
+ static final int REMOTE_VOLUME = 100;
+
+ private MediaSessionManager mMediaSessionManager;
+ private MediaSessions mMediaSessions;
+ @VisibleForTesting
+ MediaSession.Token mActiveToken;
+ @VisibleForTesting
+ MediaController mMediaController;
+
+ @VisibleForTesting
+ MediaSessions.Callbacks mCallbacks = new MediaSessions.Callbacks() {
+ @Override
+ public void onRemoteUpdate(MediaSession.Token token, String name,
+ MediaController.PlaybackInfo pi) {
+ if (mActiveToken == null) {
+ updateToken(token);
+ }
+ if (mActiveToken == token) {
+ updatePreference(mPreference, mActiveToken, pi);
+ }
+ }
+
+ @Override
+ public void onRemoteRemoved(MediaSession.Token t) {
+ if (mActiveToken == t) {
+ updateToken(null);
+ if (mPreference != null) {
+ mPreference.setVisible(false);
+ }
+ }
+ }
+
+ @Override
+ public void onRemoteVolumeChanged(MediaSession.Token token, int flags) {
+ if (mActiveToken == token) {
+ final MediaController.PlaybackInfo pi = mMediaController.getPlaybackInfo();
+ if (pi != null) {
+ setSliderPosition(pi.getCurrentVolume());
+ }
+ }
+ }
+ };
+
+ public RemoteVolumePreferenceController(Context context) {
+ super(context, KEY_REMOTE_VOLUME);
+ mMediaSessionManager = context.getSystemService(MediaSessionManager.class);
+ mMediaSessions = new MediaSessions(context, Looper.getMainLooper(), mCallbacks);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ final List<MediaController> controllers = mMediaSessionManager.getActiveSessions(null);
+ for (MediaController mediaController : controllers) {
+ final MediaController.PlaybackInfo pi = mediaController.getPlaybackInfo();
+ if (isRemote(pi)) {
+ updateToken(mediaController.getSessionToken());
+ return AVAILABLE;
+ }
+ }
+
+ // No active remote media at this point
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ if (mMediaController != null) {
+ updatePreference(mPreference, mActiveToken, mMediaController.getPlaybackInfo());
+ }
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
+ public void onResume() {
+ super.onResume();
+ //TODO(b/126199571): register callback once b/126890783 is fixed
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
+ public void onPause() {
+ super.onPause();
+ //TODO(b/126199571): unregister callback once b/126890783 is fixed
+ }
+
+ @Override
+ public int getSliderPosition() {
+ if (mPreference != null) {
+ return mPreference.getProgress();
+ }
+ if (mMediaController == null) {
+ return 0;
+ }
+ final MediaController.PlaybackInfo playbackInfo = mMediaController.getPlaybackInfo();
+ return playbackInfo != null ? playbackInfo.getCurrentVolume() : 0;
+ }
+
+ @Override
+ public boolean setSliderPosition(int position) {
+ if (mPreference != null) {
+ mPreference.setProgress(position);
+ }
+ if (mMediaController == null) {
+ return false;
+ }
+ mMediaController.setVolumeTo(position, 0);
+ return true;
+ }
+
+ @Override
+ public int getMaxSteps() {
+ if (mPreference != null) {
+ return mPreference.getMax();
+ }
+ if (mMediaController == null) {
+ return 0;
+ }
+ final MediaController.PlaybackInfo playbackInfo = mMediaController.getPlaybackInfo();
+ return playbackInfo != null ? playbackInfo.getMaxVolume() : 0;
+ }
+
+ @Override
+ public boolean isSliceable() {
+ return TextUtils.equals(getPreferenceKey(), KEY_REMOTE_VOLUME);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_REMOTE_VOLUME;
+ }
+
+ @Override
+ public int getAudioStream() {
+ // This can be anything because remote volume controller doesn't rely on it.
+ return REMOTE_VOLUME;
+ }
+
+ @Override
+ public int getMuteIcon() {
+ return R.drawable.ic_volume_remote_mute;
+ }
+
+ public static boolean isRemote(MediaController.PlaybackInfo pi) {
+ return pi != null
+ && pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE;
+ }
+
+ @Override
+ public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ //TODO(b/126199571): return RemoteVolumeSliceWorker once b/126890783 is fixed
+ return null;
+ }
+
+ private void updatePreference(VolumeSeekBarPreference seekBarPreference,
+ MediaSession.Token token, MediaController.PlaybackInfo playbackInfo) {
+ if (seekBarPreference == null || token == null || playbackInfo == null) {
+ return;
+ }
+
+ seekBarPreference.setMax(playbackInfo.getMaxVolume());
+ seekBarPreference.setVisible(true);
+ setSliderPosition(playbackInfo.getCurrentVolume());
+ }
+
+ private void updateToken(MediaSession.Token token) {
+ mActiveToken = token;
+ if (token != null) {
+ mMediaController = new MediaController(mContext, mActiveToken);
+ } else {
+ mMediaController = null;
+ }
+ }
+
+ /**
+ * Listener for background change to remote volume, which listens callback
+ * from {@code MediaSessions}
+ */
+ public static class RemoteVolumeSliceWorker extends SliceBackgroundWorker<Void> implements
+ MediaSessions.Callbacks {
+
+ private MediaSessions mMediaSessions;
+
+ public RemoteVolumeSliceWorker(Context context, Uri uri) {
+ super(context, uri);
+ mMediaSessions = new MediaSessions(context, Looper.getMainLooper(), this);
+ }
+
+ @Override
+ protected void onSlicePinned() {
+ mMediaSessions.init();
+ }
+
+ @Override
+ protected void onSliceUnpinned() {
+ mMediaSessions.destroy();
+ }
+
+ @Override
+ public void close() throws IOException {
+ mMediaSessions = null;
+ }
+
+ @Override
+ public void onRemoteUpdate(MediaSession.Token token, String name,
+ MediaController.PlaybackInfo pi) {
+ notifySliceChange();
+ }
+
+ @Override
+ public void onRemoteRemoved(MediaSession.Token t) {
+ notifySliceChange();
+ }
+
+ @Override
+ public void onRemoteVolumeChanged(MediaSession.Token token, int flags) {
+ notifySliceChange();
+ }
+ }
+}
diff --git a/src/com/android/settings/notification/RemoteVolumeSeekBarPreference.java b/src/com/android/settings/notification/RemoteVolumeSeekBarPreference.java
new file mode 100644
index 0000000..e99af6a
--- /dev/null
+++ b/src/com/android/settings/notification/RemoteVolumeSeekBarPreference.java
@@ -0,0 +1,56 @@
+/*
+ * 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.notification;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+/**
+ * A slider preference that controls remote volume, which doesn't go through
+ * {@link android.media.AudioManager}
+ **/
+public class RemoteVolumeSeekBarPreference extends VolumeSeekBarPreference {
+
+ public RemoteVolumeSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public RemoteVolumeSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public RemoteVolumeSeekBarPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public RemoteVolumeSeekBarPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void setStream(int stream) {
+ // Do nothing here, volume is not controlled by AudioManager
+ }
+
+ @Override
+ protected void init() {
+ if (mSeekBar == null) return;
+ updateIconView();
+ updateSuppressionText();
+ }
+}
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index e8b7ee0..b26b921 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -184,6 +184,7 @@
volumeControllers.add(use(RingVolumePreferenceController.class));
volumeControllers.add(use(NotificationVolumePreferenceController.class));
volumeControllers.add(use(CallVolumePreferenceController.class));
+ volumeControllers.add(use(RemoteVolumePreferenceController.class));
use(MediaOutputPreferenceController.class).setCallback(listPreference ->
onPreferenceDataChanged(listPreference));
diff --git a/src/com/android/settings/notification/VolumeSeekBarPreference.java b/src/com/android/settings/notification/VolumeSeekBarPreference.java
index 13f6300..7f36791 100644
--- a/src/com/android/settings/notification/VolumeSeekBarPreference.java
+++ b/src/com/android/settings/notification/VolumeSeekBarPreference.java
@@ -40,8 +40,8 @@
public class VolumeSeekBarPreference extends SeekBarPreference {
private static final String TAG = "VolumeSeekBarPreference";
+ protected SeekBar mSeekBar;
private int mStream;
- private SeekBar mSeekBar;
private SeekBarVolumizer mVolumizer;
private Callback mCallback;
private ImageView mIconView;
@@ -121,7 +121,7 @@
init();
}
- private void init() {
+ protected void init() {
if (mSeekBar == null) return;
final SeekBarVolumizer.Callback sbvc = new SeekBarVolumizer.Callback() {
@Override
@@ -158,7 +158,7 @@
}
}
- private void updateIconView() {
+ protected void updateIconView() {
if (mIconView == null) return;
if (mIconResId != 0) {
mIconView.setImageResource(mIconResId);
@@ -195,7 +195,7 @@
updateSuppressionText();
}
- private void updateSuppressionText() {
+ protected void updateSuppressionText() {
if (mSuppressionTextView != null && mSeekBar != null) {
mSuppressionTextView.setText(mSuppressionText);
final boolean showSuppression = !TextUtils.isEmpty(mSuppressionText);
diff --git a/src/com/android/settings/panel/VolumePanel.java b/src/com/android/settings/panel/VolumePanel.java
index 20c2272..62eca53 100644
--- a/src/com/android/settings/panel/VolumePanel.java
+++ b/src/com/android/settings/panel/VolumePanel.java
@@ -19,6 +19,7 @@
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_ALARM_URI;
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_CALL_URI;
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_MEDIA_URI;
+import static com.android.settings.slices.CustomSliceRegistry.VOLUME_REMOTE_MEDIA_URI;
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_RINGER_URI;
import android.app.settings.SettingsEnums;
@@ -52,6 +53,7 @@
@Override
public List<Uri> getSlices() {
final List<Uri> uris = new ArrayList<>();
+ uris.add(VOLUME_REMOTE_MEDIA_URI);
uris.add(VOLUME_MEDIA_URI);
uris.add(VOLUME_CALL_URI);
uris.add(VOLUME_RINGER_URI);
diff --git a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
index 453cdbf..704d1e5 100644
--- a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
+++ b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
@@ -167,7 +167,8 @@
barViewInfos[index] = new BarViewInfo(
getPermissionGroupIcon(permissionGroupInfo.getName()),
permissionGroupInfo.getAppAccessCount(),
- R.string.storage_detail_apps);
+ R.string.storage_detail_apps,
+ getPermissionGroupLabel(permissionGroupInfo.getName()));
// Set the click listener for each bar view.
// The listener will navigate user to permission usage app.
@@ -194,6 +195,18 @@
return icon;
}
+ private CharSequence getPermissionGroupLabel(CharSequence permissionGroup) {
+ CharSequence label = null;
+ try {
+ label = mPackageManager.getPermissionGroupInfo(permissionGroup.toString(), 0)
+ .loadLabel(mPackageManager);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.w(TAG, "Cannot find group label for " + permissionGroup, e);
+ }
+
+ return label;
+ }
+
private boolean areSamePermissionGroups(List<RuntimePermissionUsageInfo> newUsageInfos) {
if (newUsageInfos.size() != mOldUsageInfos.size()) {
return false;
diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java
index ab1b248..3a1db69 100644
--- a/src/com/android/settings/slices/CustomSliceRegistry.java
+++ b/src/com/android/settings/slices/CustomSliceRegistry.java
@@ -219,6 +219,17 @@
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath("media_volume")
.build();
+
+ /**
+ * Full {@link Uri} for the Remote Media Volume Slice.
+ */
+ public static final Uri VOLUME_REMOTE_MEDIA_URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath("remote_volume")
+ .build();
+
/**
* Full {@link Uri} for the Ringer volume Slice.
*/
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index 79112c7..6fe1795 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -90,6 +90,7 @@
private boolean mValidListener = false;
private boolean mEditableWfcMode = true;
private boolean mEditableWfcRoamingMode = true;
+ private boolean mUseWfcHomeModeForRoaming = false;
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
private ImsManager mImsManager;
@@ -317,6 +318,9 @@
CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL);
mEditableWfcRoamingMode = b.getBoolean(
CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL);
+ mUseWfcHomeModeForRoaming = b.getBoolean(
+ CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL,
+ false);
isWifiOnlySupported = b.getBoolean(
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, true);
}
@@ -499,7 +503,7 @@
// Don't show WFC (home) preference if it's not editable.
preferenceScreen.removePreference(mButtonWfcMode);
}
- if (mEditableWfcRoamingMode) {
+ if (mEditableWfcRoamingMode && !mUseWfcHomeModeForRoaming) {
preferenceScreen.addPreference(mButtonWfcRoamingMode);
} else {
// Don't show WFC roaming preference if it's not editable.
@@ -528,10 +532,8 @@
mImsManager.setWfcMode(buttonMode, false);
mButtonWfcMode.setSummary(getWfcModeSummary(buttonMode));
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
- }
- if (!mEditableWfcRoamingMode) {
- int currentWfcRoamingMode = mImsManager.getWfcMode(true);
- if (buttonMode != currentWfcRoamingMode) {
+
+ if (mUseWfcHomeModeForRoaming) {
mImsManager.setWfcMode(buttonMode, true);
// mButtonWfcRoamingMode.setSummary is not needed; summary is selected value
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java
index b156782..e08d845 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java
@@ -16,11 +16,13 @@
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.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH;
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 android.app.Activity;
@@ -129,6 +131,15 @@
}
@Test
+ public void longClick_deferredSetupCard_shouldNotBeClickable() {
+ final RecyclerView.ViewHolder viewHolder = getDeferredSetupViewHolder();
+ final View contentView = viewHolder.itemView.findViewById(R.id.content);
+ mRenderer.bindView(viewHolder, buildContextualCard(TEST_SLICE_URI));
+
+ assertThat(contentView.isLongClickable()).isFalse();
+ }
+
+ @Test
public void longClick_shouldAddViewHolderToSet() {
final RecyclerView.ViewHolder viewHolder = getSliceViewHolder();
final View card = viewHolder.itemView.findViewById(R.id.slice_view);
@@ -221,6 +232,18 @@
return mRenderer.createViewHolder(view, VIEW_TYPE_FULL_WIDTH);
}
+ private RecyclerView.ViewHolder getDeferredSetupViewHolder() {
+ final RecyclerView recyclerView = new RecyclerView(mActivity);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ final View view = LayoutInflater.from(mActivity).inflate(VIEW_TYPE_DEFERRED_SETUP,
+ recyclerView, false);
+ final RecyclerView.ViewHolder viewHolder = spy(
+ mRenderer.createViewHolder(view, VIEW_TYPE_DEFERRED_SETUP));
+ doReturn(VIEW_TYPE_DEFERRED_SETUP).when(viewHolder).getItemViewType();
+
+ return viewHolder;
+ }
+
private ContextualCard buildContextualCard(Uri sliceUri) {
return new ContextualCard.Builder()
.setName("test_name")
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPickerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPickerTest.java
index 6b6ed02..8f63201 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPickerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPickerTest.java
@@ -16,11 +16,11 @@
package com.android.settings.notification;
-import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.RETURNS_SMART_NULLS;
@@ -40,16 +40,20 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.robolectric.RobolectricTestRunner;
import java.util.ArrayList;
import java.util.List;
-import org.mockito.invocation.InvocationOnMock;
-import org.robolectric.RobolectricTestRunner;
-
@RunWith(RobolectricTestRunner.class)
public class NotificationAssistantPickerTest {
+ private static final String TEST_PKG = "test.package";
+ private static final String TEST_SRV = "test.component";
+ private static final String TEST_CMP = TEST_PKG + "/" + TEST_SRV;
+ private static final String TEST_NAME = "Test name";
+ private static final ComponentName TEST_COMPONENT = ComponentName.unflattenFromString(TEST_CMP);
private NotificationAssistantPicker mFragment;
@Mock
private Context mContext;
@@ -57,15 +61,11 @@
private PackageManager mPackageManager;
@Mock
private NotificationBackend mNotificationBackend;
- private static final String TEST_PKG = "test.package";
- private static final String TEST_SRV = "test.component";
- private static final String TEST_CMP = TEST_PKG + "/" + TEST_SRV;
- private static final String TEST_NAME = "Test name";
- private static final ComponentName TEST_COMPONENT = ComponentName.unflattenFromString(TEST_CMP);
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
mFragment = new TestNotificationAssistantPicker(mContext, mPackageManager,
mNotificationBackend);
}
@@ -132,7 +132,7 @@
public void noDialogOnNoAssistantSelected() {
when(mContext.getString(anyInt(), anyString())).thenAnswer(
(InvocationOnMock invocation) -> {
- return invocation.getArgument(1);
+ return invocation.getArgument(1);
});
assertNull(mFragment.getConfirmationMessage(
new NotificationAssistantPicker.CandidateNone(mContext)));
diff --git a/tests/robotests/src/com/android/settings/notification/RemoteVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RemoteVolumePreferenceControllerTest.java
new file mode 100644
index 0000000..1bf2fd8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/RemoteVolumePreferenceControllerTest.java
@@ -0,0 +1,197 @@
+/*
+ * 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.notification;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.media.session.ControllerLink;
+import android.media.session.MediaController;
+import android.media.session.MediaSession;
+import android.media.session.MediaSessionManager;
+
+import com.android.settings.R;
+
+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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class RemoteVolumePreferenceControllerTest {
+ private static final int CURRENT_POS = 5;
+ private static final int MAX_POS = 10;
+
+ @Mock
+ private MediaSessionManager mMediaSessionManager;
+ @Mock
+ private MediaController mMediaController;
+ @Mock
+ private ControllerLink.ControllerStub mStub;
+ @Mock
+ private ControllerLink.ControllerStub mStub2;
+ private MediaSession.Token mToken;
+ private MediaSession.Token mToken2;
+ private RemoteVolumePreferenceController mController;
+ private Context mContext;
+ private List<MediaController> mActiveSessions;
+ private MediaController.PlaybackInfo mPlaybackInfo;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getSystemService(MediaSessionManager.class)).thenReturn(mMediaSessionManager);
+ mActiveSessions = new ArrayList<>();
+ mActiveSessions.add(mMediaController);
+ when(mMediaSessionManager.getActiveSessions(null)).thenReturn(
+ mActiveSessions);
+ mToken = new MediaSession.Token(new ControllerLink(mStub));
+ mToken2 = new MediaSession.Token(new ControllerLink(mStub2));
+
+ mController = new RemoteVolumePreferenceController(mContext);
+ mPlaybackInfo = new MediaController.PlaybackInfo(
+ MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE, 0, MAX_POS, CURRENT_POS, null);
+ when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+ }
+
+ @Test
+ public void isAvailable_containRemoteMedia_returnTrue() {
+ when(mMediaController.getPlaybackInfo()).thenReturn(
+ new MediaController.PlaybackInfo(MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE,
+ 0, 0, 0, null));
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_noRemoteMedia_returnFalse() {
+ when(mMediaController.getPlaybackInfo()).thenReturn(
+ new MediaController.PlaybackInfo(MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
+ 0, 0, 0, null));
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void getMuteIcon_returnMuteIcon() {
+ assertThat(mController.getMuteIcon()).isEqualTo(R.drawable.ic_volume_remote_mute);
+ }
+
+ @Test
+ public void getAudioStream_returnRemoteVolume() {
+ assertThat(mController.getAudioStream()).isEqualTo(
+ RemoteVolumePreferenceController.REMOTE_VOLUME);
+ }
+
+ @Test
+ public void getSliderPosition_controllerNull_returnZero() {
+ mController.mMediaController = null;
+
+ assertThat(mController.getSliderPosition()).isEqualTo(0);
+ }
+
+ @Test
+ public void getSliderPosition_controllerExists_returnValue() {
+ mController.mMediaController = mMediaController;
+
+ assertThat(mController.getSliderPosition()).isEqualTo(CURRENT_POS);
+ }
+
+ @Test
+ public void getMaxSteps_controllerNull_returnZero() {
+ mController.mMediaController = null;
+
+ assertThat(mController.getMaxSteps()).isEqualTo(0);
+ }
+
+ @Test
+ public void getMaxSteps_controllerExists_returnValue() {
+ mController.mMediaController = mMediaController;
+
+ assertThat(mController.getMaxSteps()).isEqualTo(MAX_POS);
+ }
+
+ @Test
+ public void setSliderPosition_controllerNull_returnFalse() {
+ mController.mMediaController = null;
+
+ assertThat(mController.setSliderPosition(CURRENT_POS)).isFalse();
+ }
+
+ @Test
+ public void setSliderPosition_controllerExists_returnTrue() {
+ mController.mMediaController = mMediaController;
+
+ assertThat(mController.setSliderPosition(CURRENT_POS)).isTrue();
+ verify(mMediaController).setVolumeTo(CURRENT_POS, 0 /* flags */);
+ }
+
+ @Test
+ public void onRemoteUpdate_firstToken_updateTokenAndPreference() {
+ mController.mPreference = new VolumeSeekBarPreference(mContext);
+ mController.mActiveToken = null;
+
+ mController.mCallbacks.onRemoteUpdate(mToken, "token", mPlaybackInfo);
+
+ assertThat(mController.mActiveToken).isEqualTo(mToken);
+ assertThat(mController.mPreference.isVisible()).isTrue();
+ assertThat(mController.mPreference.getMax()).isEqualTo(MAX_POS);
+ assertThat(mController.mPreference.getProgress()).isEqualTo(CURRENT_POS);
+ }
+
+ @Test
+ public void onRemoteUpdate_differentToken_doNothing() {
+ mController.mActiveToken = mToken;
+
+ mController.mCallbacks.onRemoteUpdate(mToken2, "token2", mPlaybackInfo);
+
+ assertThat(mController.mActiveToken).isEqualTo(mToken);
+ }
+
+ @Test
+ public void onRemoteRemoved_tokenRemoved_setInvisible() {
+ mController.mPreference = new VolumeSeekBarPreference(mContext);
+ mController.mActiveToken = mToken;
+
+ mController.mCallbacks.onRemoteRemoved(mToken);
+
+ assertThat(mController.mActiveToken).isNull();
+ assertThat(mController.mPreference.isVisible()).isFalse();
+ }
+
+ @Test
+ public void onRemoteVolumeChanged_volumeChanged_updateIt() {
+ mController.mPreference = new VolumeSeekBarPreference(mContext);
+ mController.mPreference.setMax(MAX_POS);
+ mController.mActiveToken = mToken;
+ mController.mMediaController = mMediaController;
+
+ mController.mCallbacks.onRemoteVolumeChanged(mToken, 0 /* flags */);
+
+ assertThat(mController.mPreference.getProgress()).isEqualTo(CURRENT_POS);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java b/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java
index 11964cd..4665dc9 100644
--- a/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java
+++ b/tests/robotests/src/com/android/settings/panel/VolumePanelTest.java
@@ -45,6 +45,7 @@
final List<Uri> uris = mPanel.getSlices();
assertThat(uris).containsExactly(
+ CustomSliceRegistry.VOLUME_REMOTE_MEDIA_URI,
CustomSliceRegistry.VOLUME_CALL_URI,
CustomSliceRegistry.VOLUME_MEDIA_URI,
CustomSliceRegistry.VOLUME_RINGER_URI,
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
index c8b3920..39de254 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
@@ -19,18 +19,23 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
import android.telephony.ims.ProvisioningManager;
import android.view.View;
@@ -58,10 +63,15 @@
@RunWith(RobolectricTestRunner.class)
public class WifiCallingSettingsForSubTest {
+ private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
+ private static final String BUTTON_WFC_ROAMING_MODE = "wifi_calling_roaming_mode";
+
private TestFragment mFragment;
private Context mContext;
private TextView mEmptyView;
+ private final PersistableBundle mBundle = new PersistableBundle();
+ @Mock private static CarrierConfigManager sCarrierConfigManager;
@Mock private ImsManager mImsManager;
@Mock private TelephonyManager mTelephonyManager;
@Mock private PreferenceScreen mPreferenceScreen;
@@ -70,6 +80,8 @@
@Mock private ToggleSwitch mToggleSwitch;
@Mock private View mView;
@Mock private ImsConfig mImsConfig;
+ @Mock private ListPreference mButtonWfcMode;
+ @Mock private ListPreference mButtonWfcRoamingMode;
@Before
public void setUp() throws NoSuchFieldException, ImsException {
@@ -89,6 +101,8 @@
when(mFragment.getArguments()).thenReturn(bundle);
doNothing().when(mFragment).addPreferencesFromResource(anyInt());
doReturn(mock(ListPreference.class)).when(mFragment).findPreference(any());
+ doReturn(mButtonWfcMode).when(mFragment).findPreference(BUTTON_WFC_MODE);
+ doReturn(mButtonWfcRoamingMode).when(mFragment).findPreference(BUTTON_WFC_ROAMING_MODE);
doNothing().when(mFragment).finish();
doReturn(mView).when(mFragment).getView();
@@ -101,12 +115,26 @@
doReturn(mImsManager).when(mFragment).getImsManager();
doReturn(mImsConfig).when(mImsManager).getConfigInterface();
doReturn(true).when(mImsManager).isWfcProvisionedOnDevice();
+ doReturn(true).when(mImsManager).isWfcEnabledByUser();
+ doReturn(true).when(mImsManager).isNonTtyOrTtyOnVolteEnabled();
+ doReturn(ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED)
+ .when(mImsManager).getWfcMode(anyBoolean());
+
+ doReturn(mBundle).when(sCarrierConfigManager).getConfigForSubId(anyInt());
+ setDefaultCarrierConfigValues();
mFragment.onAttach(mContext);
mFragment.onCreate(null);
mFragment.onActivityCreated(null);
}
+ private void setDefaultCarrierConfigValues() {
+ mBundle.putBoolean(
+ CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL, false);
+ mBundle.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, true);
+ mBundle.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, true);
+ }
+
@Test
public void getHelpResource_shouldReturn0() {
assertThat(mFragment.getHelpResource()).isEqualTo(0);
@@ -142,13 +170,108 @@
verify(mImsConfig).removeConfigCallback(any());
}
+ @Test
+ public void onResume_useWfcHomeModeConfigFalseAndEditable_shouldShowWfcRoaming() {
+ // Call onResume to update the WFC roaming preference.
+ mFragment.onResume();
+
+ // Check that WFC roaming preference is shown.
+ verify(mPreferenceScreen, times(1)).addPreference(mButtonWfcRoamingMode);
+ verify(mPreferenceScreen, never()).removePreference(mButtonWfcRoamingMode);
+ }
+
+ @Test
+ public void onResume_useWfcHomeModeConfigTrueAndEditable_shouldHideWfcRoaming() {
+ mBundle.putBoolean(
+ CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL, true);
+ mBundle.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, true);
+
+ // Call onResume to update the WFC roaming preference.
+ mFragment.onResume();
+
+ // Check that WFC roaming preference is hidden.
+ verify(mPreferenceScreen, never()).addPreference(mButtonWfcRoamingMode);
+ verify(mPreferenceScreen, times(1)).removePreference(mButtonWfcRoamingMode);
+ }
+
+ @Test
+ public void onResume_useWfcHomeModeConfigFalseAndNotEditable_shouldHideWfcRoaming() {
+ mBundle.putBoolean(
+ CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL, false);
+ mBundle.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, false);
+
+ // Call onResume to update the WFC roaming preference.
+ mFragment.onResume();
+
+ // Check that WFC roaming preference is hidden.
+ verify(mPreferenceScreen, never()).addPreference(mButtonWfcRoamingMode);
+ verify(mPreferenceScreen, times(1)).removePreference(mButtonWfcRoamingMode);
+ }
+
+ @Test
+ public void onResume_useWfcHomeModeConfigTrueAndNotEditable_shouldHideWfcRoaming() {
+ mBundle.putBoolean(
+ CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL, true);
+ mBundle.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, false);
+
+ // Call onResume to update the WFC roaming preference.
+ mFragment.onResume();
+
+ // Check that WFC roaming preference is hidden.
+ verify(mPreferenceScreen, never()).addPreference(mButtonWfcRoamingMode);
+ verify(mPreferenceScreen, times(1)).removePreference(mButtonWfcRoamingMode);
+ }
+
+ @Test
+ public void onPreferenceChange_useWfcHomeModeConfigFalse_shouldNotSetWfcRoaming() {
+ // Call onResume to update carrier config values.
+ mFragment.onResume();
+
+ // Set the WFC home mode.
+ mFragment.onPreferenceChange(mButtonWfcMode,
+ String.valueOf(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED));
+
+ // Check that only WFC home mode is set.
+ verify(mImsManager, times(1)).setWfcMode(
+ eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
+ eq(false));
+ verify(mImsManager, never()).setWfcMode(
+ eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
+ eq(true));
+ }
+
+ @Test
+ public void onPreferenceChange_useWfcHomeModeConfigTrue_shouldSetWfcRoaming() {
+ mBundle.putBoolean(
+ CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL, true);
+
+ // Call onResume to update carrier config values.
+ mFragment.onResume();
+
+ // Set the WFC home mode.
+ mFragment.onPreferenceChange(mButtonWfcMode,
+ String.valueOf(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED));
+
+ // Check that both WFC home mode and roaming mode are set.
+ verify(mImsManager, times(1)).setWfcMode(
+ eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
+ eq(false));
+ verify(mImsManager, times(1)).setWfcMode(
+ eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
+ eq(true));
+ }
+
protected class TestFragment extends WifiCallingSettingsForSub {
@Override
protected Object getSystemService(final String name) {
- if (Context.TELEPHONY_SERVICE.equals(name)) {
- return mTelephonyManager;
+ switch (name) {
+ case Context.TELEPHONY_SERVICE:
+ return mTelephonyManager;
+ case Context.CARRIER_CONFIG_SERVICE:
+ return sCarrierConfigManager;
+ default:
+ return null;
}
- return null;
}
}
}