Merge "Make conversion functions non-inline" into pi-dev
diff --git a/packages/MediaComponents/Android.mk b/packages/MediaComponents/Android.mk
index b6480a2..b0d8e7d 100644
--- a/packages/MediaComponents/Android.mk
+++ b/packages/MediaComponents/Android.mk
@@ -40,9 +40,6 @@
LOCAL_PROGUARD_FLAG_FILES := proguard.cfg
-# TODO: Enable proguard (b/74090741)
-LOCAL_PROGUARD_ENABLED := disabled
-
LOCAL_MULTILIB := first
LOCAL_JAVA_LIBRARIES += android-support-annotations
diff --git a/packages/MediaComponents/src/com/android/media/MediaSession2Impl.java b/packages/MediaComponents/src/com/android/media/MediaSession2Impl.java
index 2b7c72a..89c29e6 100644
--- a/packages/MediaComponents/src/com/android/media/MediaSession2Impl.java
+++ b/packages/MediaComponents/src/com/android/media/MediaSession2Impl.java
@@ -48,6 +48,7 @@
import android.media.MediaSession2.CommandButton;
import android.media.MediaSession2.CommandGroup;
import android.media.MediaSession2.ControllerInfo;
+import android.media.MediaSession2.OnDataSourceMissingHelper;
import android.media.MediaSession2.SessionCallback;
import android.media.MediaSessionService2;
import android.media.SessionToken2;
@@ -61,7 +62,6 @@
import android.os.ResultReceiver;
import android.support.annotation.GuardedBy;
import android.text.TextUtils;
-import android.util.ArrayMap;
import android.util.Log;
import java.lang.ref.WeakReference;
@@ -111,9 +111,13 @@
@GuardedBy("mLock")
private MediaPlaylistAgent mPlaylistAgent;
@GuardedBy("mLock")
+ private SessionPlaylistAgent mSessionPlaylistAgent;
+ @GuardedBy("mLock")
private VolumeProvider2 mVolumeProvider;
@GuardedBy("mLock")
private PlaybackInfo mPlaybackInfo;
+ @GuardedBy("mLock")
+ private OnDataSourceMissingHelper mDsmHelper;
/**
* Can be only called by the {@link Builder#build()}.
@@ -207,7 +211,7 @@
}
@Override
- public void updatePlayer_impl(MediaPlayerBase player, MediaPlaylistAgent playlistAgent,
+ public void updatePlayer_impl(@NonNull MediaPlayerBase player, MediaPlaylistAgent playlistAgent,
VolumeProvider2 volumeProvider) throws IllegalArgumentException {
ensureCallingThread();
if (player == null) {
@@ -225,9 +229,12 @@
oldPlayer = mPlayer;
oldAgent = mPlaylistAgent;
mPlayer = player;
- // TODO(jaewan): Replace this with the proper default agent (b/74090741)
if (agent == null) {
- agent = new MediaPlaylistAgent(mContext) {};
+ mSessionPlaylistAgent = new SessionPlaylistAgent(mContext, this, mPlayer);
+ if (mDsmHelper != null) {
+ mSessionPlaylistAgent.setOnDataSourceMissingHelper(mDsmHelper);
+ }
+ agent = mSessionPlaylistAgent;
}
mPlaylistAgent = agent;
mVolumeProvider = volumeProvider;
@@ -312,6 +319,7 @@
mPlayer = null;
agent = mPlaylistAgent;
mPlaylistAgent = null;
+ mSessionPlaylistAgent = null;
}
if (player != null) {
player.unregisterPlayerEventCallback(mPlayerEventCallback);
@@ -385,7 +393,7 @@
}
@Override
- public void skipToPlaylistItem_impl(MediaItem2 item) {
+ public void skipToPlaylistItem_impl(@NonNull MediaItem2 item) {
if (item == null) {
throw new IllegalArgumentException("item shouldn't be null");
}
@@ -418,7 +426,8 @@
}
@Override
- public void setCustomLayout_impl(ControllerInfo controller, List<CommandButton> layout) {
+ public void setCustomLayout_impl(@NonNull ControllerInfo controller,
+ @NonNull List<CommandButton> layout) {
ensureCallingThread();
if (controller == null) {
throw new IllegalArgumentException("controller shouldn't be null");
@@ -434,7 +443,8 @@
//////////////////////////////////////////////////////////////////////////////////////
@Override
- public void setAllowedCommands_impl(ControllerInfo controller, CommandGroup commands) {
+ public void setAllowedCommands_impl(@NonNull ControllerInfo controller,
+ @NonNull CommandGroup commands) {
if (controller == null) {
throw new IllegalArgumentException("controller shouldn't be null");
}
@@ -445,8 +455,8 @@
}
@Override
- public void sendCustomCommand_impl(ControllerInfo controller, Command command, Bundle args,
- ResultReceiver receiver) {
+ public void sendCustomCommand_impl(@NonNull ControllerInfo controller, @NonNull Command command,
+ Bundle args, ResultReceiver receiver) {
if (controller == null) {
throw new IllegalArgumentException("controller shouldn't be null");
}
@@ -457,7 +467,7 @@
}
@Override
- public void sendCustomCommand_impl(Command command, Bundle args) {
+ public void sendCustomCommand_impl(@NonNull Command command, Bundle args) {
if (command == null) {
throw new IllegalArgumentException("command shouldn't be null");
}
@@ -465,7 +475,7 @@
}
@Override
- public void setPlaylist_impl(List<MediaItem2> list, MediaMetadata2 metadata) {
+ public void setPlaylist_impl(@NonNull List<MediaItem2> list, MediaMetadata2 metadata) {
if (list == null) {
throw new IllegalArgumentException("list shouldn't be null");
}
@@ -489,7 +499,7 @@
}
@Override
- public void addPlaylistItem_impl(int index, MediaItem2 item) {
+ public void addPlaylistItem_impl(int index, @NonNull MediaItem2 item) {
if (index < 0) {
throw new IllegalArgumentException("index shouldn't be negative");
}
@@ -505,7 +515,7 @@
}
@Override
- public void removePlaylistItem_impl(MediaItem2 item) {
+ public void removePlaylistItem_impl(@NonNull MediaItem2 item) {
if (item == null) {
throw new IllegalArgumentException("item shouldn't be null");
}
@@ -518,7 +528,7 @@
}
@Override
- public void replacePlaylistItem_impl(int index, MediaItem2 item) {
+ public void replacePlaylistItem_impl(int index, @NonNull MediaItem2 item) {
if (index < 0) {
throw new IllegalArgumentException("index shouldn't be negative");
}
@@ -685,6 +695,29 @@
mSessionStub.notifyError(errorCode, extras);
}
+ @Override
+ public void setOnDataSourceMissingHelper_impl(@NonNull OnDataSourceMissingHelper helper) {
+ if (helper == null) {
+ throw new IllegalArgumentException("helper shouldn't be null");
+ }
+ synchronized (mLock) {
+ mDsmHelper = helper;
+ if (mSessionPlaylistAgent != null) {
+ mSessionPlaylistAgent.setOnDataSourceMissingHelper(helper);
+ }
+ }
+ }
+
+ @Override
+ public void clearOnDataSourceMissingHelper_impl() {
+ synchronized (mLock) {
+ mDsmHelper = null;
+ if (mSessionPlaylistAgent != null) {
+ mSessionPlaylistAgent.clearOnDataSourceMissingHelper();
+ }
+ }
+ }
+
///////////////////////////////////////////////////
// Protected or private methods
///////////////////////////////////////////////////
@@ -1022,7 +1055,7 @@
/**
* @return a new Command instance from the Bundle
*/
- public static Command fromBundle_impl(Context context, Bundle command) {
+ public static Command fromBundle_impl(Context context, @NonNull Bundle command) {
if (command == null) {
throw new IllegalArgumentException("command shouldn't be null");
}
@@ -1092,7 +1125,7 @@
}
@Override
- public void addCommand_impl(Command command) {
+ public void addCommand_impl(@NonNull Command command) {
if (command == null) {
throw new IllegalArgumentException("command shouldn't be null");
}
@@ -1129,7 +1162,7 @@
}
@Override
- public void removeCommand_impl(Command command) {
+ public void removeCommand_impl(@NonNull Command command) {
if (command == null) {
throw new IllegalArgumentException("command shouldn't be null");
}
@@ -1137,7 +1170,7 @@
}
@Override
- public boolean hasCommand_impl(Command command) {
+ public boolean hasCommand_impl(@NonNull Command command) {
if (command == null) {
throw new IllegalArgumentException("command shouldn't be null");
}
@@ -1217,7 +1250,7 @@
private final IMediaController2 mControllerBinder;
public ControllerInfoImpl(Context context, ControllerInfo instance, int uid,
- int pid, String packageName, IMediaController2 callback) {
+ int pid, @NonNull String packageName, @NonNull IMediaController2 callback) {
if (TextUtils.isEmpty(packageName)) {
throw new IllegalArgumentException("packageName shouldn't be empty");
}
@@ -1234,7 +1267,7 @@
// Ask server whether the controller is trusted.
// App cannot know this because apps cannot query enabled notification listener for
// another package, but system server can do.
- mIsTrusted = manager.isTrusted(uid, packageName);
+ mIsTrusted = manager.isTrusted(packageName, pid, uid);
}
@Override
@@ -1468,7 +1501,7 @@
* {@link MediaSession2} or {@link MediaController2}.
*/
// TODO(jaewan): Also need executor
- public BuilderBaseImpl(Context context) {
+ public BuilderBaseImpl(@NonNull Context context) {
if (context == null) {
throw new IllegalArgumentException("context shouldn't be null");
}
@@ -1478,7 +1511,7 @@
}
@Override
- public void setPlayer_impl(MediaPlayerBase player) {
+ public void setPlayer_impl(@NonNull MediaPlayerBase player) {
if (player == null) {
throw new IllegalArgumentException("player shouldn't be null");
}
@@ -1486,7 +1519,7 @@
}
@Override
- public void setPlaylistAgent_impl(MediaPlaylistAgent playlistAgent) {
+ public void setPlaylistAgent_impl(@NonNull MediaPlaylistAgent playlistAgent) {
if (playlistAgent == null) {
throw new IllegalArgumentException("playlistAgent shouldn't be null");
}
@@ -1504,7 +1537,7 @@
}
@Override
- public void setId_impl(String id) {
+ public void setId_impl(@NonNull String id) {
if (id == null) {
throw new IllegalArgumentException("id shouldn't be null");
}
@@ -1512,7 +1545,7 @@
}
@Override
- public void setSessionCallback_impl(Executor executor, C callback) {
+ public void setSessionCallback_impl(@NonNull Executor executor, @NonNull C callback) {
if (executor == null) {
throw new IllegalArgumentException("executor shouldn't be null");
}
diff --git a/packages/MediaComponents/src/com/android/media/SessionPlaylistAgent.java b/packages/MediaComponents/src/com/android/media/SessionPlaylistAgent.java
index 6805dad..693e137 100644
--- a/packages/MediaComponents/src/com/android/media/SessionPlaylistAgent.java
+++ b/packages/MediaComponents/src/com/android/media/SessionPlaylistAgent.java
@@ -24,7 +24,6 @@
import android.media.MediaMetadata2;
import android.media.MediaPlayerBase;
import android.media.MediaPlaylistAgent;
-import android.media.MediaSession2;
import android.media.MediaSession2.OnDataSourceMissingHelper;
import android.util.ArrayMap;
@@ -47,14 +46,13 @@
private final PlayItem mEopPlayItem = new PlayItem(END_OF_PLAYLIST, null);
private final Object mLock = new Object();
- private final MediaSession2 mSession;
+ private final MediaSession2Impl mSessionImpl;
// TODO: Set data sources properly into mPlayer (b/74090741)
@GuardedBy("mLock")
private MediaPlayerBase mPlayer;
@GuardedBy("mLock")
- private OnDataSourceMissingHelper mDsdHelper;
-
+ private OnDataSourceMissingHelper mDsmHelper;
// TODO: Check if having the same item is okay (b/74090741)
@GuardedBy("mLock")
private ArrayList<MediaItem2> mPlaylist = new ArrayList<>();
@@ -118,16 +116,16 @@
}
}
- public SessionPlaylistAgent(@NonNull Context context, @NonNull MediaSession2 session,
+ public SessionPlaylistAgent(@NonNull Context context, @NonNull MediaSession2Impl sessionImpl,
@NonNull MediaPlayerBase player) {
super(context);
- if (session == null) {
- throw new IllegalArgumentException("session shouldn't be null");
+ if (sessionImpl == null) {
+ throw new IllegalArgumentException("sessionImpl shouldn't be null");
}
if (player == null) {
throw new IllegalArgumentException("player shouldn't be null");
}
- mSession = session;
+ mSessionImpl = sessionImpl;
mPlayer = player;
}
@@ -142,7 +140,13 @@
public void setOnDataSourceMissingHelper(OnDataSourceMissingHelper helper) {
synchronized (mLock) {
- mDsdHelper = helper;
+ mDsmHelper = helper;
+ }
+ }
+
+ public void clearOnDataSourceMissingHelper() {
+ synchronized (mLock) {
+ mDsmHelper = null;
}
}
@@ -154,8 +158,7 @@
}
@Override
- public void setPlaylist(@NonNull List<MediaItem2> list,
- @Nullable MediaMetadata2 metadata) {
+ public void setPlaylist(@NonNull List<MediaItem2> list, @Nullable MediaMetadata2 metadata) {
if (list == null) {
throw new IllegalArgumentException("list shouldn't be null");
}
@@ -359,10 +362,10 @@
if (dsd != null) {
return dsd;
}
- OnDataSourceMissingHelper helper = mDsdHelper;
+ OnDataSourceMissingHelper helper = mDsmHelper;
if (helper != null) {
// TODO: Do not call onDataSourceMissing with the lock (b/74090741).
- dsd = helper.onDataSourceMissing(mSession, item);
+ dsd = helper.onDataSourceMissing(mSessionImpl.getInstance(), item);
if (dsd != null) {
mItemDsdMap.put(item, dsd);
}
diff --git a/packages/MediaComponents/tests/Android.mk b/packages/MediaComponents/tests/Android.mk
index bf81efb..dddfd2a 100644
--- a/packages/MediaComponents/tests/Android.mk
+++ b/packages/MediaComponents/tests/Android.mk
@@ -20,6 +20,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := \
android.test.runner.stubs \
android.test.base.stubs \
+ mockito-target-minus-junit4 \
junit
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/packages/MediaComponents/tests/src/com/android/media/SessionPlaylistAgentTest.java b/packages/MediaComponents/tests/src/com/android/media/SessionPlaylistAgentTest.java
index 80370ec..ca941ab 100644
--- a/packages/MediaComponents/tests/src/com/android/media/SessionPlaylistAgentTest.java
+++ b/packages/MediaComponents/tests/src/com/android/media/SessionPlaylistAgentTest.java
@@ -16,19 +16,21 @@
package com.android.media;
+import static org.mockito.Mockito.*;
+
import android.content.Context;
+import android.media.AudioAttributes;
import android.media.DataSourceDesc;
import android.media.MediaItem2;
import android.media.MediaMetadata2;
-import android.media.MediaPlayer2;
import android.media.MediaPlayerBase;
import android.media.MediaPlaylistAgent;
import android.media.MediaSession2;
+import android.media.MediaSession2.OnDataSourceMissingHelper;
import android.net.Uri;
import android.os.Handler;
import android.os.HandlerThread;
import android.test.AndroidTestCase;
-import android.util.Log;
import org.junit.After;
import org.junit.Before;
@@ -52,10 +54,10 @@
private Object mWaitLock = new Object();
private Context mContext;
- private MediaSession2 mSession;
+ private MediaSession2Impl mSessionImpl;
private MediaPlayerBase mPlayer;
private SessionPlaylistAgent mAgent;
- private MyDataSourceHelper mDataSourceHelper;
+ private OnDataSourceMissingHelper mDataSourceHelper;
private MyPlaylistEventCallback mEventCallback;
public class MyPlaylistEventCallback extends MediaPlaylistAgent.PlaylistEventCallback {
@@ -108,7 +110,7 @@
}
}
- public class MyDataSourceHelper implements MediaSession2.OnDataSourceMissingHelper {
+ public class MyDataSourceHelper implements OnDataSourceMissingHelper {
@Override
public DataSourceDesc onDataSourceMissing(MediaSession2 session, MediaItem2 item) {
if (item.getMediaId().contains("WITHOUT_DSD")) {
@@ -121,8 +123,104 @@
}
}
+ public class MockPlayer extends MediaPlayerBase {
+ @Override
+ public void play() {
+ }
+
+ @Override
+ public void prepare() {
+ }
+
+ @Override
+ public void pause() {
+ }
+
+ @Override
+ public void reset() {
+ }
+
+ @Override
+ public void skipToNext() {
+ }
+
+ @Override
+ public void seekTo(long pos) {
+ }
+
+ @Override
+ public int getPlayerState() {
+ return 0;
+ }
+
+ @Override
+ public int getBufferingState() {
+ return 0;
+ }
+
+ @Override
+ public void setAudioAttributes(AudioAttributes attributes) {
+ }
+
+ @Override
+ public AudioAttributes getAudioAttributes() {
+ return null;
+ }
+
+ @Override
+ public void setDataSource(DataSourceDesc dsd) {
+ }
+
+ @Override
+ public void setNextDataSource(DataSourceDesc dsd) {
+ }
+
+ @Override
+ public void setNextDataSources(List<DataSourceDesc> dsds) {
+ }
+
+ @Override
+ public DataSourceDesc getCurrentDataSource() {
+ return null;
+ }
+
+ @Override
+ public void loopCurrent(boolean loop) {
+ }
+
+ @Override
+ public void setPlaybackSpeed(float speed) {
+ }
+
+ @Override
+ public void setPlayerVolume(float volume) {
+ }
+
+ @Override
+ public float getPlayerVolume() {
+ return 0;
+ }
+
+ @Override
+ public void registerPlayerEventCallback(Executor e, PlayerEventCallback cb) {
+ }
+
+ @Override
+ public void unregisterPlayerEventCallback(PlayerEventCallback cb) {
+ }
+
+ @Override
+ public void close() throws Exception {
+ }
+ }
+
@Before
public void setUp() throws Exception {
+ mContext = getContext();
+ // Workaround for dexmaker bug: https://code.google.com/p/dexmaker/issues/detail?id=2
+ // Dexmaker is used by mockito.
+ System.setProperty("dexmaker.dexcache", mContext.getCacheDir().getPath());
+
HandlerThread handlerThread = new HandlerThread("SessionPlaylistAgent");
handlerThread.start();
mHandler = new Handler(handlerThread.getLooper());
@@ -130,15 +228,10 @@
mHandler.post(runnable);
};
- mContext = getContext();
- mPlayer = MediaPlayer2.create();
- mSession = new MediaSession2.Builder(mContext)
- .setPlayer(mPlayer)
- .setSessionCallback(mHandlerExecutor,
- new MediaSession2.SessionCallback(mContext) {})
- .setId(TAG).build();
+ mPlayer = mock(MockPlayer.class);
+ mSessionImpl = mock(MediaSession2Impl.class);
mDataSourceHelper = new MyDataSourceHelper();
- mAgent = new SessionPlaylistAgent(mContext, mSession, mPlayer);
+ mAgent = new SessionPlaylistAgent(mContext, mSessionImpl, mPlayer);
mAgent.setOnDataSourceMissingHelper(mDataSourceHelper);
mEventCallback = new MyPlaylistEventCallback(mWaitLock);
mAgent.registerPlaylistEventCallback(mHandlerExecutor, mEventCallback);
@@ -146,8 +239,6 @@
@After
public void tearDown() throws Exception {
- mSession.close();
- mPlayer.close();
mHandler.getLooper().quitSafely();
mHandler = null;
mHandlerExecutor = null;
diff --git a/services/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h b/services/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h
index 31b7e0f..e4fd176 100644
--- a/services/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h
+++ b/services/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h
@@ -62,7 +62,8 @@
[AUDIO_POLICY_FORCE_FOR_DOCK] = "ForceUseForDock",
[AUDIO_POLICY_FORCE_FOR_SYSTEM] = "ForceUseForSystem",
[AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO] = "ForceUseForHdmiSystemAudio",
- [AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND] = "ForceUseForEncodedSurround"
+ [AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND] = "ForceUseForEncodedSurround",
+ [AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING] = "ForceUseForVibrateRinging"
};
diff --git a/services/audiopolicy/enginedefault/src/Engine.cpp b/services/audiopolicy/enginedefault/src/Engine.cpp
index 977a396..be7f7ec 100644
--- a/services/audiopolicy/enginedefault/src/Engine.cpp
+++ b/services/audiopolicy/enginedefault/src/Engine.cpp
@@ -154,6 +154,13 @@
}
mForceUse[usage] = config;
break;
+ case AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING:
+ if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_NONE) {
+ ALOGW("setForceUse() invalid config %d for FOR_VIBRATE_RINGING", config);
+ return BAD_VALUE;
+ }
+ mForceUse[usage] = config;
+ break;
default:
ALOGW("setForceUse() invalid usage %d", usage);
break; // TODO return BAD_VALUE?
@@ -423,8 +430,7 @@
// if SCO headset is connected and we are told to use it, play ringtone over
// speaker and BT SCO
- if (((availableOutputDevicesType & AUDIO_DEVICE_OUT_ALL_SCO) != 0) &&
- (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION] == AUDIO_POLICY_FORCE_BT_SCO)) {
+ if ((availableOutputDevicesType & AUDIO_DEVICE_OUT_ALL_SCO) != 0) {
uint32_t device2 = AUDIO_DEVICE_NONE;
device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
if (device2 == AUDIO_DEVICE_NONE) {
@@ -433,10 +439,23 @@
if (device2 == AUDIO_DEVICE_NONE) {
device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO;
}
-
- if (device2 != AUDIO_DEVICE_NONE) {
- device |= device2;
- break;
+ // Use ONLY Bluetooth SCO output when ringing in vibration mode
+ if (!((mForceUse[AUDIO_POLICY_FORCE_FOR_SYSTEM] == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)
+ && (strategy == STRATEGY_ENFORCED_AUDIBLE))) {
+ if (mForceUse[AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING]
+ == AUDIO_POLICY_FORCE_BT_SCO) {
+ if (device2 != AUDIO_DEVICE_NONE) {
+ device = device2;
+ break;
+ }
+ }
+ }
+ // Use both Bluetooth SCO and phone default output when ringing in normal mode
+ if (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION] == AUDIO_POLICY_FORCE_BT_SCO) {
+ if (device2 != AUDIO_DEVICE_NONE) {
+ device |= device2;
+ break;
+ }
}
}
// The second device used for sonification is the same as the device used by media strategy