1 /* 2 * Copyright (C) 2021 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 IPC_DEV_AUTH_STUB_H 17 #define IPC_DEV_AUTH_STUB_H 18 19 #include "iremote_stub.h" 20 21 #include "ipc_iface.h" 22 #include "ipc_adapt.h" 23 24 namespace OHOS { 25 typedef struct { 26 IpcServiceCall method; 27 int32_t methodId; 28 } IpcServiceCallMap; 29 const int32_t MAX_CALLMAP_SIZE = 64; 30 const int32_t MAX_CBSTUB_SIZE = 64; 31 32 class ServiceDevAuth : public IRemoteStub<IMethodsIpcCall> { 33 public: 34 ServiceDevAuth(bool serialInvokeFlag = true); 35 ~ServiceDevAuth() override; 36 int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override; 37 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, 38 MessageParcel &reply, MessageOption &option) override; 39 void ResetCallMap(void); 40 int32_t SetCallMap(IpcServiceCall method, int32_t methodId); 41 static int32_t SetRemoteObject(sptr<IRemoteObject> &object); 42 static void AddCbDeathRecipient(int32_t cbStubIdx, int32_t cbDataIdx); 43 static void ResetRemoteObject(int32_t idx); 44 static void ActCallback(int32_t objIdx, int32_t callbackId, bool sync, 45 uintptr_t cbHook, MessageParcel &dataParcel, MessageParcel &reply); 46 47 protected: 48 int32_t HandleRestoreCall(MessageParcel &data, MessageParcel &reply); 49 int32_t HandleDeviceAuthCall(uint32_t code, MessageParcel &data, 50 MessageParcel &reply, MessageOption &option); 51 52 private: 53 int32_t maxCallMapSz = MAX_CALLMAP_SIZE; 54 IpcServiceCallMap *standardCallMapTable = nullptr; 55 int32_t callMapElemNum = 0; 56 IpcServiceCall GetCallMethodByMethodId(int32_t methodId); 57 }; 58 59 class DevAuthDeathRecipient : public IRemoteObject::DeathRecipient { 60 public: DevAuthDeathRecipient()61 DevAuthDeathRecipient() {} 62 explicit DevAuthDeathRecipient(int32_t cbIdx); ~DevAuthDeathRecipient()63 ~DevAuthDeathRecipient() override {} 64 void OnRemoteDied(const wptr<IRemoteObject>& remoteObject) override; 65 private: 66 int32_t callbackIdx; 67 }; 68 } 69 #endif 70