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..6f11afe6fc5a732e8738e2867cb50fcd166646a3 100644 --- a/interfaces/innerkits/src/auth_attributes.cpp +++ b/interfaces/innerkits/src/auth_attributes.cpp @@ -20,27 +20,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() diff --git a/interfaces/innerkits/src/auth_executor.cpp b/interfaces/innerkits/src/auth_executor.cpp index 2e50d2c1bb2d27720806308c37f98a1578a51977..7ccf59c29cac77a6de150f2d7ae7793684a0d42e 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..0e8a4868c438e8ee0d813b2e80d785439f692091 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -35,6 +35,7 @@ ohos_shared_library("coauthservice") { "src/coauth_stub.cpp", "src/coauth_thread_pool.cpp", "src/executor_messenger.cpp", + "src/call_monitor.cpp", ] configs = [ @@ -49,6 +50,7 @@ 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", ] @@ -57,6 +59,8 @@ ohos_shared_library("coauthservice") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", + "ability_runtime:want", + "ces_standard:cesfwk_innerkits", ] part_name = "${coauth_native_part_name}" diff --git a/services/include/call_monitor.h b/services/include/call_monitor.h new file mode 100644 index 0000000000000000000000000000000000000000..3c7b4b56669daf071c9b07c63f8ff9db6436abe6 --- /dev/null +++ b/services/include/call_monitor.h @@ -0,0 +1,44 @@ +/* + * 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 "event_handler.h" + +namespace OHOS { +namespace UserIAM { +namespace CoAuth { +using Callback = OHOS::AppExecFwk::EventHandler::Callback; + +class CallMonitor { +public: + CallMonitor(); + + ~CallMonitor() = default; + + void MonitorCall(int64_t waitTime, Callback &timeoutFun); + +private: + Callback timeoutFun_; + 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/call_monitor.cpp b/services/src/call_monitor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dbae99d826900473e95689b183906027c2e5c2fe --- /dev/null +++ b/services/src/call_monitor.cpp @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#include "call_monitor.h" +#include "inner_event.h" +#include "event_runner.h" + +namespace OHOS { +namespace UserIAM { +namespace CoAuth { +CallMonitor::CallMonitor() +{ + std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); + runner->Run(); + eventHandler_ = std::make_shared(runner); +} + +void CallMonitor::MonitorCall(int64_t waitTime, Callback &timeoutFun) +{ + eventHandler_->PostHighPriorityTask(timeoutFun, waitTime); +} +} // 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..e2bf390bca8fa7931c4f27387baf2b7a59032d98 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 { @@ -27,6 +28,9 @@ void CoAuthManager::coAuth(uint64_t scheduleId, AuthInfo &authInfo, sptr callback) { + if (monitor_ == nullptr) { + monitor_ = std::make_shared(); + } if (callback == nullptr) { COAUTH_HILOGE(MODULE_SERVICE, "Schedule callback is null."); return; @@ -53,6 +57,23 @@ void CoAuthManager::CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptrOnFinish(saveRet, scheduleToken); } + OHOS::AppExecFwk::InnerEvent::Callback task = std::bind(&CoAuthManager::TimeOut, this, scheduleId); + if (monitor_ != nullptr) { + COAUTH_HILOGW(MODULE_SERVICE, "CoAuthManager::Excute MonitorCall"); + monitor_->MonitorCall(delay_time, task); + } + BeginExecute(scheduleInfo, executorNum, scheduleId, authInfo, executeRet); + // set timeout + if (executeRet != SUCCESS) { + COAUTH_HILOGW(MODULE_SERVICE, "There are one or more failures in execution."); + callback->OnFinish(executeRet, scheduleToken); + coAuthResMgrPtr_->DeleteScheduleCallback(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); @@ -68,11 +89,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, @@ -211,6 +227,20 @@ 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); + 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..02ed97dd2acf54027ecb07d012a8553190504834 100755 --- a/services/src/coauth_service.cpp +++ b/services/src/coauth_service.cpp @@ -22,6 +22,7 @@ #include #include #include "useriam_common.h" +#include "common_event_manager.h" #include "coauth_service.h" namespace OHOS { @@ -84,6 +85,8 @@ void CoAuthService::OnStart() } // Send registration broadcast + SendRegisterBroadcast(); + // Start other sevice std::thread checkThread(OHOS::UserIAM::CoAuth::CheckSystemAbility); checkThread.join(); @@ -172,6 +175,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