• 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 #ifndef OHOS_DMS_VERSION_MANAGER_H
16 #define OHOS_DMS_VERSION_MANAGER_H
17 
18 #include <string>
19 #include "ipc_skeleton.h"
20 
21 namespace OHOS {
22 namespace DistributedSchedule {
23 #define IN_PROCESS_CALL(theCall)                                     \
24     ([&]() {                                                         \
25         std::string identity = IPCSkeleton::ResetCallingIdentity();  \
26         auto retVal = theCall;                                       \
27         IPCSkeleton::SetCallingIdentity(identity);                   \
28         return retVal;                                               \
29     }())
30 
31 struct DmsVersion {
32     uint32_t majorVersionNum = 0;
33     uint32_t minorVersionNum = 0;
34     uint32_t featureVersionNum = 0;
35 };
36 
37 class DmsVersionManager {
38 public:
39     static bool IsRemoteDmsVersionLower(const std::string& remoteDeviceId, const DmsVersion& thresholdDmsVersion);
40 private:
41     static int32_t GetRemoteDmsVersion(const std::string& deviceId, DmsVersion& dmsVersion);
42     static int32_t GetAppInfoFromDP(const std::string& deviceId, std::string& appInfoJsonData);
43     static int32_t ParseAppInfo(const std::string& appInfoJsonData, std::string& packageNamesData,
44         std::string& versionsData);
45     static int32_t GetDmsVersionDataFromAppInfo(const std::string& packageNamesData, const std::string& versionsData,
46         std::string& dmsVersionData);
47     static bool ParseDmsVersion(const std::string& dmsVersionData, DmsVersion& dmsVersion);
48     static bool CompareDmsVersion(const DmsVersion& dmsVersion, const DmsVersion& thresholdDmsVersion);
49 };
50 } // namespace DistributedSchedule
51 } // namespace OHOS
52 #endif // OHOS_DMS_VERSION_MANAGER_H