• 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_sorting.h"
16 
17 #include "ans_log_wrapper.h"
18 #include "sts_common.h"
19 #include "sts_slot.h"
20 
21 namespace OHOS {
22 namespace NotificationSts {
WarpNotificationSorting(ani_env * env,Notification::NotificationSorting & sorting,ani_object & outObj)23 bool WarpNotificationSorting(ani_env *env, Notification::NotificationSorting &sorting, ani_object &outObj)
24 {
25     ani_class cls;
26     ani_object obj;
27     ani_object slotObj;
28     ani_status status;
29     ani_string hashCodeObj;
30     std::string hashCode;
31     if (env == nullptr) {
32         ANS_LOGE("invalid parameter value");
33         return false;
34     }
35     if (!CreateClassObjByClassName(env, "Lnotification/notificationSorting/NotificationSortingInner;", cls, obj)) {
36         ANS_LOGE("Create obj faild. NotificationSortingInner");
37         return false;
38     }
39     // readonly slot: NotificationSlot
40     if (!WrapNotificationSlot(env, sorting.GetSlot(), slotObj)) {
41         ANS_LOGE("WrapNotificationSlot faild");
42         return false;
43     }
44     if (ANI_OK != (status = env->Object_SetPropertyByName_Ref(obj, "slot", slotObj))) {
45         ANS_LOGE("set slot faild. status %{public}d", status);
46         return false;
47     }
48     hashCode = sorting.GetGroupKeyOverride();
49     if (ANI_OK != GetAniStringByString(env, hashCode, hashCodeObj) || hashCodeObj == nullptr) {
50         ANS_LOGE("GetAniStringByString faild");
51         return false;
52     }
53     // readonly hashCode: string;
54     if (ANI_OK != (status = env->Object_SetPropertyByName_Ref(obj, "hashCode", hashCodeObj))) {
55         ANS_LOGE("set hashCode faild. status %{public}d", status);
56         return false;
57     }
58     // readonly ranking: number;
59     if (ANI_OK != (status = env->Object_SetPropertyByName_Double(
60         obj, "ranking", static_cast<ani_double>(sorting.GetRanking())))) {
61         ANS_LOGE("set ranking faild. status %{public}d", status);
62         return false;
63     }
64     outObj = obj;
65     return true;
66 }
67 } // namespace NotificationSts
68 } // OHOS
69