Merge "Remove silky flag from Sound for official release" into sc-dev

This commit is contained in:
Yanting Yang
2021-05-25 07:43:47 +00:00
committed by Android (Google) Code Review
7 changed files with 86 additions and 1022 deletions

View File

@@ -19,8 +19,7 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/sound_settings"
android:key="sound_settings"
settings:keywords="@string/keywords_sounds"
settings:initialExpandedChildrenCount="9">
settings:keywords="@string/keywords_sounds">
<!-- Remote volume group -->
<PreferenceCategory
@@ -90,41 +89,17 @@
android:order="-140"
settings:controller="com.android.settings.notification.NotificationVolumePreferenceController"/>
<!-- Also vibrate for calls -->
<Preference
android:fragment="com.android.settings.sound.VibrateForCallsPreferenceFragment"
android:key="vibrate_for_calls"
android:title="@string/vibrate_when_ringing_title"
android:order="-130"
settings:controller="com.android.settings.sound.VibrateForCallsPreferenceController"
settings:keywords="@string/keywords_vibrate_for_calls"/>
<!-- TODO(b/174964721): make this a PrimarySwitchPreference -->
<!-- Interruptions -->
<com.android.settingslib.RestrictedPreference
android:key="zen_mode"
android:title="@string/zen_mode_settings_title"
android:fragment="com.android.settings.notification.zen.ZenModeSettings"
android:order="-120"
android:order="-130"
settings:useAdminDisabledSummary="true"
settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
settings:allowDividerAbove="true"
settings:controller="com.android.settings.notification.zen.ZenModePreferenceController"/>
<Preference
android:key="media_controls_summary"
android:title="@string/media_controls_title"
android:fragment="com.android.settings.sound.MediaControlsSettings"
android:order="-110"
settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
settings:keywords="@string/keywords_media_controls"/>
<com.android.settings.widget.PrimarySwitchPreference
android:key="gesture_prevent_ringing_sound"
android:title="@string/gesture_prevent_ringing_sound_title"
android:order="-107"
android:fragment="com.android.settings.gestures.PreventRingingGestureSettings"
settings:controller="com.android.settings.gestures.PreventRingingParentPreferenceController"/>
<!-- Phone ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="phone_ringtone"
@@ -132,9 +107,34 @@
android:dialogTitle="@string/ringtone_title"
android:summary="@string/summary_placeholder"
android:ringtoneType="ringtone"
android:order="-100"
android:order="-120"
settings:keywords="@string/sound_settings"/>
<!-- Live Caption -110 and Now Playing -105-->
<Preference
android:key="media_controls_summary"
android:title="@string/media_controls_title"
android:fragment="com.android.settings.sound.MediaControlsSettings"
android:order="-100"
settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
settings:keywords="@string/keywords_media_controls"/>
<!-- Also vibrate for calls -->
<Preference
android:fragment="com.android.settings.sound.VibrateForCallsPreferenceFragment"
android:key="vibrate_for_calls"
android:title="@string/vibrate_when_ringing_title"
android:order="-90"
settings:controller="com.android.settings.sound.VibrateForCallsPreferenceController"
settings:keywords="@string/keywords_vibrate_for_calls"/>
<com.android.settings.widget.PrimarySwitchPreference
android:key="gesture_prevent_ringing_sound"
android:title="@string/gesture_prevent_ringing_sound_title"
android:order="-80"
android:fragment="com.android.settings.gestures.PreventRingingGestureSettings"
settings:controller="com.android.settings.gestures.PreventRingingParentPreferenceController"/>
<!-- Default notification ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="notification_ringtone"
@@ -142,7 +142,7 @@
android:dialogTitle="@string/notification_ringtone_title"
android:summary="@string/summary_placeholder"
android:ringtoneType="notification"
android:order="-90"/>
android:order="-70"/>
<!-- Default alarm ringtone -->
<com.android.settings.DefaultRingtonePreference
@@ -152,100 +152,70 @@
android:summary="@string/summary_placeholder"
android:persistent="false"
android:ringtoneType="alarm"
android:order="-80"/>
android:order="-60"/>
<!-- Other sounds -->
<PreferenceCategory
android:key="other_sounds_and_vibrations_category"
android:title="@string/other_sound_category_preference_title"
android:order="-50">
<!-- Dial pad tones -->
<SwitchPreference
android:key="dial_pad_tones"
android:title="@string/dial_pad_tones_title"
android:order="-50"/>
<!-- Dial pad tones -->
<SwitchPreference
android:key="dial_pad_tones"
android:title="@string/dial_pad_tones_title"/>
<!-- Screen locking sounds -->
<SwitchPreference
android:key="screen_locking_sounds"
android:title="@string/screen_locking_sounds_title"
android:order="-45"/>
<!-- Screen locking sounds -->
<SwitchPreference
android:key="screen_locking_sounds"
android:title="@string/screen_locking_sounds_title"/>
<!-- Charging sounds -->
<SwitchPreference
android:key="charging_sounds"
android:title="@string/charging_sounds_title"
android:order="-40"/>
<!-- Charging sounds -->
<SwitchPreference
android:key="charging_sounds"
android:title="@string/charging_sounds_title"/>
<!-- Docking sounds -->
<SwitchPreference
android:key="docking_sounds"
android:title="@string/docking_sounds_title"
android:order="-35"/>
<!-- Docking sounds -->
<SwitchPreference
android:key="docking_sounds"
android:title="@string/docking_sounds_title"/>
<!-- Touch sounds -->
<SwitchPreference
android:key="touch_sounds"
android:title="@string/touch_sounds_title"
android:order="-30"/>
<!-- Touch sounds -->
<SwitchPreference
android:key="touch_sounds"
android:title="@string/touch_sounds_title"/>
<!-- Vibrate on touch -->
<SwitchPreference
android:key="vibrate_on_touch"
android:title="@string/vibrate_on_touch_title"
android:summary="@string/vibrate_on_touch_summary"
settings:keywords="@string/keywords_vibrate_on_touch"
android:order="-25"/>
<!-- Vibrate on touch -->
<SwitchPreference
android:key="vibrate_on_touch"
android:title="@string/vibrate_on_touch_title"
android:summary="@string/vibrate_on_touch_summary"
settings:keywords="@string/keywords_vibrate_on_touch"/>
<!-- Dock speaker plays -->
<DropDownPreference
android:key="dock_audio_media"
android:title="@string/dock_audio_media_title"
android:summary="%s"
android:order="-20"/>
<!-- Dock speaker plays -->
<DropDownPreference
android:key="dock_audio_media"
android:title="@string/dock_audio_media_title"
android:summary="%s"/>
<!-- Boot sounds -->
<SwitchPreference
android:key="boot_sounds"
android:title="@string/boot_sounds_title"
android:order="-15"/>
<!-- Boot sounds -->
<SwitchPreference
android:key="boot_sounds"
android:title="@string/boot_sounds_title"/>
<!-- Emergency tone -->
<DropDownPreference
android:key="emergency_tone"
android:title="@string/emergency_tone_title"
android:summary="%s"
android:order="-10"/>
<!-- Emergency tone -->
<DropDownPreference
android:key="emergency_tone"
android:title="@string/emergency_tone_title"
android:summary="%s"/>
</PreferenceCategory>
<com.android.settings.widget.WorkOnlyCategory
android:key="sound_work_settings_section"
<Preference
android:key="sound_work_settings"
android:title="@string/sound_work_settings"
android:order="100">
<!-- Use the same sounds of the work profile -->
<SwitchPreference
android:key="work_use_personal_sounds"
android:title="@string/work_use_personal_sounds_title"
android:summary="@string/work_use_personal_sounds_summary"
android:disableDependentsState="true"/>
<!-- Work phone ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="work_ringtone"
android:title="@string/work_ringtone_title"
android:dialogTitle="@string/work_alarm_ringtone_title"
android:ringtoneType="ringtone"
android:dependency="work_use_personal_sounds"/>
<!-- Default work notification ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="work_notification_ringtone"
android:title="@string/work_notification_ringtone_title"
android:dialogTitle="@string/work_alarm_ringtone_title"
android:ringtoneType="notification"
android:dependency="work_use_personal_sounds"/>
<!-- Default work alarm ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="work_alarm_ringtone"
android:title="@string/work_alarm_ringtone_title"
android:dialogTitle="@string/work_alarm_ringtone_title"
android:persistent="false"
android:ringtoneType="alarm"
android:dependency="work_use_personal_sounds"/>
</com.android.settings.widget.WorkOnlyCategory>
android:fragment="com.android.settings.notification.SoundWorkSettings"
android:order="100"
settings:controller="com.android.settings.notification.WorkSoundsPreferenceController"/>
</PreferenceScreen>

