• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.media.testmediaapp;
18 
19 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_ACTION_ABORTED;
20 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_APP_ERROR;
21 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_AUTHENTICATION_EXPIRED;
22 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_CONCURRENT_STREAM_LIMIT;
23 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_CONTENT_ALREADY_PLAYING;
24 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_END_OF_QUEUE;
25 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_NOT_AVAILABLE_IN_REGION;
26 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_NOT_SUPPORTED;
27 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_PARENTAL_CONTROL_RESTRICTED;
28 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED;
29 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_SKIP_LIMIT_REACHED;
30 import static android.support.v4.media.session.PlaybackStateCompat.ERROR_CODE_UNKNOWN_ERROR;
31 import static android.support.v4.media.session.PlaybackStateCompat.STATE_BUFFERING;
32 import static android.support.v4.media.session.PlaybackStateCompat.STATE_CONNECTING;
33 import static android.support.v4.media.session.PlaybackStateCompat.STATE_ERROR;
34 import static android.support.v4.media.session.PlaybackStateCompat.STATE_FAST_FORWARDING;
35 import static android.support.v4.media.session.PlaybackStateCompat.STATE_NONE;
36 import static android.support.v4.media.session.PlaybackStateCompat.STATE_PAUSED;
37 import static android.support.v4.media.session.PlaybackStateCompat.STATE_PLAYING;
38 import static android.support.v4.media.session.PlaybackStateCompat.STATE_REWINDING;
39 import static android.support.v4.media.session.PlaybackStateCompat.STATE_SKIPPING_TO_NEXT;
40 import static android.support.v4.media.session.PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS;
41 import static android.support.v4.media.session.PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM;
42 import static android.support.v4.media.session.PlaybackStateCompat.STATE_STOPPED;
43 
44 import android.support.v4.media.session.PlaybackStateCompat.State;
45 
46 /**
47  * Contains the info needed to generate a new playback state.
48  */
49 public class TmaMediaEvent {
50 
51     public static final TmaMediaEvent INSTANT_PLAYBACK =
52             new TmaMediaEvent(EventState.PLAYING, StateErrorCode.UNKNOWN_ERROR, null, null,
53                     ResolutionIntent.NONE, 0);
54 
55     /** The name of each entry is the value used in the json file. */
56     public enum EventState {
57         NONE                    (STATE_NONE),
58         STOPPED                 (STATE_STOPPED),
59         PAUSED                  (STATE_PAUSED),
60         PLAYING                 (STATE_PLAYING),
61         FAST_FORWARDING         (STATE_FAST_FORWARDING),
62         REWINDING               (STATE_REWINDING),
63         BUFFERING               (STATE_BUFFERING),
64         ERROR                   (STATE_ERROR),
65         CONNECTING              (STATE_CONNECTING),
66         SKIPPING_TO_PREVIOUS    (STATE_SKIPPING_TO_PREVIOUS),
67         SKIPPING_TO_NEXT        (STATE_SKIPPING_TO_NEXT),
68         SKIPPING_TO_QUEUE_ITEM  (STATE_SKIPPING_TO_QUEUE_ITEM);
69 
70         @State final int mValue;
71 
EventState(@tate int value)72         EventState(@State int value) {
73             mValue = value;
74         }
75     }
76 
77     /** The name of each entry is the value used in the json file. */
78     public enum StateErrorCode {
79         UNKNOWN_ERROR                   (ERROR_CODE_UNKNOWN_ERROR),
80         APP_ERROR                       (ERROR_CODE_APP_ERROR),
81         NOT_SUPPORTED                   (ERROR_CODE_NOT_SUPPORTED),
82         AUTHENTICATION_EXPIRED          (ERROR_CODE_AUTHENTICATION_EXPIRED),
83         PREMIUM_ACCOUNT_REQUIRED        (ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED),
84         CONCURRENT_STREAM_LIMIT         (ERROR_CODE_CONCURRENT_STREAM_LIMIT),
85         PARENTAL_CONTROL_RESTRICTED     (ERROR_CODE_PARENTAL_CONTROL_RESTRICTED),
86         NOT_AVAILABLE_IN_REGION         (ERROR_CODE_NOT_AVAILABLE_IN_REGION),
87         CONTENT_ALREADY_PLAYING         (ERROR_CODE_CONTENT_ALREADY_PLAYING),
88         SKIP_LIMIT_REACHED              (ERROR_CODE_SKIP_LIMIT_REACHED),
89         ACTION_ABORTED                  (ERROR_CODE_ACTION_ABORTED),
90         END_OF_QUEUE                    (ERROR_CODE_END_OF_QUEUE);
91 
92         @State final int mValue;
93 
StateErrorCode(@tate int value)94         StateErrorCode(@State int value) {
95             mValue = value;
96         }
97     }
98 
99     /** The name of each entry is the value used in the json file. */
100     public enum ResolutionIntent {
101         NONE,
102         PREFS
103     }
104 
105     final EventState mState;
106     final StateErrorCode mErrorCode;
107     final String mErrorMessage;
108     final String mActionLabel;
109     final ResolutionIntent mResolutionIntent;
110     /** How long to wait before sending the event to the app. */
111     final int mPostDelayMs;
112 
TmaMediaEvent(EventState state, StateErrorCode errorCode, String errorMessage, String actionLabel, ResolutionIntent resolutionIntent, int postDelayMs)113     public TmaMediaEvent(EventState state, StateErrorCode errorCode, String errorMessage,
114             String actionLabel, ResolutionIntent resolutionIntent, int postDelayMs) {
115         mState = state;
116         mErrorCode = errorCode;
117         mErrorMessage = errorMessage;
118         mActionLabel = actionLabel;
119         mResolutionIntent = resolutionIntent;
120         mPostDelayMs = postDelayMs;
121     }
122 
premiumAccountRequired()123     boolean premiumAccountRequired() {
124         return mState == EventState.ERROR && mErrorCode == StateErrorCode.PREMIUM_ACCOUNT_REQUIRED;
125     }
126 
127     @Override
toString()128     public String toString() {
129         return "TmaMediaEvent{" +
130                 "mState=" + mState +
131                 ", mErrorCode=" + mErrorCode +
132                 ", mErrorMessage='" + mErrorMessage + '\'' +
133                 ", mActionLabel='" + mActionLabel + '\'' +
134                 ", mResolutionIntent=" + mResolutionIntent +
135                 ", mPostDelayMs=" + mPostDelayMs +
136                 '}';
137     }
138 }
139