aboutsummaryrefslogtreecommitdiff
path: root/TestMediaApp/src
diff options
context:
space:
mode:
authorArnaud Berry <arnaudberry@google.com>2019-07-02 14:34:28 -0700
committerIgor Razumeiko <igorr@google.com>2019-10-02 04:00:15 +0000
commitbc95c5a7610f477a4a3654ee77a063c9f86a7561 (patch)
tree31323e5f29795409bdfc3bca5b0d83719b38ed5b /TestMediaApp/src
parentadd3cfaf5d90724072c42435256c81bedd65a531 (diff)
downloadtests-bc95c5a7610f477a4a3654ee77a063c9f86a7561.tar.gz
Create unbundled gradle project, and make the app work with Auto
Removed dependencies on other repositories so that the tests repository can be checked out and built independently with Android Studio. Test: manual Change-Id: If499e0510ffd5071dd674a66d74f378994b7c1f6
Diffstat (limited to 'TestMediaApp/src')
-rw-r--r--TestMediaApp/src/com/android/car/media/testmediaapp/MediaKeys.java64
-rw-r--r--TestMediaApp/src/com/android/car/media/testmediaapp/TmaBrowser.java10
-rw-r--r--TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaItem.java13
-rw-r--r--TestMediaApp/src/com/android/car/media/testmediaapp/TmaPlayer.java7
-rw-r--r--TestMediaApp/src/com/android/car/media/testmediaapp/loader/TmaMediaMetadataReader.java5
5 files changed, 78 insertions, 21 deletions
diff --git a/TestMediaApp/src/com/android/car/media/testmediaapp/MediaKeys.java b/TestMediaApp/src/com/android/car/media/testmediaapp/MediaKeys.java
new file mode 100644
index 0000000..8506b6b
--- /dev/null
+++ b/TestMediaApp/src/com/android/car/media/testmediaapp/MediaKeys.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2019, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.media.testmediaapp;
+
+/**
+ * Copy of constants defined in com.android.car.media.common.MediaConstants until they can be moved
+ * to a shared location available to all media apps. This makes un-bundling TestMediaApp easier.
+ */
+public class MediaKeys {
+
+ /**
+ * Bundle extra holding the Pending Intent to launch to let users resolve the current error.
+ * See {@link #ERROR_RESOLUTION_ACTION_LABEL} for more details.
+ */
+ static final String ERROR_RESOLUTION_ACTION_INTENT =
+ "android.media.extras.ERROR_RESOLUTION_ACTION_INTENT";
+
+
+ /**
+ * Bundle extra indicating the label of the button users can tap to resolve an error state.
+ */
+ static final String ERROR_RESOLUTION_ACTION_LABEL =
+ "android.media.extras.ERROR_RESOLUTION_ACTION_LABEL";
+
+ /**
+ * Bundle extra indicating the presentation hint for playable media items. See {@link
+ * #CONTENT_STYLE_LIST_ITEM_HINT_VALUE} or {@link #CONTENT_STYLE_GRID_ITEM_HINT_VALUE}
+ */
+ static final String CONTENT_STYLE_PLAYABLE_HINT =
+ "android.media.browse.CONTENT_STYLE_PLAYABLE_HINT";
+
+ /**
+ * Bundle extra indicating the presentation hint for browsable media items. See {@link
+ * #CONTENT_STYLE_LIST_ITEM_HINT_VALUE} or {@link #CONTENT_STYLE_GRID_ITEM_HINT_VALUE}
+ */
+ static final String CONTENT_STYLE_BROWSABLE_HINT =
+ "android.media.browse.CONTENT_STYLE_BROWSABLE_HINT";
+
+ /**
+ * Value for {@link #CONTENT_STYLE_PLAYABLE_HINT} and {@link #CONTENT_STYLE_BROWSABLE_HINT} that
+ * hints the corresponding items should be presented as lists.
+ */
+ static final int CONTENT_STYLE_LIST_ITEM_HINT_VALUE = 1;
+
+ /**
+ * Value for {@link #CONTENT_STYLE_PLAYABLE_HINT} and {@link #CONTENT_STYLE_BROWSABLE_HINT} that
+ * hints the corresponding items should be presented as grids.
+ */
+ static final int CONTENT_STYLE_GRID_ITEM_HINT_VALUE = 2;
+}
diff --git a/TestMediaApp/src/com/android/car/media/testmediaapp/TmaBrowser.java b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaBrowser.java
index ec57473..02e8292 100644
--- a/TestMediaApp/src/com/android/car/media/testmediaapp/TmaBrowser.java
+++ b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaBrowser.java
@@ -33,10 +33,8 @@ import androidx.media.MediaBrowserServiceCompat;
import com.android.car.media.testmediaapp.loader.TmaLoader;
import com.android.car.media.testmediaapp.prefs.TmaEnumPrefs.TmaAccountType;
-import com.android.car.media.testmediaapp.prefs.TmaEnumPrefs.TmaLoginEventOrder;
import com.android.car.media.testmediaapp.prefs.TmaEnumPrefs.TmaReplyDelay;
import com.android.car.media.testmediaapp.prefs.TmaPrefs;
-import com.android.internal.util.Preconditions;
import java.util.ArrayList;
import java.util.List;
@@ -149,10 +147,10 @@ public class TmaBrowser extends MediaBrowserServiceCompat {
if (QUEUE_ONLY.equals(mPrefs.mRootNodeType.getValue()) && ROOT_ID.equals(parentId)) {
TmaMediaItem queue = mLibrary.getRoot(LEAF_CHILDREN);
- Preconditions.checkNotNull(queue);
- mSession.setQueue(queue.buildQueue());
-
- mPlayer.prepareMediaItem(queue.getPlayableByIndex(0));
+ if (queue != null) {
+ mSession.setQueue(queue.buildQueue());
+ mPlayer.prepareMediaItem(queue.getPlayableByIndex(0));
+ }
}
}
diff --git a/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaItem.java b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaItem.java
index 5c53d34..f79e273 100644
--- a/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaItem.java
+++ b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaItem.java
@@ -22,11 +22,6 @@ import static android.support.v4.media.MediaBrowserCompat.MediaItem.FLAG_PLAYABL
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DURATION;
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_MEDIA_ID;
-import static com.android.car.media.common.MediaConstants.CONTENT_STYLE_BROWSABLE_HINT;
-import static com.android.car.media.common.MediaConstants.CONTENT_STYLE_GRID_ITEM_HINT_VALUE;
-import static com.android.car.media.common.MediaConstants.CONTENT_STYLE_LIST_ITEM_HINT_VALUE;
-import static com.android.car.media.common.MediaConstants.CONTENT_STYLE_PLAYABLE_HINT;
-
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaDescriptionCompat;
@@ -46,8 +41,8 @@ public class TmaMediaItem {
/** The name of each entry is the value used in the json file. */
public enum ContentStyle {
NONE (0),
- LIST (CONTENT_STYLE_LIST_ITEM_HINT_VALUE),
- GRID (CONTENT_STYLE_GRID_ITEM_HINT_VALUE);
+ LIST (MediaKeys.CONTENT_STYLE_LIST_ITEM_HINT_VALUE),
+ GRID (MediaKeys.CONTENT_STYLE_GRID_ITEM_HINT_VALUE);
final int mBundleValue;
ContentStyle(int value) {
mBundleValue = value;
@@ -212,8 +207,8 @@ public class TmaMediaItem {
extras.putAll(metadataDescription.getExtras());
}
- extras.putInt(CONTENT_STYLE_PLAYABLE_HINT, mPlayableStyle.mBundleValue);
- extras.putInt(CONTENT_STYLE_BROWSABLE_HINT, mBrowsableStyle.mBundleValue);
+ extras.putInt(MediaKeys.CONTENT_STYLE_PLAYABLE_HINT, mPlayableStyle.mBundleValue);
+ extras.putInt(MediaKeys.CONTENT_STYLE_BROWSABLE_HINT, mBrowsableStyle.mBundleValue);
bob.setExtras(extras);
return bob.build();
diff --git a/TestMediaApp/src/com/android/car/media/testmediaapp/TmaPlayer.java b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaPlayer.java
index 3df5653..2938a37 100644
--- a/TestMediaApp/src/com/android/car/media/testmediaapp/TmaPlayer.java
+++ b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaPlayer.java
@@ -28,9 +28,6 @@ import static android.support.v4.media.session.PlaybackStateCompat.ACTION_SKIP_T
import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_APP_ERROR;
import static android.support.v4.media.session.PlaybackStateCompat.STATE_ERROR;
-import static com.android.car.media.common.MediaConstants.ERROR_RESOLUTION_ACTION_INTENT;
-import static com.android.car.media.common.MediaConstants.ERROR_RESOLUTION_ACTION_LABEL;
-
import androidx.annotation.Nullable;
import android.app.PendingIntent;
import android.content.Context;
@@ -108,8 +105,8 @@ public class TmaPlayer extends MediaSessionCompat.Callback {
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, prefsIntent, 0);
Bundle extras = new Bundle();
- extras.putString(ERROR_RESOLUTION_ACTION_LABEL, event.mActionLabel);
- extras.putParcelable(ERROR_RESOLUTION_ACTION_INTENT, pendingIntent);
+ extras.putString(MediaKeys.ERROR_RESOLUTION_ACTION_LABEL, event.mActionLabel);
+ extras.putParcelable(MediaKeys.ERROR_RESOLUTION_ACTION_INTENT, pendingIntent);
state.setExtras(extras);
}
diff --git a/TestMediaApp/src/com/android/car/media/testmediaapp/loader/TmaMediaMetadataReader.java b/TestMediaApp/src/com/android/car/media/testmediaapp/loader/TmaMediaMetadataReader.java
index 95f8f89..5a4a217 100644
--- a/TestMediaApp/src/com/android/car/media/testmediaapp/loader/TmaMediaMetadataReader.java
+++ b/TestMediaApp/src/com/android/car/media/testmediaapp/loader/TmaMediaMetadataReader.java
@@ -59,6 +59,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.util.EnumSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -140,7 +141,9 @@ class TmaMediaMetadataReader {
MediaMetadataCompat fromJson(JSONObject object) throws JSONException {
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
- for (String jsonKey : object.keySet()) {
+ Iterator<String> keys = object.keys();
+ while (keys.hasNext()) {
+ String jsonKey = keys.next();
MetadataKey key = mMetadataKeys.get(jsonKey);
if (key != null) {
switch (key.mKeyType) {