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