| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.hdmi; |
| 18 |
|
| 19 |
import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_TYPE_ANALOGUE; |
| 20 |
import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_TYPE_DIGITAL; |
| 21 |
import static android.hardware.hdmi.HdmiControlManager.TIMER_RECORDING_TYPE_EXTERNAL; |
| 22 |
|
| 23 |
import android.annotation.SystemApi; |
| 24 |
import android.hardware.hdmi.HdmiRecordSources.AnalogueServiceSource; |
| 25 |
import android.hardware.hdmi.HdmiRecordSources.DigitalServiceSource; |
| 26 |
import android.hardware.hdmi.HdmiRecordSources.ExternalPhysicalAddress; |
| 27 |
import android.hardware.hdmi.HdmiRecordSources.ExternalPlugData; |
| 28 |
import android.hardware.hdmi.HdmiRecordSources.RecordSource; |
| 29 |
import android.util.Log; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
@SystemApi |
| 64 |
public class HdmiTimerRecordSources { |
| 65 |
private static final String TAG = "HdmiTimerRecordingSources"; |
| 66 |
|
| 67 |
private HdmiTimerRecordSources() {} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public static TimerRecordSource ofDigitalSource(TimerInfo timerInfo, |
| 79 |
DigitalServiceSource source) { |
| 80 |
checkTimerRecordSourceInputs(timerInfo, source); |
| 81 |
return new TimerRecordSource(timerInfo, source); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public static TimerRecordSource ofAnalogueSource(TimerInfo timerInfo, |
| 94 |
AnalogueServiceSource source) { |
| 95 |
checkTimerRecordSourceInputs(timerInfo, source); |
| 96 |
return new TimerRecordSource(timerInfo, source); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public static TimerRecordSource ofExternalPlug(TimerInfo timerInfo, ExternalPlugData source) { |
| 109 |
checkTimerRecordSourceInputs(timerInfo, source); |
| 110 |
return new TimerRecordSource(timerInfo, |
| 111 |
new ExternalSourceDecorator(source, EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PLUG)); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public static TimerRecordSource ofExternalPhysicalAddress(TimerInfo timerInfo, |
| 124 |
ExternalPhysicalAddress source) { |
| 125 |
checkTimerRecordSourceInputs(timerInfo, source); |
| 126 |
return new TimerRecordSource(timerInfo, |
| 127 |
new ExternalSourceDecorator(source, |
| 128 |
EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PHYSICAL_ADDRESS)); |
| 129 |
} |
| 130 |
|
| 131 |
private static void checkTimerRecordSourceInputs(TimerInfo timerInfo, RecordSource source) { |
| 132 |
if (timerInfo == null) { |
| 133 |
Log.w(TAG, "TimerInfo should not be null."); |
| 134 |
throw new IllegalArgumentException("TimerInfo should not be null."); |
| 135 |
} |
| 136 |
if (source == null) { |
| 137 |
Log.w(TAG, "source should not be null."); |
| 138 |
throw new IllegalArgumentException("source should not be null."); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public static Time timeOf(int hour, int minute) { |
| 151 |
checkTimeValue(hour, minute); |
| 152 |
return new Time(hour, minute); |
| 153 |
} |
| 154 |
|
| 155 |
private static void checkTimeValue(int hour, int minute) { |
| 156 |
if (hour < 0 || hour > 23) { |
| 157 |
throw new IllegalArgumentException("Hour should be in rage of [0, 23]:" + hour); |
| 158 |
} |
| 159 |
if (minute < 0 || minute > 59) { |
| 160 |
throw new IllegalArgumentException("Minute should be in rage of [0, 59]:" + minute); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
public static Duration durationOf(int hour, int minute) { |
| 173 |
checkDurationValue(hour, minute); |
| 174 |
return new Duration(hour, minute); |
| 175 |
} |
| 176 |
|
| 177 |
private static void checkDurationValue(int hour, int minute) { |
| 178 |
if (hour < 0 || hour > 99) { |
| 179 |
throw new IllegalArgumentException("Hour should be in rage of [0, 99]:" + hour); |
| 180 |
} |
| 181 |
if (minute < 0 || minute > 59) { |
| 182 |
throw new IllegalArgumentException("minute should be in rage of [0, 59]:" + minute); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
static class TimeUnit { |
| 191 |
final int mHour; |
| 192 |
final int mMinute; |
| 193 |
|
| 194 |
TimeUnit(int hour, int minute) { |
| 195 |
mHour = hour; |
| 196 |
mMinute = minute; |
| 197 |
} |
| 198 |
|
| 199 |
int toByteArray(byte[] data, int index) { |
| 200 |
data[index] = toBcdByte(mHour); |
| 201 |
data[index + 1] = toBcdByte(mMinute); |
| 202 |
return 2; |
| 203 |
} |
| 204 |
|
| 205 |
static byte toBcdByte(int value) { |
| 206 |
int digitOfTen = (value / 10) % 10; |
| 207 |
int digitOfOne = value % 10; |
| 208 |
return (byte) ((digitOfTen << 4) | digitOfOne); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
@SystemApi |
| 217 |
public static final class Time extends TimeUnit { |
| 218 |
private Time(int hour, int minute) { |
| 219 |
super(hour, minute); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
@SystemApi |
| 228 |
public static final class Duration extends TimeUnit { |
| 229 |
private Duration(int hour, int minute) { |
| 230 |
super(hour, minute); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
public static final int RECORDING_SEQUENCE_REPEAT_ONCE_ONLY = 0; |
| 239 |
public static final int RECORDING_SEQUENCE_REPEAT_SUNDAY = 1 << 0; |
| 240 |
public static final int RECORDING_SEQUENCE_REPEAT_MONDAY = 1 << 1; |
| 241 |
public static final int RECORDING_SEQUENCE_REPEAT_TUESDAY = 1 << 2; |
| 242 |
public static final int RECORDING_SEQUENCE_REPEAT_WEDNESDAY = 1 << 3; |
| 243 |
public static final int RECORDING_SEQUENCE_REPEAT_THURSDAY = 1 << 4; |
| 244 |
public static final int RECORDING_SEQUENCE_REPEAT_FRIDAY = 1 << 5; |
| 245 |
public static final int RECORDING_SEQUENCE_REPEAT_SATUREDAY = 1 << 6; |
| 246 |
|
| 247 |
private static final int RECORDING_SEQUENCE_REPEAT_MASK = |
| 248 |
(RECORDING_SEQUENCE_REPEAT_SUNDAY | RECORDING_SEQUENCE_REPEAT_MONDAY | |
| 249 |
RECORDING_SEQUENCE_REPEAT_TUESDAY | RECORDING_SEQUENCE_REPEAT_WEDNESDAY | |
| 250 |
RECORDING_SEQUENCE_REPEAT_THURSDAY | RECORDING_SEQUENCE_REPEAT_FRIDAY | |
| 251 |
RECORDING_SEQUENCE_REPEAT_SATUREDAY); |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public static TimerInfo timerInfoOf(int dayOfMonth, int monthOfYear, Time startTime, |
| 272 |
Duration duration, int recordingSequence) { |
| 273 |
if (dayOfMonth < 0 || dayOfMonth > 31) { |
| 274 |
throw new IllegalArgumentException( |
| 275 |
"Day of month should be in range of [0, 31]:" + dayOfMonth); |
| 276 |
} |
| 277 |
if (monthOfYear < 1 || monthOfYear > 12) { |
| 278 |
throw new IllegalArgumentException( |
| 279 |
"Month of year should be in range of [1, 12]:" + monthOfYear); |
| 280 |
} |
| 281 |
checkTimeValue(startTime.mHour, startTime.mMinute); |
| 282 |
checkDurationValue(duration.mHour, duration.mMinute); |
| 283 |
|
| 284 |
if ((recordingSequence != 0) |
| 285 |
&& ((recordingSequence & ~RECORDING_SEQUENCE_REPEAT_MASK) != 0)) { |
| 286 |
throw new IllegalArgumentException( |
| 287 |
"Invalid reecording sequence value:" + recordingSequence); |
| 288 |
} |
| 289 |
|
| 290 |
return new TimerInfo(dayOfMonth, monthOfYear, startTime, duration, recordingSequence); |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
@SystemApi |
| 305 |
public static final class TimerInfo { |
| 306 |
private static final int DAY_OF_MONTH_SIZE = 1; |
| 307 |
private static final int MONTH_OF_YEAR_SIZE = 1; |
| 308 |
private static final int START_TIME_SIZE = 2; |
| 309 |
private static final int DURATION_SIZE = 2; |
| 310 |
private static final int RECORDING_SEQUENCE_SIZE = 1; |
| 311 |
private static final int BASIC_INFO_SIZE = DAY_OF_MONTH_SIZE + MONTH_OF_YEAR_SIZE |
| 312 |
+ START_TIME_SIZE + DURATION_SIZE + RECORDING_SEQUENCE_SIZE; |
| 313 |
|
| 314 |
|
| 315 |
private final int mDayOfMonth; |
| 316 |
|
| 317 |
private final int mMonthOfYear; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
private final Time mStartTime; |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
private final Duration mDuration; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
private final int mRecordingSequence; |
| 335 |
|
| 336 |
private TimerInfo(int dayOfMonth, int monthOfYear, Time startTime, |
| 337 |
Duration duration, int recordingSequence) { |
| 338 |
mDayOfMonth = dayOfMonth; |
| 339 |
mMonthOfYear = monthOfYear; |
| 340 |
mStartTime = startTime; |
| 341 |
mDuration = duration; |
| 342 |
mRecordingSequence = recordingSequence; |
| 343 |
} |
| 344 |
|
| 345 |
int toByteArray(byte[] data, int index) { |
| 346 |
|
| 347 |
data[index] = (byte) mDayOfMonth; |
| 348 |
index += DAY_OF_MONTH_SIZE; |
| 349 |
|
| 350 |
data[index] = (byte) mMonthOfYear; |
| 351 |
index += MONTH_OF_YEAR_SIZE; |
| 352 |
|
| 353 |
index += mStartTime.toByteArray(data, index); |
| 354 |
index += mDuration.toByteArray(data, index); |
| 355 |
|
| 356 |
|
| 357 |
data[index] = (byte) mRecordingSequence; |
| 358 |
return getDataSize(); |
| 359 |
} |
| 360 |
|
| 361 |
int getDataSize() { |
| 362 |
return BASIC_INFO_SIZE; |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
@SystemApi |
| 380 |
public static final class TimerRecordSource { |
| 381 |
private final RecordSource mRecordSource; |
| 382 |
private final TimerInfo mTimerInfo; |
| 383 |
|
| 384 |
private TimerRecordSource(TimerInfo timerInfo, RecordSource recordSource) { |
| 385 |
mTimerInfo = timerInfo; |
| 386 |
mRecordSource = recordSource; |
| 387 |
} |
| 388 |
|
| 389 |
int getDataSize() { |
| 390 |
return mTimerInfo.getDataSize() + mRecordSource.getDataSize(false); |
| 391 |
} |
| 392 |
|
| 393 |
int toByteArray(byte[] data, int index) { |
| 394 |
|
| 395 |
|
| 396 |
index += mTimerInfo.toByteArray(data, index); |
| 397 |
|
| 398 |
mRecordSource.toByteArray(false, data, index); |
| 399 |
return getDataSize(); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
private static final int EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PLUG = 4; |
| 407 |
private static final int EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PHYSICAL_ADDRESS = 5; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
private static class ExternalSourceDecorator extends RecordSource { |
| 414 |
private final RecordSource mRecordSource; |
| 415 |
private final int mExternalSourceSpecifier; |
| 416 |
|
| 417 |
private ExternalSourceDecorator(RecordSource recordSource, int externalSourceSpecifier) { |
| 418 |
|
| 419 |
super(recordSource.mSourceType, recordSource.getDataSize(false) + 1); |
| 420 |
mRecordSource = recordSource; |
| 421 |
mExternalSourceSpecifier = externalSourceSpecifier; |
| 422 |
} |
| 423 |
|
| 424 |
@Override |
| 425 |
int extraParamToByteArray(byte[] data, int index) { |
| 426 |
data[index] = (byte) mExternalSourceSpecifier; |
| 427 |
mRecordSource.toByteArray(false, data, index + 1); |
| 428 |
return getDataSize(false); |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
@SystemApi |
| 439 |
public static boolean checkTimerRecordSource(int sourcetype, byte[] recordSource) { |
| 440 |
int recordSourceSize = recordSource.length - TimerInfo.BASIC_INFO_SIZE; |
| 441 |
switch (sourcetype) { |
| 442 |
case TIMER_RECORDING_TYPE_DIGITAL: |
| 443 |
return DigitalServiceSource.EXTRA_DATA_SIZE == recordSourceSize; |
| 444 |
case TIMER_RECORDING_TYPE_ANALOGUE: |
| 445 |
return AnalogueServiceSource.EXTRA_DATA_SIZE == recordSourceSize; |
| 446 |
case TIMER_RECORDING_TYPE_EXTERNAL: |
| 447 |
int specifier = recordSource[TimerInfo.BASIC_INFO_SIZE]; |
| 448 |
if (specifier == EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PLUG) { |
| 449 |
|
| 450 |
return ExternalPlugData.EXTRA_DATA_SIZE + 1 == recordSourceSize; |
| 451 |
} else if (specifier == EXTERNAL_SOURCE_SPECIFIER_EXTERNAL_PHYSICAL_ADDRESS) { |
| 452 |
|
| 453 |
return ExternalPhysicalAddress.EXTRA_DATA_SIZE + 1 == recordSourceSize; |
| 454 |
} else { |
| 455 |
|
| 456 |
return false; |
| 457 |
} |
| 458 |
default: |
| 459 |
return false; |
| 460 |
} |
| 461 |
} |
| 462 |
} |