View File

@@ -1,221 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/sound_settings"
android:key="sound_settings"
settings:keywords="@string/keywords_sounds">
<!-- Remote volume group -->
<PreferenceCategory
android:key="remote_media_group"
android:title=""
android:order="-185"
settings:allowDividerBelow="true"
settings:controller="com.android.settings.notification.RemoteVolumeGroupController">
</PreferenceCategory>
<!-- Media volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="media_volume"
android:icon="@drawable/ic_media_stream"
android:title="@string/media_volume_option_title"
android:order="-180"
settings:controller="com.android.settings.notification.MediaVolumePreferenceController"/>
<!-- Media output switcher -->
<Preference
android:key="media_output"
android:title="@string/media_output_title"
android:dialogTitle="@string/media_output_title"
android:order="-175"
settings:searchable="false"
settings:controller="com.android.settings.sound.MediaOutputPreferenceController"/>
<!-- Call volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="call_volume"
android:icon="@drawable/ic_local_phone_24_lib"
android:title="@string/call_volume_option_title"
android:order="-170"
settings:controller="com.android.settings.notification.CallVolumePreferenceController"/>
<!-- Hands free profile output switcher -->
<ListPreference
android:key="take_call_on_output"
android:title="@string/take_call_on_title"
android:dialogTitle="@string/take_call_on_title"
android:order="-165"
settings:searchable="false"
settings:controller="com.android.settings.sound.HandsFreeProfileOutputPreferenceController"/>
<!-- Ring volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="ring_volume"
android:icon="@drawable/ic_notifications"
android:title="@string/ring_volume_option_title"
android:order="-160"
settings:controller="com.android.settings.notification.RingVolumePreferenceController"/>
<!-- Alarm volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="alarm_volume"
android:icon="@*android:drawable/ic_audio_alarm"
android:title="@string/alarm_volume_option_title"
android:order="-150"
settings:controller="com.android.settings.notification.AlarmVolumePreferenceController"/>
<!-- Notification volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="notification_volume"
android:icon="@drawable/ic_notifications"
android:title="@string/notification_volume_option_title"
android:order="-140"
settings:controller="com.android.settings.notification.NotificationVolumePreferenceController"/>
<!-- TODO(b/174964721): make this a PrimarySwitchPreference -->
<!-- Interruptions -->
<com.android.settingslib.RestrictedPreference
android:key="zen_mode"
android:title="@string/zen_mode_settings_title"
android:fragment="com.android.settings.notification.zen.ZenModeSettings"
android:order="-130"
settings:useAdminDisabledSummary="true"
settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
settings:controller="com.android.settings.notification.zen.ZenModePreferenceController"/>
<!-- Phone ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="phone_ringtone"
android:title="@string/ringtone_title"
android:dialogTitle="@string/ringtone_title"
android:summary="@string/summary_placeholder"
android:ringtoneType="ringtone"
android:order="-120"
settings:keywords="@string/sound_settings"/>
<!-- Live Caption -110 and Now Playing -105-->
<Preference
android:key="media_controls_summary"
android:title="@string/media_controls_title"
android:fragment="com.android.settings.sound.MediaControlsSettings"
android:order="-100"
settings:controller="com.android.settings.sound.MediaControlsParentPreferenceController"
settings:keywords="@string/keywords_media_controls"/>
<!-- Also vibrate for calls -->
<Preference
android:fragment="com.android.settings.sound.VibrateForCallsPreferenceFragment"
android:key="vibrate_for_calls"
android:title="@string/vibrate_when_ringing_title"
android:order="-90"
settings:controller="com.android.settings.sound.VibrateForCallsPreferenceController"
settings:keywords="@string/keywords_vibrate_for_calls"/>
<com.android.settings.widget.PrimarySwitchPreference
android:key="gesture_prevent_ringing_sound"
android:title="@string/gesture_prevent_ringing_sound_title"
android:order="-80"
android:fragment="com.android.settings.gestures.PreventRingingGestureSettings"
settings:controller="com.android.settings.gestures.PreventRingingParentPreferenceController"/>
<!-- Default notification ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="notification_ringtone"
android:title="@string/notification_ringtone_title"
android:dialogTitle="@string/notification_ringtone_title"
android:summary="@string/summary_placeholder"
android:ringtoneType="notification"
android:order="-70"/>
<!-- Default alarm ringtone -->
<com.android.settings.DefaultRingtonePreference
android:key="alarm_ringtone"
android:title="@string/alarm_ringtone_title"
android:dialogTitle="@string/alarm_ringtone_title"
android:summary="@string/summary_placeholder"
android:persistent="false"
android:ringtoneType="alarm"
android:order="-60"/>
<!-- Dial pad tones -->
<SwitchPreference
android:key="dial_pad_tones"
android:title="@string/dial_pad_tones_title"
android:order="-50"/>
<!-- Screen locking sounds -->
<SwitchPreference
android:key="screen_locking_sounds"
android:title="@string/screen_locking_sounds_title"
android:order="-45"/>
<!-- Charging sounds -->
<SwitchPreference
android:key="charging_sounds"
android:title="@string/charging_sounds_title"
android:order="-40"/>
<!-- Docking sounds -->
<SwitchPreference
android:key="docking_sounds"
android:title="@string/docking_sounds_title"
android:order="-35"/>
<!-- Touch sounds -->
<SwitchPreference
android:key="touch_sounds"
android:title="@string/touch_sounds_title"
android:order="-30"/>
<!-- Vibrate on touch -->
<SwitchPreference
android:key="vibrate_on_touch"
android:title="@string/vibrate_on_touch_title"
android:summary="@string/vibrate_on_touch_summary"
settings:keywords="@string/keywords_vibrate_on_touch"
android:order="-25"/>
<!-- Dock speaker plays -->
<DropDownPreference
android:key="dock_audio_media"
android:title="@string/dock_audio_media_title"
android:summary="%s"
android:order="-20"/>
<!-- Boot sounds -->
<SwitchPreference
android:key="boot_sounds"
android:title="@string/boot_sounds_title"
android:order="-15"/>
<!-- Emergency tone -->
<DropDownPreference
android:key="emergency_tone"
android:title="@string/emergency_tone_title"
android:summary="%s"
android:order="-10"/>
<Preference
android:key="sound_work_settings"
android:title="@string/sound_work_settings"
android:fragment="com.android.settings.notification.SoundWorkSettings"
android:order="100"
settings:controller="com.android.settings.notification.WorkSoundsPreferenceController"/>
</PreferenceScreen>

