Merge "Revert "AudioService: permission for volume adjustment to lowest values"" into rvc-dev am: f2856e3be5
Change-Id: I8f460d0dd5105c5aabac12509ac200d5a2a12414
This commit is contained in:
@@ -29,13 +29,13 @@ import com.android.server.LocalServices;
|
|||||||
public abstract class AudioManagerInternal {
|
public abstract class AudioManagerInternal {
|
||||||
|
|
||||||
public abstract void adjustSuggestedStreamVolumeForUid(int streamType, int direction,
|
public abstract void adjustSuggestedStreamVolumeForUid(int streamType, int direction,
|
||||||
int flags, String callingPackage, int uid, int pid);
|
int flags, String callingPackage, int uid);
|
||||||
|
|
||||||
public abstract void adjustStreamVolumeForUid(int streamType, int direction, int flags,
|
public abstract void adjustStreamVolumeForUid(int streamType, int direction, int flags,
|
||||||
String callingPackage, int uid, int pid);
|
String callingPackage, int uid);
|
||||||
|
|
||||||
public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
|
public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
|
||||||
String callingPackage, int uid, int pid);
|
String callingPackage, int uid);
|
||||||
|
|
||||||
public abstract void setRingerModeDelegate(RingerModeDelegate delegate);
|
public abstract void setRingerModeDelegate(RingerModeDelegate delegate);
|
||||||
|
|
||||||
|
|||||||
@@ -955,8 +955,6 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
mMicMuteFromSystemCached = mAudioSystem.isMicrophoneMuted();
|
mMicMuteFromSystemCached = mAudioSystem.isMicrophoneMuted();
|
||||||
setMicMuteFromSwitchInput();
|
setMicMuteFromSwitchInput();
|
||||||
|
|
||||||
initMinStreamVolumeWithoutModifyAudioSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RoleObserver mRoleObserver;
|
RoleObserver mRoleObserver;
|
||||||
@@ -1310,7 +1308,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
mStreamStates[streamType].setIndex(
|
mStreamStates[streamType].setIndex(
|
||||||
mStreamStates[mStreamVolumeAlias[streamType]]
|
mStreamStates[mStreamVolumeAlias[streamType]]
|
||||||
.getIndex(AudioSystem.DEVICE_OUT_DEFAULT),
|
.getIndex(AudioSystem.DEVICE_OUT_DEFAULT),
|
||||||
device, caller, true /*hasModifyAudioSettings*/);
|
device, caller);
|
||||||
}
|
}
|
||||||
mStreamStates[streamType].checkFixedVolumeDevices();
|
mStreamStates[streamType].checkFixedVolumeDevices();
|
||||||
}
|
}
|
||||||
@@ -1875,16 +1873,13 @@ public class AudioService extends IAudioService.Stub
|
|||||||
direction, 0 /*ignored*/,
|
direction, 0 /*ignored*/,
|
||||||
extVolCtlr, 0 /*delay*/);
|
extVolCtlr, 0 /*delay*/);
|
||||||
} else {
|
} else {
|
||||||
final boolean hasModifyAudioSettings =
|
|
||||||
mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
|
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
adjustSuggestedStreamVolume(direction, suggestedStreamType, flags, callingPackage,
|
adjustSuggestedStreamVolume(direction, suggestedStreamType, flags, callingPackage,
|
||||||
caller, Binder.getCallingUid(), hasModifyAudioSettings);
|
caller, Binder.getCallingUid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
|
private void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
|
||||||
String callingPackage, String caller, int uid, boolean hasModifyAudioSettings) {
|
String callingPackage, String caller, int uid) {
|
||||||
if (DEBUG_VOL) Log.d(TAG, "adjustSuggestedStreamVolume() stream=" + suggestedStreamType
|
if (DEBUG_VOL) Log.d(TAG, "adjustSuggestedStreamVolume() stream=" + suggestedStreamType
|
||||||
+ ", flags=" + flags + ", caller=" + caller
|
+ ", flags=" + flags + ", caller=" + caller
|
||||||
+ ", volControlStream=" + mVolumeControlStream
|
+ ", volControlStream=" + mVolumeControlStream
|
||||||
@@ -1938,12 +1933,10 @@ public class AudioService extends IAudioService.Stub
|
|||||||
if (DEBUG_VOL) Log.d(TAG, "Volume controller suppressed adjustment");
|
if (DEBUG_VOL) Log.d(TAG, "Volume controller suppressed adjustment");
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustStreamVolume(streamType, direction, flags, callingPackage, caller, uid,
|
adjustStreamVolume(streamType, direction, flags, callingPackage, caller, uid);
|
||||||
hasModifyAudioSettings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see AudioManager#adjustStreamVolume(int, int, int)
|
/** @see AudioManager#adjustStreamVolume(int, int, int) */
|
||||||
* Part of service interface, check permissions here */
|
|
||||||
public void adjustStreamVolume(int streamType, int direction, int flags,
|
public void adjustStreamVolume(int streamType, int direction, int flags,
|
||||||
String callingPackage) {
|
String callingPackage) {
|
||||||
if ((streamType == AudioManager.STREAM_ACCESSIBILITY) && !canChangeAccessibilityVolume()) {
|
if ((streamType == AudioManager.STREAM_ACCESSIBILITY) && !canChangeAccessibilityVolume()) {
|
||||||
@@ -1951,17 +1944,14 @@ public class AudioService extends IAudioService.Stub
|
|||||||
+ "CHANGE_ACCESSIBILITY_VOLUME / callingPackage=" + callingPackage);
|
+ "CHANGE_ACCESSIBILITY_VOLUME / callingPackage=" + callingPackage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final boolean hasModifyAudioSettings =
|
|
||||||
mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
|
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_STREAM_VOL, streamType,
|
sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_STREAM_VOL, streamType,
|
||||||
direction/*val1*/, flags/*val2*/, callingPackage));
|
direction/*val1*/, flags/*val2*/, callingPackage));
|
||||||
adjustStreamVolume(streamType, direction, flags, callingPackage, callingPackage,
|
adjustStreamVolume(streamType, direction, flags, callingPackage, callingPackage,
|
||||||
Binder.getCallingUid(), hasModifyAudioSettings);
|
Binder.getCallingUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void adjustStreamVolume(int streamType, int direction, int flags,
|
protected void adjustStreamVolume(int streamType, int direction, int flags,
|
||||||
String callingPackage, String caller, int uid, boolean hasModifyAudioSettings) {
|
String callingPackage, String caller, int uid) {
|
||||||
if (mUseFixedVolume) {
|
if (mUseFixedVolume) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2115,8 +2105,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
Log.e(TAG, "adjustStreamVolume() safe volume index = " + oldIndex);
|
Log.e(TAG, "adjustStreamVolume() safe volume index = " + oldIndex);
|
||||||
mVolumeController.postDisplaySafeVolumeWarning(flags);
|
mVolumeController.postDisplaySafeVolumeWarning(flags);
|
||||||
} else if (!isFullVolumeDevice(device)
|
} else if (!isFullVolumeDevice(device)
|
||||||
&& (streamState.adjustIndex(direction * step, device, caller,
|
&& (streamState.adjustIndex(direction * step, device, caller)
|
||||||
hasModifyAudioSettings)
|
|
||||||
|| streamState.mIsMuted)) {
|
|| streamState.mIsMuted)) {
|
||||||
// Post message to set system volume (it in turn will post a
|
// Post message to set system volume (it in turn will post a
|
||||||
// message to persist).
|
// message to persist).
|
||||||
@@ -2338,9 +2327,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onSetStreamVolume(int streamType, int index, int flags, int device,
|
private void onSetStreamVolume(int streamType, int index, int flags, int device,
|
||||||
String caller, boolean hasModifyAudioSettings) {
|
String caller) {
|
||||||
final int stream = mStreamVolumeAlias[streamType];
|
final int stream = mStreamVolumeAlias[streamType];
|
||||||
setStreamVolumeInt(stream, index, device, false, caller, hasModifyAudioSettings);
|
setStreamVolumeInt(stream, index, device, false, caller);
|
||||||
// setting volume on ui sounds stream type also controls silent mode
|
// setting volume on ui sounds stream type also controls silent mode
|
||||||
if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
|
if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
|
||||||
(stream == getUiSoundsStreamType())) {
|
(stream == getUiSoundsStreamType())) {
|
||||||
@@ -2388,7 +2377,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
setStreamVolume(groupedStream, index, flags, callingPackage, callingPackage,
|
setStreamVolume(groupedStream, index, flags, callingPackage, callingPackage,
|
||||||
Binder.getCallingUid(), true /*hasModifyAudioSettings*/);
|
Binder.getCallingUid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2430,8 +2419,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
return AudioSystem.getMinVolumeIndexForAttributes(attr);
|
return AudioSystem.getMinVolumeIndexForAttributes(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see AudioManager#setStreamVolume(int, int, int)
|
/** @see AudioManager#setStreamVolume(int, int, int) */
|
||||||
* Part of service interface, check permissions here */
|
|
||||||
public void setStreamVolume(int streamType, int index, int flags, String callingPackage) {
|
public void setStreamVolume(int streamType, int index, int flags, String callingPackage) {
|
||||||
if ((streamType == AudioManager.STREAM_ACCESSIBILITY) && !canChangeAccessibilityVolume()) {
|
if ((streamType == AudioManager.STREAM_ACCESSIBILITY) && !canChangeAccessibilityVolume()) {
|
||||||
Log.w(TAG, "Trying to call setStreamVolume() for a11y without"
|
Log.w(TAG, "Trying to call setStreamVolume() for a11y without"
|
||||||
@@ -2454,13 +2442,10 @@ public class AudioService extends IAudioService.Stub
|
|||||||
+ " MODIFY_AUDIO_ROUTING callingPackage=" + callingPackage);
|
+ " MODIFY_AUDIO_ROUTING callingPackage=" + callingPackage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final boolean hasModifyAudioSettings =
|
|
||||||
mContext.checkCallingOrSelfPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
|
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_SET_STREAM_VOL, streamType,
|
sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_SET_STREAM_VOL, streamType,
|
||||||
index/*val1*/, flags/*val2*/, callingPackage));
|
index/*val1*/, flags/*val2*/, callingPackage));
|
||||||
setStreamVolume(streamType, index, flags, callingPackage, callingPackage,
|
setStreamVolume(streamType, index, flags, callingPackage, callingPackage,
|
||||||
Binder.getCallingUid(), hasModifyAudioSettings);
|
Binder.getCallingUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canChangeAccessibilityVolume() {
|
private boolean canChangeAccessibilityVolume() {
|
||||||
@@ -2584,7 +2569,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setStreamVolume(int streamType, int index, int flags, String callingPackage,
|
private void setStreamVolume(int streamType, int index, int flags, String callingPackage,
|
||||||
String caller, int uid, boolean hasModifyAudioSettings) {
|
String caller, int uid) {
|
||||||
if (DEBUG_VOL) {
|
if (DEBUG_VOL) {
|
||||||
Log.d(TAG, "setStreamVolume(stream=" + streamType+", index=" + index
|
Log.d(TAG, "setStreamVolume(stream=" + streamType+", index=" + index
|
||||||
+ ", calling=" + callingPackage + ")");
|
+ ", calling=" + callingPackage + ")");
|
||||||
@@ -2675,7 +2660,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
mPendingVolumeCommand = new StreamVolumeCommand(
|
mPendingVolumeCommand = new StreamVolumeCommand(
|
||||||
streamType, index, flags, device);
|
streamType, index, flags, device);
|
||||||
} else {
|
} else {
|
||||||
onSetStreamVolume(streamType, index, flags, device, caller, hasModifyAudioSettings);
|
onSetStreamVolume(streamType, index, flags, device, caller);
|
||||||
index = mStreamStates[streamType].getIndex(device);
|
index = mStreamStates[streamType].getIndex(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2887,22 +2872,19 @@ public class AudioService extends IAudioService.Stub
|
|||||||
* @param index Desired volume index of the stream
|
* @param index Desired volume index of the stream
|
||||||
* @param device the device whose volume must be changed
|
* @param device the device whose volume must be changed
|
||||||
* @param force If true, set the volume even if the desired volume is same
|
* @param force If true, set the volume even if the desired volume is same
|
||||||
* @param caller
|
|
||||||
* @param hasModifyAudioSettings true if the caller is granted MODIFY_AUDIO_SETTINGS or
|
|
||||||
* MODIFY_AUDIO_ROUTING permission
|
|
||||||
* as the current volume.
|
* as the current volume.
|
||||||
*/
|
*/
|
||||||
private void setStreamVolumeInt(int streamType,
|
private void setStreamVolumeInt(int streamType,
|
||||||
int index,
|
int index,
|
||||||
int device,
|
int device,
|
||||||
boolean force,
|
boolean force,
|
||||||
String caller, boolean hasModifyAudioSettings) {
|
String caller) {
|
||||||
if (isFullVolumeDevice(device)) {
|
if (isFullVolumeDevice(device)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VolumeStreamState streamState = mStreamStates[streamType];
|
VolumeStreamState streamState = mStreamStates[streamType];
|
||||||
|
|
||||||
if (streamState.setIndex(index, device, caller, hasModifyAudioSettings) || force) {
|
if (streamState.setIndex(index, device, caller) || force) {
|
||||||
// Post message to set system volume (it in turn will post a message
|
// Post message to set system volume (it in turn will post a message
|
||||||
// to persist).
|
// to persist).
|
||||||
sendMsg(mAudioHandler,
|
sendMsg(mAudioHandler,
|
||||||
@@ -3435,7 +3417,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
int device = vss.mIndexMap.keyAt(i);
|
int device = vss.mIndexMap.keyAt(i);
|
||||||
int value = vss.mIndexMap.valueAt(i);
|
int value = vss.mIndexMap.valueAt(i);
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
vss.setIndex(10, device, TAG, true /*hasModifyAudioSettings*/);
|
vss.setIndex(10, device, TAG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Persist volume for stream ring when it is changed here
|
// Persist volume for stream ring when it is changed here
|
||||||
@@ -3780,8 +3762,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
|
int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
|
||||||
int device = getDeviceForStream(streamType);
|
int device = getDeviceForStream(streamType);
|
||||||
int index = mStreamStates[mStreamVolumeAlias[streamType]].getIndex(device);
|
int index = mStreamStates[mStreamVolumeAlias[streamType]].getIndex(device);
|
||||||
setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, true, caller,
|
setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, true, caller);
|
||||||
true /*hasModifyAudioSettings*/);
|
|
||||||
|
|
||||||
updateStreamVolumeAlias(true /*updateVolumes*/, caller);
|
updateStreamVolumeAlias(true /*updateVolumes*/, caller);
|
||||||
|
|
||||||
@@ -4690,44 +4671,6 @@ public class AudioService extends IAudioService.Stub
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimum attenuation that can be set for alarms over speaker by an application that
|
|
||||||
* doesn't have the MODIFY_AUDIO_SETTINGS permission.
|
|
||||||
*/
|
|
||||||
protected static final float MIN_ALARM_ATTENUATION_NON_PRIVILEGED_DB = -36.0f;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the VolumeStreamState instances for minimum stream index that can be accessed
|
|
||||||
* without MODIFY_AUDIO_SETTINGS permission.
|
|
||||||
* Can only be done successfully once audio policy has finished reading its configuration files
|
|
||||||
* for the volume curves. If not, getStreamVolumeDB will return NaN, and the min value will
|
|
||||||
* remain at the stream min index value.
|
|
||||||
*/
|
|
||||||
protected void initMinStreamVolumeWithoutModifyAudioSettings() {
|
|
||||||
int idx;
|
|
||||||
int deviceForAlarm = AudioSystem.DEVICE_OUT_SPEAKER_SAFE;
|
|
||||||
if (AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_ALARM,
|
|
||||||
MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM], deviceForAlarm) == Float.NaN) {
|
|
||||||
deviceForAlarm = AudioSystem.DEVICE_OUT_SPEAKER;
|
|
||||||
}
|
|
||||||
for (idx = MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM];
|
|
||||||
idx >= MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM]; idx--) {
|
|
||||||
if (AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_ALARM, idx, deviceForAlarm)
|
|
||||||
< MIN_ALARM_ATTENUATION_NON_PRIVILEGED_DB) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final int safeIndex = idx <= MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM]
|
|
||||||
? MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM]
|
|
||||||
: Math.min(idx + 1, MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM]);
|
|
||||||
// update the VolumeStreamState for STREAM_ALARM and its aliases
|
|
||||||
for (int stream : mStreamVolumeAlias) {
|
|
||||||
if (mStreamVolumeAlias[stream] == AudioSystem.STREAM_ALARM) {
|
|
||||||
mStreamStates[stream].updateNoPermMinIndex(safeIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** only public for mocking/spying, do not call outside of AudioService */
|
/** only public for mocking/spying, do not call outside of AudioService */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public int getDeviceForStream(int stream) {
|
public int getDeviceForStream(int stream) {
|
||||||
@@ -5392,8 +5335,6 @@ public class AudioService extends IAudioService.Stub
|
|||||||
private class VolumeStreamState {
|
private class VolumeStreamState {
|
||||||
private final int mStreamType;
|
private final int mStreamType;
|
||||||
private int mIndexMin;
|
private int mIndexMin;
|
||||||
// min index when user doesn't have permission to change audio settings
|
|
||||||
private int mIndexMinNoPerm;
|
|
||||||
private int mIndexMax;
|
private int mIndexMax;
|
||||||
|
|
||||||
private boolean mIsMuted;
|
private boolean mIsMuted;
|
||||||
@@ -5435,7 +5376,6 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
mStreamType = streamType;
|
mStreamType = streamType;
|
||||||
mIndexMin = MIN_STREAM_VOLUME[streamType] * 10;
|
mIndexMin = MIN_STREAM_VOLUME[streamType] * 10;
|
||||||
mIndexMinNoPerm = mIndexMin; // may be overwritten later in updateNoPermMinIndex()
|
|
||||||
mIndexMax = MAX_STREAM_VOLUME[streamType] * 10;
|
mIndexMax = MAX_STREAM_VOLUME[streamType] * 10;
|
||||||
AudioSystem.initStreamVolume(streamType, mIndexMin / 10, mIndexMax / 10);
|
AudioSystem.initStreamVolume(streamType, mIndexMin / 10, mIndexMax / 10);
|
||||||
|
|
||||||
@@ -5446,18 +5386,6 @@ public class AudioService extends IAudioService.Stub
|
|||||||
mStreamDevicesChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
|
mStreamDevicesChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the minimum index that can be used without MODIFY_AUDIO_SETTINGS permission
|
|
||||||
* @param index minimum index expressed in "UI units", i.e. no 10x factor
|
|
||||||
*/
|
|
||||||
public void updateNoPermMinIndex(int index) {
|
|
||||||
mIndexMinNoPerm = index * 10;
|
|
||||||
if (mIndexMinNoPerm < mIndexMin) {
|
|
||||||
Log.e(TAG, "Invalid mIndexMinNoPerm for stream " + mStreamType);
|
|
||||||
mIndexMinNoPerm = mIndexMin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int observeDevicesForStream_syncVSS(boolean checkOthers) {
|
public int observeDevicesForStream_syncVSS(boolean checkOthers) {
|
||||||
if (!mSystemServer.isPrivileged()) {
|
if (!mSystemServer.isPrivileged()) {
|
||||||
return AudioSystem.DEVICE_NONE;
|
return AudioSystem.DEVICE_NONE;
|
||||||
@@ -5539,8 +5467,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mIndexMap.put(device, getValidIndex(10 * index,
|
mIndexMap.put(device, getValidIndex(10 * index));
|
||||||
true /*hasModifyAudioSettings*/));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5628,20 +5555,17 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean adjustIndex(int deltaIndex, int device, String caller,
|
public boolean adjustIndex(int deltaIndex, int device, String caller) {
|
||||||
boolean hasModifyAudioSettings) {
|
return setIndex(getIndex(device) + deltaIndex, device, caller);
|
||||||
return setIndex(getIndex(device) + deltaIndex, device, caller,
|
|
||||||
hasModifyAudioSettings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setIndex(int index, int device, String caller,
|
public boolean setIndex(int index, int device, String caller) {
|
||||||
boolean hasModifyAudioSettings) {
|
|
||||||
boolean changed;
|
boolean changed;
|
||||||
int oldIndex;
|
int oldIndex;
|
||||||
synchronized (mSettingsLock) {
|
synchronized (mSettingsLock) {
|
||||||
synchronized (VolumeStreamState.class) {
|
synchronized (VolumeStreamState.class) {
|
||||||
oldIndex = getIndex(device);
|
oldIndex = getIndex(device);
|
||||||
index = getValidIndex(index, hasModifyAudioSettings);
|
index = getValidIndex(index);
|
||||||
if ((mStreamType == AudioSystem.STREAM_SYSTEM_ENFORCED) && mCameraSoundForced) {
|
if ((mStreamType == AudioSystem.STREAM_SYSTEM_ENFORCED) && mCameraSoundForced) {
|
||||||
index = mIndexMax;
|
index = mIndexMax;
|
||||||
}
|
}
|
||||||
@@ -5661,12 +5585,10 @@ public class AudioService extends IAudioService.Stub
|
|||||||
mStreamVolumeAlias[streamType] == mStreamType &&
|
mStreamVolumeAlias[streamType] == mStreamType &&
|
||||||
(changed || !aliasStreamState.hasIndexForDevice(device))) {
|
(changed || !aliasStreamState.hasIndexForDevice(device))) {
|
||||||
final int scaledIndex = rescaleIndex(index, mStreamType, streamType);
|
final int scaledIndex = rescaleIndex(index, mStreamType, streamType);
|
||||||
aliasStreamState.setIndex(scaledIndex, device, caller,
|
aliasStreamState.setIndex(scaledIndex, device, caller);
|
||||||
hasModifyAudioSettings);
|
|
||||||
if (isCurrentDevice) {
|
if (isCurrentDevice) {
|
||||||
aliasStreamState.setIndex(scaledIndex,
|
aliasStreamState.setIndex(scaledIndex,
|
||||||
getDeviceForStream(streamType), caller,
|
getDeviceForStream(streamType), caller);
|
||||||
hasModifyAudioSettings);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5756,7 +5678,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
index = srcMap.valueAt(i);
|
index = srcMap.valueAt(i);
|
||||||
index = rescaleIndex(index, srcStreamType, mStreamType);
|
index = rescaleIndex(index, srcStreamType, mStreamType);
|
||||||
|
|
||||||
setIndex(index, device, caller, true /*hasModifyAudioSettings*/);
|
setIndex(index, device, caller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5823,10 +5745,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getValidIndex(int index, boolean hasModifyAudioSettings) {
|
private int getValidIndex(int index) {
|
||||||
final int indexMin = hasModifyAudioSettings ? mIndexMin : mIndexMinNoPerm;
|
if (index < mIndexMin) {
|
||||||
if (index < indexMin) {
|
return mIndexMin;
|
||||||
return indexMin;
|
|
||||||
} else if (mUseFixedVolume || index > mIndexMax) {
|
} else if (mUseFixedVolume || index > mIndexMax) {
|
||||||
return mIndexMax;
|
return mIndexMax;
|
||||||
}
|
}
|
||||||
@@ -5838,13 +5759,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
pw.print(" Muted: ");
|
pw.print(" Muted: ");
|
||||||
pw.println(mIsMuted);
|
pw.println(mIsMuted);
|
||||||
pw.print(" Min: ");
|
pw.print(" Min: ");
|
||||||
pw.print((mIndexMin + 5) / 10);
|
pw.println((mIndexMin + 5) / 10);
|
||||||
if (mIndexMin != mIndexMinNoPerm) {
|
|
||||||
pw.print(" w/o perm:");
|
|
||||||
pw.println((mIndexMinNoPerm + 5) / 10);
|
|
||||||
} else {
|
|
||||||
pw.println();
|
|
||||||
}
|
|
||||||
pw.print(" Max: ");
|
pw.print(" Max: ");
|
||||||
pw.println((mIndexMax + 5) / 10);
|
pw.println((mIndexMax + 5) / 10);
|
||||||
pw.print(" streamVolume:"); pw.println(getStreamVolume(mStreamType));
|
pw.print(" streamVolume:"); pw.println(getStreamVolume(mStreamType));
|
||||||
@@ -5965,9 +5880,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
final VolumeStreamState streamState = mStreamStates[update.mStreamType];
|
final VolumeStreamState streamState = mStreamStates[update.mStreamType];
|
||||||
if (update.hasVolumeIndex()) {
|
if (update.hasVolumeIndex()) {
|
||||||
final int index = update.getVolumeIndex();
|
final int index = update.getVolumeIndex();
|
||||||
streamState.setIndex(index, update.mDevice, update.mCaller,
|
streamState.setIndex(index, update.mDevice, update.mCaller);
|
||||||
// trusted as index is always validated before message is posted
|
|
||||||
true /*hasModifyAudioSettings*/);
|
|
||||||
sVolumeLogger.log(new AudioEventLogger.StringEvent(update.mCaller + " dev:0x"
|
sVolumeLogger.log(new AudioEventLogger.StringEvent(update.mCaller + " dev:0x"
|
||||||
+ Integer.toHexString(update.mDevice) + " volIdx:" + index));
|
+ Integer.toHexString(update.mDevice) + " volIdx:" + index));
|
||||||
} else {
|
} else {
|
||||||
@@ -6910,8 +6823,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
for (int device : devices) {
|
for (int device : devices) {
|
||||||
int index = streamState.getIndex(device);
|
int index = streamState.getIndex(device);
|
||||||
if (index > safeMediaVolumeIndex(device)) {
|
if (index > safeMediaVolumeIndex(device)) {
|
||||||
streamState.setIndex(safeMediaVolumeIndex(device), device, caller,
|
streamState.setIndex(safeMediaVolumeIndex(device), device, caller);
|
||||||
true /*hasModifyAudioSettings*/);
|
|
||||||
sendMsg(mAudioHandler,
|
sendMsg(mAudioHandler,
|
||||||
MSG_SET_DEVICE_VOLUME,
|
MSG_SET_DEVICE_VOLUME,
|
||||||
SENDMSG_QUEUE,
|
SENDMSG_QUEUE,
|
||||||
@@ -6945,7 +6857,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
mPendingVolumeCommand.mIndex,
|
mPendingVolumeCommand.mIndex,
|
||||||
mPendingVolumeCommand.mFlags,
|
mPendingVolumeCommand.mFlags,
|
||||||
mPendingVolumeCommand.mDevice,
|
mPendingVolumeCommand.mDevice,
|
||||||
callingPackage, true /*hasModifyAudioSettings*/);
|
callingPackage);
|
||||||
mPendingVolumeCommand = null;
|
mPendingVolumeCommand = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7553,39 +7465,29 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void adjustSuggestedStreamVolumeForUid(int streamType, int direction, int flags,
|
public void adjustSuggestedStreamVolumeForUid(int streamType, int direction, int flags,
|
||||||
String callingPackage, int uid, int pid) {
|
String callingPackage, int uid) {
|
||||||
final boolean hasModifyAudioSettings =
|
|
||||||
mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
|
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
// direction and stream type swap here because the public
|
// direction and stream type swap here because the public
|
||||||
// adjustSuggested has a different order than the other methods.
|
// adjustSuggested has a different order than the other methods.
|
||||||
adjustSuggestedStreamVolume(direction, streamType, flags, callingPackage,
|
adjustSuggestedStreamVolume(direction, streamType, flags, callingPackage,
|
||||||
callingPackage, uid, hasModifyAudioSettings);
|
callingPackage, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void adjustStreamVolumeForUid(int streamType, int direction, int flags,
|
public void adjustStreamVolumeForUid(int streamType, int direction, int flags,
|
||||||
String callingPackage, int uid, int pid) {
|
String callingPackage, int uid) {
|
||||||
if (direction != AudioManager.ADJUST_SAME) {
|
if (direction != AudioManager.ADJUST_SAME) {
|
||||||
sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_VOL_UID, streamType,
|
sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_VOL_UID, streamType,
|
||||||
direction/*val1*/, flags/*val2*/, new StringBuilder(callingPackage)
|
direction/*val1*/, flags/*val2*/, new StringBuilder(callingPackage)
|
||||||
.append(" uid:").append(uid).toString()));
|
.append(" uid:").append(uid).toString()));
|
||||||
}
|
}
|
||||||
final boolean hasModifyAudioSettings =
|
|
||||||
mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
|
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
adjustStreamVolume(streamType, direction, flags, callingPackage,
|
adjustStreamVolume(streamType, direction, flags, callingPackage,
|
||||||
callingPackage, uid, hasModifyAudioSettings);
|
callingPackage, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStreamVolumeForUid(int streamType, int direction, int flags,
|
public void setStreamVolumeForUid(int streamType, int direction, int flags,
|
||||||
String callingPackage, int uid, int pid) {
|
String callingPackage, int uid) {
|
||||||
final boolean hasModifyAudioSettings =
|
setStreamVolume(streamType, direction, flags, callingPackage, callingPackage, uid);
|
||||||
mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
|
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
setStreamVolume(streamType, direction, flags, callingPackage, callingPackage, uid,
|
|
||||||
hasModifyAudioSettings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
mAudioManagerInternal.setStreamVolumeForUid(stream, volumeValue, flags,
|
mAudioManagerInternal.setStreamVolumeForUid(stream, volumeValue, flags,
|
||||||
opPackageName, uid, pid);
|
opPackageName, uid);
|
||||||
} catch (IllegalArgumentException | SecurityException e) {
|
} catch (IllegalArgumentException | SecurityException e) {
|
||||||
Log.e(TAG, "Cannot set volume: stream=" + stream + ", value=" + volumeValue
|
Log.e(TAG, "Cannot set volume: stream=" + stream + ", value=" + volumeValue
|
||||||
+ ", flags=" + flags, e);
|
+ ", flags=" + flags, e);
|
||||||
@@ -501,15 +501,12 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
|
|||||||
// Must use opPackageName for adjusting volumes with UID.
|
// Must use opPackageName for adjusting volumes with UID.
|
||||||
final String opPackageName;
|
final String opPackageName;
|
||||||
final int uid;
|
final int uid;
|
||||||
final int pid;
|
|
||||||
if (asSystemService) {
|
if (asSystemService) {
|
||||||
opPackageName = mContext.getOpPackageName();
|
opPackageName = mContext.getOpPackageName();
|
||||||
uid = Process.SYSTEM_UID;
|
uid = Process.SYSTEM_UID;
|
||||||
pid = Process.myPid();
|
|
||||||
} else {
|
} else {
|
||||||
opPackageName = callingOpPackageName;
|
opPackageName = callingOpPackageName;
|
||||||
uid = callingUid;
|
uid = callingUid;
|
||||||
pid = callingPid;
|
|
||||||
}
|
}
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -518,15 +515,15 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
|
|||||||
if (useSuggested) {
|
if (useSuggested) {
|
||||||
if (AudioSystem.isStreamActive(stream, 0)) {
|
if (AudioSystem.isStreamActive(stream, 0)) {
|
||||||
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream,
|
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream,
|
||||||
direction, flags, opPackageName, uid, pid);
|
direction, flags, opPackageName, uid);
|
||||||
} else {
|
} else {
|
||||||
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(
|
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(
|
||||||
AudioManager.USE_DEFAULT_STREAM_TYPE, direction,
|
AudioManager.USE_DEFAULT_STREAM_TYPE, direction,
|
||||||
flags | previousFlagPlaySound, opPackageName, uid, pid);
|
flags | previousFlagPlaySound, opPackageName, uid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags,
|
mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags,
|
||||||
opPackageName, uid, pid);
|
opPackageName, uid);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | SecurityException e) {
|
} catch (IllegalArgumentException | SecurityException e) {
|
||||||
Log.e(TAG, "Cannot adjust volume: direction=" + direction + ", stream="
|
Log.e(TAG, "Cannot adjust volume: direction=" + direction + ", stream="
|
||||||
|
|||||||
@@ -2107,19 +2107,16 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
public void run() {
|
public void run() {
|
||||||
final String callingOpPackageName;
|
final String callingOpPackageName;
|
||||||
final int callingUid;
|
final int callingUid;
|
||||||
final int callingPid;
|
|
||||||
if (asSystemService) {
|
if (asSystemService) {
|
||||||
callingOpPackageName = mContext.getOpPackageName();
|
callingOpPackageName = mContext.getOpPackageName();
|
||||||
callingUid = Process.myUid();
|
callingUid = Process.myUid();
|
||||||
callingPid = Process.myPid();
|
|
||||||
} else {
|
} else {
|
||||||
callingOpPackageName = opPackageName;
|
callingOpPackageName = opPackageName;
|
||||||
callingUid = uid;
|
callingUid = uid;
|
||||||
callingPid = pid;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(suggestedStream,
|
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(suggestedStream,
|
||||||
direction, flags, callingOpPackageName, callingUid, callingPid);
|
direction, flags, callingOpPackageName, callingUid);
|
||||||
} catch (SecurityException | IllegalArgumentException e) {
|
} catch (SecurityException | IllegalArgumentException e) {
|
||||||
Log.e(TAG, "Cannot adjust volume: direction=" + direction
|
Log.e(TAG, "Cannot adjust volume: direction=" + direction
|
||||||
+ ", suggestedStream=" + suggestedStream + ", flags=" + flags
|
+ ", suggestedStream=" + suggestedStream + ", flags=" + flags
|
||||||
|
|||||||
Reference in New Issue
Block a user