1/** 2 * Copyright (C) 2018 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 17package android.hardware.radio; 18 19import android.annotation.IntDef; 20import android.annotation.NonNull; 21import android.annotation.SystemApi; 22import android.os.Parcel; 23import android.os.Parcelable; 24 25import java.lang.annotation.Retention; 26import java.lang.annotation.RetentionPolicy; 27import java.util.Collection; 28import java.util.Map; 29import java.util.Objects; 30 31/** 32 * @hide 33 */ 34@SystemApi 35public final class Announcement implements Parcelable { 36 37 /** DAB alarm, RDS emergency program type (PTY 31). */ 38 public static final int TYPE_EMERGENCY = 1; 39 /** DAB warning. */ 40 public static final int TYPE_WARNING = 2; 41 /** DAB road traffic, RDS TA, HD Radio transportation. */ 42 public static final int TYPE_TRAFFIC = 3; 43 /** Weather. */ 44 public static final int TYPE_WEATHER = 4; 45 /** News. */ 46 public static final int TYPE_NEWS = 5; 47 /** DAB event, special event. */ 48 public static final int TYPE_EVENT = 6; 49 /** DAB sport report, RDS sports. */ 50 public static final int TYPE_SPORT = 7; 51 /** All others. */ 52 public static final int TYPE_MISC = 8; 53 /** @hide */ 54 @IntDef(prefix = { "TYPE_" }, value = { 55 TYPE_EMERGENCY, 56 TYPE_WARNING, 57 TYPE_TRAFFIC, 58 TYPE_WEATHER, 59 TYPE_NEWS, 60 TYPE_EVENT, 61 TYPE_SPORT, 62 TYPE_MISC, 63 }) 64 @Retention(RetentionPolicy.SOURCE) 65 public @interface Type {} 66 67 /** 68 * Listener of announcement list events. 69 */ 70 public interface OnListUpdatedListener { 71 /** 72 * An event called whenever a list of active announcements change. 73 * 74 * The entire list is sent each time a new announcement appears or any ends broadcasting. 75 * 76 * @param activeAnnouncements a full list of active announcements 77 */ 78 void onListUpdated(Collection<Announcement> activeAnnouncements); 79 } 80 81 @NonNull private final ProgramSelector mSelector; 82 @Type private final int mType; 83 @NonNull private final Map<String, String> mVendorInfo; 84 85 /** @hide */ 86 public Announcement(@NonNull ProgramSelector selector, @Type int type, 87 @NonNull Map<String, String> vendorInfo) { 88 mSelector = Objects.requireNonNull(selector); 89 mType = Objects.requireNonNull(type); 90 mVendorInfo = Objects.requireNonNull(vendorInfo); 91 } 92 93 private Announcement(@NonNull Parcel in) { 94 mSelector = in.readTypedObject(ProgramSelector.CREATOR); 95 mType = in.readInt(); 96 mVendorInfo = Utils.readStringMap(in); 97 } 98 99 @Override 100 public void writeToParcel(Parcel dest, int flags) { 101 dest.writeTypedObject(mSelector, 0); 102 dest.writeInt(mType); 103 Utils.writeStringMap(dest, mVendorInfo); 104 } 105 106 @Override 107 public int describeContents() { 108 return 0; 109 } 110 111 public static final Parcelable.Creator<Announcement> CREATOR = 112 new Parcelable.Creator<Announcement>() { 113 public Announcement createFromParcel(Parcel in) { 114 return new Announcement(in); 115 } 116 117 public Announcement[] newArray(int size) { 118 return new Announcement[size]; 119 } 120 }; 121 122 public @NonNull ProgramSelector getSelector() { 123 return mSelector; 124 } 125 126 public @Type int getType() { 127 return mType; 128 } 129 130 public @NonNull Map<String, String> getVendorInfo() { 131 return mVendorInfo; 132 } 133} 134