• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "sts_subscribe_info.h"
16 
17 #include "sts_common.h"
18 #include "ans_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace NotificationSts {
UnwarpNotificationSubscribeInfo(ani_env * env,ani_object value,NotificationSubscribeInfo & info)22 bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, NotificationSubscribeInfo &info)
23 {
24     ANS_LOGD("enter");
25     if (env == nullptr || value == nullptr) {
26         ANS_LOGE("invalid parameter value");
27         return false;
28     }
29     std::vector<std::string> res = {};
30     ani_double userId = 0.0;
31     ani_double filterLimit = 0.0;
32     std::string deviceType;
33     ani_boolean isUndefined = ANI_TRUE;
34     if (ANI_OK != GetPropertyStringArray(env, value, "bundleNames", isUndefined, res)
35         || isUndefined == ANI_TRUE
36         || res.empty()) {
37         ANS_LOGE("UnWarpStringArrayOrUndefinedByProperty faild");
38     }
39     std::vector<std::string> bundleNames = {};
40     for (auto bundleName : res) {
41         bundleNames.emplace_back(GetResizeStr(bundleName, STR_MAX_SIZE));
42     }
43     if (ANI_OK != GetPropertyDouble(env, value, "userId", isUndefined, userId) || isUndefined == ANI_TRUE) {
44         ANS_LOGE("GetDoubleOrUndefined faild");
45     }
46     if (ANI_OK != GetPropertyString(env, value, "deviceType", isUndefined, deviceType) || isUndefined == ANI_TRUE) {
47         ANS_LOGE("GetStringOrUndefined faild");
48     }
49     if (ANI_OK != GetPropertyDouble(env, value, "filterLimit", isUndefined, filterLimit) || isUndefined == ANI_TRUE) {
50         ANS_LOGE("GetDoubleOrUndefined faild");
51     }
52     info.AddAppNames(bundleNames);
53     info.AddAppUserId(static_cast<int32_t>(userId));
54     info.SetFilterType(static_cast<int32_t>(filterLimit));
55     info.AddDeviceType(GetResizeStr(deviceType, STR_MAX_SIZE));
56     ANS_LOGD("userId %{public}d deviceType %{public}s filterLimit %{public}d",
57         info.GetAppUserId(), info.GetDeviceType().c_str(), info.GetFilterType());
58     return true;
59 }
60 
61 } // namespace NotificationSts
62 } // OHOS
63