summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
authorRicardo Cerqueira <cyanogenmod@cerqueira.org>2013-02-13 14:24:59 +0000
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2013-02-15 00:30:09 +0000
commit4815d6e5a658bb1b301f7724c8e8fff6bc764bba (patch)
tree66f6e6484d239545197d73bcca8ad2505246c981 /media/java
parenteaa7d1835c8691dd656fea99ae3d61b039ebe1b7 (diff)
parent763ef60466ac752a3031719fb86b08486c9946b1 (diff)
downloadframeworks_base-4815d6e5a658bb1b301f7724c8e8fff6bc764bba.zip
frameworks_base-4815d6e5a658bb1b301f7724c8e8fff6bc764bba.tar.gz
frameworks_base-4815d6e5a658bb1b301f7724c8e8fff6bc764bba.tar.bz2
Merge commit 'android-4.2.2_r1' into mr1.1-staging
Conflicts: core/java/android/os/Trace.java core/java/android/widget/Toast.java core/res/res/values-cs/strings.xml core/res/res/values-el/strings.xml core/res/res/values-iw/strings.xml core/res/res/values/config.xml core/res/res/values/symbols.xml media/java/android/media/AudioService.java packages/SystemUI/res/values-sv/strings.xml packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java policy/src/com/android/internal/policy/impl/keyguard/KeyguardMessageArea.java policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewManager.java policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java services/java/com/android/server/NotificationManagerService.java services/java/com/android/server/power/ElectronBeam.java Change-Id: I60b8ddf20a1d7bcf9dc7b1a4ed841aaa4d953294
Diffstat (limited to 'media/java')
-rwxr-xr-xmedia/java/android/media/AudioService.java210
-rw-r--r--media/java/android/media/MediaFormat.java8
-rw-r--r--media/java/android/media/MediaRouter.java18
3 files changed, 152 insertions, 84 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 1b0675a..5c4b315 100755
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -163,6 +163,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
private static final int MSG_BROADCAST_AUDIO_BECOMING_NOISY = 25;
private static final int MSG_CONFIGURE_SAFE_MEDIA_VOLUME = 26;
private static final int MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED = 27;
+ private static final int MSG_PERSIST_SAFE_VOLUME_STATE = 28;
// flags for MSG_PERSIST_VOLUME indicating if current and/or last audible volume should be
// persisted
@@ -445,6 +446,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
private boolean mDockAudioMediaEnabled = true;
+ private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
+
///////////////////////////////////////////////////////////////////////////
// Construction
///////////////////////////////////////////////////////////////////////////
@@ -488,6 +491,14 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
null,
0);
+ mSafeMediaVolumeState = new Integer(Settings.Global.getInt(mContentResolver,
+ Settings.Global.AUDIO_SAFE_VOLUME_STATE,
+ SAFE_MEDIA_VOLUME_NOT_CONFIGURED));
+ // The default safe volume index read here will be replaced by the actual value when
+ // the mcc is read by onConfigureSafeVolume()
+ mSafeMediaVolumeIndex = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_safe_media_volume_index) * 10;
+
readPersistedSettings();
mSettingsObserver = new SettingsObserver();
updateStreamVolumeAlias(false /*updateVolumes*/);
@@ -495,8 +506,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
mMediaServerOk = true;
- mSafeMediaVolumeState = new Integer(SAFE_MEDIA_VOLUME_NOT_CONFIGURED);
-
// Call setRingerModeInt() to apply correct mute
// state on streams affected by ringer mode.
mRingerModeMutedStreams = 0;
@@ -862,70 +871,72 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
// convert one UI step (+/-1) into a number of internal units on the stream alias
int step = rescaleIndex(10, streamType, streamTypeAlias);
- if ((direction == AudioManager.ADJUST_RAISE) &&
- !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
- return;
- }
-
int index;
int oldIndex;
- flags &= ~AudioManager.FLAG_FIXED_VOLUME;
- if ((streamTypeAlias == AudioSystem.STREAM_MUSIC) &&
- ((device & mFixedVolumeDevices) != 0)) {
- flags |= AudioManager.FLAG_FIXED_VOLUME;
- index = mStreamStates[streamType].getMaxIndex();
+ if ((direction == AudioManager.ADJUST_RAISE) &&
+ !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
+ index = mStreamStates[streamType].getIndex(device,
+ (streamState.muteCount() != 0) /* lastAudible */);
oldIndex = index;
} else {
- // If either the client forces allowing ringer modes for this adjustment,
- // or the stream type is one that is affected by ringer modes
- if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
- (streamTypeAlias == getMasterStreamType())) {
- int ringerMode = getRingerMode();
- // do not vibrate if already in vibrate mode
- if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
- flags &= ~AudioManager.FLAG_VIBRATE;
- }
- // Check if the ringer mode changes with this volume adjustment. If
- // it does, it will handle adjusting the volume, so we won't below
- adjustVolume = checkForRingerModeChange(aliasIndex, direction, step);
- if ((streamTypeAlias == getMasterStreamType()) &&
- (mRingerMode == AudioManager.RINGER_MODE_SILENT)) {
- streamState.setLastAudibleIndex(0, device);
- }
- }
-
- // If stream is muted, adjust last audible index only
- oldIndex = mStreamStates[streamType].getIndex(device,
- (mStreamStates[streamType].muteCount() != 0) /* lastAudible */);
-
- if (streamState.muteCount() != 0) {
- if (adjustVolume) {
- // Post a persist volume msg
- // no need to persist volume on all streams sharing the same alias
- streamState.adjustLastAudibleIndex(direction * step, device);
- sendMsg(mAudioHandler,
- MSG_PERSIST_VOLUME,
- SENDMSG_QUEUE,
- PERSIST_LAST_AUDIBLE,
- device,
- streamState,
- PERSIST_DELAY);
- }
- index = mStreamStates[streamType].getIndex(device, true /* lastAudible */);
+ flags &= ~AudioManager.FLAG_FIXED_VOLUME;
+ if ((streamTypeAlias == AudioSystem.STREAM_MUSIC) &&
+ ((device & mFixedVolumeDevices) != 0)) {
+ flags |= AudioManager.FLAG_FIXED_VOLUME;
+ index = mStreamStates[streamType].getMaxIndex();
+ oldIndex = index;
} else {
- if (adjustVolume && streamState.adjustIndex(direction * step, device)) {
- // Post message to set system volume (it in turn will post a message
- // to persist). Do not change volume if stream is muted.
- sendMsg(mAudioHandler,
- MSG_SET_DEVICE_VOLUME,
- SENDMSG_QUEUE,
- device,
- 0,
- streamState,
- 0);
+ // If either the client forces allowing ringer modes for this adjustment,
+ // or the stream type is one that is affected by ringer modes
+ if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
+ (streamTypeAlias == getMasterStreamType())) {
+ int ringerMode = getRingerMode();
+ // do not vibrate if already in vibrate mode
+ if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
+ flags &= ~AudioManager.FLAG_VIBRATE;
+ }
+ // Check if the ringer mode changes with this volume adjustment. If
+ // it does, it will handle adjusting the volume, so we won't below
+ adjustVolume = checkForRingerModeChange(aliasIndex, direction, step);
+ if ((streamTypeAlias == getMasterStreamType()) &&
+ (mRingerMode == AudioManager.RINGER_MODE_SILENT)) {
+ streamState.setLastAudibleIndex(0, device);
+ }
+ }
+
+ // If stream is muted, adjust last audible index only
+ oldIndex = mStreamStates[streamType].getIndex(device,
+ (mStreamStates[streamType].muteCount() != 0) /* lastAudible */);
+
+ if (streamState.muteCount() != 0) {
+ if (adjustVolume) {
+ // Post a persist volume msg
+ // no need to persist volume on all streams sharing the same alias
+ streamState.adjustLastAudibleIndex(direction * step, device);
+ sendMsg(mAudioHandler,
+ MSG_PERSIST_VOLUME,
+ SENDMSG_QUEUE,
+ PERSIST_LAST_AUDIBLE,
+ device,
+ streamState,
+ PERSIST_DELAY);
+ }
+ index = mStreamStates[streamType].getIndex(device, true /* lastAudible */);
+ } else {
+ if (adjustVolume && streamState.adjustIndex(direction * step, device)) {
+ // Post message to set system volume (it in turn will post a message
+ // to persist). Do not change volume if stream is muted.
+ sendMsg(mAudioHandler,
+ MSG_SET_DEVICE_VOLUME,
+ SENDMSG_QUEUE,
+ device,
+ 0,
+ streamState,
+ 0);
+ }
+ index = mStreamStates[streamType].getIndex(device, false /* lastAudible */);
}
- index = mStreamStates[streamType].getIndex(device, false /* lastAudible */);
}
}
sendVolumeUpdate(streamType, oldIndex, index, flags);
@@ -2353,13 +2364,33 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
if ((mMcc != mcc) || ((mMcc == 0) && force)) {
mSafeMediaVolumeIndex = mContext.getResources().getInteger(
com.android.internal.R.integer.config_safe_media_volume_index) * 10;
- if (mSafeVolumeEnabled) {
- mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
- enforceSafeMediaVolume();
+ boolean safeMediaVolumeEnabled = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_safe_media_volume_enabled);
+
+ // The persisted state is either "disabled" or "active": this is the state applied
+ // next time we boot and cannot be "inactive"
+ int persistedState;
+ if (safeMediaVolumeEnabled) {
+ persistedState = SAFE_MEDIA_VOLUME_ACTIVE;
+ // The state can already be "inactive" here if the user has forced it before
+ // the 30 seconds timeout for forced configuration. In this case we don't reset
+ // it to "active".
+ if (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_INACTIVE) {
+ mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
+ enforceSafeMediaVolume();
+ }
} else {
+ persistedState = SAFE_MEDIA_VOLUME_DISABLED;
mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED;
}
mMcc = mcc;
+ sendMsg(mAudioHandler,
+ MSG_PERSIST_SAFE_VOLUME_STATE,
+ SENDMSG_QUEUE,
+ persistedState,
+ 0,
+ null,
+ 0);
}
}
}
@@ -3278,6 +3309,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
AudioSystem.setForceUse(usage, config);
}
+ private void onPersistSafeVolumeState(int state) {
+ Settings.Global.putInt(mContentResolver,
+ Settings.Global.AUDIO_SAFE_VOLUME_STATE,
+ state);
+ }
+
@Override
public void handleMessage(Message msg) {
@@ -3380,6 +3417,13 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
mBluetoothA2dpEnabled ?
AudioSystem.FORCE_NONE : AudioSystem.FORCE_NO_BT_A2DP);
}
+
+ synchronized (mSettingsLock) {
+ AudioSystem.setForceUse(AudioSystem.FOR_DOCK,
+ mDockAudioMediaEnabled ?
+ AudioSystem.FORCE_ANALOG_DOCK : AudioSystem.FORCE_NONE);
+ }
+
// indicate the end of reconfiguration phase to audio HAL
AudioSystem.setParameters("restarting=false");
break;
@@ -3480,6 +3524,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
case MSG_CONFIGURE_SAFE_MEDIA_VOLUME:
onConfigureSafeVolume((msg.what == MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED));
break;
+ case MSG_PERSIST_SAFE_VOLUME_STATE:
+ onPersistSafeVolumeState(msg.arg1);
+ break;
}
}
}
@@ -3830,13 +3877,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
config = AudioSystem.FORCE_BT_CAR_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_LE_DESK:
- synchronized (mSettingsLock) {
- if (mDockAudioMediaEnabled) {
- config = AudioSystem.FORCE_ANALOG_DOCK;
- } else {
- config = AudioSystem.FORCE_NONE;
- }
- }
+ config = AudioSystem.FORCE_ANALOG_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_HE_DESK:
config = AudioSystem.FORCE_DIGITAL_DOCK;
@@ -3846,7 +3887,14 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
config = AudioSystem.FORCE_NONE;
}
- AudioSystem.setForceUse(AudioSystem.FOR_DOCK, config);
+ // Low end docks have a menu to enable or disable audio
+ // (see mDockAudioMediaEnabled)
+ if (!((dockState == Intent.EXTRA_DOCK_STATE_LE_DESK) ||
+ ((dockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) &&
+ (mDockState == Intent.EXTRA_DOCK_STATE_LE_DESK)))) {
+ AudioSystem.setForceUse(AudioSystem.FOR_DOCK, config);
+ }
+ mDockState = dockState;
} else if (action.equals(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED) && noDelayInATwoDP) {
state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
BluetoothProfile.STATE_DISCONNECTED);
@@ -5317,18 +5365,23 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
// top of the stack for the media button event receivers : simply using the top of the
// stack would make the entry disappear from the RemoteControlDisplay in conditions such as
// notifications playing during music playback.
- // crawl the AudioFocus stack until an entry is found with the following characteristics:
+ // Crawl the AudioFocus stack from the top until an entry is found with the following
+ // characteristics:
// - focus gain on STREAM_MUSIC stream
// - non-transient focus gain on a stream other than music
FocusStackEntry af = null;
- Iterator<FocusStackEntry> stackIterator = mFocusStack.iterator();
- while(stackIterator.hasNext()) {
- FocusStackEntry fse = (FocusStackEntry)stackIterator.next();
- if ((fse.mStreamType == AudioManager.STREAM_MUSIC)
- || (fse.mFocusChangeType == AudioManager.AUDIOFOCUS_GAIN)) {
- af = fse;
- break;
+ try {
+ for (int index = mFocusStack.size()-1; index >= 0; index--) {
+ FocusStackEntry fse = mFocusStack.elementAt(index);
+ if ((fse.mStreamType == AudioManager.STREAM_MUSIC)
+ || (fse.mFocusChangeType == AudioManager.AUDIOFOCUS_GAIN)) {
+ af = fse;
+ break;
+ }
}
+ } catch (ArrayIndexOutOfBoundsException e) {
+ Log.e(TAG, "Wrong index accessing audio focus stack when updating RCD: " + e);
+ af = null;
}
if (af == null) {
clearRemoteControlDisplay_syncAfRcs();
@@ -5349,6 +5402,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
clearRemoteControlDisplay_syncAfRcs();
return;
}
+
// refresh conditions were verified: update the remote controls
// ok to call: synchronized mAudioFocusLock then on mRCStack, mRCStack is not empty
updateRemoteControlDisplay_syncAfRcs(infoChangedFlags);
diff --git a/media/java/android/media/MediaFormat.java b/media/java/android/media/MediaFormat.java
index 4414191..a2eb8d9 100644
--- a/media/java/android/media/MediaFormat.java
+++ b/media/java/android/media/MediaFormat.java
@@ -26,7 +26,7 @@ import java.util.Map;
*
* The format of the media data is specified as string/value pairs.
*
- * Keys common to all formats:
+ * Keys common to all formats, <b>all keys not marked optional are mandatory</b>:
*
* <table>
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
@@ -50,9 +50,9 @@ import java.util.Map;
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
* <tr><td>{@link #KEY_CHANNEL_COUNT}</td><td>Integer</td><td></td></tr>
* <tr><td>{@link #KEY_SAMPLE_RATE}</td><td>Integer</td><td></td></tr>
- * <tr><td>{@link #KEY_IS_ADTS}</td><td>Integer</td><td>optional, if content is AAC audio, setting this key to 1 indicates that each audio frame is prefixed by the ADTS header.</td></tr>
+ * <tr><td>{@link #KEY_IS_ADTS}</td><td>Integer</td><td>optional, if <em>decoding</em> AAC audio content, setting this key to 1 indicates that each audio frame is prefixed by the ADTS header.</td></tr>
* <tr><td>{@link #KEY_AAC_PROFILE}</td><td>Integer</td><td><b>encoder-only</b>, optional, if content is AAC audio, specifies the desired profile.</td></tr>
- * <tr><td>{@link #KEY_CHANNEL_MASK}</td><td>Integer</td><td>A mask of audio channel assignments</td></tr>
+ * <tr><td>{@link #KEY_CHANNEL_MASK}</td><td>Integer</td><td>optional, a mask of audio channel assignments</td></tr>
* <tr><td>{@link #KEY_FLAC_COMPRESSION_LEVEL}</td><td>Integer</td><td><b>encoder-only</b>, optional, if content is FLAC audio, specifies the desired compression level.</td></tr>
* </table>
*
@@ -140,6 +140,8 @@ public final class MediaFormat {
* A key mapping to a value of 1 if the content is AAC audio and
* audio frames are prefixed with an ADTS header.
* The associated value is an integer (0 or 1).
+ * This key is only supported when _decoding_ content, it cannot
+ * be used to configure an encoder to emit ADTS output.
*/
public static final String KEY_IS_ADTS = "is-adts";
diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java
index 2a5a16e..8b489b1 100644
--- a/media/java/android/media/MediaRouter.java
+++ b/media/java/android/media/MediaRouter.java
@@ -313,13 +313,25 @@ public class MediaRouter {
}
/**
- * Return the currently selected route for the given types
+ * Return the currently selected route for any of the given types
*
* @param type route types
* @return the selected route
*/
public RouteInfo getSelectedRoute(int type) {
- return sStatic.mSelectedRoute;
+ if (sStatic.mSelectedRoute != null &&
+ (sStatic.mSelectedRoute.mSupportedTypes & type) != 0) {
+ // If the selected route supports any of the types supplied, it's still considered
+ // 'selected' for that type.
+ return sStatic.mSelectedRoute;
+ } else if (type == ROUTE_TYPE_USER) {
+ // The caller specifically asked for a user route and the currently selected route
+ // doesn't qualify.
+ return null;
+ }
+ // If the above didn't match and we're not specifically asking for a user route,
+ // consider the default selected.
+ return sStatic.mDefaultAudioVideo;
}
/**
@@ -862,7 +874,7 @@ public class MediaRouter {
private static WifiDisplay findMatchingDisplay(WifiDisplay d, WifiDisplay[] displays) {
for (int i = 0; i < displays.length; i++) {
final WifiDisplay other = displays[i];
- if (d.getDeviceAddress().equals(other.getDeviceAddress())) {
+ if (d.hasSameAddress(other)) {
return other;
}
}