Merge "audioservice: fix camera sound control for dual SIMs" into udc-dev
This commit is contained in:
@@ -170,6 +170,7 @@ import android.provider.Settings;
|
||||
import android.provider.Settings.System;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import android.util.ArrayMap;
|
||||
@@ -184,6 +185,7 @@ import android.view.KeyEvent;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
|
||||
@@ -393,6 +395,7 @@ public class AudioService extends IAudioService.Stub
|
||||
private static final int MSG_NO_LOG_FOR_PLAYER_I = 51;
|
||||
private static final int MSG_DISPATCH_PREFERRED_MIXER_ATTRIBUTES = 52;
|
||||
private static final int MSG_LOWER_VOLUME_TO_RS1 = 53;
|
||||
private static final int MSG_CONFIGURATION_CHANGED = 54;
|
||||
|
||||
/** Messages handled by the {@link SoundDoseHelper}. */
|
||||
/*package*/ static final int SAFE_MEDIA_VOLUME_MSG_START = 1000;
|
||||
@@ -1219,17 +1222,6 @@ public class AudioService extends IAudioService.Stub
|
||||
|
||||
updateAudioHalPids();
|
||||
|
||||
boolean cameraSoundForced = readCameraSoundForced();
|
||||
mCameraSoundForced = new Boolean(cameraSoundForced);
|
||||
sendMsg(mAudioHandler,
|
||||
MSG_SET_FORCE_USE,
|
||||
SENDMSG_QUEUE,
|
||||
AudioSystem.FOR_SYSTEM,
|
||||
cameraSoundForced ?
|
||||
AudioSystem.FORCE_SYSTEM_ENFORCED : AudioSystem.FORCE_NONE,
|
||||
new String("AudioService ctor"),
|
||||
0);
|
||||
|
||||
mUseFixedVolume = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_useFixedVolume);
|
||||
|
||||
@@ -1314,6 +1306,18 @@ public class AudioService extends IAudioService.Stub
|
||||
* Called by handling of MSG_INIT_STREAMS_VOLUMES
|
||||
*/
|
||||
private void onInitStreamsAndVolumes() {
|
||||
synchronized (mSettingsLock) {
|
||||
mCameraSoundForced = readCameraSoundForced();
|
||||
sendMsg(mAudioHandler,
|
||||
MSG_SET_FORCE_USE,
|
||||
SENDMSG_QUEUE,
|
||||
AudioSystem.FOR_SYSTEM,
|
||||
mCameraSoundForced
|
||||
? AudioSystem.FORCE_SYSTEM_ENFORCED : AudioSystem.FORCE_NONE,
|
||||
new String("AudioService ctor"),
|
||||
0);
|
||||
}
|
||||
|
||||
createStreamStates();
|
||||
|
||||
// must be called after createStreamStates() as it uses MUSIC volume as default if no
|
||||
@@ -1349,8 +1353,19 @@ public class AudioService extends IAudioService.Stub
|
||||
|
||||
// check on volume initialization
|
||||
checkVolumeRangeInitialization("AudioService()");
|
||||
|
||||
}
|
||||
|
||||
private SubscriptionManager.OnSubscriptionsChangedListener mSubscriptionChangedListener =
|
||||
new SubscriptionManager.OnSubscriptionsChangedListener() {
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
Log.i(TAG, "onSubscriptionsChanged()");
|
||||
sendMsg(mAudioHandler, MSG_CONFIGURATION_CHANGED, SENDMSG_REPLACE,
|
||||
0, 0, null, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize intent receives and settings observers for this service.
|
||||
* Must be called after createStreamStates() as the handling of some events
|
||||
@@ -1388,6 +1403,13 @@ public class AudioService extends IAudioService.Stub
|
||||
mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, intentFilter, null, null,
|
||||
Context.RECEIVER_EXPORTED);
|
||||
|
||||
SubscriptionManager subscriptionManager = mContext.getSystemService(
|
||||
SubscriptionManager.class);
|
||||
if (subscriptionManager == null) {
|
||||
Log.e(TAG, "initExternalEventReceivers cannot create SubscriptionManager!");
|
||||
} else {
|
||||
subscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionChangedListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void systemReady() {
|
||||
@@ -3665,7 +3687,7 @@ public class AudioService extends IAudioService.Stub
|
||||
for (int stream = 0; stream < mStreamStates.length; stream++) {
|
||||
VolumeStreamState vss = mStreamStates[stream];
|
||||
if (streamAlias == mStreamVolumeAlias[stream] && vss.isMutable()) {
|
||||
if (!(readCameraSoundForced()
|
||||
if (!(mCameraSoundForced
|
||||
&& (vss.getStreamType()
|
||||
== AudioSystem.STREAM_SYSTEM_ENFORCED))) {
|
||||
boolean changed = vss.mute(state, /* apply= */ false);
|
||||
@@ -9237,6 +9259,10 @@ public class AudioService extends IAudioService.Stub
|
||||
onLowerVolumeToRs1();
|
||||
break;
|
||||
|
||||
case MSG_CONFIGURATION_CHANGED:
|
||||
onConfigurationChanged();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (msg.what >= SAFE_MEDIA_VOLUME_MSG_START) {
|
||||
// msg could be for the SoundDoseHelper
|
||||
@@ -9419,7 +9445,12 @@ public class AudioService extends IAudioService.Stub
|
||||
}
|
||||
AudioSystem.setParameters("screen_state=off");
|
||||
} else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
|
||||
handleConfigurationChanged(context);
|
||||
sendMsg(mAudioHandler,
|
||||
MSG_CONFIGURATION_CHANGED,
|
||||
SENDMSG_REPLACE,
|
||||
0,
|
||||
0,
|
||||
null, 0);
|
||||
} else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
|
||||
if (mUserSwitchedReceived) {
|
||||
// attempt to stop music playback for background user except on first user
|
||||
@@ -10161,10 +10192,30 @@ public class AudioService extends IAudioService.Stub
|
||||
}
|
||||
|
||||
//==========================================================================================
|
||||
|
||||
// camera sound is forced if any of the resources corresponding to one active SIM
|
||||
// demands it.
|
||||
private boolean readCameraSoundForced() {
|
||||
return SystemProperties.getBoolean("audio.camerasound.force", false) ||
|
||||
mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_camera_sound_forced);
|
||||
if (SystemProperties.getBoolean("audio.camerasound.force", false)
|
||||
|| mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_camera_sound_forced)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
SubscriptionManager subscriptionManager = mContext.getSystemService(
|
||||
SubscriptionManager.class);
|
||||
if (subscriptionManager == null) {
|
||||
Log.e(TAG, "readCameraSoundForced cannot create SubscriptionManager!");
|
||||
return false;
|
||||
}
|
||||
int[] subscriptionIds = subscriptionManager.getActiveSubscriptionIdList(false);
|
||||
for (int subId : subscriptionIds) {
|
||||
if (SubscriptionManager.getResourcesForSubId(mContext, subId).getBoolean(
|
||||
com.android.internal.R.bool.config_camera_sound_forced)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//==========================================================================================
|
||||
@@ -10375,11 +10426,11 @@ public class AudioService extends IAudioService.Stub
|
||||
* Monitoring rotation is optional, and is defined by the definition and value
|
||||
* of the "ro.audio.monitorRotation" system property.
|
||||
*/
|
||||
private void handleConfigurationChanged(Context context) {
|
||||
private void onConfigurationChanged() {
|
||||
try {
|
||||
// reading new configuration "safely" (i.e. under try catch) in case anything
|
||||
// goes wrong.
|
||||
Configuration config = context.getResources().getConfiguration();
|
||||
Configuration config = mContext.getResources().getConfiguration();
|
||||
mSoundDoseHelper.configureSafeMedia(/*forced*/false, TAG);
|
||||
|
||||
boolean cameraSoundForced = readCameraSoundForced();
|
||||
@@ -10406,7 +10457,7 @@ public class AudioService extends IAudioService.Stub
|
||||
mDeviceBroker.setForceUse_Async(AudioSystem.FOR_SYSTEM,
|
||||
cameraSoundForced ?
|
||||
AudioSystem.FORCE_SYSTEM_ENFORCED : AudioSystem.FORCE_NONE,
|
||||
"handleConfigurationChanged");
|
||||
"onConfigurationChanged");
|
||||
sendMsg(mAudioHandler,
|
||||
MSG_SET_ALL_VOLUMES,
|
||||
SENDMSG_QUEUE,
|
||||
|
||||
Reference in New Issue
Block a user