| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.radio; |
| 18 |
|
| 19 |
import android.Manifest; |
| 20 |
import android.annotation.CallbackExecutor; |
| 21 |
import android.annotation.IntDef; |
| 22 |
import android.annotation.NonNull; |
| 23 |
import android.annotation.Nullable; |
| 24 |
import android.annotation.RequiresFeature; |
| 25 |
import android.annotation.RequiresPermission; |
| 26 |
import android.annotation.SystemApi; |
| 27 |
import android.annotation.SystemService; |
| 28 |
import android.content.Context; |
| 29 |
import android.content.pm.PackageManager; |
| 30 |
import android.os.Handler; |
| 31 |
import android.os.Parcel; |
| 32 |
import android.os.Parcelable; |
| 33 |
import android.os.RemoteException; |
| 34 |
import android.os.ServiceManager; |
| 35 |
import android.os.ServiceManager.ServiceNotFoundException; |
| 36 |
import android.text.TextUtils; |
| 37 |
import android.util.Log; |
| 38 |
|
| 39 |
import com.android.internal.util.Preconditions; |
| 40 |
|
| 41 |
import java.lang.annotation.Retention; |
| 42 |
import java.lang.annotation.RetentionPolicy; |
| 43 |
import java.util.Arrays; |
| 44 |
import java.util.Collection; |
| 45 |
import java.util.Collections; |
| 46 |
import java.util.HashMap; |
| 47 |
import java.util.List; |
| 48 |
import java.util.Map; |
| 49 |
import java.util.Objects; |
| 50 |
import java.util.Set; |
| 51 |
import java.util.concurrent.Executor; |
| 52 |
import java.util.stream.Collectors; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
@SystemApi |
| 62 |
@SystemService(Context.RADIO_SERVICE) |
| 63 |
@RequiresFeature(PackageManager.FEATURE_BROADCAST_RADIO) |
| 64 |
public class RadioManager { |
| 65 |
private static final String TAG = "BroadcastRadio.manager"; |
| 66 |
|
| 67 |
|
| 68 |
public static final int STATUS_OK = 0; |
| 69 |
|
| 70 |
public static final int STATUS_ERROR = Integer.MIN_VALUE; |
| 71 |
|
| 72 |
public static final int STATUS_PERMISSION_DENIED = -1; |
| 73 |
|
| 74 |
public static final int STATUS_NO_INIT = -19; |
| 75 |
|
| 76 |
public static final int STATUS_BAD_VALUE = -22; |
| 77 |
|
| 78 |
public static final int STATUS_DEAD_OBJECT = -32; |
| 79 |
|
| 80 |
public static final int STATUS_INVALID_OPERATION = -38; |
| 81 |
|
| 82 |
public static final int STATUS_TIMED_OUT = -110; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static final int CLASS_AM_FM = 0; |
| 88 |
|
| 89 |
public static final int CLASS_SAT = 1; |
| 90 |
|
| 91 |
public static final int CLASS_DT = 2; |
| 92 |
|
| 93 |
public static final int BAND_INVALID = -1; |
| 94 |
|
| 95 |
|
| 96 |
public static final int BAND_AM = 0; |
| 97 |
|
| 98 |
|
| 99 |
public static final int BAND_FM = 1; |
| 100 |
|
| 101 |
|
| 102 |
public static final int BAND_FM_HD = 2; |
| 103 |
|
| 104 |
|
| 105 |
public static final int BAND_AM_HD = 3; |
| 106 |
@IntDef(prefix = { "BAND_" }, value = { |
| 107 |
BAND_INVALID, |
| 108 |
BAND_AM, |
| 109 |
BAND_FM, |
| 110 |
BAND_AM_HD, |
| 111 |
BAND_FM_HD, |
| 112 |
}) |
| 113 |
@Retention(RetentionPolicy.SOURCE) |
| 114 |
public @interface Band {} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public static final int REGION_ITU_1 = 0; |
| 120 |
|
| 121 |
|
| 122 |
public static final int REGION_ITU_2 = 1; |
| 123 |
|
| 124 |
|
| 125 |
public static final int REGION_OIRT = 2; |
| 126 |
|
| 127 |
|
| 128 |
public static final int REGION_JAPAN = 3; |
| 129 |
|
| 130 |
|
| 131 |
public static final int REGION_KOREA = 4; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public static final int CONFIG_FORCE_MONO = 1; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public static final int CONFIG_FORCE_ANALOG = 2; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public static final int CONFIG_FORCE_DIGITAL = 3; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
public static final int CONFIG_RDS_AF = 4; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public static final int CONFIG_RDS_REG = 5; |
| 174 |
|
| 175 |
public static final int CONFIG_DAB_DAB_LINKING = 6; |
| 176 |
|
| 177 |
public static final int CONFIG_DAB_FM_LINKING = 7; |
| 178 |
|
| 179 |
public static final int CONFIG_DAB_DAB_SOFT_LINKING = 8; |
| 180 |
|
| 181 |
public static final int CONFIG_DAB_FM_SOFT_LINKING = 9; |
| 182 |
|
| 183 |
|
| 184 |
@IntDef(prefix = { "CONFIG_" }, value = { |
| 185 |
CONFIG_FORCE_MONO, |
| 186 |
CONFIG_FORCE_ANALOG, |
| 187 |
CONFIG_FORCE_DIGITAL, |
| 188 |
CONFIG_RDS_AF, |
| 189 |
CONFIG_RDS_REG, |
| 190 |
CONFIG_DAB_DAB_LINKING, |
| 191 |
CONFIG_DAB_FM_LINKING, |
| 192 |
CONFIG_DAB_DAB_SOFT_LINKING, |
| 193 |
CONFIG_DAB_FM_SOFT_LINKING, |
| 194 |
}) |
| 195 |
@Retention(RetentionPolicy.SOURCE) |
| 196 |
public @interface ConfigFlag {} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public static class ModuleProperties implements Parcelable { |
| 204 |
|
| 205 |
private final int mId; |
| 206 |
@NonNull private final String mServiceName; |
| 207 |
private final int mClassId; |
| 208 |
private final String mImplementor; |
| 209 |
private final String mProduct; |
| 210 |
private final String mVersion; |
| 211 |
private final String mSerial; |
| 212 |
private final int mNumTuners; |
| 213 |
private final int mNumAudioSources; |
| 214 |
private final boolean mIsInitializationRequired; |
| 215 |
private final boolean mIsCaptureSupported; |
| 216 |
private final BandDescriptor[] mBands; |
| 217 |
private final boolean mIsBgScanSupported; |
| 218 |
private final Set<Integer> mSupportedProgramTypes; |
| 219 |
private final Set<Integer> mSupportedIdentifierTypes; |
| 220 |
@Nullable private final Map<String, Integer> mDabFrequencyTable; |
| 221 |
@NonNull private final Map<String, String> mVendorInfo; |
| 222 |
|
| 223 |
|
| 224 |
public ModuleProperties(int id, String serviceName, int classId, String implementor, |
| 225 |
String product, String version, String serial, int numTuners, int numAudioSources, |
| 226 |
boolean isInitializationRequired, boolean isCaptureSupported, |
| 227 |
BandDescriptor[] bands, boolean isBgScanSupported, |
| 228 |
@ProgramSelector.ProgramType int[] supportedProgramTypes, |
| 229 |
@ProgramSelector.IdentifierType int[] supportedIdentifierTypes, |
| 230 |
@Nullable Map<String, Integer> dabFrequencyTable, |
| 231 |
Map<String, String> vendorInfo) { |
| 232 |
mId = id; |
| 233 |
mServiceName = TextUtils.isEmpty(serviceName) ? "default" : serviceName; |
| 234 |
mClassId = classId; |
| 235 |
mImplementor = implementor; |
| 236 |
mProduct = product; |
| 237 |
mVersion = version; |
| 238 |
mSerial = serial; |
| 239 |
mNumTuners = numTuners; |
| 240 |
mNumAudioSources = numAudioSources; |
| 241 |
mIsInitializationRequired = isInitializationRequired; |
| 242 |
mIsCaptureSupported = isCaptureSupported; |
| 243 |
mBands = bands; |
| 244 |
mIsBgScanSupported = isBgScanSupported; |
| 245 |
mSupportedProgramTypes = arrayToSet(supportedProgramTypes); |
| 246 |
mSupportedIdentifierTypes = arrayToSet(supportedIdentifierTypes); |
| 247 |
if (dabFrequencyTable != null) { |
| 248 |
for (Map.Entry<String, Integer> entry : dabFrequencyTable.entrySet()) { |
| 249 |
Objects.requireNonNull(entry.getKey()); |
| 250 |
Objects.requireNonNull(entry.getValue()); |
| 251 |
} |
| 252 |
} |
| 253 |
mDabFrequencyTable = dabFrequencyTable; |
| 254 |
mVendorInfo = (vendorInfo == null) ? new HashMap<>() : vendorInfo; |
| 255 |
} |
| 256 |
|
| 257 |
private static Set<Integer> arrayToSet(int[] arr) { |
| 258 |
return Arrays.stream(arr).boxed().collect(Collectors.toSet()); |
| 259 |
} |
| 260 |
|
| 261 |
private static int[] setToArray(Set<Integer> set) { |
| 262 |
return set.stream().mapToInt(Integer::intValue).toArray(); |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public int getId() { |
| 270 |
return mId; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
public @NonNull String getServiceName() { |
| 278 |
return mServiceName; |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
public int getClassId() { |
| 285 |
return mClassId; |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public String getImplementor() { |
| 292 |
return mImplementor; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
public String getProduct() { |
| 299 |
return mProduct; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
public String getVersion() { |
| 306 |
return mVersion; |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
public String getSerial() { |
| 314 |
return mSerial; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
public int getNumTuners() { |
| 322 |
return mNumTuners; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
public int getNumAudioSources() { |
| 332 |
return mNumAudioSources; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
public boolean isInitializationRequired() { |
| 344 |
return mIsInitializationRequired; |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
public boolean isCaptureSupported() { |
| 353 |
return mIsCaptureSupported; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
public boolean isBackgroundScanningSupported() { |
| 364 |
return mIsBgScanSupported; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
public boolean isProgramTypeSupported(@ProgramSelector.ProgramType int type) { |
| 376 |
return mSupportedProgramTypes.contains(type); |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
public boolean isProgramIdentifierSupported(@ProgramSelector.IdentifierType int type) { |
| 389 |
return mSupportedIdentifierTypes.contains(type); |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
public @Nullable Map<String, Integer> getDabFrequencyTable() { |
| 402 |
return mDabFrequencyTable; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
public @NonNull Map<String, String> getVendorInfo() { |
| 416 |
return mVendorInfo; |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
public BandDescriptor[] getBands() { |
| 423 |
return mBands; |
| 424 |
} |
| 425 |
|
| 426 |
private ModuleProperties(Parcel in) { |
| 427 |
mId = in.readInt(); |
| 428 |
String serviceName = in.readString(); |
| 429 |
mServiceName = TextUtils.isEmpty(serviceName) ? "default" : serviceName; |
| 430 |
mClassId = in.readInt(); |
| 431 |
mImplementor = in.readString(); |
| 432 |
mProduct = in.readString(); |
| 433 |
mVersion = in.readString(); |
| 434 |
mSerial = in.readString(); |
| 435 |
mNumTuners = in.readInt(); |
| 436 |
mNumAudioSources = in.readInt(); |
| 437 |
mIsInitializationRequired = in.readInt() == 1; |
| 438 |
mIsCaptureSupported = in.readInt() == 1; |
| 439 |
Parcelable[] tmp = in.readParcelableArray(BandDescriptor.class.getClassLoader(), |
| 440 |
BandDescriptor.class); |
| 441 |
mBands = new BandDescriptor[tmp.length]; |
| 442 |
for (int i = 0; i < tmp.length; i++) { |
| 443 |
mBands[i] = (BandDescriptor) tmp[i]; |
| 444 |
} |
| 445 |
mIsBgScanSupported = in.readInt() == 1; |
| 446 |
mSupportedProgramTypes = arrayToSet(in.createIntArray()); |
| 447 |
mSupportedIdentifierTypes = arrayToSet(in.createIntArray()); |
| 448 |
mDabFrequencyTable = Utils.readStringIntMap(in); |
| 449 |
mVendorInfo = Utils.readStringMap(in); |
| 450 |
} |
| 451 |
|
| 452 |
public static final @android.annotation.NonNull Parcelable.Creator<ModuleProperties> CREATOR |
| 453 |
= new Parcelable.Creator<ModuleProperties>() { |
| 454 |
public ModuleProperties createFromParcel(Parcel in) { |
| 455 |
return new ModuleProperties(in); |
| 456 |
} |
| 457 |
|
| 458 |
public ModuleProperties[] newArray(int size) { |
| 459 |
return new ModuleProperties[size]; |
| 460 |
} |
| 461 |
}; |
| 462 |
|
| 463 |
@Override |
| 464 |
public void writeToParcel(Parcel dest, int flags) { |
| 465 |
dest.writeInt(mId); |
| 466 |
dest.writeString(mServiceName); |
| 467 |
dest.writeInt(mClassId); |
| 468 |
dest.writeString(mImplementor); |
| 469 |
dest.writeString(mProduct); |
| 470 |
dest.writeString(mVersion); |
| 471 |
dest.writeString(mSerial); |
| 472 |
dest.writeInt(mNumTuners); |
| 473 |
dest.writeInt(mNumAudioSources); |
| 474 |
dest.writeInt(mIsInitializationRequired ? 1 : 0); |
| 475 |
dest.writeInt(mIsCaptureSupported ? 1 : 0); |
| 476 |
dest.writeParcelableArray(mBands, flags); |
| 477 |
dest.writeInt(mIsBgScanSupported ? 1 : 0); |
| 478 |
dest.writeIntArray(setToArray(mSupportedProgramTypes)); |
| 479 |
dest.writeIntArray(setToArray(mSupportedIdentifierTypes)); |
| 480 |
Utils.writeStringIntMap(dest, mDabFrequencyTable); |
| 481 |
Utils.writeStringMap(dest, mVendorInfo); |
| 482 |
} |
| 483 |
|
| 484 |
@Override |
| 485 |
public int describeContents() { |
| 486 |
return 0; |
| 487 |
} |
| 488 |
|
| 489 |
@NonNull |
| 490 |
@Override |
| 491 |
public String toString() { |
| 492 |
return "ModuleProperties [mId=" + mId |
| 493 |
+ ", mServiceName=" + mServiceName + ", mClassId=" + mClassId |
| 494 |
+ ", mImplementor=" + mImplementor + ", mProduct=" + mProduct |
| 495 |
+ ", mVersion=" + mVersion + ", mSerial=" + mSerial |
| 496 |
+ ", mNumTuners=" + mNumTuners |
| 497 |
+ ", mNumAudioSources=" + mNumAudioSources |
| 498 |
+ ", mIsInitializationRequired=" + mIsInitializationRequired |
| 499 |
+ ", mIsCaptureSupported=" + mIsCaptureSupported |
| 500 |
+ ", mIsBgScanSupported=" + mIsBgScanSupported |
| 501 |
+ ", mBands=" + Arrays.toString(mBands) + "]"; |
| 502 |
} |
| 503 |
|
| 504 |
@Override |
| 505 |
public int hashCode() { |
| 506 |
return Objects.hash(mId, mServiceName, mClassId, mImplementor, mProduct, mVersion, |
| 507 |
mSerial, mNumTuners, mNumAudioSources, mIsInitializationRequired, |
| 508 |
mIsCaptureSupported, Arrays.hashCode(mBands), mIsBgScanSupported, |
| 509 |
mDabFrequencyTable, mVendorInfo); |
| 510 |
} |
| 511 |
|
| 512 |
@Override |
| 513 |
public boolean equals(@Nullable Object obj) { |
| 514 |
if (this == obj) return true; |
| 515 |
if (!(obj instanceof ModuleProperties)) return false; |
| 516 |
ModuleProperties other = (ModuleProperties) obj; |
| 517 |
|
| 518 |
if (mId != other.getId()) return false; |
| 519 |
if (!TextUtils.equals(mServiceName, other.mServiceName)) return false; |
| 520 |
if (mClassId != other.mClassId) return false; |
| 521 |
if (!Objects.equals(mImplementor, other.mImplementor)) return false; |
| 522 |
if (!Objects.equals(mProduct, other.mProduct)) return false; |
| 523 |
if (!Objects.equals(mVersion, other.mVersion)) return false; |
| 524 |
if (!Objects.equals(mSerial, other.mSerial)) return false; |
| 525 |
if (mNumTuners != other.mNumTuners) return false; |
| 526 |
if (mNumAudioSources != other.mNumAudioSources) return false; |
| 527 |
if (mIsInitializationRequired != other.mIsInitializationRequired) return false; |
| 528 |
if (mIsCaptureSupported != other.mIsCaptureSupported) return false; |
| 529 |
if (!Arrays.equals(mBands, other.mBands)) return false; |
| 530 |
if (mIsBgScanSupported != other.mIsBgScanSupported) return false; |
| 531 |
if (!Objects.equals(mDabFrequencyTable, other.mDabFrequencyTable)) return false; |
| 532 |
if (!Objects.equals(mVendorInfo, other.mVendorInfo)) return false; |
| 533 |
return true; |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
public static class BandDescriptor implements Parcelable { |
| 540 |
|
| 541 |
private final int mRegion; |
| 542 |
private final int mType; |
| 543 |
private final int mLowerLimit; |
| 544 |
private final int mUpperLimit; |
| 545 |
private final int mSpacing; |
| 546 |
|
| 547 |
BandDescriptor(int region, int type, int lowerLimit, int upperLimit, int spacing) { |
| 548 |
if (type != BAND_AM && type != BAND_FM && type != BAND_FM_HD && type != BAND_AM_HD) { |
| 549 |
throw new IllegalArgumentException("Unsupported band: " + type); |
| 550 |
} |
| 551 |
mRegion = region; |
| 552 |
mType = type; |
| 553 |
mLowerLimit = lowerLimit; |
| 554 |
mUpperLimit = upperLimit; |
| 555 |
mSpacing = spacing; |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
public int getRegion() { |
| 562 |
return mRegion; |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
public int getType() { |
| 572 |
return mType; |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
public boolean isAmBand() { |
| 581 |
return mType == BAND_AM || mType == BAND_AM_HD; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
public boolean isFmBand() { |
| 590 |
return mType == BAND_FM || mType == BAND_FM_HD; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
public int getLowerLimit() { |
| 598 |
return mLowerLimit; |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
public int getUpperLimit() { |
| 605 |
return mUpperLimit; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
public int getSpacing() { |
| 612 |
return mSpacing; |
| 613 |
} |
| 614 |
|
| 615 |
private BandDescriptor(Parcel in) { |
| 616 |
mRegion = in.readInt(); |
| 617 |
mType = in.readInt(); |
| 618 |
mLowerLimit = in.readInt(); |
| 619 |
mUpperLimit = in.readInt(); |
| 620 |
mSpacing = in.readInt(); |
| 621 |
} |
| 622 |
|
| 623 |
private static int lookupTypeFromParcel(Parcel in) { |
| 624 |
int pos = in.dataPosition(); |
| 625 |
in.readInt(); |
| 626 |
int type = in.readInt(); |
| 627 |
in.setDataPosition(pos); |
| 628 |
return type; |
| 629 |
} |
| 630 |
|
| 631 |
public static final @android.annotation.NonNull Parcelable.Creator<BandDescriptor> CREATOR |
| 632 |
= new Parcelable.Creator<BandDescriptor>() { |
| 633 |
public BandDescriptor createFromParcel(Parcel in) { |
| 634 |
int type = lookupTypeFromParcel(in); |
| 635 |
switch (type) { |
| 636 |
case BAND_FM: |
| 637 |
case BAND_FM_HD: |
| 638 |
return new FmBandDescriptor(in); |
| 639 |
case BAND_AM: |
| 640 |
case BAND_AM_HD: |
| 641 |
return new AmBandDescriptor(in); |
| 642 |
default: |
| 643 |
throw new IllegalArgumentException("Unsupported band: " + type); |
| 644 |
} |
| 645 |
} |
| 646 |
|
| 647 |
public BandDescriptor[] newArray(int size) { |
| 648 |
return new BandDescriptor[size]; |
| 649 |
} |
| 650 |
}; |
| 651 |
|
| 652 |
@Override |
| 653 |
public void writeToParcel(Parcel dest, int flags) { |
| 654 |
dest.writeInt(mRegion); |
| 655 |
dest.writeInt(mType); |
| 656 |
dest.writeInt(mLowerLimit); |
| 657 |
dest.writeInt(mUpperLimit); |
| 658 |
dest.writeInt(mSpacing); |
| 659 |
} |
| 660 |
|
| 661 |
@Override |
| 662 |
public int describeContents() { |
| 663 |
return 0; |
| 664 |
} |
| 665 |
|
| 666 |
@NonNull |
| 667 |
@Override |
| 668 |
public String toString() { |
| 669 |
return "BandDescriptor [mRegion=" + mRegion + ", mType=" + mType + ", mLowerLimit=" |
| 670 |
+ mLowerLimit + ", mUpperLimit=" + mUpperLimit + ", mSpacing=" + mSpacing + "]"; |
| 671 |
} |
| 672 |
|
| 673 |
@Override |
| 674 |
public int hashCode() { |
| 675 |
final int prime = 31; |
| 676 |
int result = 1; |
| 677 |
result = prime * result + mRegion; |
| 678 |
result = prime * result + mType; |
| 679 |
result = prime * result + mLowerLimit; |
| 680 |
result = prime * result + mUpperLimit; |
| 681 |
result = prime * result + mSpacing; |
| 682 |
return result; |
| 683 |
} |
| 684 |
|
| 685 |
@Override |
| 686 |
public boolean equals(@Nullable Object obj) { |
| 687 |
if (this == obj) |
| 688 |
return true; |
| 689 |
if (!(obj instanceof BandDescriptor)) |
| 690 |
return false; |
| 691 |
BandDescriptor other = (BandDescriptor) obj; |
| 692 |
if (mRegion != other.getRegion()) |
| 693 |
return false; |
| 694 |
if (mType != other.getType()) |
| 695 |
return false; |
| 696 |
if (mLowerLimit != other.getLowerLimit()) |
| 697 |
return false; |
| 698 |
if (mUpperLimit != other.getUpperLimit()) |
| 699 |
return false; |
| 700 |
if (mSpacing != other.getSpacing()) |
| 701 |
return false; |
| 702 |
return true; |
| 703 |
} |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
public static class FmBandDescriptor extends BandDescriptor { |
| 710 |
private final boolean mStereo; |
| 711 |
private final boolean mRds; |
| 712 |
private final boolean mTa; |
| 713 |
private final boolean mAf; |
| 714 |
private final boolean mEa; |
| 715 |
|
| 716 |
|
| 717 |
public FmBandDescriptor(int region, int type, int lowerLimit, int upperLimit, int spacing, |
| 718 |
boolean stereo, boolean rds, boolean ta, boolean af, boolean ea) { |
| 719 |
super(region, type, lowerLimit, upperLimit, spacing); |
| 720 |
mStereo = stereo; |
| 721 |
mRds = rds; |
| 722 |
mTa = ta; |
| 723 |
mAf = af; |
| 724 |
mEa = ea; |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
public boolean isStereoSupported() { |
| 731 |
return mStereo; |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
public boolean isRdsSupported() { |
| 737 |
return mRds; |
| 738 |
} |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
public boolean isTaSupported() { |
| 743 |
return mTa; |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
public boolean isAfSupported() { |
| 749 |
return mAf; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
public boolean isEaSupported() { |
| 756 |
return mEa; |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
private FmBandDescriptor(Parcel in) { |
| 761 |
super(in); |
| 762 |
mStereo = in.readByte() == 1; |
| 763 |
mRds = in.readByte() == 1; |
| 764 |
mTa = in.readByte() == 1; |
| 765 |
mAf = in.readByte() == 1; |
| 766 |
mEa = in.readByte() == 1; |
| 767 |
} |
| 768 |
|
| 769 |
public static final @android.annotation.NonNull Parcelable.Creator<FmBandDescriptor> CREATOR |
| 770 |
= new Parcelable.Creator<FmBandDescriptor>() { |
| 771 |
public FmBandDescriptor createFromParcel(Parcel in) { |
| 772 |
return new FmBandDescriptor(in); |
| 773 |
} |
| 774 |
|
| 775 |
public FmBandDescriptor[] newArray(int size) { |
| 776 |
return new FmBandDescriptor[size]; |
| 777 |
} |
| 778 |
}; |
| 779 |
|
| 780 |
@Override |
| 781 |
public void writeToParcel(Parcel dest, int flags) { |
| 782 |
super.writeToParcel(dest, flags); |
| 783 |
dest.writeByte((byte) (mStereo ? 1 : 0)); |
| 784 |
dest.writeByte((byte) (mRds ? 1 : 0)); |
| 785 |
dest.writeByte((byte) (mTa ? 1 : 0)); |
| 786 |
dest.writeByte((byte) (mAf ? 1 : 0)); |
| 787 |
dest.writeByte((byte) (mEa ? 1 : 0)); |
| 788 |
} |
| 789 |
|
| 790 |
@Override |
| 791 |
public int describeContents() { |
| 792 |
return 0; |
| 793 |
} |
| 794 |
|
| 795 |
@NonNull |
| 796 |
@Override |
| 797 |
public String toString() { |
| 798 |
return "FmBandDescriptor [ "+ super.toString() + " mStereo=" + mStereo |
| 799 |
+ ", mRds=" + mRds + ", mTa=" + mTa + ", mAf=" + mAf + |
| 800 |
", mEa =" + mEa + "]"; |
| 801 |
} |
| 802 |
|
| 803 |
@Override |
| 804 |
public int hashCode() { |
| 805 |
final int prime = 31; |
| 806 |
int result = super.hashCode(); |
| 807 |
result = prime * result + (mStereo ? 1 : 0); |
| 808 |
result = prime * result + (mRds ? 1 : 0); |
| 809 |
result = prime * result + (mTa ? 1 : 0); |
| 810 |
result = prime * result + (mAf ? 1 : 0); |
| 811 |
result = prime * result + (mEa ? 1 : 0); |
| 812 |
return result; |
| 813 |
} |
| 814 |
|
| 815 |
@Override |
| 816 |
public boolean equals(@Nullable Object obj) { |
| 817 |
if (this == obj) |
| 818 |
return true; |
| 819 |
if (!super.equals(obj)) |
| 820 |
return false; |
| 821 |
if (!(obj instanceof FmBandDescriptor)) |
| 822 |
return false; |
| 823 |
FmBandDescriptor other = (FmBandDescriptor) obj; |
| 824 |
if (mStereo != other.isStereoSupported()) |
| 825 |
return false; |
| 826 |
if (mRds != other.isRdsSupported()) |
| 827 |
return false; |
| 828 |
if (mTa != other.isTaSupported()) |
| 829 |
return false; |
| 830 |
if (mAf != other.isAfSupported()) |
| 831 |
return false; |
| 832 |
if (mEa != other.isEaSupported()) |
| 833 |
return false; |
| 834 |
return true; |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
public static class AmBandDescriptor extends BandDescriptor { |
| 841 |
|
| 842 |
private final boolean mStereo; |
| 843 |
|
| 844 |
|
| 845 |
public AmBandDescriptor(int region, int type, int lowerLimit, int upperLimit, int spacing, |
| 846 |
boolean stereo) { |
| 847 |
super(region, type, lowerLimit, upperLimit, spacing); |
| 848 |
mStereo = stereo; |
| 849 |
} |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
public boolean isStereoSupported() { |
| 855 |
return mStereo; |
| 856 |
} |
| 857 |
|
| 858 |
private AmBandDescriptor(Parcel in) { |
| 859 |
super(in); |
| 860 |
mStereo = in.readByte() == 1; |
| 861 |
} |
| 862 |
|
| 863 |
public static final @android.annotation.NonNull Parcelable.Creator<AmBandDescriptor> CREATOR |
| 864 |
= new Parcelable.Creator<AmBandDescriptor>() { |
| 865 |
public AmBandDescriptor createFromParcel(Parcel in) { |
| 866 |
return new AmBandDescriptor(in); |
| 867 |
} |
| 868 |
|
| 869 |
public AmBandDescriptor[] newArray(int size) { |
| 870 |
return new AmBandDescriptor[size]; |
| 871 |
} |
| 872 |
}; |
| 873 |
|
| 874 |
@Override |
| 875 |
public void writeToParcel(Parcel dest, int flags) { |
| 876 |
super.writeToParcel(dest, flags); |
| 877 |
dest.writeByte((byte) (mStereo ? 1 : 0)); |
| 878 |
} |
| 879 |
|
| 880 |
@Override |
| 881 |
public int describeContents() { |
| 882 |
return 0; |
| 883 |
} |
| 884 |
|
| 885 |
@NonNull |
| 886 |
@Override |
| 887 |
public String toString() { |
| 888 |
return "AmBandDescriptor [ "+ super.toString() + " mStereo=" + mStereo + "]"; |
| 889 |
} |
| 890 |
|
| 891 |
@Override |
| 892 |
public int hashCode() { |
| 893 |
final int prime = 31; |
| 894 |
int result = super.hashCode(); |
| 895 |
result = prime * result + (mStereo ? 1 : 0); |
| 896 |
return result; |
| 897 |
} |
| 898 |
|
| 899 |
@Override |
| 900 |
public boolean equals(@Nullable Object obj) { |
| 901 |
if (this == obj) |
| 902 |
return true; |
| 903 |
if (!super.equals(obj)) |
| 904 |
return false; |
| 905 |
if (!(obj instanceof AmBandDescriptor)) |
| 906 |
return false; |
| 907 |
AmBandDescriptor other = (AmBandDescriptor) obj; |
| 908 |
if (mStereo != other.isStereoSupported()) |
| 909 |
return false; |
| 910 |
return true; |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
public static class BandConfig implements Parcelable { |
| 917 |
|
| 918 |
@NonNull final BandDescriptor mDescriptor; |
| 919 |
|
| 920 |
BandConfig(BandDescriptor descriptor) { |
| 921 |
mDescriptor = Objects.requireNonNull(descriptor); |
| 922 |
} |
| 923 |
|
| 924 |
BandConfig(int region, int type, int lowerLimit, int upperLimit, int spacing) { |
| 925 |
mDescriptor = new BandDescriptor(region, type, lowerLimit, upperLimit, spacing); |
| 926 |
} |
| 927 |
|
| 928 |
private BandConfig(Parcel in) { |
| 929 |
mDescriptor = new BandDescriptor(in); |
| 930 |
} |
| 931 |
|
| 932 |
BandDescriptor getDescriptor() { |
| 933 |
return mDescriptor; |
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
public int getRegion() { |
| 940 |
return mDescriptor.getRegion(); |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
public int getType() { |
| 950 |
return mDescriptor.getType(); |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
public int getLowerLimit() { |
| 957 |
return mDescriptor.getLowerLimit(); |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
public int getUpperLimit() { |
| 964 |
return mDescriptor.getUpperLimit(); |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
public int getSpacing() { |
| 971 |
return mDescriptor.getSpacing(); |
| 972 |
} |
| 973 |
|
| 974 |
|
| 975 |
public static final @android.annotation.NonNull Parcelable.Creator<BandConfig> CREATOR |
| 976 |
= new Parcelable.Creator<BandConfig>() { |
| 977 |
public BandConfig createFromParcel(Parcel in) { |
| 978 |
int type = BandDescriptor.lookupTypeFromParcel(in); |
| 979 |
switch (type) { |
| 980 |
case BAND_FM: |
| 981 |
case BAND_FM_HD: |
| 982 |
return new FmBandConfig(in); |
| 983 |
case BAND_AM: |
| 984 |
case BAND_AM_HD: |
| 985 |
return new AmBandConfig(in); |
| 986 |
default: |
| 987 |
throw new IllegalArgumentException("Unsupported band: " + type); |
| 988 |
} |
| 989 |
} |
| 990 |
|
| 991 |
public BandConfig[] newArray(int size) { |
| 992 |
return new BandConfig[size]; |
| 993 |
} |
| 994 |
}; |
| 995 |
|
| 996 |
@Override |
| 997 |
public void writeToParcel(Parcel dest, int flags) { |
| 998 |
mDescriptor.writeToParcel(dest, flags); |
| 999 |
} |
| 1000 |
|
| 1001 |
@Override |
| 1002 |
public int describeContents() { |
| 1003 |
return 0; |
| 1004 |
} |
| 1005 |
|
| 1006 |
@NonNull |
| 1007 |
@Override |
| 1008 |
public String toString() { |
| 1009 |
return "BandConfig [ " + mDescriptor.toString() + "]"; |
| 1010 |
} |
| 1011 |
|
| 1012 |
@Override |
| 1013 |
public int hashCode() { |
| 1014 |
final int prime = 31; |
| 1015 |
int result = 1; |
| 1016 |
result = prime * result + mDescriptor.hashCode(); |
| 1017 |
return result; |
| 1018 |
} |
| 1019 |
|
| 1020 |
@Override |
| 1021 |
public boolean equals(@Nullable Object obj) { |
| 1022 |
if (this == obj) |
| 1023 |
return true; |
| 1024 |
if (!(obj instanceof BandConfig)) |
| 1025 |
return false; |
| 1026 |
BandConfig other = (BandConfig) obj; |
| 1027 |
BandDescriptor otherDesc = other.getDescriptor(); |
| 1028 |
if ((mDescriptor == null) != (otherDesc == null)) return false; |
| 1029 |
if (mDescriptor != null && !mDescriptor.equals(otherDesc)) return false; |
| 1030 |
return true; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
public static class FmBandConfig extends BandConfig { |
| 1038 |
private final boolean mStereo; |
| 1039 |
private final boolean mRds; |
| 1040 |
private final boolean mTa; |
| 1041 |
private final boolean mAf; |
| 1042 |
private final boolean mEa; |
| 1043 |
|
| 1044 |
|
| 1045 |
public FmBandConfig(FmBandDescriptor descriptor) { |
| 1046 |
super((BandDescriptor)descriptor); |
| 1047 |
mStereo = descriptor.isStereoSupported(); |
| 1048 |
mRds = descriptor.isRdsSupported(); |
| 1049 |
mTa = descriptor.isTaSupported(); |
| 1050 |
mAf = descriptor.isAfSupported(); |
| 1051 |
mEa = descriptor.isEaSupported(); |
| 1052 |
} |
| 1053 |
|
| 1054 |
FmBandConfig(int region, int type, int lowerLimit, int upperLimit, int spacing, |
| 1055 |
boolean stereo, boolean rds, boolean ta, boolean af, boolean ea) { |
| 1056 |
super(region, type, lowerLimit, upperLimit, spacing); |
| 1057 |
mStereo = stereo; |
| 1058 |
mRds = rds; |
| 1059 |
mTa = ta; |
| 1060 |
mAf = af; |
| 1061 |
mEa = ea; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
public boolean getStereo() { |
| 1068 |
return mStereo; |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
public boolean getRds() { |
| 1075 |
return mRds; |
| 1076 |
} |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
public boolean getTa() { |
| 1082 |
return mTa; |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
public boolean getAf() { |
| 1089 |
return mAf; |
| 1090 |
} |
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
public boolean getEa() { |
| 1097 |
return mEa; |
| 1098 |
} |
| 1099 |
|
| 1100 |
private FmBandConfig(Parcel in) { |
| 1101 |
super(in); |
| 1102 |
mStereo = in.readByte() == 1; |
| 1103 |
mRds = in.readByte() == 1; |
| 1104 |
mTa = in.readByte() == 1; |
| 1105 |
mAf = in.readByte() == 1; |
| 1106 |
mEa = in.readByte() == 1; |
| 1107 |
} |
| 1108 |
|
| 1109 |
public static final @android.annotation.NonNull Parcelable.Creator<FmBandConfig> CREATOR |
| 1110 |
= new Parcelable.Creator<FmBandConfig>() { |
| 1111 |
public FmBandConfig createFromParcel(Parcel in) { |
| 1112 |
return new FmBandConfig(in); |
| 1113 |
} |
| 1114 |
|
| 1115 |
public FmBandConfig[] newArray(int size) { |
| 1116 |
return new FmBandConfig[size]; |
| 1117 |
} |
| 1118 |
}; |
| 1119 |
|
| 1120 |
@Override |
| 1121 |
public void writeToParcel(Parcel dest, int flags) { |
| 1122 |
super.writeToParcel(dest, flags); |
| 1123 |
dest.writeByte((byte) (mStereo ? 1 : 0)); |
| 1124 |
dest.writeByte((byte) (mRds ? 1 : 0)); |
| 1125 |
dest.writeByte((byte) (mTa ? 1 : 0)); |
| 1126 |
dest.writeByte((byte) (mAf ? 1 : 0)); |
| 1127 |
dest.writeByte((byte) (mEa ? 1 : 0)); |
| 1128 |
} |
| 1129 |
|
| 1130 |
@Override |
| 1131 |
public int describeContents() { |
| 1132 |
return 0; |
| 1133 |
} |
| 1134 |
|
| 1135 |
@NonNull |
| 1136 |
@Override |
| 1137 |
public String toString() { |
| 1138 |
return "FmBandConfig [" + super.toString() |
| 1139 |
+ ", mStereo=" + mStereo + ", mRds=" + mRds + ", mTa=" + mTa |
| 1140 |
+ ", mAf=" + mAf + ", mEa =" + mEa + "]"; |
| 1141 |
} |
| 1142 |
|
| 1143 |
@Override |
| 1144 |
public int hashCode() { |
| 1145 |
final int prime = 31; |
| 1146 |
int result = super.hashCode(); |
| 1147 |
result = prime * result + (mStereo ? 1 : 0); |
| 1148 |
result = prime * result + (mRds ? 1 : 0); |
| 1149 |
result = prime * result + (mTa ? 1 : 0); |
| 1150 |
result = prime * result + (mAf ? 1 : 0); |
| 1151 |
result = prime * result + (mEa ? 1 : 0); |
| 1152 |
return result; |
| 1153 |
} |
| 1154 |
|
| 1155 |
@Override |
| 1156 |
public boolean equals(@Nullable Object obj) { |
| 1157 |
if (this == obj) |
| 1158 |
return true; |
| 1159 |
if (!super.equals(obj)) |
| 1160 |
return false; |
| 1161 |
if (!(obj instanceof FmBandConfig)) |
| 1162 |
return false; |
| 1163 |
FmBandConfig other = (FmBandConfig) obj; |
| 1164 |
if (mStereo != other.mStereo) |
| 1165 |
return false; |
| 1166 |
if (mRds != other.mRds) |
| 1167 |
return false; |
| 1168 |
if (mTa != other.mTa) |
| 1169 |
return false; |
| 1170 |
if (mAf != other.mAf) |
| 1171 |
return false; |
| 1172 |
if (mEa != other.mEa) |
| 1173 |
return false; |
| 1174 |
return true; |
| 1175 |
} |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
public static class Builder { |
| 1181 |
private final BandDescriptor mDescriptor; |
| 1182 |
private boolean mStereo; |
| 1183 |
private boolean mRds; |
| 1184 |
private boolean mTa; |
| 1185 |
private boolean mAf; |
| 1186 |
private boolean mEa; |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
public Builder(FmBandDescriptor descriptor) { |
| 1193 |
mDescriptor = new BandDescriptor(descriptor.getRegion(), descriptor.getType(), |
| 1194 |
descriptor.getLowerLimit(), descriptor.getUpperLimit(), |
| 1195 |
descriptor.getSpacing()); |
| 1196 |
mStereo = descriptor.isStereoSupported(); |
| 1197 |
mRds = descriptor.isRdsSupported(); |
| 1198 |
mTa = descriptor.isTaSupported(); |
| 1199 |
mAf = descriptor.isAfSupported(); |
| 1200 |
mEa = descriptor.isEaSupported(); |
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
public Builder(FmBandConfig config) { |
| 1208 |
mDescriptor = new BandDescriptor(config.getRegion(), config.getType(), |
| 1209 |
config.getLowerLimit(), config.getUpperLimit(), config.getSpacing()); |
| 1210 |
mStereo = config.getStereo(); |
| 1211 |
mRds = config.getRds(); |
| 1212 |
mTa = config.getTa(); |
| 1213 |
mAf = config.getAf(); |
| 1214 |
mEa = config.getEa(); |
| 1215 |
} |
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
public FmBandConfig build() { |
| 1223 |
FmBandConfig config = new FmBandConfig(mDescriptor.getRegion(), |
| 1224 |
mDescriptor.getType(), mDescriptor.getLowerLimit(), |
| 1225 |
mDescriptor.getUpperLimit(), mDescriptor.getSpacing(), |
| 1226 |
mStereo, mRds, mTa, mAf, mEa); |
| 1227 |
return config; |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
public Builder setStereo(boolean state) { |
| 1235 |
mStereo = state; |
| 1236 |
return this; |
| 1237 |
} |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
public Builder setRds(boolean state) { |
| 1244 |
mRds = state; |
| 1245 |
return this; |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
public Builder setTa(boolean state) { |
| 1253 |
mTa = state; |
| 1254 |
return this; |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
public Builder setAf(boolean state) { |
| 1262 |
mAf = state; |
| 1263 |
return this; |
| 1264 |
} |
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
public Builder setEa(boolean state) { |
| 1271 |
mEa = state; |
| 1272 |
return this; |
| 1273 |
} |
| 1274 |
}; |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
public static class AmBandConfig extends BandConfig { |
| 1280 |
private final boolean mStereo; |
| 1281 |
|
| 1282 |
|
| 1283 |
public AmBandConfig(AmBandDescriptor descriptor) { |
| 1284 |
super((BandDescriptor)descriptor); |
| 1285 |
mStereo = descriptor.isStereoSupported(); |
| 1286 |
} |
| 1287 |
|
| 1288 |
AmBandConfig(int region, int type, int lowerLimit, int upperLimit, int spacing, |
| 1289 |
boolean stereo) { |
| 1290 |
super(region, type, lowerLimit, upperLimit, spacing); |
| 1291 |
mStereo = stereo; |
| 1292 |
} |
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
public boolean getStereo() { |
| 1298 |
return mStereo; |
| 1299 |
} |
| 1300 |
|
| 1301 |
private AmBandConfig(Parcel in) { |
| 1302 |
super(in); |
| 1303 |
mStereo = in.readByte() == 1; |
| 1304 |
} |
| 1305 |
|
| 1306 |
public static final @android.annotation.NonNull Parcelable.Creator<AmBandConfig> CREATOR |
| 1307 |
= new Parcelable.Creator<AmBandConfig>() { |
| 1308 |
public AmBandConfig createFromParcel(Parcel in) { |
| 1309 |
return new AmBandConfig(in); |
| 1310 |
} |
| 1311 |
|
| 1312 |
public AmBandConfig[] newArray(int size) { |
| 1313 |
return new AmBandConfig[size]; |
| 1314 |
} |
| 1315 |
}; |
| 1316 |
|
| 1317 |
@Override |
| 1318 |
public void writeToParcel(Parcel dest, int flags) { |
| 1319 |
super.writeToParcel(dest, flags); |
| 1320 |
dest.writeByte((byte) (mStereo ? 1 : 0)); |
| 1321 |
} |
| 1322 |
|
| 1323 |
@Override |
| 1324 |
public int describeContents() { |
| 1325 |
return 0; |
| 1326 |
} |
| 1327 |
|
| 1328 |
@NonNull |
| 1329 |
@Override |
| 1330 |
public String toString() { |
| 1331 |
return "AmBandConfig [" + super.toString() |
| 1332 |
+ ", mStereo=" + mStereo + "]"; |
| 1333 |
} |
| 1334 |
|
| 1335 |
@Override |
| 1336 |
public int hashCode() { |
| 1337 |
final int prime = 31; |
| 1338 |
int result = super.hashCode(); |
| 1339 |
result = prime * result + (mStereo ? 1 : 0); |
| 1340 |
return result; |
| 1341 |
} |
| 1342 |
|
| 1343 |
@Override |
| 1344 |
public boolean equals(@Nullable Object obj) { |
| 1345 |
if (this == obj) |
| 1346 |
return true; |
| 1347 |
if (!super.equals(obj)) |
| 1348 |
return false; |
| 1349 |
if (!(obj instanceof AmBandConfig)) |
| 1350 |
return false; |
| 1351 |
AmBandConfig other = (AmBandConfig) obj; |
| 1352 |
if (mStereo != other.getStereo()) |
| 1353 |
return false; |
| 1354 |
return true; |
| 1355 |
} |
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
public static class Builder { |
| 1361 |
private final BandDescriptor mDescriptor; |
| 1362 |
private boolean mStereo; |
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
public Builder(AmBandDescriptor descriptor) { |
| 1369 |
mDescriptor = new BandDescriptor(descriptor.getRegion(), descriptor.getType(), |
| 1370 |
descriptor.getLowerLimit(), descriptor.getUpperLimit(), |
| 1371 |
descriptor.getSpacing()); |
| 1372 |
mStereo = descriptor.isStereoSupported(); |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
public Builder(AmBandConfig config) { |
| 1380 |
mDescriptor = new BandDescriptor(config.getRegion(), config.getType(), |
| 1381 |
config.getLowerLimit(), config.getUpperLimit(), config.getSpacing()); |
| 1382 |
mStereo = config.getStereo(); |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
public AmBandConfig build() { |
| 1391 |
AmBandConfig config = new AmBandConfig(mDescriptor.getRegion(), |
| 1392 |
mDescriptor.getType(), mDescriptor.getLowerLimit(), |
| 1393 |
mDescriptor.getUpperLimit(), mDescriptor.getSpacing(), |
| 1394 |
mStereo); |
| 1395 |
return config; |
| 1396 |
} |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
public Builder setStereo(boolean state) { |
| 1403 |
mStereo = state; |
| 1404 |
return this; |
| 1405 |
} |
| 1406 |
}; |
| 1407 |
} |
| 1408 |
|
| 1409 |
|
| 1410 |
public static class ProgramInfo implements Parcelable { |
| 1411 |
|
| 1412 |
|
| 1413 |
private static final int FLAG_LIVE = 1 << 0; |
| 1414 |
private static final int FLAG_MUTED = 1 << 1; |
| 1415 |
private static final int FLAG_TRAFFIC_PROGRAM = 1 << 2; |
| 1416 |
private static final int FLAG_TRAFFIC_ANNOUNCEMENT = 1 << 3; |
| 1417 |
private static final int FLAG_TUNED = 1 << 4; |
| 1418 |
private static final int FLAG_STEREO = 1 << 5; |
| 1419 |
|
| 1420 |
@NonNull private final ProgramSelector mSelector; |
| 1421 |
@Nullable private final ProgramSelector.Identifier mLogicallyTunedTo; |
| 1422 |
@Nullable private final ProgramSelector.Identifier mPhysicallyTunedTo; |
| 1423 |
@NonNull private final Collection<ProgramSelector.Identifier> mRelatedContent; |
| 1424 |
private final int mInfoFlags; |
| 1425 |
private final int mSignalQuality; |
| 1426 |
@Nullable private final RadioMetadata mMetadata; |
| 1427 |
@NonNull private final Map<String, String> mVendorInfo; |
| 1428 |
|
| 1429 |
|
| 1430 |
public ProgramInfo(@NonNull ProgramSelector selector, |
| 1431 |
@Nullable ProgramSelector.Identifier logicallyTunedTo, |
| 1432 |
@Nullable ProgramSelector.Identifier physicallyTunedTo, |
| 1433 |
@Nullable Collection<ProgramSelector.Identifier> relatedContent, |
| 1434 |
int infoFlags, int signalQuality, @Nullable RadioMetadata metadata, |
| 1435 |
@Nullable Map<String, String> vendorInfo) { |
| 1436 |
mSelector = Objects.requireNonNull(selector); |
| 1437 |
mLogicallyTunedTo = logicallyTunedTo; |
| 1438 |
mPhysicallyTunedTo = physicallyTunedTo; |
| 1439 |
if (relatedContent == null) { |
| 1440 |
mRelatedContent = Collections.emptyList(); |
| 1441 |
} else { |
| 1442 |
Preconditions.checkCollectionElementsNotNull(relatedContent, "relatedContent"); |
| 1443 |
mRelatedContent = relatedContent; |
| 1444 |
} |
| 1445 |
mInfoFlags = infoFlags; |
| 1446 |
mSignalQuality = signalQuality; |
| 1447 |
mMetadata = metadata; |
| 1448 |
mVendorInfo = (vendorInfo == null) ? new HashMap<>() : vendorInfo; |
| 1449 |
} |
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
public @NonNull ProgramSelector getSelector() { |
| 1457 |
return mSelector; |
| 1458 |
} |
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
public @Nullable ProgramSelector.Identifier getLogicallyTunedTo() { |
| 1473 |
return mLogicallyTunedTo; |
| 1474 |
} |
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
public @Nullable ProgramSelector.Identifier getPhysicallyTunedTo() { |
| 1486 |
return mPhysicallyTunedTo; |
| 1487 |
} |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
public @Nullable Collection<ProgramSelector.Identifier> getRelatedContent() { |
| 1502 |
return mRelatedContent; |
| 1503 |
} |
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
@Deprecated |
| 1511 |
public int getChannel() { |
| 1512 |
try { |
| 1513 |
return (int) mSelector.getFirstId(ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY); |
| 1514 |
} catch (IllegalArgumentException ex) { |
| 1515 |
Log.w(TAG, "Not an AM/FM program"); |
| 1516 |
return 0; |
| 1517 |
} |
| 1518 |
} |
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
@Deprecated |
| 1525 |
public int getSubChannel() { |
| 1526 |
try { |
| 1527 |
return (int) mSelector.getFirstId( |
| 1528 |
ProgramSelector.IDENTIFIER_TYPE_HD_SUBCHANNEL) + 1; |
| 1529 |
} catch (IllegalArgumentException ex) { |
| 1530 |
|
| 1531 |
return 0; |
| 1532 |
} |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
public boolean isTuned() { |
| 1539 |
return (mInfoFlags & FLAG_TUNED) != 0; |
| 1540 |
} |
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
public boolean isStereo() { |
| 1546 |
return (mInfoFlags & FLAG_STEREO) != 0; |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
@Deprecated |
| 1554 |
public boolean isDigital() { |
| 1555 |
ProgramSelector.Identifier id = mLogicallyTunedTo; |
| 1556 |
if (id == null) id = mSelector.getPrimaryId(); |
| 1557 |
|
| 1558 |
int type = id.getType(); |
| 1559 |
return (type != ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY |
| 1560 |
&& type != ProgramSelector.IDENTIFIER_TYPE_RDS_PI); |
| 1561 |
} |
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
public boolean isLive() { |
| 1569 |
return (mInfoFlags & FLAG_LIVE) != 0; |
| 1570 |
} |
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
public boolean isMuted() { |
| 1579 |
return (mInfoFlags & FLAG_MUTED) != 0; |
| 1580 |
} |
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
public boolean isTrafficProgram() { |
| 1587 |
return (mInfoFlags & FLAG_TRAFFIC_PROGRAM) != 0; |
| 1588 |
} |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
public boolean isTrafficAnnouncementActive() { |
| 1595 |
return (mInfoFlags & FLAG_TRAFFIC_ANNOUNCEMENT) != 0; |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
public int getSignalStrength() { |
| 1604 |
return mSignalQuality; |
| 1605 |
} |
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
public RadioMetadata getMetadata() { |
| 1612 |
return mMetadata; |
| 1613 |
} |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
public @NonNull Map<String, String> getVendorInfo() { |
| 1626 |
return mVendorInfo; |
| 1627 |
} |
| 1628 |
|
| 1629 |
private ProgramInfo(Parcel in) { |
| 1630 |
mSelector = Objects.requireNonNull(in.readTypedObject(ProgramSelector.CREATOR)); |
| 1631 |
mLogicallyTunedTo = in.readTypedObject(ProgramSelector.Identifier.CREATOR); |
| 1632 |
mPhysicallyTunedTo = in.readTypedObject(ProgramSelector.Identifier.CREATOR); |
| 1633 |
mRelatedContent = in.createTypedArrayList(ProgramSelector.Identifier.CREATOR); |
| 1634 |
mInfoFlags = in.readInt(); |
| 1635 |
mSignalQuality = in.readInt(); |
| 1636 |
mMetadata = in.readTypedObject(RadioMetadata.CREATOR); |
| 1637 |
mVendorInfo = Utils.readStringMap(in); |
| 1638 |
} |
| 1639 |
|
| 1640 |
public static final @android.annotation.NonNull Parcelable.Creator<ProgramInfo> CREATOR |
| 1641 |
= new Parcelable.Creator<ProgramInfo>() { |
| 1642 |
public ProgramInfo createFromParcel(Parcel in) { |
| 1643 |
return new ProgramInfo(in); |
| 1644 |
} |
| 1645 |
|
| 1646 |
public ProgramInfo[] newArray(int size) { |
| 1647 |
return new ProgramInfo[size]; |
| 1648 |
} |
| 1649 |
}; |
| 1650 |
|
| 1651 |
@Override |
| 1652 |
public void writeToParcel(Parcel dest, int flags) { |
| 1653 |
dest.writeTypedObject(mSelector, flags); |
| 1654 |
dest.writeTypedObject(mLogicallyTunedTo, flags); |
| 1655 |
dest.writeTypedObject(mPhysicallyTunedTo, flags); |
| 1656 |
Utils.writeTypedCollection(dest, mRelatedContent); |
| 1657 |
dest.writeInt(mInfoFlags); |
| 1658 |
dest.writeInt(mSignalQuality); |
| 1659 |
dest.writeTypedObject(mMetadata, flags); |
| 1660 |
Utils.writeStringMap(dest, mVendorInfo); |
| 1661 |
} |
| 1662 |
|
| 1663 |
@Override |
| 1664 |
public int describeContents() { |
| 1665 |
return 0; |
| 1666 |
} |
| 1667 |
|
| 1668 |
@NonNull |
| 1669 |
@Override |
| 1670 |
public String toString() { |
| 1671 |
return "ProgramInfo" |
| 1672 |
+ " [selector=" + mSelector |
| 1673 |
+ ", logicallyTunedTo=" + Objects.toString(mLogicallyTunedTo) |
| 1674 |
+ ", physicallyTunedTo=" + Objects.toString(mPhysicallyTunedTo) |
| 1675 |
+ ", relatedContent=" + mRelatedContent.size() |
| 1676 |
+ ", infoFlags=" + mInfoFlags |
| 1677 |
+ ", mSignalQuality=" + mSignalQuality |
| 1678 |
+ ", mMetadata=" + Objects.toString(mMetadata) |
| 1679 |
+ "]"; |
| 1680 |
} |
| 1681 |
|
| 1682 |
@Override |
| 1683 |
public int hashCode() { |
| 1684 |
return Objects.hash(mSelector, mLogicallyTunedTo, mPhysicallyTunedTo, |
| 1685 |
mRelatedContent, mInfoFlags, mSignalQuality, mMetadata, mVendorInfo); |
| 1686 |
} |
| 1687 |
|
| 1688 |
@Override |
| 1689 |
public boolean equals(@Nullable Object obj) { |
| 1690 |
if (this == obj) return true; |
| 1691 |
if (!(obj instanceof ProgramInfo)) return false; |
| 1692 |
ProgramInfo other = (ProgramInfo) obj; |
| 1693 |
|
| 1694 |
if (!Objects.equals(mSelector, other.mSelector)) return false; |
| 1695 |
if (!Objects.equals(mLogicallyTunedTo, other.mLogicallyTunedTo)) return false; |
| 1696 |
if (!Objects.equals(mPhysicallyTunedTo, other.mPhysicallyTunedTo)) return false; |
| 1697 |
if (!Objects.equals(mRelatedContent, other.mRelatedContent)) return false; |
| 1698 |
if (mInfoFlags != other.mInfoFlags) return false; |
| 1699 |
if (mSignalQuality != other.mSignalQuality) return false; |
| 1700 |
if (!Objects.equals(mMetadata, other.mMetadata)) return false; |
| 1701 |
if (!Objects.equals(mVendorInfo, other.mVendorInfo)) return false; |
| 1702 |
|
| 1703 |
return true; |
| 1704 |
} |
| 1705 |
} |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
@RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO) |
| 1721 |
public int listModules(List<ModuleProperties> modules) { |
| 1722 |
if (modules == null) { |
| 1723 |
Log.e(TAG, "the output list must not be empty"); |
| 1724 |
return STATUS_BAD_VALUE; |
| 1725 |
} |
| 1726 |
|
| 1727 |
Log.d(TAG, "Listing available tuners..."); |
| 1728 |
List<ModuleProperties> returnedList; |
| 1729 |
try { |
| 1730 |
returnedList = mService.listModules(); |
| 1731 |
} catch (RemoteException e) { |
| 1732 |
Log.e(TAG, "Failed listing available tuners", e); |
| 1733 |
return STATUS_DEAD_OBJECT; |
| 1734 |
} |
| 1735 |
|
| 1736 |
if (returnedList == null) { |
| 1737 |
Log.e(TAG, "Returned list was a null"); |
| 1738 |
return STATUS_ERROR; |
| 1739 |
} |
| 1740 |
|
| 1741 |
modules.addAll(returnedList); |
| 1742 |
return STATUS_OK; |
| 1743 |
} |
| 1744 |
|
| 1745 |
private native int nativeListModules(List<ModuleProperties> modules); |
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
@RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO) |
| 1762 |
public RadioTuner openTuner(int moduleId, BandConfig config, boolean withAudio, |
| 1763 |
RadioTuner.Callback callback, Handler handler) { |
| 1764 |
if (callback == null) { |
| 1765 |
throw new IllegalArgumentException("callback must not be empty"); |
| 1766 |
} |
| 1767 |
|
| 1768 |
Log.d(TAG, "Opening tuner " + moduleId + "..."); |
| 1769 |
|
| 1770 |
ITuner tuner; |
| 1771 |
TunerCallbackAdapter halCallback = new TunerCallbackAdapter(callback, handler); |
| 1772 |
try { |
| 1773 |
tuner = mService.openTuner(moduleId, config, withAudio, halCallback); |
| 1774 |
} catch (RemoteException | IllegalArgumentException | IllegalStateException ex) { |
| 1775 |
Log.e(TAG, "Failed to open tuner", ex); |
| 1776 |
return null; |
| 1777 |
} |
| 1778 |
if (tuner == null) { |
| 1779 |
Log.e(TAG, "Failed to open tuner"); |
| 1780 |
return null; |
| 1781 |
} |
| 1782 |
return new TunerAdapter(tuner, halCallback, |
| 1783 |
config != null ? config.getType() : BAND_INVALID); |
| 1784 |
} |
| 1785 |
|
| 1786 |
private final Map<Announcement.OnListUpdatedListener, ICloseHandle> mAnnouncementListeners = |
| 1787 |
new HashMap<>(); |
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
@RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO) |
| 1796 |
public void addAnnouncementListener(@NonNull Set<Integer> enabledAnnouncementTypes, |
| 1797 |
@NonNull Announcement.OnListUpdatedListener listener) { |
| 1798 |
addAnnouncementListener(cmd -> cmd.run(), enabledAnnouncementTypes, listener); |
| 1799 |
} |
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
@RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO) |
| 1809 |
public void addAnnouncementListener(@NonNull @CallbackExecutor Executor executor, |
| 1810 |
@NonNull Set<Integer> enabledAnnouncementTypes, |
| 1811 |
@NonNull Announcement.OnListUpdatedListener listener) { |
| 1812 |
Objects.requireNonNull(executor); |
| 1813 |
Objects.requireNonNull(listener); |
| 1814 |
int[] types = enabledAnnouncementTypes.stream().mapToInt(Integer::intValue).toArray(); |
| 1815 |
IAnnouncementListener listenerIface = new IAnnouncementListener.Stub() { |
| 1816 |
public void onListUpdated(List<Announcement> activeAnnouncements) { |
| 1817 |
executor.execute(() -> listener.onListUpdated(activeAnnouncements)); |
| 1818 |
} |
| 1819 |
}; |
| 1820 |
synchronized (mAnnouncementListeners) { |
| 1821 |
ICloseHandle closeHandle = null; |
| 1822 |
try { |
| 1823 |
closeHandle = mService.addAnnouncementListener(types, listenerIface); |
| 1824 |
} catch (RemoteException ex) { |
| 1825 |
ex.rethrowFromSystemServer(); |
| 1826 |
} |
| 1827 |
Objects.requireNonNull(closeHandle); |
| 1828 |
ICloseHandle oldCloseHandle = mAnnouncementListeners.put(listener, closeHandle); |
| 1829 |
if (oldCloseHandle != null) Utils.close(oldCloseHandle); |
| 1830 |
} |
| 1831 |
} |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
@RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO) |
| 1840 |
public void removeAnnouncementListener(@NonNull Announcement.OnListUpdatedListener listener) { |
| 1841 |
Objects.requireNonNull(listener); |
| 1842 |
synchronized (mAnnouncementListeners) { |
| 1843 |
ICloseHandle closeHandle = mAnnouncementListeners.remove(listener); |
| 1844 |
if (closeHandle != null) Utils.close(closeHandle); |
| 1845 |
} |
| 1846 |
} |
| 1847 |
|
| 1848 |
@NonNull private final Context mContext; |
| 1849 |
@NonNull private final IRadioService mService; |
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
public RadioManager(@NonNull Context context) throws ServiceNotFoundException { |
| 1855 |
mContext = context; |
| 1856 |
mService = IRadioService.Stub.asInterface( |
| 1857 |
ServiceManager.getServiceOrThrow(Context.RADIO_SERVICE)); |
| 1858 |
} |
| 1859 |
} |