1 /* 2 * Copyright (C) 2015 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.tv; 18 19 import android.annotation.IntRange; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 import android.util.Log; 25 26 /** 27 * A digital video broadcasting (DVB) device. 28 * 29 * <p> Simple wrapper around a <a href="https://www.linuxtv.org/docs/dvbapi/dvbapi.html">Linux DVB 30 * v3</a> device. 31 * 32 * @see TvInputManager#getDvbDeviceList() 33 * @see TvInputManager#openDvbDevice(DvbDeviceInfo, int) 34 * @hide 35 */ 36 @SystemApi 37 public final class DvbDeviceInfo implements Parcelable { 38 static final String TAG = "DvbDeviceInfo"; 39 40 public static final @NonNull Parcelable.Creator<DvbDeviceInfo> CREATOR = 41 new Parcelable.Creator<DvbDeviceInfo>() { 42 @Override 43 public DvbDeviceInfo createFromParcel(Parcel source) { 44 try { 45 return new DvbDeviceInfo(source); 46 } catch (Exception e) { 47 Log.e(TAG, "Exception creating DvbDeviceInfo from parcel", e); 48 return null; 49 } 50 } 51 52 @Override 53 public DvbDeviceInfo[] newArray(int size) { 54 return new DvbDeviceInfo[size]; 55 } 56 }; 57 58 private final int mAdapterId; 59 private final int mDeviceId; 60 DvbDeviceInfo(Parcel source)61 private DvbDeviceInfo(Parcel source) { 62 mAdapterId = source.readInt(); 63 mDeviceId = source.readInt(); 64 } 65 66 /** 67 * Constructs a new {@link DvbDeviceInfo} with the given adapter ID and device ID. 68 */ DvbDeviceInfo(int adapterId, int deviceId)69 public DvbDeviceInfo(int adapterId, int deviceId) { 70 mAdapterId = adapterId; 71 mDeviceId = deviceId; 72 } 73 74 /** 75 * Returns the adapter ID. 76 * 77 * <p>DVB Adapters contain one or more devices. 78 */ 79 @IntRange(from = 0) getAdapterId()80 public int getAdapterId() { 81 return mAdapterId; 82 } 83 84 /** 85 * Returns the device ID. 86 */ 87 @IntRange(from = 0) getDeviceId()88 public int getDeviceId() { 89 return mDeviceId; 90 } 91 92 // Parcelable 93 @Override describeContents()94 public int describeContents() { 95 return 0; 96 } 97 98 @Override writeToParcel(@onNull Parcel dest, int flags)99 public void writeToParcel(@NonNull Parcel dest, int flags) { 100 dest.writeInt(mAdapterId); 101 dest.writeInt(mDeviceId); 102 } 103 } 104