View File

@@ -25,9 +25,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.UserHandle;
import android.preference.SeekBarVolumizer;
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
@@ -35,7 +33,6 @@ import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.OnActivityResultListener;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -155,9 +152,6 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
@Override
protected int getPreferenceScreenResId() {
if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
return R.xml.sound_settings_v2;
}
return R.xml.sound_settings;
}
@@ -251,12 +245,6 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
controllers.add(new AlarmRingtonePreferenceController(context));
controllers.add(new NotificationRingtonePreferenceController(context));
if (!FeatureFlagUtils.isEnabled(context, FeatureFlags.SILKY_HOME)) {
// TODO(b/174964721): This should be removed when the flag is deprecated.
// === Work Sound Settings ===
controllers.add(new WorkSoundPreferenceController(context, fragment, lifecycle));
}
// === Other Sound Settings ===
final DialPadTonePreferenceController dialPadTonePreferenceController =
new DialPadTonePreferenceController(context, fragment, lifecycle);
@@ -312,30 +300,8 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
return buildPreferenceControllers(context, null /* fragment */,
null /* lifecycle */);
}
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = FeatureFlagUtils.isEnabled(context, FeatureFlags.SILKY_HOME)
? R.xml.sound_settings_v2 : R.xml.sound_settings;
return Arrays.asList(sir);
}
};
// === Work Sound Settings ===
void enableWorkSync() {
// TODO(b/174964721): This should be refined when the flag is deprecated.
if (!FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
final WorkSoundPreferenceController workSoundController =
use(WorkSoundPreferenceController.class);
if (workSoundController != null) {
workSoundController.enableWorkSync();
}
}
}
private void onPreferenceDataChanged(ListPreference preference) {
if (mDialogFragment != null) {
mDialogFragment.onListPreferenceUpdated(preference);

View File

@@ -23,13 +23,11 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.OnActivityResultListener;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -123,16 +121,12 @@ public class SoundWorkSettings extends DashboardFragment implements OnActivityRe
}
static final boolean isSupportWorkProfileSound(Context context) {
// TODO(b/174964721): Feature flag should be removed when silky home launched.
final boolean isSilkyEnabled = FeatureFlagUtils.isEnabled(context,
FeatureFlags.SILKY_HOME);
final AudioHelper audioHelper = new AudioHelper(context);
final boolean hasWorkProfile = audioHelper.getManagedProfileId(
UserManager.get(context)) != UserHandle.USER_NULL;
final boolean shouldShowRingtoneSettings = !audioHelper.isSingleVolume();
return isSilkyEnabled && hasWorkProfile && shouldShowRingtoneSettings;
return hasWorkProfile && shouldShowRingtoneSettings;
}
void enableWorkSync() {

View File

@@ -1,368 +0,0 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.annotation.UserIdInt;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import androidx.preference.TwoStatePreference;
import com.android.settings.DefaultRingtonePreference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import java.util.List;
/**
* TODO(b/183670633): Remove this file when silky flag deprecated.
*/
public class WorkSoundPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, OnPreferenceChangeListener, LifecycleObserver,
OnResume, OnPause {
private static final String TAG = "WorkSoundPrefController";
private static final String KEY_WORK_CATEGORY = "sound_work_settings_section";
private static final String KEY_WORK_USE_PERSONAL_SOUNDS = "work_use_personal_sounds";
private static final String KEY_WORK_PHONE_RINGTONE = "work_ringtone";
private static final String KEY_WORK_NOTIFICATION_RINGTONE = "work_notification_ringtone";
private static final String KEY_WORK_ALARM_RINGTONE = "work_alarm_ringtone";
private final boolean mVoiceCapable;
private final UserManager mUserManager;
private final SoundSettings mParent;
private final AudioHelper mHelper;
private PreferenceGroup mWorkPreferenceCategory;
private TwoStatePreference mWorkUsePersonalSounds;
private Preference mWorkPhoneRingtonePreference;
private Preference mWorkNotificationRingtonePreference;
private Preference mWorkAlarmRingtonePreference;
@UserIdInt
private int mManagedProfileId;
public WorkSoundPreferenceController(Context context, SoundSettings parent,
Lifecycle lifecycle) {
this(context, parent, lifecycle, new AudioHelper(context));
}
@VisibleForTesting
WorkSoundPreferenceController(Context context, SoundSettings parent, Lifecycle lifecycle,
AudioHelper helper) {
super(context);
mUserManager = UserManager.get(context);
mVoiceCapable = Utils.isVoiceCapable(mContext);
mParent = parent;
mHelper = helper;
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mWorkPreferenceCategory = screen.findPreference(KEY_WORK_CATEGORY);
}
@Override
public void onResume() {
IntentFilter managedProfileFilter = new IntentFilter();
managedProfileFilter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
managedProfileFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
mContext.registerReceiver(mManagedProfileReceiver, managedProfileFilter);
mManagedProfileId = mHelper.getManagedProfileId(mUserManager);
updateWorkPreferences();
}
@Override
public void onPause() {
mContext.unregisterReceiver(mManagedProfileReceiver);
}
@Override
public String getPreferenceKey() {
return KEY_WORK_CATEGORY;
}
@Override
public boolean isAvailable() {
return mHelper.getManagedProfileId(mUserManager) != UserHandle.USER_NULL
&& shouldShowRingtoneSettings();
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
return false;
}
/**
* Updates the summary of work preferences
*
* This controller listens to changes on the work ringtone preferences, identified by keys
* "work_ringtone", "work_notification_ringtone" and "work_alarm_ringtone".
*/
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int ringtoneType;
if (KEY_WORK_PHONE_RINGTONE.equals(preference.getKey())) {
ringtoneType = RingtoneManager.TYPE_RINGTONE;
} else if (KEY_WORK_NOTIFICATION_RINGTONE.equals(preference.getKey())) {
ringtoneType = RingtoneManager.TYPE_NOTIFICATION;
} else if (KEY_WORK_ALARM_RINGTONE.equals(preference.getKey())) {
ringtoneType = RingtoneManager.TYPE_ALARM;
} else {
return true;
}
preference.setSummary(updateRingtoneName(getManagedProfileContext(), ringtoneType));
return true;
}
@Override
public void updateNonIndexableKeys(List<String> keys) {
if (isAvailable()) {
return;
}
keys.add(KEY_WORK_CATEGORY);
keys.add(KEY_WORK_USE_PERSONAL_SOUNDS);
keys.add(KEY_WORK_NOTIFICATION_RINGTONE);
keys.add(KEY_WORK_PHONE_RINGTONE);
keys.add(KEY_WORK_ALARM_RINGTONE);
}
// === Phone & notification ringtone ===
private boolean shouldShowRingtoneSettings() {
return !mHelper.isSingleVolume();
}
private CharSequence updateRingtoneName(Context context, int type) {
if (context == null || !mHelper.isUserUnlocked(mUserManager, context.getUserId())) {
return mContext.getString(R.string.managed_profile_not_available_label);
}
Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type);
return Ringtone.getTitle(context, ringtoneUri, false /* followSettingsUri */,
true /* allowRemote */);
}
private Context getManagedProfileContext() {
if (mManagedProfileId == UserHandle.USER_NULL) {
return null;
}
return mHelper.createPackageContextAsUser(mManagedProfileId);
}
private DefaultRingtonePreference initWorkPreference(PreferenceGroup root, String key) {
DefaultRingtonePreference pref =
(DefaultRingtonePreference) root.findPreference(key);
pref.setOnPreferenceChangeListener(this);
// Required so that RingtonePickerActivity lists the work profile ringtones
pref.setUserId(mManagedProfileId);
return pref;
}
private void updateWorkPreferences() {
if (mWorkPreferenceCategory == null) {
return;
}
final boolean isAvailable = isAvailable();
mWorkPreferenceCategory.setVisible(isAvailable);
if (!isAvailable) {
return;
}
if (mWorkUsePersonalSounds == null) {
mWorkUsePersonalSounds = (TwoStatePreference)
mWorkPreferenceCategory.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS);
mWorkUsePersonalSounds.setOnPreferenceChangeListener((Preference p, Object value) -> {
if ((boolean) value) {
UnifyWorkDialogFragment.show(mParent);
return false;
} else {
disableWorkSync();
return true;
}
});
}
if (mWorkPhoneRingtonePreference == null) {
mWorkPhoneRingtonePreference = initWorkPreference(mWorkPreferenceCategory,
KEY_WORK_PHONE_RINGTONE);
}
if (mWorkNotificationRingtonePreference == null) {
mWorkNotificationRingtonePreference = initWorkPreference(mWorkPreferenceCategory,
KEY_WORK_NOTIFICATION_RINGTONE);
}
if (mWorkAlarmRingtonePreference == null) {
mWorkAlarmRingtonePreference = initWorkPreference(mWorkPreferenceCategory,
KEY_WORK_ALARM_RINGTONE);
}
if (!mVoiceCapable) {
mWorkPhoneRingtonePreference.setVisible(false);
mWorkPhoneRingtonePreference = null;
}
final Context managedProfileContext = getManagedProfileContext();
if (Settings.Secure.getIntForUser(managedProfileContext.getContentResolver(),
Settings.Secure.SYNC_PARENT_SOUNDS, 0, mManagedProfileId) == 1) {
enableWorkSyncSettings();
} else {
disableWorkSyncSettings();
}
}
void enableWorkSync() {
RingtoneManager.enableSyncFromParent(getManagedProfileContext());
enableWorkSyncSettings();
}
private void enableWorkSyncSettings() {
mWorkUsePersonalSounds.setChecked(true);
if (mWorkPhoneRingtonePreference != null) {
mWorkPhoneRingtonePreference.setSummary(R.string.work_sound_same_as_personal);
}
mWorkNotificationRingtonePreference.setSummary(R.string.work_sound_same_as_personal);
mWorkAlarmRingtonePreference.setSummary(R.string.work_sound_same_as_personal);
}
private void disableWorkSync() {
RingtoneManager.disableSyncFromParent(getManagedProfileContext());
disableWorkSyncSettings();
}
private void disableWorkSyncSettings() {
if (mWorkPhoneRingtonePreference != null) {
mWorkPhoneRingtonePreference.setEnabled(true);
}
mWorkNotificationRingtonePreference.setEnabled(true);
mWorkAlarmRingtonePreference.setEnabled(true);
updateWorkRingtoneSummaries();
}
private void updateWorkRingtoneSummaries() {
Context managedProfileContext = getManagedProfileContext();
if (mWorkPhoneRingtonePreference != null) {
mWorkPhoneRingtonePreference.setSummary(
updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_RINGTONE));
}
mWorkNotificationRingtonePreference.setSummary(
updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_NOTIFICATION));
mWorkAlarmRingtonePreference.setSummary(
updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_ALARM));
}
public void onManagedProfileAdded(@UserIdInt int profileId) {
if (mManagedProfileId == UserHandle.USER_NULL) {
mManagedProfileId = profileId;
updateWorkPreferences();
}
}
public void onManagedProfileRemoved(@UserIdInt int profileId) {
if (mManagedProfileId == profileId) {
mManagedProfileId = mHelper.getManagedProfileId(mUserManager);
updateWorkPreferences();
}
}
private final BroadcastReceiver mManagedProfileReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final int userId = ((UserHandle) intent.getExtra(Intent.EXTRA_USER)).getIdentifier();
switch (intent.getAction()) {
case Intent.ACTION_MANAGED_PROFILE_ADDED: {
onManagedProfileAdded(userId);
return;
}
case Intent.ACTION_MANAGED_PROFILE_REMOVED: {
onManagedProfileRemoved(userId);
return;
}
}
}
};
public static class UnifyWorkDialogFragment extends InstrumentedDialogFragment
implements DialogInterface.OnClickListener {
private static final String TAG = "UnifyWorkDialogFragment";
private static final int REQUEST_CODE = 200;
@Override
public int getMetricsCategory() {
return SettingsEnums.DIALOG_UNIFY_SOUND_SETTINGS;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.work_sync_dialog_title)
.setMessage(R.string.work_sync_dialog_message)
.setPositiveButton(R.string.work_sync_dialog_yes, UnifyWorkDialogFragment.this)
.setNegativeButton(android.R.string.no, null)
.create();
}
public static void show(SoundSettings parent) {
FragmentManager fm = parent.getFragmentManager();
if (fm.findFragmentByTag(TAG) == null) {
UnifyWorkDialogFragment fragment = new UnifyWorkDialogFragment();
fragment.setTargetFragment(parent, REQUEST_CODE);
fragment.show(fm, TAG);
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
SoundSettings soundSettings = (SoundSettings) getTargetFragment();
if (soundSettings.isAdded()) {
soundSettings.enableWorkSync();
}
}
}
}

