Donate to
e Foundation
|
Murena
handsets with /e/OS | Own a part of Murena!
Learn more
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
android_frameworks_base
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
e
os
android_frameworks_base
Commits
e0112b77
Commit
e0112b77
authored
2 years ago
by
Vlad Popa
Committed by
Android (Google) Code Review
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge "CSD: Improve map from device type to volume index" into udc-dev
parents
aede9255
3ca01c57
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/core/java/com/android/server/audio/SoundDoseHelper.java
+44
-47
44 additions, 47 deletions
...s/core/java/com/android/server/audio/SoundDoseHelper.java
with
44 additions
and
47 deletions
services/core/java/com/android/server/audio/SoundDoseHelper.java
+
44
−
47
View file @
e0112b77
...
@@ -41,6 +41,7 @@ import android.provider.Settings;
...
@@ -41,6 +41,7 @@ import android.provider.Settings;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.Log
;
import
android.util.MathUtils
;
import
android.util.MathUtils
;
import
android.util.SparseIntArray
;
import
com.android.internal.R
;
import
com.android.internal.R
;
import
com.android.internal.annotations.GuardedBy
;
import
com.android.internal.annotations.GuardedBy
;
...
@@ -52,7 +53,6 @@ import com.android.server.utils.EventLogger;
...
@@ -52,7 +53,6 @@ import com.android.server.utils.EventLogger;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.concurrent.atomic.AtomicReference
;
...
@@ -112,6 +112,8 @@ public class SoundDoseHelper {
...
@@ -112,6 +112,8 @@ public class SoundDoseHelper {
private
static
final
long
GLOBAL_TIME_OFFSET_UNINITIALIZED
=
-
1
;
private
static
final
long
GLOBAL_TIME_OFFSET_UNINITIALIZED
=
-
1
;
private
static
final
int
SAFE_MEDIA_VOLUME_UNINITIALIZED
=
-
1
;
private
final
EventLogger
mLogger
=
new
EventLogger
(
AudioService
.
LOG_NB_EVENTS_SOUND_DOSE
,
private
final
EventLogger
mLogger
=
new
EventLogger
(
AudioService
.
LOG_NB_EVENTS_SOUND_DOSE
,
"CSD updates"
);
"CSD updates"
);
...
@@ -132,15 +134,6 @@ public class SoundDoseHelper {
...
@@ -132,15 +134,6 @@ public class SoundDoseHelper {
// For now using the same value for CSD supported devices
// For now using the same value for CSD supported devices
private
float
mSafeMediaVolumeDbfs
;
private
float
mSafeMediaVolumeDbfs
;
private
static
class
SafeDeviceVolumeInfo
{
int
mDeviceType
;
int
mSafeVolumeIndex
=
-
1
;
SafeDeviceVolumeInfo
(
int
deviceType
)
{
mDeviceType
=
deviceType
;
}
}
/**
/**
* mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced.
* mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced.
* Contains a safe volume index for a given device type.
* Contains a safe volume index for a given device type.
...
@@ -152,25 +145,7 @@ public class SoundDoseHelper {
...
@@ -152,25 +145,7 @@ public class SoundDoseHelper {
* This level corresponds to a loudness of 85 dB SPL for the warning to be displayed when
* This level corresponds to a loudness of 85 dB SPL for the warning to be displayed when
* the headset is compliant to EN 60950 with a max loudness of 100dB SPL.
* the headset is compliant to EN 60950 with a max loudness of 100dB SPL.
*/
*/
private
final
HashMap
<
Integer
,
SafeDeviceVolumeInfo
>
mSafeMediaVolumeDevices
=
private
final
SparseIntArray
mSafeMediaVolumeDevices
=
new
SparseIntArray
();
new
HashMap
<>()
{{
put
(
AudioSystem
.
DEVICE_OUT_WIRED_HEADSET
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_WIRED_HEADSET
));
put
(
AudioSystem
.
DEVICE_OUT_WIRED_HEADPHONE
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_WIRED_HEADPHONE
));
put
(
AudioSystem
.
DEVICE_OUT_USB_HEADSET
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_USB_HEADSET
));
put
(
AudioSystem
.
DEVICE_OUT_BLE_HEADSET
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_BLE_HEADSET
));
put
(
AudioSystem
.
DEVICE_OUT_BLE_BROADCAST
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_BLE_BROADCAST
));
put
(
AudioSystem
.
DEVICE_OUT_HEARING_AID
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_HEARING_AID
));
put
(
AudioSystem
.
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES
));
put
(
AudioSystem
.
DEVICE_OUT_BLUETOOTH_A2DP
,
new
SafeDeviceVolumeInfo
(
AudioSystem
.
DEVICE_OUT_BLUETOOTH_A2DP
));
}};
// mMusicActiveMs is the cumulative time of music activity since safe volume was disabled.
// mMusicActiveMs is the cumulative time of music activity since safe volume was disabled.
// When this time reaches UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX, the safe media volume is re-enabled
// When this time reaches UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX, the safe media volume is re-enabled
...
@@ -291,6 +266,7 @@ public class SoundDoseHelper {
...
@@ -291,6 +266,7 @@ public class SoundDoseHelper {
mEnableCsd
=
mContext
.
getResources
().
getBoolean
(
R
.
bool
.
config_audio_csd_enabled_default
);
mEnableCsd
=
mContext
.
getResources
().
getBoolean
(
R
.
bool
.
config_audio_csd_enabled_default
);
initCsd
();
initCsd
();
initSafeVolumes
();
mSafeMediaVolumeState
=
mSettings
.
getGlobalInt
(
audioService
.
getContentResolver
(),
mSafeMediaVolumeState
=
mSettings
.
getGlobalInt
(
audioService
.
getContentResolver
(),
Settings
.
Global
.
AUDIO_SAFE_VOLUME_STATE
,
SAFE_MEDIA_VOLUME_NOT_CONFIGURED
);
Settings
.
Global
.
AUDIO_SAFE_VOLUME_STATE
,
SAFE_MEDIA_VOLUME_NOT_CONFIGURED
);
...
@@ -305,6 +281,25 @@ public class SoundDoseHelper {
...
@@ -305,6 +281,25 @@ public class SoundDoseHelper {
Context
.
ALARM_SERVICE
);
Context
.
ALARM_SERVICE
);
}
}
void
initSafeVolumes
()
{
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_WIRED_HEADSET
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_WIRED_HEADPHONE
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_USB_HEADSET
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_BLE_HEADSET
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_BLE_BROADCAST
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_HEARING_AID
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
mSafeMediaVolumeDevices
.
append
(
AudioSystem
.
DEVICE_OUT_BLUETOOTH_A2DP
,
SAFE_MEDIA_VOLUME_UNINITIALIZED
);
}
float
getRs2Value
()
{
float
getRs2Value
()
{
if
(!
mEnableCsd
)
{
if
(!
mEnableCsd
)
{
return
0
.
f
;
return
0
.
f
;
...
@@ -435,12 +430,12 @@ public class SoundDoseHelper {
...
@@ -435,12 +430,12 @@ public class SoundDoseHelper {
}
}
/*package*/
int
safeMediaVolumeIndex
(
int
device
)
{
/*package*/
int
safeMediaVolumeIndex
(
int
device
)
{
final
SafeDeviceVolumeInfo
vi
=
mSafeMediaVolumeDevices
.
get
(
device
);
final
int
vol
=
mSafeMediaVolumeDevices
.
get
(
device
);
if
(
v
i
==
null
)
{
if
(
v
ol
==
SAFE_MEDIA_VOLUME_UNINITIALIZED
)
{
return
MAX_STREAM_VOLUME
[
AudioSystem
.
STREAM_MUSIC
];
return
MAX_STREAM_VOLUME
[
AudioSystem
.
STREAM_MUSIC
];
}
}
return
v
i
.
mSafeVolumeIndex
;
return
v
ol
;
}
}
/*package*/
void
restoreMusicActiveMs
()
{
/*package*/
void
restoreMusicActiveMs
()
{
...
@@ -465,14 +460,15 @@ public class SoundDoseHelper {
...
@@ -465,14 +460,15 @@ public class SoundDoseHelper {
AudioService
.
VolumeStreamState
streamState
=
mAudioService
.
getVssVolumeForStream
(
AudioService
.
VolumeStreamState
streamState
=
mAudioService
.
getVssVolumeForStream
(
AudioSystem
.
STREAM_MUSIC
);
AudioSystem
.
STREAM_MUSIC
);
for
(
SafeDeviceVolumeInfo
vi
:
mSafeMediaVolumeDevices
.
values
())
{
for
(
int
i
=
0
;
i
<
mSafeMediaVolumeDevices
.
size
();
++
i
)
{
int
index
=
streamState
.
getIndex
(
vi
.
mDeviceType
);
int
deviceType
=
mSafeMediaVolumeDevices
.
keyAt
(
i
);
int
safeIndex
=
safeMediaVolumeIndex
(
vi
.
mDeviceType
);
int
index
=
streamState
.
getIndex
(
deviceType
);
int
safeIndex
=
safeMediaVolumeIndex
(
deviceType
);
if
(
index
>
safeIndex
)
{
if
(
index
>
safeIndex
)
{
streamState
.
setIndex
(
safeIndex
,
vi
.
mD
eviceType
,
caller
,
streamState
.
setIndex
(
safeIndex
,
d
eviceType
,
caller
,
true
/*hasModifyAudioSettings*/
);
true
/*hasModifyAudioSettings*/
);
mAudioHandler
.
sendMessageAtTime
(
mAudioHandler
.
sendMessageAtTime
(
mAudioHandler
.
obtainMessage
(
MSG_SET_DEVICE_VOLUME
,
vi
.
mD
eviceType
,
mAudioHandler
.
obtainMessage
(
MSG_SET_DEVICE_VOLUME
,
d
eviceType
,
/*arg2=*/
0
,
streamState
),
/*delay=*/
0
);
/*arg2=*/
0
,
streamState
),
/*delay=*/
0
);
}
}
}
}
...
@@ -494,7 +490,7 @@ public class SoundDoseHelper {
...
@@ -494,7 +490,7 @@ public class SoundDoseHelper {
private
boolean
checkSafeMediaVolume_l
(
int
streamType
,
int
index
,
int
device
)
{
private
boolean
checkSafeMediaVolume_l
(
int
streamType
,
int
index
,
int
device
)
{
return
(
mSafeMediaVolumeState
==
SAFE_MEDIA_VOLUME_ACTIVE
)
return
(
mSafeMediaVolumeState
==
SAFE_MEDIA_VOLUME_ACTIVE
)
&&
(
AudioService
.
mStreamVolumeAlias
[
streamType
]
==
AudioSystem
.
STREAM_MUSIC
)
&&
(
AudioService
.
mStreamVolumeAlias
[
streamType
]
==
AudioSystem
.
STREAM_MUSIC
)
&&
(
mSafeMediaVolum
eDevices
.
c
ontains
Key
(
device
)
)
&&
saf
eDevices
C
ontains
(
device
)
&&
(
index
>
safeMediaVolumeIndex
(
device
));
&&
(
index
>
safeMediaVolumeIndex
(
device
));
}
}
...
@@ -546,7 +542,7 @@ public class SoundDoseHelper {
...
@@ -546,7 +542,7 @@ public class SoundDoseHelper {
synchronized
(
mSafeMediaVolumeStateLock
)
{
synchronized
(
mSafeMediaVolumeStateLock
)
{
if
(
mSafeMediaVolumeState
==
SAFE_MEDIA_VOLUME_INACTIVE
)
{
if
(
mSafeMediaVolumeState
==
SAFE_MEDIA_VOLUME_INACTIVE
)
{
int
device
=
mAudioService
.
getDeviceForStream
(
AudioSystem
.
STREAM_MUSIC
);
int
device
=
mAudioService
.
getDeviceForStream
(
AudioSystem
.
STREAM_MUSIC
);
if
(
mS
afe
MediaVolume
Devices
.
c
ontains
Key
(
device
)
&&
isStreamActive
)
{
if
(
s
afeDevices
C
ontains
(
device
)
&&
isStreamActive
)
{
scheduleMusicActiveCheck
();
scheduleMusicActiveCheck
();
int
index
=
mAudioService
.
getVssVolumeForDevice
(
AudioSystem
.
STREAM_MUSIC
,
int
index
=
mAudioService
.
getVssVolumeForDevice
(
AudioSystem
.
STREAM_MUSIC
,
device
);
device
);
...
@@ -589,14 +585,15 @@ public class SoundDoseHelper {
...
@@ -589,14 +585,15 @@ public class SoundDoseHelper {
}
}
/*package*/
void
initSafeMediaVolumeIndex
()
{
/*package*/
void
initSafeMediaVolumeIndex
()
{
for
(
SafeDeviceVolumeInfo
vi
:
mSafeMediaVolumeDevices
.
values
())
{
for
(
int
i
=
0
;
i
<
mSafeMediaVolumeDevices
.
size
();
++
i
)
{
vi
.
mSafeVolumeIndex
=
getSafeDeviceMediaVolumeIndex
(
vi
.
mDeviceType
);
int
deviceType
=
mSafeMediaVolumeDevices
.
keyAt
(
i
);
mSafeMediaVolumeDevices
.
put
(
deviceType
,
getSafeDeviceMediaVolumeIndex
(
deviceType
));
}
}
}
}
/*package*/
int
getSafeMediaVolumeIndex
(
int
device
)
{
/*package*/
int
getSafeMediaVolumeIndex
(
int
device
)
{
if
(
mSafeMediaVolumeState
==
SAFE_MEDIA_VOLUME_ACTIVE
if
(
mSafeMediaVolumeState
==
SAFE_MEDIA_VOLUME_ACTIVE
&&
mS
afe
MediaVolume
Devices
.
c
ontains
Key
(
device
))
{
&&
s
afeDevices
C
ontains
(
device
))
{
return
safeMediaVolumeIndex
(
device
);
return
safeMediaVolumeIndex
(
device
);
}
else
{
}
else
{
return
-
1
;
return
-
1
;
...
@@ -614,7 +611,7 @@ public class SoundDoseHelper {
...
@@ -614,7 +611,7 @@ public class SoundDoseHelper {
}
}
/*package*/
boolean
safeDevicesContains
(
int
device
)
{
/*package*/
boolean
safeDevicesContains
(
int
device
)
{
return
mSafeMediaVolumeDevices
.
contains
Key
(
device
);
return
mSafeMediaVolumeDevices
.
indexOf
Key
(
device
)
>=
0
;
}
}
/*package*/
void
invalidatPendingVolumeCommand
()
{
/*package*/
void
invalidatPendingVolumeCommand
()
{
...
@@ -665,9 +662,9 @@ public class SoundDoseHelper {
...
@@ -665,9 +662,9 @@ public class SoundDoseHelper {
pw
.
print
(
" mSafeMediaVolumeState="
);
pw
.
print
(
" mSafeMediaVolumeState="
);
pw
.
println
(
safeMediaVolumeStateToString
(
mSafeMediaVolumeState
));
pw
.
println
(
safeMediaVolumeStateToString
(
mSafeMediaVolumeState
));
pw
.
print
(
" mSafeMediaVolumeIndex="
);
pw
.
println
(
mSafeMediaVolumeIndex
);
pw
.
print
(
" mSafeMediaVolumeIndex="
);
pw
.
println
(
mSafeMediaVolumeIndex
);
for
(
SafeDeviceVolumeInfo
v
i
:
mSafeMediaVolumeDevices
.
values
())
{
for
(
int
i
=
0
;
i
<
mSafeMediaVolumeDevices
.
size
();
++
i
)
{
pw
.
print
(
" mSafeMediaVolumeIndex["
);
pw
.
print
(
vi
.
mDeviceType
);
pw
.
print
(
" mSafeMediaVolumeIndex["
);
pw
.
print
(
mSafeMediaVolumeDevices
.
keyAt
(
i
)
);
pw
.
print
(
"]="
);
pw
.
println
(
vi
.
mSafeVolume
Index
);
pw
.
print
(
"]="
);
pw
.
println
(
mSafe
Media
Volume
Devices
.
valueAt
(
i
)
);
}
}
pw
.
print
(
" mSafeMediaVolumeDbfs="
);
pw
.
println
(
mSafeMediaVolumeDbfs
);
pw
.
print
(
" mSafeMediaVolumeDbfs="
);
pw
.
println
(
mSafeMediaVolumeDbfs
);
pw
.
print
(
" mMusicActiveMs="
);
pw
.
println
(
mMusicActiveMs
);
pw
.
print
(
" mMusicActiveMs="
);
pw
.
println
(
mMusicActiveMs
);
...
@@ -721,7 +718,7 @@ public class SoundDoseHelper {
...
@@ -721,7 +718,7 @@ public class SoundDoseHelper {
}
}
if
(
AudioService
.
mStreamVolumeAlias
[
streamType
]
==
AudioSystem
.
STREAM_MUSIC
if
(
AudioService
.
mStreamVolumeAlias
[
streamType
]
==
AudioSystem
.
STREAM_MUSIC
&&
mS
afe
MediaVolume
Devices
.
c
ontains
Key
(
device
))
{
&&
s
afeDevices
C
ontains
(
device
))
{
soundDose
.
updateAttenuation
(
soundDose
.
updateAttenuation
(
AudioSystem
.
getStreamVolumeDB
(
AudioSystem
.
STREAM_MUSIC
,
AudioSystem
.
getStreamVolumeDB
(
AudioSystem
.
STREAM_MUSIC
,
(
newIndex
+
5
)
/
10
,
(
newIndex
+
5
)
/
10
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment