Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2013 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 android.media;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 import java.util.ArrayList;
     23 
     24 /**
     25  * Information available from MediaRouterService about the state perceived by
     26  * a particular client and the routes that are available to it.
     27  *
     28  * Clients must not modify the contents of this object.
     29  * @hide
     30  */
     31 public final class MediaRouterClientState implements Parcelable {
     32     /**
     33      * A list of all known routes.
     34      */
     35     public final ArrayList<RouteInfo> routes;
     36 
     37     /**
     38      * The id of the current globally selected route, or null if none.
     39      * Globally selected routes override any other route selections that applications
     40      * may have made.  Used for remote displays.
     41      */
     42     public String globallySelectedRouteId;
     43 
     44     public MediaRouterClientState() {
     45         routes = new ArrayList<RouteInfo>();
     46     }
     47 
     48     MediaRouterClientState(Parcel src) {
     49         routes = src.createTypedArrayList(RouteInfo.CREATOR);
     50         globallySelectedRouteId = src.readString();
     51     }
     52 
     53     public RouteInfo getRoute(String id) {
     54         final int count = routes.size();
     55         for (int i = 0; i < count; i++) {
     56             final RouteInfo route = routes.get(i);
     57             if (route.id.equals(id)) {
     58                 return route;
     59             }
     60         }
     61         return null;
     62     }
     63 
     64     @Override
     65     public int describeContents() {
     66         return 0;
     67     }
     68 
     69     @Override
     70     public void writeToParcel(Parcel dest, int flags) {
     71         dest.writeTypedList(routes);
     72         dest.writeString(globallySelectedRouteId);
     73     }
     74 
     75     @Override
     76     public String toString() {
     77         return "MediaRouterClientState{ globallySelectedRouteId="
     78                 + globallySelectedRouteId + ", routes=" + routes.toString() + " }";
     79     }
     80 
     81     public static final Parcelable.Creator<MediaRouterClientState> CREATOR =
     82             new Parcelable.Creator<MediaRouterClientState>() {
     83         @Override
     84         public MediaRouterClientState createFromParcel(Parcel in) {
     85             return new MediaRouterClientState(in);
     86         }
     87 
     88         @Override
     89         public MediaRouterClientState[] newArray(int size) {
     90             return new MediaRouterClientState[size];
     91         }
     92     };
     93 
     94     public static final class RouteInfo implements Parcelable {
     95         public String id;
     96         public String name;
     97         public String description;
     98         public int supportedTypes;
     99         public boolean enabled;
    100         public int statusCode;
    101         public int playbackType;
    102         public int playbackStream;
    103         public int volume;
    104         public int volumeMax;
    105         public int volumeHandling;
    106         public int presentationDisplayId;
    107 
    108         public RouteInfo(String id) {
    109             this.id = id;
    110             enabled = true;
    111             statusCode = MediaRouter.RouteInfo.STATUS_NONE;
    112             playbackType = MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE;
    113             playbackStream = -1;
    114             volumeHandling = MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
    115             presentationDisplayId = -1;
    116         }
    117 
    118         public RouteInfo(RouteInfo other) {
    119             id = other.id;
    120             name = other.name;
    121             description = other.description;
    122             supportedTypes = other.supportedTypes;
    123             enabled = other.enabled;
    124             statusCode = other.statusCode;
    125             playbackType = other.playbackType;
    126             playbackStream = other.playbackStream;
    127             volume = other.volume;
    128             volumeMax = other.volumeMax;
    129             volumeHandling = other.volumeHandling;
    130             presentationDisplayId = other.presentationDisplayId;
    131         }
    132 
    133         RouteInfo(Parcel in) {
    134             id = in.readString();
    135             name = in.readString();
    136             description = in.readString();
    137             supportedTypes = in.readInt();
    138             enabled = in.readInt() != 0;
    139             statusCode = in.readInt();
    140             playbackType = in.readInt();
    141             playbackStream = in.readInt();
    142             volume = in.readInt();
    143             volumeMax = in.readInt();
    144             volumeHandling = in.readInt();
    145             presentationDisplayId = in.readInt();
    146         }
    147 
    148         @Override
    149         public int describeContents() {
    150             return 0;
    151         }
    152 
    153         @Override
    154         public void writeToParcel(Parcel dest, int flags) {
    155             dest.writeString(id);
    156             dest.writeString(name);
    157             dest.writeString(description);
    158             dest.writeInt(supportedTypes);
    159             dest.writeInt(enabled ? 1 : 0);
    160             dest.writeInt(statusCode);
    161             dest.writeInt(playbackType);
    162             dest.writeInt(playbackStream);
    163             dest.writeInt(volume);
    164             dest.writeInt(volumeMax);
    165             dest.writeInt(volumeHandling);
    166             dest.writeInt(presentationDisplayId);
    167         }
    168 
    169         @Override
    170         public String toString() {
    171             return "RouteInfo{ id=" + id
    172                     + ", name=" + name
    173                     + ", description=" + description
    174                     + ", supportedTypes=0x" + Integer.toHexString(supportedTypes)
    175                     + ", enabled=" + enabled
    176                     + ", statusCode=" + statusCode
    177                     + ", playbackType=" + playbackType
    178                     + ", playbackStream=" + playbackStream
    179                     + ", volume=" + volume
    180                     + ", volumeMax=" + volumeMax
    181                     + ", volumeHandling=" + volumeHandling
    182                     + ", presentationDisplayId=" + presentationDisplayId
    183                     + " }";
    184         }
    185 
    186         @SuppressWarnings("hiding")
    187         public static final Parcelable.Creator<RouteInfo> CREATOR =
    188                 new Parcelable.Creator<RouteInfo>() {
    189             @Override
    190             public RouteInfo createFromParcel(Parcel in) {
    191                 return new RouteInfo(in);
    192             }
    193 
    194             @Override
    195             public RouteInfo[] newArray(int size) {
    196                 return new RouteInfo[size];
    197             }
    198         };
    199     }
    200 }
    201