diff --git a/bundle.json b/bundle.json index 38419432d5c684a321cf44455b51d3422cc20b2b..5bc0b2ec97138c42341d57c58bd701cacc9da3b3 100644 --- a/bundle.json +++ b/bundle.json @@ -18,7 +18,7 @@ "adapted_system_type": [ "standard" ], "syscap": ["SystemCapability.UserIAM.AuthExecutorMgr"], "features": [], - "rom": "500KB", + "rom": "1024KB", "ram": "2500KB", "deps": { "components": [ diff --git a/common/database/src/idm_database.c b/common/database/src/idm_database.c index 73a9b9c3ef9350d2fb207aa726e06f9dfcd7a4ea..e07d446cfbddf780290c17baea83ac9f66b43d37 100644 --- a/common/database/src/idm_database.c +++ b/common/database/src/idm_database.c @@ -130,6 +130,7 @@ ResultCode GetEnrolledInfoAuthType(int32_t userId, uint32_t authType, EnrolledIn *enrolledInfo = *nodeInfo; return RESULT_SUCCESS; } + temp = temp->next; } return RESULT_NOT_FOUND; diff --git a/frameworks/kitsimpl/src/coauth_proxy.cpp b/frameworks/kitsimpl/src/coauth_proxy.cpp index 4d788af044676e3cfd2b8d9f6d6cf06e574ad27e..f9fde10cc7693b155634542c32c09d09fa59c5f7 100755 --- a/frameworks/kitsimpl/src/coauth_proxy.cpp +++ b/frameworks/kitsimpl/src/coauth_proxy.cpp @@ -12,6 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include #include #include #include "coauth_hilog_wrapper.h" @@ -34,7 +36,7 @@ uint32_t CoAuthProxy::WriteAuthExecutor(AuthResPool::AuthExecutor &executorInfo, if (!data.WriteUint64(authAbility)) { return FAIL; } - COAUTH_HILOGD(MODULE_INNERKIT, "WriteUint64,authAbility:%{public}llu", authAbility); + COAUTH_HILOGD(MODULE_INNERKIT, "WriteUint64,authAbility:%{public}" PRIu64, authAbility); ExecutorSecureLevel executorSecLevel; executorInfo.GetExecutorSecLevel(executorSecLevel); @@ -93,7 +95,7 @@ uint64_t CoAuthProxy::Register(std::shared_ptr execut bool ret = SendRequest(static_cast(ICoAuth::COAUTH_EXECUTOR_REGIST), data, reply); if (ret) { result = reply.ReadUint64(); - COAUTH_HILOGD(MODULE_INNERKIT, "result = %{public}llu", result); + COAUTH_HILOGD(MODULE_INNERKIT, "result = %{public}" PRIu64, result); } return result; } @@ -142,12 +144,12 @@ void CoAuthProxy::coAuth(uint64_t scheduleId, AuthInfo &authInfo, const sptrAsObject())) { @@ -214,7 +216,7 @@ int32_t CoAuthProxy::GetExecutorProp(AuthResPool::AuthAttributes &conditions, std::vector valuesReply; bool ret = SendRequest(static_cast(ICoAuth::COAUTH_GET_PROPERTY), data, reply); if (!ret) { - COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); + COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); return FAIL; } if (!reply.ReadInt32(result)) { diff --git a/frameworks/kitsimpl/src/executor_messenger_stub.cpp b/frameworks/kitsimpl/src/executor_messenger_stub.cpp index b6157e4cf2fd0c0e0a328217ed0d28f11c6f138e..ce0ceb09b1f753ea0ad0705b0b4348da8aa4f56b 100644 --- a/frameworks/kitsimpl/src/executor_messenger_stub.cpp +++ b/frameworks/kitsimpl/src/executor_messenger_stub.cpp @@ -24,7 +24,7 @@ const std::string PERMISSION_ACCESS_COAUTH = "ohos.permission.ACCESS_COAUTH"; int32_t ExecutorMessengerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub::OnRemoteRequest, cmd = %d, flags= %d", + COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d", code, option.GetFlags()); std::u16string descripter = ExecutorMessengerStub::GetDescriptor(); std::u16string remoteDescripter = data.ReadInterfaceToken(); diff --git a/frameworks/kitsimpl/src/set_prop_callback_proxy.cpp b/frameworks/kitsimpl/src/set_prop_callback_proxy.cpp index 45ca9d7f43f40b5de60e16a46052d625bb6d52ea..e76d33a7a1bdbb6f7b56a0a8656189d4a19d0e79 100644 --- a/frameworks/kitsimpl/src/set_prop_callback_proxy.cpp +++ b/frameworks/kitsimpl/src/set_prop_callback_proxy.cpp @@ -35,7 +35,7 @@ void SetPropCallbackProxy::OnResult(uint32_t result, std::vector &extra bool ret = SendRequest(static_cast(ISetPropCallback::ONRESULT), data, reply); if (!ret) { - COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); + COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret); } } diff --git a/interfaces/innerkits/include/auth_attributes.h b/interfaces/innerkits/include/auth_attributes.h index 87bf8ba9544b3361faae6581218a96c4b95fc868..4b6c17592cfe844456a457e5fe52f27d7085a646 100644 --- a/interfaces/innerkits/include/auth_attributes.h +++ b/interfaces/innerkits/include/auth_attributes.h @@ -85,10 +85,6 @@ private: std::vector &buffer); void Write64Array(std::vector &uint64ArraylValue, uint8_t *writePointer, std::vector &buffer); - void InsertMap(AuthAttributeType a, ValueType b) - { - authAttributesPosition_.insert(std::map::value_type(a, b)); - } }; } // namespace AuthResPool } // namespace UserIAM diff --git a/interfaces/innerkits/include/coauth_info_define.h b/interfaces/innerkits/include/coauth_info_define.h index 5fe87ad83764720cf6353bf4f9d9a56fd26c5f2f..2370238353130c0cbae7eb12a92adaa28ea8c28c 100644 --- a/interfaces/innerkits/include/coauth_info_define.h +++ b/interfaces/innerkits/include/coauth_info_define.h @@ -161,6 +161,7 @@ enum ResultCode { }; const uint64_t INVALID_EXECUTOR_ID = 0; +const std::string REGISTER_NOTIFICATION = "EXECUTOR_REGISTER_NOTIFICATION"; } // namespace UserIAM } // namespace OHOS #endif // COAUTH_INFO_DEFINE_H diff --git a/interfaces/innerkits/src/auth_attributes.cpp b/interfaces/innerkits/src/auth_attributes.cpp index d5815ca259fbd6ccaf9d5698b56c35a801c54f71..c4ac9872731baba2859ea831dd33fd35c4f9ff94 100644 --- a/interfaces/innerkits/src/auth_attributes.cpp +++ b/interfaces/innerkits/src/auth_attributes.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "auth_attributes.h" namespace OHOS { @@ -20,27 +21,28 @@ namespace UserIAM { namespace AuthResPool { AuthAttributes::AuthAttributes() { - InsertMap(AUTH_RESULT_CODE, UINT32TYPE); - InsertMap(AUTH_SIGNATURE, UINT8ARRAYTYPE); - InsertMap(AUTH_IDENTIFY_MODE, UINT32TYPE); - InsertMap(AUTH_TEMPLATE_ID, UINT64TYPE); - InsertMap(AUTH_TEMPLATE_ID_LIST, UINT64ARRAYTYPE); - InsertMap(AUTH_REMAIN_COUNT, UINT32TYPE); - InsertMap(AUTH_REMAIN_TIME, UINT32TYPE); - InsertMap(AUTH_SESSION_ID, UINT64TYPE); - InsertMap(AUTH_CALLER_NAME, UINT8ARRAYTYPE); - InsertMap(AUTH_SCHEDULE_VERSION, UINT32TYPE); - InsertMap(AUTH_LOCK_OUT_TEMPLATE, UINT64TYPE); - InsertMap(AUTH_UNLOCK_TEMPLATE, UINT64TYPE); - InsertMap(AUTH_SUBTYPE, UINT64TYPE); - InsertMap(AUTH_SCHEDULE_MODE, UINT32TYPE); - InsertMap(AUTH_PROPERTY_MODE, UINT32TYPE); - InsertMap(AUTH_TYPE, UINT32TYPE); - InsertMap(AUTH_CREDENTIAL_ID, UINT64TYPE); - InsertMap(AUTH_CONTROLLER, BOOLTYPE); - InsertMap(AUTH_CALLER_UID, UINT64TYPE); - InsertMap(AUTH_RESULT, UINT8ARRAYTYPE); - InsertMap(ALGORITHM_INFO, UINT8ARRAYTYPE); + authAttributesPosition_ = {{AUTH_RESULT_CODE, UINT32TYPE}, + {AUTH_RESULT_CODE, UINT32TYPE}, + {AUTH_SIGNATURE, UINT8ARRAYTYPE}, + {AUTH_IDENTIFY_MODE, UINT32TYPE}, + {AUTH_TEMPLATE_ID, UINT64TYPE}, + {AUTH_TEMPLATE_ID_LIST, UINT64ARRAYTYPE}, + {AUTH_REMAIN_COUNT, UINT32TYPE}, + {AUTH_REMAIN_TIME, UINT32TYPE}, + {AUTH_SESSION_ID, UINT64TYPE}, + {AUTH_CALLER_NAME, UINT8ARRAYTYPE}, + {AUTH_SCHEDULE_VERSION, UINT32TYPE}, + {AUTH_LOCK_OUT_TEMPLATE, UINT64TYPE}, + {AUTH_UNLOCK_TEMPLATE, UINT64TYPE}, + {AUTH_SUBTYPE, UINT64TYPE}, + {AUTH_SCHEDULE_MODE, UINT32TYPE}, + {AUTH_PROPERTY_MODE, UINT32TYPE}, + {AUTH_TYPE, UINT32TYPE}, + {AUTH_CREDENTIAL_ID, UINT64TYPE}, + {AUTH_CONTROLLER, BOOLTYPE}, + {AUTH_CALLER_UID, UINT64TYPE}, + {AUTH_RESULT, UINT8ARRAYTYPE}, + {ALGORITHM_INFO, UINT8ARRAYTYPE}}; } void AuthAttributes::clear() @@ -144,7 +146,7 @@ int32_t AuthAttributes::SetUint32Value(AuthAttributeType attrType, uint32_t valu } uint32ValueMap_[attrType] = value; existAttributes_.push_back(attrType); - COAUTH_HILOGD(MODULE_INNERKIT, "SetUint32Value : %{public}d.", value); + COAUTH_HILOGD(MODULE_INNERKIT, "SetUint32Value : %{public}u.", value); return ret; } @@ -287,7 +289,7 @@ std::vector AuthAttributes::GetUint32ArrayFromUint8(std::vector AuthAttributes::GetUint64ArrayFromUint8(std::vector &buffer) tag = authAttributesPosition_.find(existAttributes_[i])->first; writePointer = static_cast(static_cast(&tag)); buffer.insert(buffer.end(), writePointer, writePointer + sizeof(AuthAttributeType)); - COAUTH_HILOGD(MODULE_INNERKIT, "data Write tag : %{public}d.", tag); + COAUTH_HILOGD(MODULE_INNERKIT, "data Write tag : %{public}u.", tag); PackToBuffer(authAttributesPosition_.find(existAttributes_[i]), dataLength, writePointer, buffer); } diff --git a/interfaces/innerkits/src/auth_executor.cpp b/interfaces/innerkits/src/auth_executor.cpp index 2e50d2c1bb2d27720806308c37f98a1578a51977..cb5b4b120c291887d124fe034566d3e5cc8bcd2d 100644 --- a/interfaces/innerkits/src/auth_executor.cpp +++ b/interfaces/innerkits/src/auth_executor.cpp @@ -18,85 +18,85 @@ namespace OHOS { namespace UserIAM { namespace AuthResPool { - AuthExecutor::AuthExecutor() - : authTypeValue_(PIN), - authAbilityValue_(0), - executorSecLevelValue_(ESL0), - executorTypeValue_(TYPE_CO_AUTH), - publicKeyValue_(0), - deviceIdValue_(0) - { - } +AuthExecutor::AuthExecutor() + : authTypeValue_(PIN), + authAbilityValue_(0), + executorSecLevelValue_(ESL0), + executorTypeValue_(TYPE_CO_AUTH), + publicKeyValue_(0), + deviceIdValue_(0) +{ +} - AuthExecutor::~AuthExecutor() - { - } +AuthExecutor::~AuthExecutor() +{ +} - int32_t AuthExecutor::GetAuthType(AuthType &value) - { - value = authTypeValue_; - return 0; - } - int32_t AuthExecutor::SetAuthType(AuthType value) - { - authTypeValue_ = value; - return 0; - } +int32_t AuthExecutor::GetAuthType(AuthType &value) +{ + value = authTypeValue_; + return 0; +} +int32_t AuthExecutor::SetAuthType(AuthType value) +{ + authTypeValue_ = value; + return 0; +} - int32_t AuthExecutor::GetAuthAbility(uint64_t &value) - { - value = authAbilityValue_; - return 0; - } - int32_t AuthExecutor::SetAuthAbility(uint64_t value) - { - authAbilityValue_ = value; - return 0; - } +int32_t AuthExecutor::GetAuthAbility(uint64_t &value) +{ + value = authAbilityValue_; + return 0; +} +int32_t AuthExecutor::SetAuthAbility(uint64_t value) +{ + authAbilityValue_ = value; + return 0; +} - int32_t AuthExecutor::GetExecutorSecLevel(ExecutorSecureLevel &value) - { - value = executorSecLevelValue_; - return 0; - } - int32_t AuthExecutor::SetExecutorSecLevel(ExecutorSecureLevel value) - { - executorSecLevelValue_ = value; - return 0; - } +int32_t AuthExecutor::GetExecutorSecLevel(ExecutorSecureLevel &value) +{ + value = executorSecLevelValue_; + return 0; +} +int32_t AuthExecutor::SetExecutorSecLevel(ExecutorSecureLevel value) +{ + executorSecLevelValue_ = value; + return 0; +} - int32_t AuthExecutor::GetExecutorType(ExecutorType &value) - { - value = executorTypeValue_; - return 0; - } - int32_t AuthExecutor::SetExecutorType(ExecutorType value) - { - executorTypeValue_ = value; - return 0; - } +int32_t AuthExecutor::GetExecutorType(ExecutorType &value) +{ + value = executorTypeValue_; + return 0; +} +int32_t AuthExecutor::SetExecutorType(ExecutorType value) +{ + executorTypeValue_ = value; + return 0; +} - int32_t AuthExecutor::GetPublicKey(std::vector &value) - { - value = publicKeyValue_; - return 0; - } - int32_t AuthExecutor::SetPublicKey(std::vector &value) - { - publicKeyValue_ = value; - return 0; - } +int32_t AuthExecutor::GetPublicKey(std::vector &value) +{ + value = publicKeyValue_; + return 0; +} +int32_t AuthExecutor::SetPublicKey(std::vector &value) +{ + publicKeyValue_ = value; + return 0; +} - int32_t AuthExecutor::GetDeviceId(std::vector &value) - { - value = deviceIdValue_; - return 0; - } - int32_t AuthExecutor::SetDeviceId(std::vector &value) - { - deviceIdValue_ = value; - return 0; - } +int32_t AuthExecutor::GetDeviceId(std::vector &value) +{ + value = deviceIdValue_; + return 0; +} +int32_t AuthExecutor::SetDeviceId(std::vector &value) +{ + deviceIdValue_ = value; + return 0; +} } // namespace ohos } // namespace userIAM } // namespace authResPool \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index 644db9d7c8927c4ab83f015cfcd79bf49bab30c4..2da47bcf08f8fea83d6695b1df6bcc19b5176b9d 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -30,6 +30,7 @@ ohos_shared_library("coauthservice") { sources = [ "src/auth_res_manager.cpp", "src/auth_res_pool.cpp", + "src/call_monitor.cpp", "src/coauth_manager.cpp", "src/coauth_service.cpp", "src/coauth_stub.cpp", @@ -49,10 +50,13 @@ ohos_shared_library("coauthservice") { "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", "//base/user_iam/auth_executor_mgr/common:useriam_common_lib", "//drivers/peripheral/display/hal:hdi_display_device", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", "//utils/native/base:utils", ] external_deps = [ + "ability_runtime:want", + "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/include/call_monitor.h b/services/include/call_monitor.h new file mode 100644 index 0000000000000000000000000000000000000000..37d32579b7536fe8ff00a22fdb547f2fce287d0d --- /dev/null +++ b/services/include/call_monitor.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CALL_MONITOR_H +#define CALL_MONITOR_H + +#include +#include + +#include "coauth_hilog_wrapper.h" +#include "event_handler.h" + +namespace OHOS { +namespace UserIAM { +namespace CoAuth { +using Callback = OHOS::AppExecFwk::EventHandler::Callback; + +class CallMonitor : public DelayedRefSingleton { + DECLARE_DELAYED_REF_SINGLETON(CallMonitor); +public: + DISALLOW_COPY_AND_MOVE(CallMonitor); + + void MonitorCall(int64_t waitTime, uint64_t scheduleId, Callback &timeoutFun); + + void MonitorRemoveCall(uint64_t scheduleId); +private: + std::shared_ptr eventHandler_; +}; +} // namespace CoAuth +} // namespace UserIAM +} // namespace OHOS + +#endif // CALL_MONITOR_H \ No newline at end of file diff --git a/services/include/coauth_manager.h b/services/include/coauth_manager.h index c065e7aa996c0dc5cb54197e2746201c8756541d..b5aecdb786b4dd7d2f9751f81ebcafb2ab99970b 100644 --- a/services/include/coauth_manager.h +++ b/services/include/coauth_manager.h @@ -19,12 +19,14 @@ #include "auth_res_pool.h" #include "auth_executor.h" #include "iexecutor_callback.h" +#include "call_monitor.h" #include "iquery_callback.h" #include "auth_res_manager.h" namespace OHOS { namespace UserIAM { namespace CoAuth { +const int64_t delay_time = 300 * 1000; class CoAuthManager { public: void coAuth(uint64_t scheduleId, AuthInfo &authInfo, sptr callback); @@ -34,9 +36,12 @@ public: void RegistResourceManager(AuthResManager* resMgr); void CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptr callback); + void TimeOut(uint64_t scheduleId); private: void SetAuthAttributes(std::shared_ptr commandAttrs, ScheduleInfo &scheduleInfo, AuthInfo &authInfo); + void BeginExecute(ScheduleInfo &scheduleInfo, std::size_t executorNum, uint64_t scheduleId, + AuthInfo &authInfo, int32_t &executeRet); class ResICoAuthCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: ResICoAuthCallbackDeathRecipient(uint64_t scheduleId, CoAuthManager* parent); @@ -49,6 +54,7 @@ private: DISALLOW_COPY_AND_MOVE(ResICoAuthCallbackDeathRecipient); }; AuthResManager* coAuthResMgrPtr_; + std::shared_ptr monitor_ = nullptr; }; } // namespace CoAuth } // namespace UserIAM diff --git a/services/include/coauth_service.h b/services/include/coauth_service.h index 93874c6a802e33080b0df3c8daa590282e8f29fb..fc1a2a6dca1d4a3d51d740eda03557c30514ed8e 100755 --- a/services/include/coauth_service.h +++ b/services/include/coauth_service.h @@ -49,6 +49,8 @@ public: virtual void SetExecutorProp(ResAuthAttributes &conditions, const sptr &callback) override; private: + void SendRegisterBroadcast(); + CoAuthRunningState state_ = CoAuthRunningState::STATE_STOPPED; AuthResManager authResMgr_; CoAuthManager coAuthMgr_; diff --git a/services/src/auth_res_manager.cpp b/services/src/auth_res_manager.cpp index aabb7776382cf32297bd19cb85b6aa6cfae64745..5b62687d292aadbb44c1c8a80bee39c4c07ad76f 100644 --- a/services/src/auth_res_manager.cpp +++ b/services/src/auth_res_manager.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "executor_messenger.h" #include "auth_res_manager.h" @@ -62,11 +63,11 @@ uint64_t AuthResManager::Register(std::shared_ptr executorInfo, sptr messenger = new UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_); callback->OnMessengerReady(messenger); - COAUTH_HILOGD(MODULE_SERVICE, "register is sucessfull,exeID is XXXX%{public}04llx!!!", executorId); + COAUTH_HILOGD(MODULE_SERVICE, "register is sucessfull,exeID is XXXX%{public}04" PRIx64, executorId); return executorId; // executorId returned after successful registration } if (result == FAIL) { - COAUTH_HILOGE(MODULE_SERVICE, "register is failure!"); + COAUTH_HILOGE(MODULE_SERVICE, "register is failure!"); return INVALID_EXECUTOR_ID; // If the registration fails, an invalid id0 is returned } return executorId; diff --git a/services/src/auth_res_pool.cpp b/services/src/auth_res_pool.cpp index e861fa5a5125f09efc911bf78ca25150b2f8f866..8b34021c238db4f76782d957e71417e6839f48b9 100644 --- a/services/src/auth_res_pool.cpp +++ b/services/src/auth_res_pool.cpp @@ -12,8 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "auth_res_pool.h" +#include #include "coauth_info_define.h" +#include "auth_res_pool.h" namespace OHOS { namespace UserIAM { @@ -66,7 +67,7 @@ int32_t AuthResPool::FindExecutorCallback(uint64_t executorID, sptr runner = AppExecFwk::EventRunner::Create(true); + runner->Run(); + eventHandler_ = std::make_shared(runner); +} + +CallMonitor::~CallMonitor() = default; + +void CallMonitor::MonitorCall(int64_t waitTime, uint64_t scheduleId, Callback &timeoutFun) +{ + if (eventHandler_ == nullptr) { + COAUTH_HILOGE(MODULE_SERVICE, "eventHandler_ is nullptr"); + return; + } + std::string name = std::to_string(scheduleId); + COAUTH_HILOGI(MODULE_SERVICE, "CallMonitor MonitorCall is called, name is %{public}s", name.c_str()); + eventHandler_->PostHighPriorityTask(timeoutFun, name, waitTime); +} + +void CallMonitor::MonitorRemoveCall(uint64_t scheduleId) +{ + if (eventHandler_ == nullptr) { + COAUTH_HILOGE(MODULE_SERVICE, "eventHandler_ is nullptr"); + return; + } + std::string name = std::to_string(scheduleId); + COAUTH_HILOGI(MODULE_SERVICE, "CallMonitor MonitorRemoveCall is called, name is %{public}s", name.c_str()); + eventHandler_->RemoveTask(name); +} +} // namespace PinAuth +} // namespace UserIAM +} // namespace OHOS \ No newline at end of file diff --git a/services/src/coauth_manager.cpp b/services/src/coauth_manager.cpp index 15d1bd7571d14f77ae3f23681391d2960157f112..f0f069cd593320382a3244f5ddc1710f27e17833 100644 --- a/services/src/coauth_manager.cpp +++ b/services/src/coauth_manager.cpp @@ -14,6 +14,7 @@ */ #include "coauth_manager.h" +#include "inner_event.h" #include "coauth_thread_pool.h" namespace OHOS { @@ -53,9 +54,25 @@ void CoAuthManager::CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptrOnFinish(saveRet, scheduleToken); } + OHOS::AppExecFwk::InnerEvent::Callback task = std::bind(&CoAuthManager::TimeOut, this, scheduleId); + COAUTH_HILOGW(MODULE_SERVICE, "CoAuthManager::Excute MonitorCall"); + CallMonitor::GetInstance().MonitorCall(delay_time, scheduleId, task); + BeginExecute(scheduleInfo, executorNum, scheduleId, authInfo, executeRet); + + if (executeRet != SUCCESS) { + COAUTH_HILOGW(MODULE_SERVICE, "There are one or more failures in execution."); + callback->OnFinish(executeRet, scheduleToken); + coAuthResMgrPtr_->DeleteScheduleCallback(scheduleId); + CallMonitor::GetInstance().MonitorRemoveCall(scheduleId); + } +} + +void CoAuthManager::BeginExecute(ScheduleInfo &scheduleInfo, std::size_t executorNum, uint64_t scheduleId, + AuthInfo &authInfo, int32_t &executeRet) +{ for (std::size_t i = 0; i < executorNum; i++) { uint32_t authType = scheduleInfo.executors[i].authType; - COAUTH_HILOGD(MODULE_SERVICE, "get authType = XXXX%{public}04d", authType); + COAUTH_HILOGD(MODULE_SERVICE, "get authType = %{public}u", authType); sptr executorCallback; std::vector publicKey(scheduleInfo.executors[i].publicKey, scheduleInfo.executors[i].publicKey + PUBLIC_KEY_LEN); @@ -68,11 +85,6 @@ void CoAuthManager::CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptrOnBeginExecute(scheduleId, publicKey, commandAttrs); } - // set timeout - if (executeRet != SUCCESS) { - COAUTH_HILOGW(MODULE_SERVICE, "There are one or more failures in execution."); - return callback->OnFinish(executeRet, scheduleToken); - } } void CoAuthManager::SetAuthAttributes(std::shared_ptr commandAttrs, @@ -111,7 +123,7 @@ int32_t CoAuthManager::Cancel(uint64_t scheduleId) for (std::size_t i = 0; i < executorNum; i++) { uint32_t authType = scheduleInfo.executors[i].authType; sptr executorCallback; - COAUTH_HILOGD(MODULE_SERVICE, "get exeID = XXXX%{public}04d", authType); + COAUTH_HILOGD(MODULE_SERVICE, "get exeID = %{public}u", authType); int32_t findRet = coAuthResMgrPtr_->FindExecutorCallback(authType, executorCallback); if ((findRet != 0) || (executorCallback == nullptr)) { COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found."); @@ -147,7 +159,7 @@ void CoAuthManager::SetExecutorProp(ResAuthAttributes &conditions, sptr extraInfo; uint32_t authType; conditions.GetUint32Value(AUTH_TYPE, authType); - COAUTH_HILOGD(MODULE_SERVICE, "get authType = XXXX%{public}d", authType); + COAUTH_HILOGD(MODULE_SERVICE, "get authType = XXXX%{public}u", authType); coAuthResMgrPtr_->FindExecutorCallback(authType, execallback); if (execallback == nullptr) { COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found."); @@ -171,7 +183,7 @@ int32_t CoAuthManager::GetExecutorProp(ResAuthAttributes &conditions, std::share uint32_t authType; sptr execallback = nullptr; conditions.GetUint32Value(AUTH_TYPE, authType); - COAUTH_HILOGD(MODULE_SERVICE, "authType is %{public}d", authType); + COAUTH_HILOGD(MODULE_SERVICE, "authType is %{public}u", authType); coAuthResMgrPtr_->FindExecutorCallback(authType, execallback); if (execallback == nullptr) { COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found."); @@ -211,6 +223,21 @@ void CoAuthManager::ResICoAuthCallbackDeathRecipient::OnRemoteDied(const wptr callback; + int32_t findRet = coAuthResMgrPtr_->FindScheduleCallback(scheduleId, callback); + if (findRet == SUCCESS && callback != nullptr) { + std::vector scheduleToken; + callback->OnFinish(TIMEOUT, scheduleToken); + Cancel(scheduleId); // cancel schedule + COAUTH_HILOGW(MODULE_SERVICE, "Schedule timeout"); + coAuthResMgrPtr_->DeleteScheduleCallback(scheduleId); + } else { + COAUTH_HILOGD(MODULE_SERVICE, "Schedule has ended"); + } +} } // namespace CoAuth } // namespace UserIAM } // namespace OHOS diff --git a/services/src/coauth_service.cpp b/services/src/coauth_service.cpp index a923d6f79db1ff705a6ad75dd9561459e9810e80..04e7eb0a5e1e15c9b962845a13d74d9a3c7c4866 100755 --- a/services/src/coauth_service.cpp +++ b/services/src/coauth_service.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include "useriam_common.h" +#include "common_event_manager.h" #include "coauth_service.h" namespace OHOS { @@ -84,6 +86,8 @@ void CoAuthService::OnStart() } // Send registration broadcast + SendRegisterBroadcast(); + // Start other sevice std::thread checkThread(OHOS::UserIAM::CoAuth::CheckSystemAbility); checkThread.join(); @@ -123,7 +127,7 @@ uint64_t CoAuthService::Register(std::shared_ptr executorInfo, } uint64_t exeID = authResMgr_.Register(executorInfo, callback); - COAUTH_HILOGE(MODULE_SERVICE, "exeID is XXXX%{public}04llx", exeID); + COAUTH_HILOGE(MODULE_SERVICE, "exeID is XXXX%{public}" PRIx64, exeID); return exeID; } @@ -172,6 +176,16 @@ int32_t CoAuthService::GetExecutorProp(ResAuthAttributes &conditions, std::share } return coAuthMgr_.GetExecutorProp(conditions, values); } + +void CoAuthService::SendRegisterBroadcast() +{ + EventFwk::Want want; + want.SetAction(REGISTER_NOTIFICATION); + EventFwk::CommonEventData data; + data.SetWant(want); + bool ret = EventFwk::CommonEventManager::PublishCommonEvent(data); + COAUTH_HILOGI(MODULE_SERVICE, "send broadcast result = %{public}d", ret); +} } // namespace CoAu } // namespace UserIAM } // namespace OHOS diff --git a/services/src/coauth_stub.cpp b/services/src/coauth_stub.cpp index 143b9de8f23ec5f84f33fa22515b93eccd58b288..3e3fcae2f1db5c808763ae49a31a6b0a57987373 100755 --- a/services/src/coauth_stub.cpp +++ b/services/src/coauth_stub.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "coauth_hilog_wrapper.h" #include "coauth_errors.h" @@ -23,7 +24,7 @@ namespace CoAuth { int32_t CoAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub::OnRemoteRequest, cmd = %d, flags= %d", + COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d", code, option.GetFlags()); std::u16string descripter = CoAuthStub::GetDescriptor(); std::u16string remoteDescripter = data.ReadInterfaceToken(); @@ -58,7 +59,7 @@ void CoAuthStub::ReadAuthExecutor(AuthResPool::AuthExecutor &executorInfo, Messa uint64_t authAbility = data.ReadUint64(); executorInfo.SetAuthAbility(authAbility); - COAUTH_HILOGD(MODULE_INNERKIT, "ReadInt64,authAbility:%{public}llu", authAbility); + COAUTH_HILOGD(MODULE_INNERKIT, "ReadInt64,authAbility:%{public}" PRIu64, authAbility); int32_t executorSecLevel = data.ReadInt32(); executorInfo.SetExecutorSecLevel(static_cast(executorSecLevel)); @@ -116,10 +117,10 @@ int32_t CoAuthStub::coAuthStub(MessageParcel& data, MessageParcel& reply) authInfo.SetPkgName(GetPkgName); uint64_t GetCallerUid = data.ReadUint64(); authInfo.SetCallerUid(GetCallerUid); - COAUTH_HILOGD(MODULE_INNERKIT, "ReadUint64,GetCallerUid:%{public}llu", GetCallerUid); + COAUTH_HILOGD(MODULE_INNERKIT, "ReadUint64,GetCallerUid:%{public}" PRIu64, GetCallerUid); uint64_t scheduleId = data.ReadUint64(); - COAUTH_HILOGD(MODULE_INNERKIT, "ReadUint64,scheduleId:%{public}llu", scheduleId); + COAUTH_HILOGD(MODULE_INNERKIT, "ReadUint64,scheduleId:%{public}" PRIu64, scheduleId); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { @@ -137,7 +138,7 @@ int32_t CoAuthStub::CancelStub(MessageParcel& data, MessageParcel& reply) COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub: CancelStub enter"); uint64_t scheduleId = data.ReadUint64(); - COAUTH_HILOGD(MODULE_INNERKIT, "ReadUint64 scheduleId:%{public}llu", scheduleId); + COAUTH_HILOGD(MODULE_INNERKIT, "ReadUint64 scheduleId:%{public}" PRIu64, scheduleId); int ret = Cancel(scheduleId); if (!reply.WriteInt32(ret)) { diff --git a/services/src/executor_messenger.cpp b/services/src/executor_messenger.cpp index dc41bec20a9b25f96c664e35bf4074c0d0f4deb9..34a272ea6e34c1d162f119e3c10eecea1dd0c5c0 100644 --- a/services/src/executor_messenger.cpp +++ b/services/src/executor_messenger.cpp @@ -15,6 +15,7 @@ #include "securec.h" #include "coauth_interface.h" +#include "call_monitor.h" #include "executor_messenger.h" namespace OHOS { @@ -72,6 +73,7 @@ int32_t ExecutorMessenger::Finish(uint64_t scheduleId, int32_t srcType, int32_t ScheResPool_->ScheduleCountMinus(scheduleId); return SUCCESS; } + UserIAM::CoAuth::CallMonitor::GetInstance().MonitorRemoveCall(scheduleId); sptr callback; int32_t findRet = ScheResPool_->FindScheduleCallback(scheduleId, callback); if (findRet != SUCCESS || callback == nullptr) {