• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #include "mock_want_utils.h"
17 
18 #include "ability_util.h"
19 #include "in_process_call_wrapper.h"
20 #include "utils/app_mgr_util.h"
21 #include "hilog_tag_wrapper.h"
22 
23 namespace OHOS {
24 namespace AAFwk {
25 constexpr int32_t CONVERT_CALLBACK_TIMEOUT_SECONDS = 2; // 2s
26 constexpr uint32_t TYPE_ATOMIC_SERVICE = 0;
27 constexpr uint32_t TYPE_APP = 1;
28 constexpr uint32_t TYPE_IS_SHORTURL = 2;
29 const std::string NOT_SHORTURL = "NOT_SHORTURL";
30 const std::string IS_SHORTURL = "IS_SHORTURL";
31 const std::string CONVERT_FAILED = "CONVERT_FAILED";
32 const std::string ATOMIC_SERVICE = "ATOMIC_SERVICE";
33 const std::string APP = "APP";
34 
GetCallerBundleName(std::string & callerBundleName)35 int32_t WantUtils::GetCallerBundleName(std::string &callerBundleName)
36 {
37     TAG_LOGI(AAFwkTag::TEST, "Mock GetCallerBundleName");
38     return ERR_OK;
39 }
40 
ConvertToExplicitWant(Want & want,uint32_t & targetType)41 int32_t WantUtils::ConvertToExplicitWant(Want &want, uint32_t &targetType)
42 {
43     TAG_LOGI(AAFwkTag::TEST, "Mock ConvertToExplicitWant");
44     int32_t retCode = ERR_OK;
45     std::string url = want.GetUriString();
46     if (url == CONVERT_FAILED) {
47         return CHECK_PERMISSION_FAILED;
48     }
49     if (url == ATOMIC_SERVICE) {
50         targetType = TYPE_ATOMIC_SERVICE;
51     }
52     if (url == APP) {
53         targetType = TYPE_APP;
54     }
55     if (url == IS_SHORTURL) {
56         targetType = TYPE_IS_SHORTURL;
57     }
58     return retCode;
59 }
60 
IsShortUrl(const Want & want)61 bool WantUtils::IsShortUrl(const Want &want)
62 {
63     TAG_LOGI(AAFwkTag::TEST, "Mock IsShortUrl");
64     std::string url = want.GetUriString();
65     bool isShortUrl = false;
66     if (url != NOT_SHORTURL) {
67         isShortUrl = true;
68     }
69     if (!isShortUrl) {
70         TAG_LOGI(AAFwkTag::ABILITYMGR, "not short url");
71     }
72     return isShortUrl;
73 }
74 
IsAtomicService(uint32_t targetType)75 bool WantUtils::IsAtomicService(uint32_t targetType)
76 {
77     TAG_LOGI(AAFwkTag::TEST, "Mock IsAtomicService, targetType %{public}d", targetType);
78     return targetType == 0;
79 }
80 
IsNormalApp(uint32_t targetType)81 bool WantUtils::IsNormalApp(uint32_t targetType)
82 {
83     TAG_LOGI(AAFwkTag::TEST, "Mock IsNormalApp, targetType %{public}d", targetType);
84     return targetType == 1;
85 }
86 }  // namespace AAFwk
87 }  // namespace OHOS
88