Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 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 { |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 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; |
Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 34 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 35 | public CharSequence bluetoothName; |
| 36 | public int mainType = MAIN_SPEAKER; |
Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 37 | |
| 38 | public AudioRoutesInfo() { |
| 39 | } |
| 40 | |
| 41 | public AudioRoutesInfo(AudioRoutesInfo o) { |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 42 | bluetoothName = o.bluetoothName; |
| 43 | mainType = o.mainType; |
Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | AudioRoutesInfo(Parcel src) { |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 47 | bluetoothName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(src); |
| 48 | mainType = src.readInt(); |
Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public int describeContents() { |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | @Override |
Jae Seo | 18687b7 | 2016-05-07 14:09:43 -0700 | [diff] [blame] | 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 |
Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 74 | public void writeToParcel(Parcel dest, int flags) { |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 75 | TextUtils.writeToParcel(bluetoothName, dest, flags); |
| 76 | dest.writeInt(mainType); |
Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 79 | public static final @android.annotation.NonNull Parcelable.Creator<AudioRoutesInfo> CREATOR |
Dianne Hackborn | 632ca41 | 2012-06-14 19:34:10 -0700 | [diff] [blame] | 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 | } |