blob: 3e1dff7db2d485013b7fddce7c31e35d1c4cced2 [file] [log] [blame]
Mike Lockwood335dd2b2010-05-19 10:33:39 -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 *
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
Mike Lockwooda6c490b2010-06-05 22:45:01 -040017#define LOG_TAG "MtpDeviceInfo"
Mike Lockwood335dd2b2010-05-19 10:33:39 -040018
Mike Lockwoodb14e5882010-06-29 18:11:52 -040019#include "MtpDebug.h"
Mike Lockwood335dd2b2010-05-19 10:33:39 -040020#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),
Mike Lockwoodab063842014-11-12 14:20:06 -080031 mFunctionalMode(0),
Mike Lockwood335dd2b2010-05-19 10:33:39 -040032 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
Mike Lockwoodab063842014-11-12 14:20:06 -080062bool MtpDeviceInfo::read(MtpDataPacket& packet) {
Mike Lockwood335dd2b2010-05-19 10:33:39 -040063 MtpStringBuffer string;
64
65 // read the device info
Mike Lockwoodab063842014-11-12 14:20:06 -080066 if (!packet.getUInt16(mStandardVersion)) return false;
67 if (!packet.getUInt32(mVendorExtensionID)) return false;
68 if (!packet.getUInt16(mVendorExtensionVersion)) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040069
Mike Lockwoodab063842014-11-12 14:20:06 -080070 if (!packet.getString(string)) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040071 mVendorExtensionDesc = strdup((const char *)string);
72
Mike Lockwoodab063842014-11-12 14:20:06 -080073 if (!packet.getUInt16(mFunctionalMode)) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040074 mOperations = packet.getAUInt16();
Mike Lockwoodab063842014-11-12 14:20:06 -080075 if (!mOperations) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040076 mEvents = packet.getAUInt16();
Mike Lockwoodab063842014-11-12 14:20:06 -080077 if (!mEvents) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040078 mDeviceProperties = packet.getAUInt16();
Mike Lockwoodab063842014-11-12 14:20:06 -080079 if (!mDeviceProperties) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040080 mCaptureFormats = packet.getAUInt16();
Mike Lockwoodab063842014-11-12 14:20:06 -080081 if (!mCaptureFormats) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040082 mPlaybackFormats = packet.getAUInt16();
Mike Lockwoodab063842014-11-12 14:20:06 -080083 if (!mCaptureFormats) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040084
Mike Lockwoodab063842014-11-12 14:20:06 -080085 if (!packet.getString(string)) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040086 mManufacturer = strdup((const char *)string);
Mike Lockwoodab063842014-11-12 14:20:06 -080087 if (!packet.getString(string)) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040088 mModel = strdup((const char *)string);
Mike Lockwoodab063842014-11-12 14:20:06 -080089 if (!packet.getString(string)) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040090 mVersion = strdup((const char *)string);
Mike Lockwoodab063842014-11-12 14:20:06 -080091 if (!packet.getString(string)) return false;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040092 mSerial = strdup((const char *)string);
Mike Lockwoodab063842014-11-12 14:20:06 -080093
94 return true;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040095}
96
97void MtpDeviceInfo::print() {
Steve Block3856b092011-10-20 11:56:00 +010098 ALOGV("Device Info:\n\tmStandardVersion: %d\n\tmVendorExtensionID: %d\n\tmVendorExtensionVersiony: %d\n",
Mike Lockwood335dd2b2010-05-19 10:33:39 -040099 mStandardVersion, mVendorExtensionID, mVendorExtensionVersion);
Mike Lockwoodab063842014-11-12 14:20:06 -0800100 ALOGV("\tmVendorExtensionDesc: %s\n\tmFunctionalMode: %d\n\tmManufacturer: %s\n\tmModel: %s\n\tmVersion: %s\n\tmSerial: %s\n",
101 mVendorExtensionDesc, mFunctionalMode, mManufacturer, mModel, mVersion, mSerial);
Mike Lockwood335dd2b2010-05-19 10:33:39 -0400102}
103
104} // namespace android