• 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 #ifndef NUMBER_IDENTITY_SERVICE_H
17 #define NUMBER_IDENTITY_SERVICE_H
18 
19 #include "ability_connect_callback_stub.h"
20 #include "ffrt.h"
21 #include "ipc_object_stub.h"
22 #include "iremote_broker.h"
23 #include "iremote_proxy.h"
24 #include "message_option.h"
25 #include "message_parcel.h"
26 #include "singleton.h"
27 #include <atomic>
28 #include <cstdint>
29 #include <functional>
30 
31 namespace OHOS {
32 namespace Telephony {
33 
34 using std::atomic;
35 using std::function;
36 using ffrt::recursive_mutex;
37 using ConnectedCallback = function<void(sptr<IRemoteObject>)>;
38 using DisconnectedCallback = function<void()>;
39 using RemoteRequestCallBack = function<int32_t(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)>;
40 
41 class NumberIdentityCallbackStub : public IPCObjectStub {
42   public:
43     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS::Telephony::NumberIdentityCallback");
44 
45     explicit NumberIdentityCallbackStub(RemoteRequestCallBack callback);
46 
47     ~NumberIdentityCallbackStub() = default;
48 
49     virtual int32_t OnRemoteRequest(
50         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
51 
52   private:
53     RemoteRequestCallBack callback_;
54 };
55 
56 class NumberIdentityConnection : public AAFwk::AbilityConnectionStub {
57   public:
58     explicit NumberIdentityConnection(ConnectedCallback onConnected, DisconnectedCallback onDisconnected);
59 
60     ~NumberIdentityConnection();
61 
62     void OnAbilityConnectDone(
63         const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
64 
65     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
66 
67     bool IsAlive();
68 
69     sptr<IRemoteObject> GetAbilityProxy();
70 
71   private:
72     ConnectedCallback connectedCallback_;
73 
74     DisconnectedCallback disconnectedCallback_;
75 
76     recursive_mutex remoteProxyMutex_;
77 
78     sptr<IRemoteObject> remoteObject_;
79 };
80 
81 class NumberIdentityServiceHelper {
82     DECLARE_DELAYED_REF_SINGLETON(NumberIdentityServiceHelper);
83 
84   public:
85     void NotifyNumberMarkDataUpdate();
86 
87   private:
88     int Connect(ConnectedCallback connectedCallback, DisconnectedCallback disconnectedCallback);
89 
90     void Disconnect();
91 
92     int Request(ConnectedCallback connectedCallback);
93 
94     atomic<bool> working_ = false;
95 
96     recursive_mutex connectionMutex_;
97 
98     sptr<NumberIdentityConnection> connection_;
99 };
100 
101 enum NumberIdentityServiceMessageCode {
102     IMPORT_NUMBER_MARK_DATA_FILE = 0,
103 };
104 
105 class INumberIdentityService : public IRemoteBroker {
106   public:
107     DECLARE_INTERFACE_DESCRIPTOR(u"com.numberidentity:NumberIdentityService");
108 
109     virtual void NotifyNumberMarkDataUpdate() = 0;
110 };
111 
112 class NumberIdentityServiceProxy : IRemoteProxy<INumberIdentityService> {
113   public:
114     explicit NumberIdentityServiceProxy(const sptr<IRemoteObject> &remote);
115 
116     virtual ~NumberIdentityServiceProxy() = default;
117 
118     virtual void NotifyNumberMarkDataUpdate() override;
119 };
120 
121 } // namespace Telephony
122 } // namespace OHOS
123 
124 #endif /* NUMBER_IDENTITY_SERVICE_H */