• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.bluetooth.avrcpcontroller;
18 
19 import android.support.v4.media.session.PlaybackStateCompat;
20 
21 /** A package global set of utilities for the AVRCP Controller implementation to leverage */
22 public final class AvrcpControllerUtils {
23     public static final String TAG_PREFIX_AVRCP = "Avrcp";
24     public static final String TAG_PREFIX_AVRCP_CONTROLLER = TAG_PREFIX_AVRCP + "Controller.";
25 
26     /** Convert an AVRCP Passthrough command id to a human readable version of the key */
passThruIdToString(int id)27     public static String passThruIdToString(int id) {
28         StringBuilder sb = new StringBuilder();
29         switch (id) {
30             case AvrcpControllerService.PASS_THRU_CMD_ID_PLAY:
31                 sb.append("PLAY");
32                 break;
33             case AvrcpControllerService.PASS_THRU_CMD_ID_PAUSE:
34                 sb.append("PAUSE");
35                 break;
36             case AvrcpControllerService.PASS_THRU_CMD_ID_VOL_UP:
37                 sb.append("VOL_UP");
38                 break;
39             case AvrcpControllerService.PASS_THRU_CMD_ID_VOL_DOWN:
40                 sb.append("VOL_DOWN");
41                 break;
42             case AvrcpControllerService.PASS_THRU_CMD_ID_STOP:
43                 sb.append("STOP");
44                 break;
45             case AvrcpControllerService.PASS_THRU_CMD_ID_FF:
46                 sb.append("FF");
47                 break;
48             case AvrcpControllerService.PASS_THRU_CMD_ID_REWIND:
49                 sb.append("REWIND");
50                 break;
51             case AvrcpControllerService.PASS_THRU_CMD_ID_FORWARD:
52                 sb.append("FORWARD");
53                 break;
54             case AvrcpControllerService.PASS_THRU_CMD_ID_BACKWARD:
55                 sb.append("BACKWARD");
56                 break;
57             default:
58                 sb.append("UNKNOWN_CMD_").append(id);
59                 break;
60         }
61         sb.append(" (").append(id).append(")");
62         return sb.toString();
63     }
64 
65     /** Convert an entire PlaybackStateCompat to a string that contains human readable states */
playbackStateCompatToString(PlaybackStateCompat playbackState)66     public static String playbackStateCompatToString(PlaybackStateCompat playbackState) {
67         if (playbackState == null) {
68             return null;
69         }
70 
71         StringBuilder sb = new StringBuilder("PlaybackState {");
72         sb.append("state=").append(playbackStateToString(playbackState.getState()));
73         sb.append(", position=").append(playbackState.getPosition());
74         sb.append(", buffered position=").append(playbackState.getBufferedPosition());
75         sb.append(", speed=").append(playbackState.getPlaybackSpeed());
76         sb.append(", updated=").append(playbackState.getLastPositionUpdateTime());
77         sb.append(", actions=").append(playbackState.getActions());
78         sb.append(", error code=").append(playbackState.getErrorCode());
79         sb.append(", error message=").append(playbackState.getErrorMessage());
80         sb.append(", custom actions=").append(playbackState.getCustomActions());
81         sb.append(", active item id=").append(playbackState.getActiveQueueItemId());
82         sb.append("}");
83         return sb.toString();
84     }
85 
86     /** Convert a playback state constant to a human readable version of the state */
playbackStateToString(int playbackState)87     public static String playbackStateToString(int playbackState) {
88         StringBuilder sb = new StringBuilder();
89         switch (playbackState) {
90             case PlaybackStateCompat.STATE_NONE:
91                 sb.append("STATE_NONE");
92                 break;
93             case PlaybackStateCompat.STATE_STOPPED:
94                 sb.append("STATE_STOPPED");
95                 break;
96             case PlaybackStateCompat.STATE_PAUSED:
97                 sb.append("STATE_PAUSED");
98                 break;
99             case PlaybackStateCompat.STATE_PLAYING:
100                 sb.append("STATE_PLAYING");
101                 break;
102             case PlaybackStateCompat.STATE_FAST_FORWARDING:
103                 sb.append("STATE_FAST_FORWARDING");
104                 break;
105             case PlaybackStateCompat.STATE_REWINDING:
106                 sb.append("STATE_REWINDING");
107                 break;
108             case PlaybackStateCompat.STATE_BUFFERING:
109                 sb.append("STATE_BUFFERING");
110                 break;
111             case PlaybackStateCompat.STATE_ERROR:
112                 sb.append("STATE_ERROR");
113                 break;
114             case PlaybackStateCompat.STATE_CONNECTING:
115                 sb.append("STATE_CONNECTING");
116                 break;
117             case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS:
118                 sb.append("STATE_SKIPPING_TO_PREVIOUS");
119                 break;
120             case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT:
121                 sb.append("STATE_SKIPPING_TO_NEXT");
122                 break;
123             case PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM:
124                 sb.append("STATE_SKIPPING_TO_QUEUE_ITEM");
125                 break;
126             default:
127                 sb.append("UNKNOWN_PLAYBACK_STATE");
128                 break;
129         }
130         sb.append(" (").append(playbackState).append(")");
131         return sb.toString();
132     }
133 }
134