• 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 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
16 #include "swing_callback_stub.h"
17 
18 #include "ans_log_wrapper.h"
19 #include "event_handler.h"
20 #include "ipc_types.h"
21 #include "message_parcel.h"
22 #include "singleton.h"
23 #include "ans_inner_errors.h"
24 
25 namespace OHOS {
26 namespace Notification {
SwingCallBackStub()27 SwingCallBackStub::SwingCallBackStub() {}
SwingCallBackStub(std::function<void (bool,int)> swingCallback)28 SwingCallBackStub::SwingCallBackStub(std::function<void(bool, int)> swingCallback) : swingCallback_(swingCallback) {}
~SwingCallBackStub()29 SwingCallBackStub::~SwingCallBackStub() {}
OnUpdateStatus(bool isEnable,int triggerMode)30 int32_t SwingCallBackStub::OnUpdateStatus(bool isEnable, int triggerMode)
31 {
32     return ERR_OK;
33 }
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int SwingCallBackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
35 {
36     ANS_LOGD("called.");
37     if (data.ReadInterfaceToken() != GetDescriptor()) {
38         ANS_LOGE("local descriptor is not equal to remote");
39         return ERR_INVALID_STATE;
40     }
41     switch (code) {
42         case static_cast<uint32_t>(NotificationInterfaceCode::ON_UPDATE_STATUS): {
43             bool isEnable = static_cast<bool>(data.ReadInt8());
44             int triggerMode = static_cast<int>(data.ReadInt32());
45             if (swingCallback_) {
46                 ANS_LOGI("swingCallback(isEnable: %{public}d, triggerMode: %{public}d)", isEnable, triggerMode);
47                 swingCallback_(isEnable, triggerMode);
48                 return NO_ERROR;
49             }
50             return ERR_UNKNOWN_OBJECT;
51         }
52         default:
53             return ERR_INVALID_STATE;
54     }
55 }
56 }
57 }
58 #endif