• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "payload_data/get_device_info_data.h"
16 #include "media_log.h"
17 #include "media_mtp_utils.h"
18 #include "mtp_constants.h"
19 #include "mtp_operation_utils.h"
20 #include "mtp_packet_tools.h"
21 #include "mtp_manager.h"
22 #include "playback_formats.h"
23 
24 using namespace std;
25 
26 namespace OHOS {
27 namespace Media {
28 static const char *EXTENSION_DESC = "microsoft.com: 1.0; openharmony: 1.0;";
29 
30 static const uint16_t CaptureFormats[] = {};
31 
32 static const uint16_t DeviceProperties[] = {
33     MTP_DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER_CODE,
34     MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME_CODE,
35     MTP_DEVICE_PROPERTY_IMAGE_SIZE_CODE,
36     MTP_DEVICE_PROPERTY_BATTERY_LEVEL_CODE,
37     MTP_DEVICE_PROPERTY_PERCEIVED_DEVICE_TYPE_CODE,
38     MTP_DEVICE_PROPERTY_SESSION_INITIATOR_VERSION_INFO_CODE,
39 };
40 
41 static const uint16_t Events[] = {
42     MTP_EVENT_OBJECT_ADDED_CODE,
43     MTP_EVENT_OBJECT_REMOVED_CODE,
44     MTP_EVENT_STORE_ADDED_CODE,
45     MTP_EVENT_STORE_REMOVED_CODE,
46     MTP_EVENT_DEVICE_PROP_CHANGED_CODE,
47     MTP_EVENT_OBJECT_INFO_CHANGED_CODE,
48 };
49 
50 static const uint16_t Operations[] = {
51     MTP_OPERATION_GET_DEVICE_INFO_CODE,
52     MTP_OPERATION_OPEN_SESSION_CODE,
53     MTP_OPERATION_CLOSE_SESSION_CODE,
54     MTP_OPERATION_GET_STORAGE_IDS_CODE,
55     MTP_OPERATION_GET_STORAGE_INFO_CODE,
56     MTP_OPERATION_GET_NUM_OBJECTS_CODE,
57     MTP_OPERATION_GET_OBJECT_HANDLES_CODE,
58     MTP_OPERATION_GET_OBJECT_INFO_CODE,
59     MTP_OPERATION_GET_OBJECT_CODE,
60     MTP_OPERATION_GET_THUMB_CODE,
61     MTP_OPERATION_DELETE_OBJECT_CODE,
62     MTP_OPERATION_SEND_OBJECT_INFO_CODE,
63     MTP_OPERATION_SEND_OBJECT_CODE,
64     MTP_OPERATION_RESET_DEVICE_CODE,
65     MTP_OPERATION_GET_DEVICE_PROP_DESC_CODE,
66     MTP_OPERATION_GET_DEVICE_PROP_VALUE_CODE,
67     MTP_OPERATION_SET_DEVICE_PROP_VALUE_CODE,
68     MTP_OPERATION_RESET_DEVICE_PROP_VALUE_CODE,
69     MTP_OPERATION_MOVE_OBJECT_CODE,
70     MTP_OPERATION_COPY_OBJECT_CODE,
71     MTP_OPERATION_GET_PARTIAL_OBJECT_CODE,
72     MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED_CODE,
73     MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE,
74     MTP_OPERATION_GET_OBJECT_PROP_VALUE_CODE,
75     MTP_OPERATION_SET_OBJECT_PROP_VALUE_CODE,
76     MTP_OPERATION_GET_OBJECT_PROP_LIST_CODE,
77 };
78 
79 const int EXTENSION_ID = 6;
GetDeviceInfoData(std::shared_ptr<MtpOperationContext> & context)80 GetDeviceInfoData::GetDeviceInfoData(std::shared_ptr<MtpOperationContext> &context)
81     : PayloadData(context), functionalMode_(0), serialNum_("0")
82 {
83     standardVersion_ = MTP_STANDARD_VERSION;
84     vendorExtensionID_ = EXTENSION_ID;
85     vendorExtensionVersion_ = MTP_STANDARD_VERSION;
86     vendorExtensionDesc_ = EXTENSION_DESC;
87     manufacturer_ = DEFAULT_PRODUCT_MANUFACTURER;
88     model_ = DEFAULT_PRODUCT_MODEL;
89     version_ = DEFAULT_PRODUCT_SOFTWARE_VERSION;
90     Maker(mOutBuffer);
91 }
92 
GetDeviceInfoData()93 GetDeviceInfoData::GetDeviceInfoData()
94 {
95     standardVersion_ = MTP_STANDARD_VERSION;
96     vendorExtensionID_ = EXTENSION_ID;
97     vendorExtensionVersion_ = MTP_STANDARD_VERSION;
98     vendorExtensionDesc_ = EXTENSION_DESC;
99     functionalMode_ = 0;
100     manufacturer_ = DEFAULT_PRODUCT_MANUFACTURER;
101     model_ = DEFAULT_PRODUCT_MODEL;
102     version_ = DEFAULT_PRODUCT_SOFTWARE_VERSION;
103     serialNum_ = "0";
104     Maker(mOutBuffer);
105 }
106 
~GetDeviceInfoData()107 GetDeviceInfoData::~GetDeviceInfoData()
108 {
109 }
110 
Parser(const std::vector<uint8_t> & buffer,int32_t readSize)111 int GetDeviceInfoData::Parser(const std::vector<uint8_t> &buffer, int32_t readSize)
112 {
113     return MTP_SUCCESS;
114 }
115 
Maker(std::vector<uint8_t> & outBuffer)116 int GetDeviceInfoData::Maker(std::vector<uint8_t> &outBuffer)
117 {
118     MtpPacketTool::PutUInt16(outBuffer, standardVersion_);
119     MtpPacketTool::PutUInt32(outBuffer, vendorExtensionID_);
120     MtpPacketTool::PutUInt16(outBuffer, vendorExtensionVersion_);
121     MtpPacketTool::PutString(outBuffer, vendorExtensionDesc_);
122     MtpPacketTool::PutUInt16(outBuffer, functionalMode_);
123     MtpPacketTool::PutAUInt16(outBuffer, Operations, sizeof(Operations) / sizeof(uint16_t));
124     MtpPacketTool::PutAUInt16(outBuffer, Events, sizeof(Events) / sizeof(uint16_t));
125     MtpPacketTool::PutAUInt16(outBuffer, DeviceProperties, sizeof(DeviceProperties) / sizeof(uint16_t));
126     MtpPacketTool::PutAUInt16(outBuffer, CaptureFormats, sizeof(CaptureFormats) / sizeof(uint16_t));
127     MtpPacketTool::PutAUInt16(outBuffer, PLAYBACK_FORMATS, sizeof(PLAYBACK_FORMATS) / sizeof(uint16_t));
128     MtpPacketTool::PutString(outBuffer, manufacturer_);
129     MtpPacketTool::PutString(outBuffer, model_);
130     MtpPacketTool::PutString(outBuffer, version_);
131     MtpPacketTool::PutString(outBuffer, serialNum_);
132 
133     return MTP_SUCCESS;
134 }
135 
CalculateSize()136 uint32_t GetDeviceInfoData::CalculateSize()
137 {
138     std::vector<uint8_t> tmpVar;
139 
140     int res = Maker(tmpVar);
141     if (res != MTP_SUCCESS) {
142         return res;
143     }
144 
145     return tmpVar.size();
146 }
147 
SetManufacturer(const std::string & manufacturer)148 void GetDeviceInfoData::SetManufacturer(const std::string &manufacturer)
149 {
150     manufacturer_ = manufacturer;
151 }
152 
SetModel(const std::string & model)153 void GetDeviceInfoData::SetModel(const std::string &model)
154 {
155     model_ = model;
156 }
157 
SetVersion(const std::string & version)158 void GetDeviceInfoData::SetVersion(const std::string &version)
159 {
160     version_ = version;
161 }
162 
SetSerialNum(const std::string & serialNum)163 void GetDeviceInfoData::SetSerialNum(const std::string &serialNum)
164 {
165     serialNum_ = serialNum;
166 }
167 } // namespace Media
168 } // namespace OHOS