Merge "Move AudioService to services."

This commit is contained in:
John Spurlock
2015-02-09 23:34:42 +00:00
committed by Android (Google) Code Review
14 changed files with 238 additions and 191 deletions

View File

@@ -45,8 +45,9 @@ public final class AudioFocusInfo implements Parcelable {
* @param gainRequest
* @param lossReceived
* @param flags
* @hide
*/
AudioFocusInfo(AudioAttributes aa, String clientId, String packageName,
public AudioFocusInfo(AudioAttributes aa, String clientId, String packageName,
int gainRequest, int lossReceived, int flags) {
mAttributes = aa == null ? new AudioAttributes.Builder().build() : aa;
mClientId = clientId == null ? "" : clientId;
@@ -91,7 +92,7 @@ public final class AudioFocusInfo implements Parcelable {
public int getLossReceived() { return mLossReceived; }
/** @hide */
void clearLossReceived() { mLossReceived = 0; }
public void clearLossReceived() { mLossReceived = 0; }
/**
* The flags set in the audio focus request.

View File

@@ -663,8 +663,7 @@ public class AudioManager {
int keyCode = event.getKeyCode();
if (keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP
&& keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
&& mVolumeKeyUpTime + AudioService.PLAY_SOUND_DELAY
> SystemClock.uptimeMillis()) {
&& mVolumeKeyUpTime + AudioSystem.PLAY_SOUND_DELAY > SystemClock.uptimeMillis()) {
/*
* The user has hit another key during the delay (e.g., 300ms)
* since the last volume key up, so cancel any sounds.
@@ -2501,7 +2500,7 @@ public class AudioManager {
service.requestAudioFocus(new AudioAttributes.Builder()
.setInternalLegacyStreamType(streamType).build(),
durationHint, mICallBack, null,
MediaFocusControl.IN_VOICE_COMM_FOCUS_ID,
AudioSystem.IN_VOICE_COMM_FOCUS_ID,
mContext.getOpPackageName(),
AUDIOFOCUS_FLAG_LOCK,
null /* policy token */);
@@ -2519,7 +2518,7 @@ public class AudioManager {
public void abandonAudioFocusForCall() {
IAudioService service = getService();
try {
service.abandonAudioFocus(null, MediaFocusControl.IN_VOICE_COMM_FOCUS_ID,
service.abandonAudioFocus(null, AudioSystem.IN_VOICE_COMM_FOCUS_ID,
null /*AudioAttributes, legacy behavior*/);
} catch (RemoteException e) {
Log.e(TAG, "Can't call abandonAudioFocusForCall() on AudioService:", e);

View File

@@ -25,27 +25,27 @@ import android.text.TextUtils;
* @hide
*/
public class AudioRoutesInfo implements Parcelable {
static final int MAIN_SPEAKER = 0;
static final int MAIN_HEADSET = 1<<0;
static final int MAIN_HEADPHONES = 1<<1;
static final int MAIN_DOCK_SPEAKERS = 1<<2;
static final int MAIN_HDMI = 1<<3;
static final int MAIN_USB = 1<<4;
public static final int MAIN_SPEAKER = 0;
public static final int MAIN_HEADSET = 1<<0;
public static final int MAIN_HEADPHONES = 1<<1;
public static final int MAIN_DOCK_SPEAKERS = 1<<2;
public static final int MAIN_HDMI = 1<<3;
public static final int MAIN_USB = 1<<4;
CharSequence mBluetoothName;
int mMainType = MAIN_SPEAKER;
public CharSequence bluetoothName;
public int mainType = MAIN_SPEAKER;
public AudioRoutesInfo() {
}
public AudioRoutesInfo(AudioRoutesInfo o) {
mBluetoothName = o.mBluetoothName;
mMainType = o.mMainType;
bluetoothName = o.bluetoothName;
mainType = o.mainType;
}
AudioRoutesInfo(Parcel src) {
mBluetoothName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(src);
mMainType = src.readInt();
bluetoothName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(src);
mainType = src.readInt();
}
@Override
@@ -55,8 +55,8 @@ public class AudioRoutesInfo implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
TextUtils.writeToParcel(mBluetoothName, dest, flags);
dest.writeInt(mMainType);
TextUtils.writeToParcel(bluetoothName, dest, flags);
dest.writeInt(mainType);
}
public static final Parcelable.Creator<AudioRoutesInfo> CREATOR

View File

@@ -16,7 +16,10 @@
package android.media;
import android.content.Context;
import android.content.pm.PackageManager;
import android.media.audiopolicy.AudioMix;
import java.util.ArrayList;
/* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET
@@ -65,6 +68,19 @@ public class AudioSystem
private static final int NUM_STREAM_TYPES = 10;
public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; }
public static final String[] STREAM_NAMES = new String[] {
"STREAM_VOICE_CALL",
"STREAM_SYSTEM",
"STREAM_RING",
"STREAM_MUSIC",
"STREAM_ALARM",
"STREAM_NOTIFICATION",
"STREAM_BLUETOOTH_SCO",
"STREAM_SYSTEM_ENFORCED",
"STREAM_DTMF",
"STREAM_TTS"
};
/*
* Sets the microphone mute on or off.
*
@@ -570,5 +586,93 @@ public class AudioSystem
public static native int getAudioHwSyncForSession(int sessionId);
public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register);
// Items shared with audio service
/**
* The delay before playing a sound. This small period exists so the user
* can press another key (non-volume keys, too) to have it NOT be audible.
* <p>
* PhoneWindow will implement this part.
*/
public static final int PLAY_SOUND_DELAY = 300;
/**
* Constant to identify a focus stack entry that is used to hold the focus while the phone
* is ringing or during a call. Used by com.android.internal.telephony.CallManager when
* entering and exiting calls.
*/
public final static String IN_VOICE_COMM_FOCUS_ID = "AudioFocus_For_Phone_Ring_And_Calls";
/**
* @see AudioManager#setVibrateSetting(int, int)
*/
public static int getValueForVibrateSetting(int existingValue, int vibrateType,
int vibrateSetting) {
// First clear the existing setting. Each vibrate type has two bits in
// the value. Note '3' is '11' in binary.
existingValue &= ~(3 << (vibrateType * 2));
// Set into the old value
existingValue |= (vibrateSetting & 3) << (vibrateType * 2);
return existingValue;
}
public static int getDefaultStreamVolume(int streamType) {
return DEFAULT_STREAM_VOLUME[streamType];
}
public static int[] DEFAULT_STREAM_VOLUME = new int[] {
4, // STREAM_VOICE_CALL
7, // STREAM_SYSTEM
5, // STREAM_RING
11, // STREAM_MUSIC
6, // STREAM_ALARM
5, // STREAM_NOTIFICATION
7, // STREAM_BLUETOOTH_SCO
7, // STREAM_SYSTEM_ENFORCED
11, // STREAM_DTMF
11 // STREAM_TTS
};
public static String streamToString(int stream) {
if (stream >= 0 && stream < STREAM_NAMES.length) return STREAM_NAMES[stream];
if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) return "USE_DEFAULT_STREAM_TYPE";
return "UNKNOWN_STREAM_" + stream;
}
/** The platform has no specific capabilities */
public static final int PLATFORM_DEFAULT = 0;
/** The platform is voice call capable (a phone) */
public static final int PLATFORM_VOICE = 1;
/** The platform is a television or a set-top box */
public static final int PLATFORM_TELEVISION = 2;
/**
* Return the platform type that this is running on. One of:
* <ul>
* <li>{@link #PLATFORM_VOICE}</li>
* <li>{@link #PLATFORM_TELEVISION}</li>
* <li>{@link #PLATFORM_DEFAULT}</li>
* </ul>
*/
public static int getPlatformType(Context context) {
if (context.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable)) {
return PLATFORM_VOICE;
} else if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
return PLATFORM_TELEVISION;
} else {
return PLATFORM_DEFAULT;
}
}
public static final int DEFAULT_MUTE_STREAMS_AFFECTED =
(1 << STREAM_MUSIC) |
(1 << STREAM_RING) |
(1 << STREAM_NOTIFICATION) |
(1 << STREAM_SYSTEM);
}

View File

@@ -171,15 +171,15 @@ public class MediaRouter {
}
void updateAudioRoutes(AudioRoutesInfo newRoutes) {
if (newRoutes.mMainType != mCurAudioRoutesInfo.mMainType) {
mCurAudioRoutesInfo.mMainType = newRoutes.mMainType;
if (newRoutes.mainType != mCurAudioRoutesInfo.mainType) {
mCurAudioRoutesInfo.mainType = newRoutes.mainType;
int name;
if ((newRoutes.mMainType&AudioRoutesInfo.MAIN_HEADPHONES) != 0
|| (newRoutes.mMainType&AudioRoutesInfo.MAIN_HEADSET) != 0) {
if ((newRoutes.mainType&AudioRoutesInfo.MAIN_HEADPHONES) != 0
|| (newRoutes.mainType&AudioRoutesInfo.MAIN_HEADSET) != 0) {
name = com.android.internal.R.string.default_audio_route_name_headphones;
} else if ((newRoutes.mMainType&AudioRoutesInfo.MAIN_DOCK_SPEAKERS) != 0) {
} else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_DOCK_SPEAKERS) != 0) {
name = com.android.internal.R.string.default_audio_route_name_dock_speakers;
} else if ((newRoutes.mMainType&AudioRoutesInfo.MAIN_HDMI) != 0) {
} else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_HDMI) != 0) {
name = com.android.internal.R.string.default_media_route_name_hdmi;
} else {
name = com.android.internal.R.string.default_audio_route_name;
@@ -188,21 +188,21 @@ public class MediaRouter {
dispatchRouteChanged(sStatic.mDefaultAudioVideo);
}
final int mainType = mCurAudioRoutesInfo.mMainType;
final int mainType = mCurAudioRoutesInfo.mainType;
if (!TextUtils.equals(newRoutes.mBluetoothName, mCurAudioRoutesInfo.mBluetoothName)) {
mCurAudioRoutesInfo.mBluetoothName = newRoutes.mBluetoothName;
if (mCurAudioRoutesInfo.mBluetoothName != null) {
if (!TextUtils.equals(newRoutes.bluetoothName, mCurAudioRoutesInfo.bluetoothName)) {
mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName;
if (mCurAudioRoutesInfo.bluetoothName != null) {
if (sStatic.mBluetoothA2dpRoute == null) {
final RouteInfo info = new RouteInfo(sStatic.mSystemCategory);
info.mName = mCurAudioRoutesInfo.mBluetoothName;
info.mName = mCurAudioRoutesInfo.bluetoothName;
info.mDescription = sStatic.mResources.getText(
com.android.internal.R.string.bluetooth_a2dp_audio_route_name);
info.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO;
sStatic.mBluetoothA2dpRoute = info;
addRouteStatic(sStatic.mBluetoothA2dpRoute);
} else {
sStatic.mBluetoothA2dpRoute.mName = mCurAudioRoutesInfo.mBluetoothName;
sStatic.mBluetoothA2dpRoute.mName = mCurAudioRoutesInfo.bluetoothName;
dispatchRouteChanged(sStatic.mBluetoothA2dpRoute);
}
} else if (sStatic.mBluetoothA2dpRoute != null) {

View File

@@ -28,8 +28,8 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.media.AudioSystem;
import android.media.AudioManager;
import android.media.AudioService;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Environment;
@@ -568,7 +568,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
@@ -2051,11 +2051,11 @@ public class DatabaseHelper extends SQLiteOpenHelper {
int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0);
// If the ringer vibrate value is invalid, set it to the default
if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) {
vibrateSetting = AudioService.getValueForVibrateSetting(0,
vibrateSetting = AudioSystem.getValueForVibrateSetting(0,
AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
}
// Apply the same setting to the notification vibrate value
vibrateSetting = AudioService.getValueForVibrateSetting(vibrateSetting,
vibrateSetting = AudioSystem.getValueForVibrateSetting(vibrateSetting,
AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting);
SQLiteStatement stmt = null;
@@ -2199,25 +2199,25 @@ public class DatabaseHelper extends SQLiteOpenHelper {
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.VOLUME_MUSIC,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
loadSetting(stmt, Settings.System.VOLUME_RING,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_RING));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
loadSetting(
stmt,
Settings.System.VOLUME_VOICE,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
loadSetting(stmt, Settings.System.VOLUME_ALARM,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
loadSetting(
stmt,
Settings.System.VOLUME_NOTIFICATION,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
loadSetting(
stmt,
Settings.System.VOLUME_BLUETOOTH_SCO,
AudioService.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
// By default:
// - ringtones, notification, system and music streams are affected by ringer mode
@@ -2236,7 +2236,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
ringerModeAffectedStreams);
loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
AudioService.DEFAULT_MUTE_STREAMS_AFFECTED);
AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
} finally {
if (stmt != null) stmt.close();
}
@@ -2256,10 +2256,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
// Vibrate on by default for ringer, on for notification
int vibrate = 0;
vibrate = AudioService.getValueForVibrateSetting(vibrate,
vibrate = AudioSystem.getValueForVibrateSetting(vibrate,
AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_ONLY_SILENT);
vibrate |= AudioService.getValueForVibrateSetting(vibrate,
vibrate |= AudioSystem.getValueForVibrateSetting(vibrate,
AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
} finally {

View File

@@ -37,7 +37,6 @@ import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioService;
import android.media.AudioSystem;
import android.media.RingtoneManager;
import android.media.ToneGenerator;
@@ -88,7 +87,7 @@ public class VolumePanel extends Handler implements DemoMode {
private static final String TAG = "VolumePanel";
private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
private static final int PLAY_SOUND_DELAY = AudioService.PLAY_SOUND_DELAY;
private static final int PLAY_SOUND_DELAY = AudioSystem.PLAY_SOUND_DELAY;
/**
* The delay before vibrating. This small period exists so if the user is
@@ -1012,7 +1011,7 @@ public class VolumePanel extends Handler implements DemoMode {
}
private static String streamToString(int stream) {
return AudioService.streamToString(stream);
return AudioSystem.streamToString(stream);
}
/**

View File

@@ -43,7 +43,7 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioService;
import android.media.AudioSystem;
import android.media.IAudioService;
import android.media.Ringtone;
import android.media.RingtoneManager;
@@ -1269,7 +1269,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
com.android.internal.R.integer.config_triplePressOnPowerBehavior);
mUseTvRouting = AudioService.getPlatformType(mContext) == AudioService.PLATFORM_TELEVISION;
mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
mUseMasterVolume = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useMasterVolume);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package android.media;
package com.android.server.audio;
import static android.Manifest.permission.REMOTE_AUDIO_PLAYBACK;
import static android.media.AudioManager.RINGER_MODE_NORMAL;
@@ -46,8 +46,30 @@ import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiPlaybackClient;
import android.hardware.hdmi.HdmiTvClient;
import android.hardware.usb.UsbManager;
import android.media.AudioAttributes;
import android.media.AudioDevicePort;
import android.media.AudioSystem;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioManagerInternal;
import android.media.AudioPort;
import android.media.AudioRoutesInfo;
import android.media.AudioSystem;
import android.media.IAudioFocusDispatcher;
import android.media.IAudioRoutesObserver;
import android.media.IAudioService;
import android.media.IRemoteControlDisplay;
import android.media.IRingtonePlayer;
import android.media.IVolumeController;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.media.AudioAttributes.Builder;
import android.media.AudioManagerInternal.RingerModeDelegate;
import android.media.AudioSystem.ErrorCallback;
import android.media.IAudioService.Stub;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.SoundPool.OnLoadCompleteListener;
import android.media.audiopolicy.AudioMix;
import android.media.audiopolicy.AudioPolicy;
import android.media.audiopolicy.AudioPolicyConfig;
@@ -138,14 +160,6 @@ public class AudioService extends IAudioService.Stub {
/** How long to delay after a volume down event before unmuting a stream */
private static final int UNMUTE_STREAM_DELAY = 350;
/**
* The delay before playing a sound. This small period exists so the user
* can press another key (non-volume keys, too) to have it NOT be audible.
* <p>
* PhoneWindow will implement this part.
*/
public static final int PLAY_SOUND_DELAY = 300;
/**
* Only used in the result from {@link #checkForRingerModeChange(int, int, int)}
*/
@@ -155,21 +169,15 @@ public class AudioService extends IAudioService.Stub {
private final ContentResolver mContentResolver;
private final AppOpsManager mAppOps;
// the platform has no specific capabilities
public static final int PLATFORM_DEFAULT = 0;
// the platform is voice call capable (a phone)
public static final int PLATFORM_VOICE = 1;
// the platform is a television or a set-top box
public static final int PLATFORM_TELEVISION = 2;
// the platform type affects volume and silent mode behavior
private final int mPlatformType;
private boolean isPlatformVoice() {
return mPlatformType == PLATFORM_VOICE;
return mPlatformType == AudioSystem.PLATFORM_VOICE;
}
private boolean isPlatformTelevision() {
return mPlatformType == PLATFORM_TELEVISION;
return mPlatformType == AudioSystem.PLATFORM_TELEVISION;
}
/** The controller for the volume UI. */
@@ -267,19 +275,6 @@ public class AudioService extends IAudioService.Stub {
15 // STREAM_TTS
};
private static int[] DEFAULT_STREAM_VOLUME = new int[] {
4, // STREAM_VOICE_CALL
7, // STREAM_SYSTEM
5, // STREAM_RING
11, // STREAM_MUSIC
6, // STREAM_ALARM
5, // STREAM_NOTIFICATION
7, // STREAM_BLUETOOTH_SCO
7, // STREAM_SYSTEM_ENFORCED
11, // STREAM_DTMF
11 // STREAM_TTS
};
/* mStreamVolumeAlias[] indicates for each stream if it uses the volume settings
* of another stream: This avoids multiplying the volume settings for hidden
* stream types that follow other stream behavior for volume settings
@@ -346,26 +341,6 @@ public class AudioService extends IAudioService.Stub {
private final boolean mUseFixedVolume;
// stream names used by dumpStreamStates()
private static final String[] STREAM_NAMES = new String[] {
"STREAM_VOICE_CALL",
"STREAM_SYSTEM",
"STREAM_RING",
"STREAM_MUSIC",
"STREAM_ALARM",
"STREAM_NOTIFICATION",
"STREAM_BLUETOOTH_SCO",
"STREAM_SYSTEM_ENFORCED",
"STREAM_DTMF",
"STREAM_TTS"
};
public static final int DEFAULT_MUTE_STREAMS_AFFECTED =
(1 << AudioSystem.STREAM_MUSIC) |
(1 << AudioSystem.STREAM_RING) |
(1 << AudioSystem.STREAM_NOTIFICATION) |
(1 << AudioSystem.STREAM_SYSTEM);
private final AudioSystem.ErrorCallback mAudioSystemCallback = new AudioSystem.ErrorCallback() {
public void onError(int error) {
switch (error) {
@@ -570,7 +545,7 @@ public class AudioService extends IAudioService.Stub {
mContentResolver = context.getContentResolver();
mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
mPlatformType = getPlatformType(context);
mPlatformType = AudioSystem.getPlatformType(context);
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
mAudioEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleAudioEvent");
@@ -583,13 +558,13 @@ public class AudioService extends IAudioService.Stub {
MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]);
if (maxVolume != MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]) {
MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = maxVolume;
DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = (maxVolume * 3) / 4;
AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = (maxVolume * 3) / 4;
}
maxVolume = SystemProperties.getInt("ro.config.media_vol_steps",
MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]);
if (maxVolume != MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]) {
MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = maxVolume;
DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = (maxVolume * 3) / 4;
AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = (maxVolume * 3) / 4;
}
sSoundEffectVolumeDb = context.getResources().getInteger(
@@ -683,26 +658,6 @@ public class AudioService extends IAudioService.Stub {
LocalServices.addService(AudioManagerInternal.class, new AudioServiceInternal());
}
/**
* Return the platform type that this is running on. One of:
* <ul>
* <li>{@link #PLATFORM_VOICE}</li>
* <li>{@link #PLATFORM_TELEVISION}</li>
* <li>{@link #PLATFORM_DEFAULT}</li>
* </ul>
*/
public static int getPlatformType(Context context) {
if (context.getResources().getBoolean(
com.android.internal.R.bool.config_voice_capable)) {
return PLATFORM_VOICE;
} else if (context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_LEANBACK)) {
return PLATFORM_TELEVISION;
} else {
return PLATFORM_DEFAULT;
}
}
public void systemReady() {
sendMsg(mAudioHandler, MSG_SYSTEM_READY, SENDMSG_QUEUE,
0, 0, null, 0);
@@ -819,7 +774,7 @@ public class AudioService extends IAudioService.Stub {
pw.println("\nStream volumes (device: index)");
int numStreamTypes = AudioSystem.getNumStreamTypes();
for (int i = 0; i < numStreamTypes; i++) {
pw.println("- "+STREAM_NAMES[i]+":");
pw.println("- " + AudioSystem.STREAM_NAMES[i] + ":");
mStreamStates[i].dump(pw);
pw.println("");
}
@@ -827,22 +782,15 @@ public class AudioService extends IAudioService.Stub {
pw.println(Integer.toHexString(mMuteAffectedStreams));
}
/** @hide */
public static String streamToString(int stream) {
if (stream >= 0 && stream < STREAM_NAMES.length) return STREAM_NAMES[stream];
if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) return "USE_DEFAULT_STREAM_TYPE";
return "UNKNOWN_STREAM_" + stream;
}
private void updateStreamVolumeAlias(boolean updateVolumes) {
int dtmfStreamAlias;
switch (mPlatformType) {
case PLATFORM_VOICE:
case AudioSystem.PLATFORM_VOICE:
mStreamVolumeAlias = STREAM_VOLUME_ALIAS_VOICE;
dtmfStreamAlias = AudioSystem.STREAM_RING;
break;
case PLATFORM_TELEVISION:
case AudioSystem.PLATFORM_TELEVISION:
mStreamVolumeAlias = STREAM_VOLUME_ALIAS_TELEVISION;
dtmfStreamAlias = AudioSystem.STREAM_MUSIC;
break;
@@ -921,11 +869,11 @@ public class AudioService extends IAudioService.Stub {
// System.VIBRATE_ON is not used any more but defaults for mVibrateSetting
// are still needed while setVibrateSetting() and getVibrateSetting() are being
// deprecated.
mVibrateSetting = getValueForVibrateSetting(0,
mVibrateSetting = AudioSystem.getValueForVibrateSetting(0,
AudioManager.VIBRATE_TYPE_NOTIFICATION,
mHasVibrator ? AudioManager.VIBRATE_SETTING_ONLY_SILENT
: AudioManager.VIBRATE_SETTING_OFF);
mVibrateSetting = getValueForVibrateSetting(mVibrateSetting,
mVibrateSetting = AudioSystem.getValueForVibrateSetting(mVibrateSetting,
AudioManager.VIBRATE_TYPE_RINGER,
mHasVibrator ? AudioManager.VIBRATE_SETTING_ONLY_SILENT
: AudioManager.VIBRATE_SETTING_OFF);
@@ -935,7 +883,7 @@ public class AudioService extends IAudioService.Stub {
}
mMuteAffectedStreams = System.getIntForUser(cr,
System.MUTE_STREAMS_AFFECTED, DEFAULT_MUTE_STREAMS_AFFECTED,
System.MUTE_STREAMS_AFFECTED, AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED,
UserHandle.USER_CURRENT);
boolean masterMute = System.getIntForUser(cr, System.VOLUME_MASTER_MUTE,
@@ -1746,10 +1694,6 @@ public class AudioService extends IAudioService.Stub {
return MAX_STREAM_VOLUME[streamType];
}
public static int getDefaultStreamVolume(int streamType) {
return DEFAULT_STREAM_VOLUME[streamType];
}
/** @see AudioManager#getStreamVolume(int) */
public int getStreamVolume(int streamType) {
ensureValidStreamType(streamType);
@@ -2044,29 +1988,14 @@ public class AudioService extends IAudioService.Stub {
if (!mHasVibrator) return;
mVibrateSetting = getValueForVibrateSetting(mVibrateSetting, vibrateType, vibrateSetting);
mVibrateSetting = AudioSystem.getValueForVibrateSetting(mVibrateSetting, vibrateType,
vibrateSetting);
// Broadcast change
broadcastVibrateSetting(vibrateType);
}
/**
* @see #setVibrateSetting(int, int)
*/
public static int getValueForVibrateSetting(int existingValue, int vibrateType,
int vibrateSetting) {
// First clear the existing setting. Each vibrate type has two bits in
// the value. Note '3' is '11' in binary.
existingValue &= ~(3 << (vibrateType * 2));
// Set into the old value
existingValue |= (vibrateSetting & 3) << (vibrateType * 2);
return existingValue;
}
private class SetModeDeathHandler implements IBinder.DeathRecipient {
private IBinder mCb; // To be notified of client's death
private int mPid;
@@ -3245,7 +3174,7 @@ public class AudioService extends IAudioService.Stub {
(1 << AudioSystem.STREAM_SYSTEM);
switch (mPlatformType) {
case PLATFORM_TELEVISION:
case AudioSystem.PLATFORM_TELEVISION:
ringerModeAffectedStreams = 0;
break;
default:
@@ -3338,7 +3267,7 @@ public class AudioService extends IAudioService.Stub {
private int getActiveStreamType(int suggestedStreamType) {
switch (mPlatformType) {
case PLATFORM_VOICE:
case AudioSystem.PLATFORM_VOICE:
if (isInCommunication()) {
if (AudioSystem.getForceUse(AudioSystem.FOR_COMMUNICATION)
== AudioSystem.FORCE_BT_SCO) {
@@ -3364,7 +3293,7 @@ public class AudioService extends IAudioService.Stub {
return AudioSystem.STREAM_MUSIC;
}
break;
case PLATFORM_TELEVISION:
case AudioSystem.PLATFORM_TELEVISION:
if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {
// TV always defaults to STREAM_MUSIC
return AudioSystem.STREAM_MUSIC;
@@ -3599,7 +3528,7 @@ public class AudioService extends IAudioService.Stub {
// only be stale values
if ((mStreamType == AudioSystem.STREAM_SYSTEM) ||
(mStreamType == AudioSystem.STREAM_SYSTEM_ENFORCED)) {
int index = 10 * DEFAULT_STREAM_VOLUME[mStreamType];
int index = 10 * AudioSystem.DEFAULT_STREAM_VOLUME[mStreamType];
synchronized (mCameraSoundForced) {
if (mCameraSoundForced) {
index = mIndexMax;
@@ -3623,7 +3552,7 @@ public class AudioService extends IAudioService.Stub {
// if no volume stored for current stream and device, use default volume if default
// device, continue otherwise
int defaultIndex = (device == AudioSystem.DEVICE_OUT_DEFAULT) ?
DEFAULT_STREAM_VOLUME[mStreamType] : -1;
AudioSystem.DEFAULT_STREAM_VOLUME[mStreamType] : -1;
int index = Settings.System.getIntForUser(
mContentResolver, name, defaultIndex, UserHandle.USER_CURRENT);
if (index == -1) {
@@ -4497,8 +4426,8 @@ public class AudioService extends IAudioService.Stub {
mConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP);
synchronized (mCurAudioRoutes) {
// Remove A2DP routes as well
if (mCurAudioRoutes.mBluetoothName != null) {
mCurAudioRoutes.mBluetoothName = null;
if (mCurAudioRoutes.bluetoothName != null) {
mCurAudioRoutes.bluetoothName = null;
sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
SENDMSG_NOOP, 0, 0, null, 0);
}
@@ -4578,8 +4507,8 @@ public class AudioService extends IAudioService.Stub {
makeA2dpDeviceUnavailableNow(address);
}
synchronized (mCurAudioRoutes) {
if (mCurAudioRoutes.mBluetoothName != null) {
mCurAudioRoutes.mBluetoothName = null;
if (mCurAudioRoutes.bluetoothName != null) {
mCurAudioRoutes.bluetoothName = null;
sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
SENDMSG_NOOP, 0, 0, null, 0);
}
@@ -4600,8 +4529,8 @@ public class AudioService extends IAudioService.Stub {
makeA2dpDeviceAvailable(address);
synchronized (mCurAudioRoutes) {
String name = btDevice.getAliasName();
if (!TextUtils.equals(mCurAudioRoutes.mBluetoothName, name)) {
mCurAudioRoutes.mBluetoothName = name;
if (!TextUtils.equals(mCurAudioRoutes.bluetoothName, name)) {
mCurAudioRoutes.bluetoothName = name;
sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
SENDMSG_NOOP, 0, 0, null, 0);
}
@@ -4757,14 +4686,14 @@ public class AudioService extends IAudioService.Stub {
synchronized (mCurAudioRoutes) {
if (connType != 0) {
int newConn = mCurAudioRoutes.mMainType;
int newConn = mCurAudioRoutes.mainType;
if (state != 0) {
newConn |= connType;
} else {
newConn &= ~connType;
}
if (newConn != mCurAudioRoutes.mMainType) {
mCurAudioRoutes.mMainType = newConn;
if (newConn != mCurAudioRoutes.mainType) {
mCurAudioRoutes.mainType = newConn;
sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
SENDMSG_NOOP, 0, 0, null, 0);
}
@@ -5096,7 +5025,7 @@ public class AudioService extends IAudioService.Stub {
IAudioPolicyCallback pcb) {
// permission checks
if ((flags & AudioManager.AUDIOFOCUS_FLAG_LOCK) == AudioManager.AUDIOFOCUS_FLAG_LOCK) {
if (mMediaFocusControl.IN_VOICE_COMM_FOCUS_ID.equals(clientId)) {
if (AudioSystem.IN_VOICE_COMM_FOCUS_ID.equals(clientId)) {
if (PackageManager.PERMISSION_GRANTED != mContext.checkCallingOrSelfPermission(
android.Manifest.permission.MODIFY_PHONE_STATE)) {
Log.e(TAG, "Invalid permission to (un)lock audio focus", new Exception());
@@ -5564,8 +5493,8 @@ public class AudioService extends IAudioService.Stub {
dumpStreamStates(pw);
dumpRingerMode(pw);
pw.println("\nAudio routes:");
pw.print(" mMainType=0x"); pw.println(Integer.toHexString(mCurAudioRoutes.mMainType));
pw.print(" mBluetoothName="); pw.println(mCurAudioRoutes.mBluetoothName);
pw.print(" mMainType=0x"); pw.println(Integer.toHexString(mCurAudioRoutes.mainType));
pw.print(" mBluetoothName="); pw.println(mCurAudioRoutes.bluetoothName);
pw.println("\nOther state:");
pw.print(" mVolumeController="); pw.println(mVolumeController);

View File

@@ -14,13 +14,18 @@
* limitations under the License.
*/
package android.media;
package com.android.server.audio;
import android.annotation.NonNull;
import android.media.MediaFocusControl.AudioFocusDeathHandler;
import android.media.AudioAttributes;
import android.media.AudioFocusInfo;
import android.media.AudioManager;
import android.media.IAudioFocusDispatcher;
import android.os.IBinder;
import android.util.Log;
import com.android.server.audio.MediaFocusControl.AudioFocusDeathHandler;
import java.io.PrintWriter;
/**
@@ -29,7 +34,7 @@ import java.io.PrintWriter;
* instance is managed by android.media.MediaFocusControl, from its addition to the audio focus
* stack to its release.
*/
class FocusRequester {
public class FocusRequester {
// on purpose not using this classe's name, as it will only be used from MediaFocusControl
private static final String TAG = "MediaFocusControl";

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package android.media;
package com.android.server.audio;
import android.app.Activity;
import android.app.ActivityManager;
@@ -32,7 +32,17 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.media.PlayerRecord.RemotePlaybackState;
import android.media.AudioAttributes;
import android.media.AudioFocusInfo;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.IAudioFocusDispatcher;
import android.media.IAudioService;
import android.media.IRemoteControlClient;
import android.media.IRemoteControlDisplay;
import android.media.IRemoteVolumeObserver;
import android.media.RemoteControlClient;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.audiopolicy.IAudioPolicyCallback;
import android.net.Uri;
import android.os.Binder;
@@ -53,6 +63,8 @@ import android.util.Log;
import android.util.Slog;
import android.view.KeyEvent;
import com.android.server.audio.PlayerRecord.RemotePlaybackState;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
@@ -391,13 +403,6 @@ public class MediaFocusControl implements OnFinished {
// AudioFocus
//==========================================================================================
/**
* Constant to identify a focus stack entry that is used to hold the focus while the phone
* is ringing or during a call. Used by com.android.internal.telephony.CallManager when
* entering and exiting calls.
*/
protected final static String IN_VOICE_COMM_FOCUS_ID = "AudioFocus_For_Phone_Ring_And_Calls";
private final static Object mAudioFocusLock = new Object();
private final static Object mRingingLock = new Object();
@@ -565,7 +570,7 @@ public class MediaFocusControl implements OnFinished {
}
private boolean isLockedFocusOwner(FocusRequester fr) {
return (fr.hasSameClient(IN_VOICE_COMM_FOCUS_ID) || fr.isLockedFocusOwner());
return (fr.hasSameClient(AudioSystem.IN_VOICE_COMM_FOCUS_ID) || fr.isLockedFocusOwner());
}
/**

View File

@@ -14,10 +14,14 @@
* limitations under the License.
*/
package android.media;
package com.android.server.audio;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.media.AudioManager;
import android.media.IRemoteControlClient;
import android.media.IRemoteVolumeObserver;
import android.media.RemoteControlClient;
import android.os.Binder;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;

View File

@@ -29,7 +29,6 @@ import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.media.AudioService;
import android.media.tv.TvInputManager;
import android.os.Build;
import android.os.Environment;
@@ -60,6 +59,7 @@ import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accounts.AccountManagerService;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.BatteryStatsService;
import com.android.server.audio.AudioService;
import com.android.server.clipboard.ClipboardService;
import com.android.server.content.ContentService;
import com.android.server.devicepolicy.DevicePolicyManagerService;

View File

@@ -24,7 +24,6 @@ import android.content.res.Resources;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbInterface;
import android.media.AudioService;
import android.media.AudioSystem;
import android.media.IAudioService;
import android.midi.MidiDeviceInfo;
@@ -38,6 +37,8 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.util.Slog;
import com.android.server.audio.AudioService;
import libcore.io.IoUtils;
import java.io.File;