| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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.mtp; |
| 18 | |
| 19 | /** |
| 20 | * This class encapsulates information about an object on an MTP device. |
| 21 | * This corresponds to the ObjectInfo Dataset described in |
| 22 | * section 5.3.1 of the MTP specification. |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 23 | */ |
| 24 | public final class MtpObjectInfo { |
| 25 | private int mHandle; |
| 26 | private int mStorageId; |
| 27 | private int mFormat; |
| 28 | private int mProtectionStatus; |
| 29 | private int mCompressedSize; |
| 30 | private int mThumbFormat; |
| 31 | private int mThumbCompressedSize; |
| 32 | private int mThumbPixWidth; |
| 33 | private int mThumbPixHeight; |
| 34 | private int mImagePixWidth; |
| 35 | private int mImagePixHeight; |
| 36 | private int mImagePixDepth; |
| 37 | private int mParent; |
| 38 | private int mAssociationType; |
| 39 | private int mAssociationDesc; |
| 40 | private int mSequenceNumber; |
| 41 | private String mName; |
| 42 | private long mDateCreated; |
| 43 | private long mDateModified; |
| 44 | private String mKeywords; |
| 45 | |
| Tomasz Mikolajewski | b049905 | 2015-08-06 19:13:09 +0900 | [diff] [blame] | 46 | // only instantiated via JNI or via a builder |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 47 | private MtpObjectInfo() { |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the object handle for the MTP object |
| 52 | * |
| 53 | * @return the object handle |
| 54 | */ |
| 55 | public final int getObjectHandle() { |
| 56 | return mHandle; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the storage ID for the MTP object's storage unit |
| 61 | * |
| 62 | * @return the storage ID |
| 63 | */ |
| 64 | public final int getStorageId() { |
| 65 | return mStorageId; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the format code for the MTP object |
| 70 | * |
| 71 | * @return the format code |
| 72 | */ |
| 73 | public final int getFormat() { |
| 74 | return mFormat; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns the protection status for the MTP object |
| 79 | * Possible values are: |
| 80 | * |
| 81 | * <ul> |
| 82 | * <li> {@link android.mtp.MtpConstants#PROTECTION_STATUS_NONE} |
| 83 | * <li> {@link android.mtp.MtpConstants#PROTECTION_STATUS_READ_ONLY} |
| 84 | * <li> {@link android.mtp.MtpConstants#PROTECTION_STATUS_NON_TRANSFERABLE_DATA} |
| 85 | * </ul> |
| 86 | * |
| 87 | * @return the protection status |
| 88 | */ |
| 89 | public final int getProtectionStatus() { |
| 90 | return mProtectionStatus; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Returns the size of the MTP object |
| 95 | * |
| 96 | * @return the object size |
| 97 | */ |
| 98 | public final int getCompressedSize() { |
| 99 | return mCompressedSize; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns the format code for the MTP object's thumbnail |
| 104 | * Will be zero for objects with no thumbnail |
| 105 | * |
| 106 | * @return the thumbnail format code |
| 107 | */ |
| 108 | public final int getThumbFormat() { |
| 109 | return mThumbFormat; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns the size of the MTP object's thumbnail |
| 114 | * Will be zero for objects with no thumbnail |
| 115 | * |
| 116 | * @return the thumbnail size |
| 117 | */ |
| 118 | public final int getThumbCompressedSize() { |
| 119 | return mThumbCompressedSize; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns the width of the MTP object's thumbnail in pixels |
| 124 | * Will be zero for objects with no thumbnail |
| 125 | * |
| 126 | * @return the thumbnail width |
| 127 | */ |
| 128 | public final int getThumbPixWidth() { |
| 129 | return mThumbPixWidth; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Returns the height of the MTP object's thumbnail in pixels |
| 134 | * Will be zero for objects with no thumbnail |
| 135 | * |
| 136 | * @return the thumbnail height |
| 137 | */ |
| 138 | public final int getThumbPixHeight() { |
| 139 | return mThumbPixHeight; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Returns the width of the MTP object in pixels |
| 144 | * Will be zero for non-image objects |
| 145 | * |
| 146 | * @return the image width |
| 147 | */ |
| 148 | public final int getImagePixWidth() { |
| 149 | return mImagePixWidth; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Returns the height of the MTP object in pixels |
| 154 | * Will be zero for non-image objects |
| 155 | * |
| 156 | * @return the image height |
| 157 | */ |
| 158 | public final int getImagePixHeight() { |
| 159 | return mImagePixHeight; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Returns the depth of the MTP object in bits per pixel |
| 164 | * Will be zero for non-image objects |
| 165 | * |
| 166 | * @return the image depth |
| 167 | */ |
| 168 | public final int getImagePixDepth() { |
| 169 | return mImagePixDepth; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Returns the object handle for the object's parent |
| 174 | * Will be zero for the root directory of a storage unit |
| 175 | * |
| 176 | * @return the object's parent |
| 177 | */ |
| 178 | public final int getParent() { |
| 179 | return mParent; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Returns the association type for the MTP object |
| 184 | * Will be zero objects that are not of format |
| 185 | * {@link android.mtp.MtpConstants#FORMAT_ASSOCIATION} |
| 186 | * For directories the association type is typically |
| 187 | * {@link android.mtp.MtpConstants#ASSOCIATION_TYPE_GENERIC_FOLDER} |
| 188 | * |
| 189 | * @return the object's association type |
| 190 | */ |
| 191 | public final int getAssociationType() { |
| 192 | return mAssociationType; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Returns the association description for the MTP object |
| 197 | * Will be zero objects that are not of format |
| 198 | * {@link android.mtp.MtpConstants#FORMAT_ASSOCIATION} |
| 199 | * |
| 200 | * @return the object's association description |
| 201 | */ |
| 202 | public final int getAssociationDesc() { |
| 203 | return mAssociationDesc; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Returns the sequence number for the MTP object |
| 208 | * This field is typically not used for MTP devices, |
| 209 | * but is sometimes used to define a sequence of photos |
| 210 | * on PTP cameras. |
| 211 | * |
| 212 | * @return the object's sequence number |
| 213 | */ |
| 214 | public final int getSequenceNumber() { |
| 215 | return mSequenceNumber; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Returns the name of the MTP object |
| 220 | * |
| 221 | * @return the object's name |
| 222 | */ |
| 223 | public final String getName() { |
| 224 | return mName; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Returns the creation date of the MTP object |
| 229 | * The value is represented as milliseconds since January 1, 1970 |
| 230 | * |
| 231 | * @return the object's creation date |
| 232 | */ |
| 233 | public final long getDateCreated() { |
| 234 | return mDateCreated; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Returns the modification date of the MTP object |
| 239 | * The value is represented as milliseconds since January 1, 1970 |
| 240 | * |
| 241 | * @return the object's modification date |
| 242 | */ |
| 243 | public final long getDateModified() { |
| 244 | return mDateModified; |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Returns a comma separated list of keywords for the MTP object |
| 249 | * |
| 250 | * @return the object's keyword list |
| 251 | */ |
| 252 | public final String getKeywords() { |
| 253 | return mKeywords; |
| 254 | } |
| Tomasz Mikolajewski | b049905 | 2015-08-06 19:13:09 +0900 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * Builds a new object info instance. |
| 258 | */ |
| Tomasz Mikolajewski | 87763e6 | 2015-08-10 10:10:22 +0900 | [diff] [blame] | 259 | public static class Builder { |
| Tomasz Mikolajewski | b049905 | 2015-08-06 19:13:09 +0900 | [diff] [blame] | 260 | private MtpObjectInfo mObjectInfo; |
| 261 | |
| 262 | public Builder() { |
| 263 | mObjectInfo = new MtpObjectInfo(); |
| 264 | mObjectInfo.mHandle = -1; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Creates a builder on a copy of an existing object info. |
| 269 | * All fields, except the object handle will be copied. |
| 270 | * |
| 271 | * @param objectInfo object info of an existing entry |
| 272 | */ |
| 273 | public Builder(MtpObjectInfo objectInfo) { |
| 274 | mObjectInfo = new MtpObjectInfo(); |
| 275 | mObjectInfo.mHandle = -1; |
| Tomasz Mikolajewski | b80a3cf | 2015-08-24 16:10:51 +0900 | [diff] [blame^] | 276 | mObjectInfo.mAssociationDesc = objectInfo.mAssociationDesc; |
| 277 | mObjectInfo.mAssociationType = objectInfo.mAssociationType; |
| 278 | mObjectInfo.mCompressedSize = objectInfo.mCompressedSize; |
| 279 | mObjectInfo.mDateCreated = objectInfo.mDateCreated; |
| 280 | mObjectInfo.mDateModified = objectInfo.mDateModified; |
| 281 | mObjectInfo.mFormat = objectInfo.mFormat; |
| 282 | mObjectInfo.mImagePixDepth = objectInfo.mImagePixDepth; |
| 283 | mObjectInfo.mImagePixHeight = objectInfo.mImagePixHeight; |
| 284 | mObjectInfo.mImagePixWidth = objectInfo.mImagePixWidth; |
| 285 | mObjectInfo.mKeywords = objectInfo.mKeywords; |
| 286 | mObjectInfo.mName = objectInfo.mName; |
| 287 | mObjectInfo.mParent = objectInfo.mParent; |
| 288 | mObjectInfo.mProtectionStatus = objectInfo.mProtectionStatus; |
| 289 | mObjectInfo.mSequenceNumber = objectInfo.mSequenceNumber; |
| 290 | mObjectInfo.mStorageId = objectInfo.mStorageId; |
| 291 | mObjectInfo.mThumbCompressedSize = objectInfo.mThumbCompressedSize; |
| 292 | mObjectInfo.mThumbFormat = objectInfo.mThumbFormat; |
| 293 | mObjectInfo.mThumbPixHeight = objectInfo.mThumbPixHeight; |
| 294 | mObjectInfo.mThumbPixWidth = objectInfo.mThumbPixWidth; |
| Tomasz Mikolajewski | b049905 | 2015-08-06 19:13:09 +0900 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | public Builder setAssociationDesc(int value) { |
| 298 | mObjectInfo.mAssociationDesc = value; |
| 299 | return this; |
| 300 | } |
| 301 | |
| 302 | public Builder setAssociationType(int value) { |
| 303 | mObjectInfo.mAssociationType = value; |
| 304 | return this; |
| 305 | } |
| 306 | |
| 307 | public Builder setCompressedSize(int value) { |
| 308 | mObjectInfo.mCompressedSize = value; |
| 309 | return this; |
| 310 | } |
| 311 | |
| 312 | public Builder setDateCreated(long value) { |
| 313 | mObjectInfo.mDateCreated = value; |
| 314 | return this; |
| 315 | } |
| 316 | |
| 317 | public Builder setDateModified(long value) { |
| 318 | mObjectInfo.mDateModified = value; |
| 319 | return this; |
| 320 | } |
| 321 | |
| 322 | public Builder setFormat(int value) { |
| 323 | mObjectInfo.mFormat = value; |
| 324 | return this; |
| 325 | } |
| 326 | |
| 327 | public Builder setImagePixDepth(int value) { |
| 328 | mObjectInfo.mImagePixDepth = value; |
| 329 | return this; |
| 330 | } |
| 331 | |
| 332 | public Builder setImagePixHeight(int value) { |
| 333 | mObjectInfo.mImagePixHeight = value; |
| 334 | return this; |
| 335 | } |
| 336 | |
| 337 | public Builder setImagePixWidth(int value) { |
| 338 | mObjectInfo.mImagePixWidth = value; |
| 339 | return this; |
| 340 | } |
| 341 | |
| 342 | public Builder setKeywords(String value) { |
| 343 | mObjectInfo.mKeywords = value; |
| 344 | return this; |
| 345 | } |
| 346 | |
| 347 | public Builder setName(String value) { |
| 348 | mObjectInfo.mName = value; |
| 349 | return this; |
| 350 | } |
| 351 | |
| 352 | public Builder setParent(int value) { |
| 353 | mObjectInfo.mParent = value; |
| 354 | return this; |
| 355 | } |
| 356 | |
| 357 | public Builder setProtectionStatus(int value) { |
| 358 | mObjectInfo.mProtectionStatus = value; |
| 359 | return this; |
| 360 | } |
| 361 | |
| 362 | public Builder setSequenceNumber(int value) { |
| 363 | mObjectInfo.mSequenceNumber = value; |
| 364 | return this; |
| 365 | } |
| 366 | |
| 367 | public Builder setStorageId(int value) { |
| 368 | mObjectInfo.mStorageId = value; |
| 369 | return this; |
| 370 | } |
| 371 | |
| 372 | public Builder setThumbCompressedSize(int value) { |
| 373 | mObjectInfo.mThumbCompressedSize = value; |
| 374 | return this; |
| 375 | } |
| 376 | |
| 377 | public Builder setThumbFormat(int value) { |
| 378 | mObjectInfo.mThumbFormat = value; |
| 379 | return this; |
| 380 | } |
| 381 | |
| 382 | public Builder setThumbPixHeight(int value) { |
| 383 | mObjectInfo.mThumbPixHeight = value; |
| 384 | return this; |
| 385 | } |
| 386 | |
| 387 | public Builder setThumbPixWidth(int value) { |
| 388 | mObjectInfo.mThumbPixWidth = value; |
| 389 | return this; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Builds the object info instance. Once called, methods of the builder |
| 394 | * must not be called anymore. |
| 395 | * |
| 396 | * @return the object info of the newly created file, or NULL in case |
| 397 | * of an error. |
| 398 | */ |
| 399 | public MtpObjectInfo build() { |
| 400 | MtpObjectInfo result = mObjectInfo; |
| 401 | mObjectInfo = null; |
| 402 | return result; |
| 403 | } |
| 404 | } |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 405 | } |