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