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 #include "el5_filekey_callback_proxy.h"
17 #include "el5_filekey_manager_error.h"
18 #include "el5_filekey_manager_log.h"
19
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
El5FilekeyCallbackProxy(const sptr<IRemoteObject> & impl)23 El5FilekeyCallbackProxy::El5FilekeyCallbackProxy(const sptr<IRemoteObject>& impl)
24 : IRemoteProxy<El5FilekeyCallbackInterface>(impl) {
25 }
26
~El5FilekeyCallbackProxy()27 El5FilekeyCallbackProxy::~El5FilekeyCallbackProxy()
28 {
29 }
30
OnRegenerateAppKey(std::vector<AppKeyInfo> & infos)31 void El5FilekeyCallbackProxy::OnRegenerateAppKey(std::vector<AppKeyInfo> &infos)
32 {
33 MessageParcel data;
34 if (!data.WriteInterfaceToken(El5FilekeyCallbackInterface::GetDescriptor())) {
35 LOG_ERROR("Failed to write WriteInterfaceToken.");
36 return;
37 }
38 if (!data.WriteUint32(infos.size())) {
39 LOG_ERROR("Failed to WriteUint32(%{public}d).", static_cast<uint32_t>(infos.size()));
40 return;
41 }
42 for (AppKeyInfo info : infos) {
43 if (!data.WriteParcelable(&info)) {
44 LOG_ERROR("Failed to write AppKeyInfo.");
45 return;
46 }
47 }
48
49 MessageParcel reply;
50 MessageOption option;
51 sptr<IRemoteObject> remote = Remote();
52 if (remote == nullptr) {
53 LOG_ERROR("Remote service is null.");
54 return;
55 }
56
57 int32_t result = remote->SendRequest(
58 static_cast<int32_t>(El5FilekeyCallbackInterface::Code::ON_REGENERATE_APP_KEY), data, reply, option);
59 if (result != NO_ERROR) {
60 LOG_ERROR("SendRequest failed, result: %{public}d.", result);
61 }
62 }
63 } // namespace AccessToken
64 } // namespace Security
65 } // namespace OHOS
66