View File

@@ -1,274 +0,0 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
import android.telephony.TelephonyManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.TwoStatePreference;
import com.android.settings.DefaultRingtonePreference;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
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;
@RunWith(RobolectricTestRunner.class)
public class WorkSoundPreferenceControllerTest {
private static final String KEY_WORK_CATEGORY = "sound_work_settings_section";
private static final String KEY_WORK_USE_PERSONAL_SOUNDS = "work_use_personal_sounds";
private static final String KEY_WORK_PHONE_RINGTONE = "work_ringtone";
private static final String KEY_WORK_NOTIFICATION_RINGTONE = "work_notification_ringtone";
private static final String KEY_WORK_ALARM_RINGTONE = "work_alarm_ringtone";
@Mock
private Context mContext;
@Mock
private PreferenceScreen mScreen;
@Mock
private PreferenceCategory mWorkCategory;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private AudioHelper mAudioHelper;
@Mock
private SoundSettings mFragment;
private WorkSoundPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
when(mScreen.findPreference(KEY_WORK_CATEGORY))
.thenReturn(mWorkCategory);
when(mWorkCategory.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS))
.thenReturn(mock(TwoStatePreference.class));
when(mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
.thenReturn(mock(DefaultRingtonePreference.class));
when(mWorkCategory.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
.thenReturn(mock(DefaultRingtonePreference.class));
when(mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
.thenReturn(mock(DefaultRingtonePreference.class));
mController = new WorkSoundPreferenceController(mContext, mFragment, null, mAudioHelper);
}
@Test
public void isAvailable_managedProfileAndNotSingleVolume_shouldReturnTrue() {
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_noManagedProfile_shouldReturnFalse() {
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_singleVolume_shouldReturnFalse() {
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(true);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void onManagedProfileAdded_shouldDisplayPreferenceCategory() {
// Given a device without any managed profiles:
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
// When the fragment first displays, the category should not appear.
mController.displayPreference(mScreen);
verify(mWorkCategory).setVisible(false);
// However, when a managed profile is added later, the category should appear.
mController.onResume();
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
mController.onManagedProfileAdded(UserHandle.myUserId());
verify(mWorkCategory).setVisible(true);
}
@Test
public void onManagedProfileRemoved_shouldHidePreferenceCategory() {
// Given a device with a managed profile:
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
// Which is in resumed state:
mController.displayPreference(mScreen);
mController.onResume();
verify(mWorkCategory, times(2)).setVisible(true);
// When a managed profile is removed, the category should be hidden.
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
mController.onManagedProfileRemoved(UserHandle.myUserId());
verify(mWorkCategory).setVisible(false);
}
@Test
public void displayPreference_isAvailable_shouldShowPreferenceCategory() {
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
mController.displayPreference(mScreen);
verify(mWorkCategory).setVisible(true);
}
@Test
public void displayPreference_notAvailable_shouldHidePreferenceCategory() {
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
when(mAudioHelper.isSingleVolume()).thenReturn(true);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
mController.displayPreference(mScreen);
verify(mWorkCategory).setVisible(false);
}
@Test
public void onPreferenceChange_shouldUpdateSummary() {
final Preference preference = mock(Preference.class);
when(preference.getKey()).thenReturn(KEY_WORK_PHONE_RINGTONE);
mController.onPreferenceChange(preference, "hello");
verify(preference).setSummary(nullable(String.class));
}
@Test
public void onResume_noVoiceCapability_shouldHidePhoneRingtone() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
mController = new WorkSoundPreferenceController(mContext, mFragment, null, mAudioHelper);
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
// Precondition: work profile is available.
assertThat(mController.isAvailable()).isTrue();
mController.displayPreference(mScreen);
mController.onResume();
verify((Preference) mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
.setVisible(false);
}
@Test
public void onResume_availableButLocked_shouldRedactPreferences() {
final String notAvailable = "(not available)";
when(mContext.getString(R.string.managed_profile_not_available_label))
.thenReturn(notAvailable);
// Given a device with a managed profile:
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(false);
// When resumed:
mController.displayPreference(mScreen);
mController.onResume();
verify(mWorkCategory, times(2)).setVisible(true);
// Sound preferences should explain that the profile isn't available yet.
verify((Preference) mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
.setSummary(eq(notAvailable));
verify((Preference) mWorkCategory.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
.setSummary(eq(notAvailable));
verify((Preference) mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
.setSummary(eq(notAvailable));
}
@Test
public void onResume_shouldSetUserIdToPreference() {
final int managedProfileUserId = 10;
when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(managedProfileUserId);
when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
mController.displayPreference(mScreen);
mController.onResume();
verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
.setUserId(managedProfileUserId);
verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
.setUserId(managedProfileUserId);
verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
.setUserId(managedProfileUserId);
}
}

View File

@@ -23,9 +23,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.UserHandle;
import android.util.FeatureFlagUtils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.testutils.shadow.ShadowAudioHelper;
import org.junit.After;
@@ -56,7 +54,6 @@ public class WorkSoundsPreferenceControllerTest {
@Test
public void getAvailabilityStatus_supportWorkProfileSound_shouldReturnAvailable() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, true);
ShadowAudioHelper.setIsSingleVolume(false);
ShadowAudioHelper.setManagedProfileId(UserHandle.USER_CURRENT);