Implement a separate controller for ring volume

When ring volume is separated from notification, a new xml preferece and
controller is needed for it, so that the settings search can show/hide
the slice correctly.

1. Use a separate preference and controller for ring volume (vs ring &
notification combined)
2. Notification slice in settings no longer grays out when ringer mode
is set to mute or vibrate.
3. Introduce an abstract RingerModeAffected preference controller class
to factor out duplicate code among ring, notification, and separate-ring
controller classes.

Bug: b/259084354

Test:   make ROBOTEST_FILTER=RingVolumePreferenceControllerTest
RunSettingsRoboTests -j40
        make ROBOTEST_FILTER=SeparateRingVolumePreferenceControllerTest
RunSettingsRoboTests -j40
        make ROBOTEST_FILTER=NotificationVolumePreferenceControllerTest
RunSettingsRoboTests -j40
        make ROBOTEST_FILTER=VolumePanelTest RunSettingsRoboTests -j40
	make
ROBOTEST_FILTER=RingerModeAffectedVolumePreferenceControllerTest -j40

Known Issue:
1. When streams are separate and ring volume set to mute/vibrate,
notification is set to zero, but not disabled. So it can be turned on
by user (and in settings the icon will stay mute/vibrate instead of
changing to the normal notification icon).

2. In the above scenario after notification is unmuted in settings,
the notification icon continues to stay vibrate/mute -- should change
to the normal notification icon.

Note: This feature is controlled using a boolean DeviceConfig flag:
systemui/"volume_separate_ring". The default value is 'false', which is
meant to keep the experience the same as before. It will be set to
'true' for teamfood and dogfood. Eventually the flag will be removed and
the code in the 'true' branch will prevail.


Change-Id: Ibec871eafeef4081e96c5e0dd04535565d50a077
This commit is contained in:
Behnam Heydarshahi
2022-12-15 21:51:13 +00:00
parent e722587923
commit 4f87dd4b56
13 changed files with 615 additions and 288 deletions

View File

@@ -0,0 +1,168 @@
/*
* Copyright (C) 2022 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.app.INotificationManager;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.media.AudioManager;
import android.os.ServiceManager;
import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import java.util.Objects;
/**
* Shared functionality and interfaces for volume controllers whose state can change by ringer mode
*/
public abstract class RingerModeAffectedVolumePreferenceController extends
VolumeSeekBarPreferenceController {
private final String mTag;
protected int mNormalIconId;
protected int mVibrateIconId;
protected int mSilentIconId;
protected int mMuteIcon;
protected Vibrator mVibrator;
protected int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
protected ComponentName mSuppressor;
protected boolean mSeparateNotification;
protected INotificationManager mNoMan;
private static final boolean CONFIG_SEPARATE_NOTIFICATION_DEFAULT_VAL = false;
public RingerModeAffectedVolumePreferenceController(Context context, String key, String tag) {
super(context, key);
mTag = tag;
mVibrator = mContext.getSystemService(Vibrator.class);
if (mVibrator != null && !mVibrator.hasVibrator()) {
mVibrator = null;
}
}
protected void updateEffectsSuppressor() {
final ComponentName suppressor = NotificationManager.from(mContext).getEffectsSuppressor();
if (Objects.equals(suppressor, mSuppressor)) return;
if (mNoMan == null) {
mNoMan = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
}
final int hints;
try {
hints = mNoMan.getHintsFromListenerNoToken();
} catch (android.os.RemoteException ex) {
Log.w(mTag, "updateEffectsSuppressor: " + ex.getMessage());
return;
}
if (hintsMatch(hints)) {
mSuppressor = suppressor;
if (mPreference != null) {
final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
mPreference.setSuppressionText(text);
}
}
}
@VisibleForTesting
void setPreference(VolumeSeekBarPreference volumeSeekBarPreference) {
mPreference = volumeSeekBarPreference;
}
@VisibleForTesting
void setVibrator(Vibrator vibrator) {
mVibrator = vibrator;
}
@Override
public boolean isSliceable() {
return true;
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
public boolean useDynamicSliceSummary() {
return true;
}
@Override
public int getMuteIcon() {
return mMuteIcon;
}
protected boolean isSeparateNotificationConfigEnabled() {
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION,
CONFIG_SEPARATE_NOTIFICATION_DEFAULT_VAL);
}
/**
* side effect: updates the cached value of the config
* @return has the config changed?
*/
protected boolean readSeparateNotificationVolumeConfig() {
boolean newVal = isSeparateNotificationConfigEnabled();
boolean valueUpdated = newVal != mSeparateNotification;
if (valueUpdated) {
mSeparateNotification = newVal;
}
return valueUpdated;
}
protected void updateRingerMode() {
final int ringerMode = mHelper.getRingerModeInternal();
if (mRingerMode == ringerMode) return;
mRingerMode = ringerMode;
selectPreferenceIconState();
}
/**
* Switching among normal/mute/vibrate
*/
protected void selectPreferenceIconState() {
if (mPreference != null) {
if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
mPreference.showIcon(mNormalIconId);
} else {
if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE && mVibrator != null) {
mMuteIcon = mVibrateIconId;
} else {
mMuteIcon = mSilentIconId;
}
mPreference.showIcon(getMuteIcon());
}
}
}
protected abstract boolean hintsMatch(int hints);
}