1 /*
2  * Copyright (c) 2023-2023 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_bundle_mgr.h"
17 
18 #include <functional>
19 #include <gtest/gtest.h>
20 #include "ans_ut_constant.h"
21 
22 namespace OHOS {
23 namespace Notification {
24 namespace {
25 bool g_isNonBundleName = false;
26 bool g_isEnable = true;
27 }
28 
MockIsNonBundleName(bool isNonBundleName)29 void MockIsNonBundleName(bool isNonBundleName)
30 {
31     g_isNonBundleName = isNonBundleName;
32 }
33 
MockDistributedNotificationEnabled(bool isEnable)34 void MockDistributedNotificationEnabled(bool isEnable)
35 {
36     g_isEnable = isEnable;
37 }
38 }
39 }
40 
41 namespace OHOS {
42 namespace AppExecFwk {
GetNameForUid(const int uid,std::string & name)43 ErrCode BundleMgrProxy::GetNameForUid(const int uid, std::string &name)
44 {
45     name = Notification::g_isNonBundleName ? "": "bundleName";
46     return ERR_OK;
47 }
48 
GetBundleInfo(const std::string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo,int32_t userId)49 bool BundleMgrProxy::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo,
50     int32_t userId)
51 {
52     return true;
53 }
54 
GetUidByBundleName(const std::string & bundleName,const int userId)55 int BundleMgrProxy::GetUidByBundleName(const std::string &bundleName, const int userId)
56 {
57     if (userId == 0) {
58         return -1;
59     } else {
60         return Notification::NON_SYSTEM_APP_UID;
61     }
62 }
63 
GetApplicationInfo(const std::string & appName,const ApplicationFlag flag,const int userId,ApplicationInfo & appInfo)64 bool BundleMgrProxy::GetApplicationInfo(
65     const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo)
66 {
67     appInfo.distributedNotificationEnabled = Notification::g_isEnable;
68     return true;
69 }
70 
71 } // namespace AppExecFwk
72 } // namespace OHOS
73