aboutsummaryrefslogtreecommitdiff
path: root/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaEvent.java
diff options
context:
space:
mode:
authorArnaud Berry <arnaudberry@google.com>2019-05-16 16:52:30 -0700
committerArnaud Berry <arnaudberry@google.com>2019-05-21 18:56:32 -0700
commitb6d873275f754b1dbd72f02ff2295219adf5373a (patch)
tree1bb51843a2f9c6f01e9568d658d404f392368a21 /TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaEvent.java
parentd003b9e3fc81bb6fbf2ab320c0c9351cc2347075 (diff)
downloadtests-b6d873275f754b1dbd72f02ff2295219adf5373a.tar.gz
Create Test Media App
This application is intended to help test the Car/Media app by making it easy to send it media items and playback states. Those media items are bundled within the assets of the TestMediaApp, as very readable json files. Quick overview: - loader package interprets the json files - prefs package implements the app's preferences (account type, root node, reply delay) - TmaBrowser implements the MediaBrowserService. It send replies based on the content of the prefs and the json files - TmaLibrary caches the interpreted files - TmaPlayer simulates all media interactions (without playing any sound) - TmaMediaItem represents the media items of the test app - TmaMediaEvent represents playback events to send to the media session Test: manual Change-Id: I5f4e6c537d8d0e49d4f5a1dc958e73722b78534e
Diffstat (limited to 'TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaEvent.java')
-rw-r--r--TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaEvent.java138
1 files changed, 138 insertions, 0 deletions
diff --git a/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaEvent.java b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaEvent.java
new file mode 100644
index 0000000..98a9b6b
--- /dev/null
+++ b/TestMediaApp/src/com/android/car/media/testmediaapp/TmaMediaEvent.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 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;
+
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_ACTION_ABORTED;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_APP_ERROR;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_AUTHENTICATION_EXPIRED;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_CONCURRENT_STREAM_LIMIT;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_CONTENT_ALREADY_PLAYING;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_END_OF_QUEUE;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_NOT_AVAILABLE_IN_REGION;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_NOT_SUPPORTED;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_PARENTAL_CONTROL_RESTRICTED;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_SKIP_LIMIT_REACHED;
+import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_UNKNOWN_ERROR;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_BUFFERING;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_CONNECTING;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_ERROR;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_FAST_FORWARDING;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_NONE;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_PAUSED;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_PLAYING;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_REWINDING;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_SKIPPING_TO_NEXT;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM;
+import static android.support.v4.media.session.PlaybackStateCompat.STATE_STOPPED;
+
+import android.support.v4.media.session.PlaybackStateCompat.State;
+
+/**
+ * Contains the info needed to generate a new playback state.
+ */
+public class TmaMediaEvent {
+
+ public static final TmaMediaEvent INSTANT_PLAYBACK =
+ new TmaMediaEvent(EventState.PLAYING, StateErrorCode.UNKNOWN_ERROR, null, null,
+ ResolutionIntent.NONE, 0);
+
+ /** The name of each entry is the value used in the json file. */
+ public enum EventState {
+ NONE (STATE_NONE),
+ STOPPED (STATE_STOPPED),
+ PAUSED (STATE_PAUSED),
+ PLAYING (STATE_PLAYING),
+ FAST_FORWARDING (STATE_FAST_FORWARDING),
+ REWINDING (STATE_REWINDING),
+ BUFFERING (STATE_BUFFERING),
+ ERROR (STATE_ERROR),
+ CONNECTING (STATE_CONNECTING),
+ SKIPPING_TO_PREVIOUS (STATE_SKIPPING_TO_PREVIOUS),
+ SKIPPING_TO_NEXT (STATE_SKIPPING_TO_NEXT),
+ SKIPPING_TO_QUEUE_ITEM (STATE_SKIPPING_TO_QUEUE_ITEM);
+
+ @State final int mValue;
+
+ EventState(@State int value) {
+ mValue = value;
+ }
+ }
+
+ /** The name of each entry is the value used in the json file. */
+ public enum StateErrorCode {
+ UNKNOWN_ERROR (ERROR_CODE_UNKNOWN_ERROR),
+ APP_ERROR (ERROR_CODE_APP_ERROR),
+ NOT_SUPPORTED (ERROR_CODE_NOT_SUPPORTED),
+ AUTHENTICATION_EXPIRED (ERROR_CODE_AUTHENTICATION_EXPIRED),
+ PREMIUM_ACCOUNT_REQUIRED (ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED),
+ CONCURRENT_STREAM_LIMIT (ERROR_CODE_CONCURRENT_STREAM_LIMIT),
+ PARENTAL_CONTROL_RESTRICTED (ERROR_CODE_PARENTAL_CONTROL_RESTRICTED),
+ NOT_AVAILABLE_IN_REGION (ERROR_CODE_NOT_AVAILABLE_IN_REGION),
+ CONTENT_ALREADY_PLAYING (ERROR_CODE_CONTENT_ALREADY_PLAYING),
+ SKIP_LIMIT_REACHED (ERROR_CODE_SKIP_LIMIT_REACHED),
+ ACTION_ABORTED (ERROR_CODE_ACTION_ABORTED),
+ END_OF_QUEUE (ERROR_CODE_END_OF_QUEUE);
+
+ @State final int mValue;
+
+ StateErrorCode(@State int value) {
+ mValue = value;
+ }
+ }
+
+ /** The name of each entry is the value used in the json file. */
+ public enum ResolutionIntent {
+ NONE,
+ PREFS
+ }
+
+ public final EventState mState;
+ public final StateErrorCode mErrorCode;
+ public final String mErrorMessage;
+ final String mActionLabel;
+ final ResolutionIntent mResolutionIntent;
+ /** How long to wait before sending the event to the app. */
+ final int mPostDelayMs;
+
+ public TmaMediaEvent(EventState state, StateErrorCode errorCode, String errorMessage,
+ String actionLabel, ResolutionIntent resolutionIntent, int postDelayMs) {
+ mState = state;
+ mErrorCode = errorCode;
+ mErrorMessage = errorMessage;
+ mActionLabel = actionLabel;
+ mResolutionIntent = resolutionIntent;
+ mPostDelayMs = postDelayMs;
+ }
+
+ boolean premiumAccountRequired() {
+ return mState == EventState.ERROR && mErrorCode == StateErrorCode.PREMIUM_ACCOUNT_REQUIRED;
+ }
+
+ @Override
+ public String toString() {
+ return "TmaMediaEvent{" +
+ "mState=" + mState +
+ ", mErrorCode=" + mErrorCode +
+ ", mErrorMessage='" + mErrorMessage + '\'' +
+ ", mActionLabel='" + mActionLabel + '\'' +
+ ", mResolutionIntent=" + mResolutionIntent +
+ ", mPostDelayMs=" + mPostDelayMs +
+ '}';
+ }
+}