| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.mtp; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.os.Build; |
| 21 |
|
| 22 |
import com.android.internal.util.Preconditions; |
| 23 |
|
| 24 |
import dalvik.system.VMRuntime; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public final class MtpObjectInfo { |
| 32 |
private int mHandle; |
| 33 |
private int mStorageId; |
| 34 |
private int mFormat; |
| 35 |
private int mProtectionStatus; |
| 36 |
private int mCompressedSize; |
| 37 |
private int mThumbFormat; |
| 38 |
private int mThumbCompressedSize; |
| 39 |
private int mThumbPixWidth; |
| 40 |
private int mThumbPixHeight; |
| 41 |
private int mImagePixWidth; |
| 42 |
private int mImagePixHeight; |
| 43 |
private int mImagePixDepth; |
| 44 |
private int mParent; |
| 45 |
private int mAssociationType; |
| 46 |
private int mAssociationDesc; |
| 47 |
private int mSequenceNumber; |
| 48 |
private String mName = ""; |
| 49 |
private long mDateCreated; |
| 50 |
private long mDateModified; |
| 51 |
private String mKeywords = ""; |
| 52 |
|
| 53 |
|
| 54 |
private MtpObjectInfo() { |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public final int getObjectHandle() { |
| 63 |
return mHandle; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public final int getStorageId() { |
| 72 |
return mStorageId; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public final int getFormat() { |
| 81 |
return mFormat; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public final int getProtectionStatus() { |
| 97 |
return mProtectionStatus; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public final int getCompressedSize() { |
| 106 |
Preconditions.checkState(mCompressedSize >= 0); |
| 107 |
return mCompressedSize; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public final long getCompressedSizeLong() { |
| 116 |
return uint32ToLong(mCompressedSize); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public final int getThumbFormat() { |
| 126 |
return mThumbFormat; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public final int getThumbCompressedSize() { |
| 136 |
Preconditions.checkState(mThumbCompressedSize >= 0); |
| 137 |
return mThumbCompressedSize; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public final long getThumbCompressedSizeLong() { |
| 147 |
return uint32ToLong(mThumbCompressedSize); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public final int getThumbPixWidth() { |
| 157 |
Preconditions.checkState(mThumbPixWidth >= 0); |
| 158 |
return mThumbPixWidth; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public final long getThumbPixWidthLong() { |
| 168 |
return uint32ToLong(mThumbPixWidth); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public final int getThumbPixHeight() { |
| 178 |
Preconditions.checkState(mThumbPixHeight >= 0); |
| 179 |
return mThumbPixHeight; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public final long getThumbPixHeightLong() { |
| 189 |
return uint32ToLong(mThumbPixHeight); |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
public final int getImagePixWidth() { |
| 199 |
Preconditions.checkState(mImagePixWidth >= 0); |
| 200 |
return mImagePixWidth; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public final long getImagePixWidthLong() { |
| 210 |
return uint32ToLong(mImagePixWidth); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public final int getImagePixHeight() { |
| 220 |
Preconditions.checkState(mImagePixHeight >= 0); |
| 221 |
return mImagePixHeight; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
public final long getImagePixHeightLong() { |
| 231 |
return uint32ToLong(mImagePixHeight); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
public final int getImagePixDepth() { |
| 241 |
Preconditions.checkState(mImagePixDepth >= 0); |
| 242 |
return mImagePixDepth; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
public final long getImagePixDepthLong() { |
| 252 |
return uint32ToLong(mImagePixDepth); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public final int getParent() { |
| 262 |
return mParent; |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
public final int getAssociationType() { |
| 275 |
return mAssociationType; |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public final int getAssociationDesc() { |
| 286 |
return mAssociationDesc; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
public final int getSequenceNumber() { |
| 298 |
Preconditions.checkState(mSequenceNumber >= 0); |
| 299 |
return mSequenceNumber; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public final long getSequenceNumberLong() { |
| 311 |
return uint32ToLong(mSequenceNumber); |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
public final @NonNull String getName() { |
| 320 |
return mName; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public final long getDateCreated() { |
| 330 |
return mDateCreated; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
public final long getDateModified() { |
| 340 |
return mDateModified; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public final @NonNull String getKeywords() { |
| 349 |
return mKeywords; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
public static class Builder { |
| 356 |
private MtpObjectInfo mObjectInfo; |
| 357 |
|
| 358 |
public Builder() { |
| 359 |
mObjectInfo = new MtpObjectInfo(); |
| 360 |
mObjectInfo.mHandle = -1; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
public Builder(MtpObjectInfo objectInfo) { |
| 370 |
mObjectInfo = new MtpObjectInfo(); |
| 371 |
mObjectInfo.mHandle = -1; |
| 372 |
mObjectInfo.mAssociationDesc = objectInfo.mAssociationDesc; |
| 373 |
mObjectInfo.mAssociationType = objectInfo.mAssociationType; |
| 374 |
mObjectInfo.mCompressedSize = objectInfo.mCompressedSize; |
| 375 |
mObjectInfo.mDateCreated = objectInfo.mDateCreated; |
| 376 |
mObjectInfo.mDateModified = objectInfo.mDateModified; |
| 377 |
mObjectInfo.mFormat = objectInfo.mFormat; |
| 378 |
mObjectInfo.mImagePixDepth = objectInfo.mImagePixDepth; |
| 379 |
mObjectInfo.mImagePixHeight = objectInfo.mImagePixHeight; |
| 380 |
mObjectInfo.mImagePixWidth = objectInfo.mImagePixWidth; |
| 381 |
mObjectInfo.mKeywords = objectInfo.mKeywords; |
| 382 |
mObjectInfo.mName = objectInfo.mName; |
| 383 |
mObjectInfo.mParent = objectInfo.mParent; |
| 384 |
mObjectInfo.mProtectionStatus = objectInfo.mProtectionStatus; |
| 385 |
mObjectInfo.mSequenceNumber = objectInfo.mSequenceNumber; |
| 386 |
mObjectInfo.mStorageId = objectInfo.mStorageId; |
| 387 |
mObjectInfo.mThumbCompressedSize = objectInfo.mThumbCompressedSize; |
| 388 |
mObjectInfo.mThumbFormat = objectInfo.mThumbFormat; |
| 389 |
mObjectInfo.mThumbPixHeight = objectInfo.mThumbPixHeight; |
| 390 |
mObjectInfo.mThumbPixWidth = objectInfo.mThumbPixWidth; |
| 391 |
} |
| 392 |
|
| 393 |
public Builder setObjectHandle(int value) { |
| 394 |
mObjectInfo.mHandle = value; |
| 395 |
return this; |
| 396 |
} |
| 397 |
|
| 398 |
public Builder setAssociationDesc(int value) { |
| 399 |
mObjectInfo.mAssociationDesc = value; |
| 400 |
return this; |
| 401 |
} |
| 402 |
|
| 403 |
public Builder setAssociationType(int value) { |
| 404 |
mObjectInfo.mAssociationType = value; |
| 405 |
return this; |
| 406 |
} |
| 407 |
|
| 408 |
public Builder setCompressedSize(long value) { |
| 409 |
mObjectInfo.mCompressedSize = longToUint32(value, "value"); |
| 410 |
return this; |
| 411 |
} |
| 412 |
|
| 413 |
public Builder setDateCreated(long value) { |
| 414 |
mObjectInfo.mDateCreated = value; |
| 415 |
return this; |
| 416 |
} |
| 417 |
|
| 418 |
public Builder setDateModified(long value) { |
| 419 |
mObjectInfo.mDateModified = value; |
| 420 |
return this; |
| 421 |
} |
| 422 |
|
| 423 |
public Builder setFormat(int value) { |
| 424 |
mObjectInfo.mFormat = value; |
| 425 |
return this; |
| 426 |
} |
| 427 |
|
| 428 |
public Builder setImagePixDepth(long value) { |
| 429 |
mObjectInfo.mImagePixDepth = longToUint32(value, "value"); |
| 430 |
return this; |
| 431 |
} |
| 432 |
|
| 433 |
public Builder setImagePixHeight(long value) { |
| 434 |
mObjectInfo.mImagePixHeight = longToUint32(value, "value"); |
| 435 |
return this; |
| 436 |
} |
| 437 |
|
| 438 |
public Builder setImagePixWidth(long value) { |
| 439 |
mObjectInfo.mImagePixWidth = longToUint32(value, "value"); |
| 440 |
return this; |
| 441 |
} |
| 442 |
|
| 443 |
public Builder setKeywords(@NonNull String value) { |
| 444 |
if (VMRuntime.getRuntime().getTargetSdkVersion() > Build.VERSION_CODES.N_MR1) { |
| 445 |
Preconditions.checkNotNull(value); |
| 446 |
} else if (value == null) { |
| 447 |
|
| 448 |
|
| 449 |
value = ""; |
| 450 |
} |
| 451 |
mObjectInfo.mKeywords = value; |
| 452 |
return this; |
| 453 |
} |
| 454 |
|
| 455 |
public Builder setName(@NonNull String value) { |
| 456 |
Preconditions.checkNotNull(value); |
| 457 |
mObjectInfo.mName = value; |
| 458 |
return this; |
| 459 |
} |
| 460 |
|
| 461 |
public Builder setParent(int value) { |
| 462 |
mObjectInfo.mParent = value; |
| 463 |
return this; |
| 464 |
} |
| 465 |
|
| 466 |
public Builder setProtectionStatus(int value) { |
| 467 |
mObjectInfo.mProtectionStatus = value; |
| 468 |
return this; |
| 469 |
} |
| 470 |
|
| 471 |
public Builder setSequenceNumber(long value) { |
| 472 |
mObjectInfo.mSequenceNumber = longToUint32(value, "value"); |
| 473 |
return this; |
| 474 |
} |
| 475 |
|
| 476 |
public Builder setStorageId(int value) { |
| 477 |
mObjectInfo.mStorageId = value; |
| 478 |
return this; |
| 479 |
} |
| 480 |
|
| 481 |
public Builder setThumbCompressedSize(long value) { |
| 482 |
mObjectInfo.mThumbCompressedSize = longToUint32(value, "value"); |
| 483 |
return this; |
| 484 |
} |
| 485 |
|
| 486 |
public Builder setThumbFormat(int value) { |
| 487 |
mObjectInfo.mThumbFormat = value; |
| 488 |
return this; |
| 489 |
} |
| 490 |
|
| 491 |
public Builder setThumbPixHeight(long value) { |
| 492 |
mObjectInfo.mThumbPixHeight = longToUint32(value, "value"); |
| 493 |
return this; |
| 494 |
} |
| 495 |
|
| 496 |
public Builder setThumbPixWidth(long value) { |
| 497 |
mObjectInfo.mThumbPixWidth = longToUint32(value, "value"); |
| 498 |
return this; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
public MtpObjectInfo build() { |
| 509 |
MtpObjectInfo result = mObjectInfo; |
| 510 |
mObjectInfo = null; |
| 511 |
return result; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
private static long uint32ToLong(int value) { |
| 516 |
return value < 0 ? 0x100000000L + value : value; |
| 517 |
} |
| 518 |
|
| 519 |
private static int longToUint32(long value, String valueName) { |
| 520 |
Preconditions.checkArgumentInRange(value, 0, 0xffffffffL, valueName); |
| 521 |
return (int) value; |
| 522 |
} |
| 523 |
} |