MtpStorageInfo.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #define LOG_TAG "MtpStorageInfo"
  17. #include <inttypes.h>
  18. #include "MtpDebug.h"
  19. #include "MtpDataPacket.h"
  20. #include "MtpStorageInfo.h"
  21. #include "MtpStringBuffer.h"
  22. namespace android {
  23. MtpStorageInfo::MtpStorageInfo(MtpStorageID id)
  24. : mStorageID(id),
  25. mStorageType(0),
  26. mFileSystemType(0),
  27. mAccessCapability(0),
  28. mMaxCapacity(0),
  29. mFreeSpaceBytes(0),
  30. mFreeSpaceObjects(0),
  31. mStorageDescription(NULL),
  32. mVolumeIdentifier(NULL)
  33. {
  34. }
  35. MtpStorageInfo::~MtpStorageInfo() {
  36. if (mStorageDescription)
  37. free(mStorageDescription);
  38. if (mVolumeIdentifier)
  39. free(mVolumeIdentifier);
  40. }
  41. bool MtpStorageInfo::read(MtpDataPacket& packet) {
  42. MtpStringBuffer string;
  43. // read the device info
  44. if (!packet.getUInt16(mStorageType)) return false;
  45. if (!packet.getUInt16(mFileSystemType)) return false;
  46. if (!packet.getUInt16(mAccessCapability)) return false;
  47. if (!packet.getUInt64(mMaxCapacity)) return false;
  48. if (!packet.getUInt64(mFreeSpaceBytes)) return false;
  49. if (!packet.getUInt32(mFreeSpaceObjects)) return false;
  50. if (!packet.getString(string)) return false;
  51. mStorageDescription = strdup((const char *)string);
  52. if (!mStorageDescription) return false;
  53. if (!packet.getString(string)) return false;
  54. mVolumeIdentifier = strdup((const char *)string);
  55. if (!mVolumeIdentifier) return false;
  56. return true;
  57. }
  58. void MtpStorageInfo::print() {
  59. ALOGD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n",
  60. mStorageID, mStorageType, mFileSystemType, mAccessCapability);
  61. ALOGD("\tmMaxCapacity: %" PRIu64 "\n\tmFreeSpaceBytes: %" PRIu64 "\n\tmFreeSpaceObjects: %d\n",
  62. mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects);
  63. ALOGD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n",
  64. mStorageDescription, mVolumeIdentifier);
  65. }
  66. } // namespace android