| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [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 |  | 
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 17 | #define LOG_TAG "MtpStorageInfo" | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 18 |  | 
| Mark Salyzyn | d239cb6 | 2014-06-18 16:32:27 -0700 | [diff] [blame] | 19 | #include <inttypes.h> | 
 | 20 |  | 
| Mike Lockwood | b14e588 | 2010-06-29 18:11:52 -0400 | [diff] [blame] | 21 | #include "MtpDebug.h" | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 22 | #include "MtpDataPacket.h" | 
 | 23 | #include "MtpStorageInfo.h" | 
 | 24 | #include "MtpStringBuffer.h" | 
 | 25 |  | 
 | 26 | namespace android { | 
 | 27 |  | 
 | 28 | MtpStorageInfo::MtpStorageInfo(MtpStorageID id) | 
 | 29 |     :   mStorageID(id), | 
 | 30 |         mStorageType(0), | 
 | 31 |         mFileSystemType(0), | 
 | 32 |         mAccessCapability(0), | 
 | 33 |         mMaxCapacity(0), | 
 | 34 |         mFreeSpaceBytes(0), | 
 | 35 |         mFreeSpaceObjects(0), | 
 | 36 |         mStorageDescription(NULL), | 
 | 37 |         mVolumeIdentifier(NULL) | 
 | 38 | { | 
 | 39 | } | 
 | 40 |  | 
 | 41 | MtpStorageInfo::~MtpStorageInfo() { | 
 | 42 |     if (mStorageDescription) | 
 | 43 |         free(mStorageDescription); | 
 | 44 |     if (mVolumeIdentifier) | 
 | 45 |         free(mVolumeIdentifier); | 
 | 46 | } | 
 | 47 |  | 
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 48 | bool MtpStorageInfo::read(MtpDataPacket& packet) { | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 49 |     MtpStringBuffer string; | 
 | 50 |  | 
 | 51 |     // read the device info | 
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 52 |     if (!packet.getUInt16(mStorageType)) return false; | 
 | 53 |     if (!packet.getUInt16(mFileSystemType)) return false; | 
 | 54 |     if (!packet.getUInt16(mAccessCapability)) return false; | 
 | 55 |     if (!packet.getUInt64(mMaxCapacity)) return false; | 
 | 56 |     if (!packet.getUInt64(mFreeSpaceBytes)) return false; | 
 | 57 |     if (!packet.getUInt32(mFreeSpaceObjects)) return false; | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 58 |  | 
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 59 |     if (!packet.getString(string)) return false; | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 60 |     mStorageDescription = strdup((const char *)string); | 
| Daichi Hirono | 96a8408 | 2016-07-07 17:50:23 +0900 | [diff] [blame] | 61 |     if (!mStorageDescription) return false; | 
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 62 |     if (!packet.getString(string)) return false; | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 63 |     mVolumeIdentifier = strdup((const char *)string); | 
| Daichi Hirono | 96a8408 | 2016-07-07 17:50:23 +0900 | [diff] [blame] | 64 |     if (!mVolumeIdentifier) return false; | 
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 65 |  | 
 | 66 |     return true; | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 67 | } | 
 | 68 |  | 
 | 69 | void MtpStorageInfo::print() { | 
| Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 70 |     ALOGD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n", | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 71 |             mStorageID, mStorageType, mFileSystemType, mAccessCapability); | 
| Mark Salyzyn | d239cb6 | 2014-06-18 16:32:27 -0700 | [diff] [blame] | 72 |     ALOGD("\tmMaxCapacity: %" PRIu64 "\n\tmFreeSpaceBytes: %" PRIu64 "\n\tmFreeSpaceObjects: %d\n", | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 73 |             mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects); | 
| Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 74 |     ALOGD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n", | 
| Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 75 |             mStorageDescription, mVolumeIdentifier); | 
 | 76 | } | 
 | 77 |  | 
 | 78 | }  // namespace android |