Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2012 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 import android.text.TextUtils;
     22 
     23 /**
     24  * Information available from AudioService about the current routes.
     25  * @hide
     26  */
     27 public class AudioRoutesInfo implements Parcelable {
     28     public static final int MAIN_SPEAKER = 0;
     29     public static final int MAIN_HEADSET = 1<<0;
     30     public static final int MAIN_HEADPHONES = 1<<1;
     31     public static final int MAIN_DOCK_SPEAKERS = 1<<2;
     32     public static final int MAIN_HDMI = 1<<3;
     33     public static final int MAIN_USB = 1<<4;
     34 
     35     public CharSequence bluetoothName;
     36     public int mainType = MAIN_SPEAKER;
     37 
     38     public AudioRoutesInfo() {
     39     }
     40 
     41     public AudioRoutesInfo(AudioRoutesInfo o) {
     42         bluetoothName = o.bluetoothName;
     43         mainType = o.mainType;
     44     }
     45 
     46     AudioRoutesInfo(Parcel src) {
     47         bluetoothName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(src);
     48         mainType = src.readInt();
     49     }
     50 
     51     @Override
     52     public int describeContents() {
     53         return 0;
     54     }
     55 
     56     @Override
     57     public String toString() {
     58         return getClass().getSimpleName() + "{ type=" + typeToString(mainType)
     59                 + (TextUtils.isEmpty(bluetoothName) ? "" : ", bluetoothName=" + bluetoothName)
     60                 + " }";
     61     }
     62 
     63     private static String typeToString(int type) {
     64         if (type == MAIN_SPEAKER) return "SPEAKER";
     65         if ((type & MAIN_HEADSET) != 0) return "HEADSET";
     66         if ((type & MAIN_HEADPHONES) != 0) return "HEADPHONES";
     67         if ((type & MAIN_DOCK_SPEAKERS) != 0) return "DOCK_SPEAKERS";
     68         if ((type & MAIN_HDMI) != 0) return "HDMI";
     69         if ((type & MAIN_USB) != 0) return "USB";
     70         return Integer.toHexString(type);
     71     }
     72 
     73     @Override
     74     public void writeToParcel(Parcel dest, int flags) {
     75         TextUtils.writeToParcel(bluetoothName, dest, flags);
     76         dest.writeInt(mainType);
     77     }
     78 
     79     public static final Parcelable.Creator<AudioRoutesInfo> CREATOR
     80             = new Parcelable.Creator<AudioRoutesInfo>() {
     81         public AudioRoutesInfo createFromParcel(Parcel in) {
     82             return new AudioRoutesInfo(in);
     83         }
     84 
     85         public AudioRoutesInfo[] newArray(int size) {
     86             return new AudioRoutesInfo[size];
     87         }
     88     };
     89 }
     90