MtpDeviceInfo.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "MtpDeviceInfo"
  17. #include "MtpDebug.h"
  18. #include "MtpDataPacket.h"
  19. #include "MtpDeviceInfo.h"
  20. #include "MtpStringBuffer.h"
  21. namespace android {
  22. MtpDeviceInfo::MtpDeviceInfo()
  23. : mStandardVersion(0),
  24. mVendorExtensionID(0),
  25. mVendorExtensionVersion(0),
  26. mVendorExtensionDesc(NULL),
  27. mFunctionalMode(0),
  28. mOperations(NULL),
  29. mEvents(NULL),
  30. mDeviceProperties(NULL),
  31. mCaptureFormats(NULL),
  32. mPlaybackFormats(NULL),
  33. mManufacturer(NULL),
  34. mModel(NULL),
  35. mVersion(NULL),
  36. mSerial(NULL)
  37. {
  38. }
  39. MtpDeviceInfo::~MtpDeviceInfo() {
  40. if (mVendorExtensionDesc)
  41. free(mVendorExtensionDesc);
  42. delete mOperations;
  43. delete mEvents;
  44. delete mDeviceProperties;
  45. delete mCaptureFormats;
  46. delete mPlaybackFormats;
  47. if (mManufacturer)
  48. free(mManufacturer);
  49. if (mModel)
  50. free(mModel);
  51. if (mVersion)
  52. free(mVersion);
  53. if (mSerial)
  54. free(mSerial);
  55. }
  56. bool MtpDeviceInfo::read(MtpDataPacket& packet) {
  57. MtpStringBuffer string;
  58. // read the device info
  59. if (!packet.getUInt16(mStandardVersion)) return false;
  60. if (!packet.getUInt32(mVendorExtensionID)) return false;
  61. if (!packet.getUInt16(mVendorExtensionVersion)) return false;
  62. if (!packet.getString(string)) return false;
  63. mVendorExtensionDesc = strdup((const char *)string);
  64. if (!mVendorExtensionDesc) return false;
  65. if (!packet.getUInt16(mFunctionalMode)) return false;
  66. mOperations = packet.getAUInt16();
  67. if (!mOperations) return false;
  68. mEvents = packet.getAUInt16();
  69. if (!mEvents) return false;
  70. mDeviceProperties = packet.getAUInt16();
  71. if (!mDeviceProperties) return false;
  72. mCaptureFormats = packet.getAUInt16();
  73. if (!mCaptureFormats) return false;
  74. mPlaybackFormats = packet.getAUInt16();
  75. if (!mCaptureFormats) return false;
  76. if (!packet.getString(string)) return false;
  77. mManufacturer = strdup((const char *)string);
  78. if (!mManufacturer) return false;
  79. if (!packet.getString(string)) return false;
  80. mModel = strdup((const char *)string);
  81. if (!mModel) return false;
  82. if (!packet.getString(string)) return false;
  83. mVersion = strdup((const char *)string);
  84. if (!mVersion) return false;
  85. if (!packet.getString(string)) return false;
  86. mSerial = strdup((const char *)string);
  87. if (!mSerial) return false;
  88. return true;
  89. }
  90. void MtpDeviceInfo::print() {
  91. ALOGV("Device Info:\n\tmStandardVersion: %d\n\tmVendorExtensionID: %d\n\tmVendorExtensionVersiony: %d\n",
  92. mStandardVersion, mVendorExtensionID, mVendorExtensionVersion);
  93. ALOGV("\tmVendorExtensionDesc: %s\n\tmFunctionalMode: %d\n\tmManufacturer: %s\n\tmModel: %s\n\tmVersion: %s\n\tmSerial: %s\n",
  94. mVendorExtensionDesc, mFunctionalMode, mManufacturer, mModel, mVersion, mSerial);
  95. }
  96. } // namespace android