blob: fa2f95b2d3b3cf34b858a1129c8bc35dae34aa34 [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04001/*
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 bigbiffaf32bb92018-12-18 18:39:53 -05008 * http://www.apache.org/licenses/LICENSE-2.0
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04009 *
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 bigbiffc7eee6f2014-09-02 18:59:01 -040015 */
16
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050017#define LOG_TAG "MtpDeviceInfo"
18
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040019#include "MtpDebug.h"
20#include "MtpDataPacket.h"
21#include "MtpDeviceInfo.h"
22#include "MtpStringBuffer.h"
23
24MtpDeviceInfo::MtpDeviceInfo()
25 : mStandardVersion(0),
26 mVendorExtensionID(0),
27 mVendorExtensionVersion(0),
28 mVendorExtensionDesc(NULL),
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050029 mFunctionalMode(0),
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040030 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
42MtpDeviceInfo::~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 bigbiffaf32bb92018-12-18 18:39:53 -050060bool MtpDeviceInfo::read(MtpDataPacket& packet) {
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040061 MtpStringBuffer string;
62
63 // read the device info
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050064 if (!packet.getUInt16(mStandardVersion)) return false;
65 if (!packet.getUInt32(mVendorExtensionID)) return false;
66 if (!packet.getUInt16(mVendorExtensionVersion)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040067
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050068 if (!packet.getString(string)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040069 mVendorExtensionDesc = strdup((const char *)string);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050070 if (!mVendorExtensionDesc) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040071
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050072 if (!packet.getUInt16(mFunctionalMode)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040073 mOperations = packet.getAUInt16();
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050074 if (!mOperations) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040075 mEvents = packet.getAUInt16();
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050076 if (!mEvents) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040077 mDeviceProperties = packet.getAUInt16();
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050078 if (!mDeviceProperties) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040079 mCaptureFormats = packet.getAUInt16();
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050080 if (!mCaptureFormats) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040081 mPlaybackFormats = packet.getAUInt16();
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050082 if (!mCaptureFormats) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040083
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050084 if (!packet.getString(string)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040085 mManufacturer = strdup((const char *)string);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050086 if (!mManufacturer) return false;
87 if (!packet.getString(string)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040088 mModel = strdup((const char *)string);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050089 if (!mModel) return false;
90 if (!packet.getString(string)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040091 mVersion = strdup((const char *)string);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050092 if (!mVersion) return false;
93 if (!packet.getString(string)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040094 mSerial = strdup((const char *)string);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050095 if (!mSerial) return false;
96
97 return true;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040098}
99
100void MtpDeviceInfo::print() {
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -0500101 ALOGV("Device Info:\n\tmStandardVersion: %d\n\tmVendorExtensionID: %d\n\tmVendorExtensionVersiony: %d\n",
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400102 mStandardVersion, mVendorExtensionID, mVendorExtensionVersion);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -0500103 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 bigbiffc7eee6f2014-09-02 18:59:01 -0400105}