From 03bc0ba3c94f5e5267bb264bf11e1319df89fbd3 Mon Sep 17 00:00:00 2001 From: zhirenx Date: Sat, 5 Mar 2022 15:36:05 +0800 Subject: [PATCH] fix: code review fix Signed-off-by: zhirenx Change-Id: I0dd0f2535204c68f9de463465abd6b4a7cdebd07 --- frameworks/kitsimpl/src/userauth.cpp | 16 +-- .../kitsimpl/src/userauth_async_stub.cpp | 11 +- frameworks/kitsimpl/src/userauth_proxy.cpp | 24 ++-- .../innerkits/napi/include/auth_build.h | 9 +- .../innerkits/napi/include/auth_common.h | 20 ++- .../innerkits/napi/include/result_convert.h | 4 +- interfaces/innerkits/napi/src/auth_build.cpp | 26 ++-- .../innerkits/native/include/iuser_auth.h | 6 +- .../native/include/iuserauth_callback.h | 3 +- .../innerkits/native/include/user_auth.h | 15 +-- .../native/include/userauth_async_stub.h | 5 +- .../native/include/userauth_callback.h | 2 +- .../innerkits/native/include/userauth_info.h | 118 +++++++++--------- .../innerkits/native/include/userauth_proxy.h | 17 +-- services/include/context_thread_pool.h | 27 ++-- services/include/userauth_adapter.h | 34 +++-- services/include/userauth_async_proxy.h | 18 +-- services/include/userauth_controller.h | 12 +- services/include/userauth_datamgr.h | 10 +- services/include/userauth_service.h | 31 ++--- services/include/userauth_stub.h | 18 +-- services/src/userauth_adapter.cpp | 74 +++++------ services/src/userauth_async_proxy.cpp | 5 - services/src/userauth_controller.cpp | 10 +- services/src/userauth_service.cpp | 47 ++++--- services/src/userauth_stub.cpp | 35 +++--- 26 files changed, 291 insertions(+), 306 deletions(-) diff --git a/frameworks/kitsimpl/src/userauth.cpp b/frameworks/kitsimpl/src/userauth.cpp index 88ad3c8..eb19627 100644 --- a/frameworks/kitsimpl/src/userauth.cpp +++ b/frameworks/kitsimpl/src/userauth.cpp @@ -19,8 +19,8 @@ #include #include "system_ability_definition.h" -#include "userauth_hilog_wrapper.h" #include "user_auth.h" +#include "userauth_hilog_wrapper.h" namespace OHOS { namespace UserIAM { @@ -58,7 +58,7 @@ sptr UserAuth::GetProxy() return proxy_; } -void UserAuth::ResetProxy(const wptr& remote) +void UserAuth::ResetProxy(const wptr &remote) { USERAUTH_HILOGD(MODULE_INNERKIT, "userauth ResetProxy is start"); std::lock_guard lock(mutex_); @@ -73,7 +73,7 @@ void UserAuth::ResetProxy(const wptr& remote) } } -void UserAuth::UserAuthDeathRecipient::OnRemoteDied(const wptr& remote) +void UserAuth::UserAuthDeathRecipient::OnRemoteDied(const wptr &remote) { USERAUTH_HILOGD(MODULE_INNERKIT, "OnRemoteDied is start"); if (remote == nullptr) { @@ -138,7 +138,7 @@ void UserAuth::SetProperty(const SetPropertyRequest request, std::shared_ptrSetProperty(request, asyncStub); } uint64_t UserAuth::Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, - std::shared_ptr callback) + std::shared_ptr callback) { USERAUTH_HILOGD(MODULE_INNERKIT, "userauth Auth is start"); if (callback == nullptr) { @@ -158,7 +158,7 @@ uint64_t UserAuth::Auth(const uint64_t challenge, const AuthType authType, const return ret; } uint64_t UserAuth::AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType, - const AuthTurstLevel authTurstLevel, std::shared_ptr callback) + const AuthTurstLevel authTurstLevel, std::shared_ptr callback) { USERAUTH_HILOGD(MODULE_INNERKIT, "userauth AuthUser is start"); if (callback == nullptr) { @@ -199,6 +199,6 @@ int32_t UserAuth::GetVersion() int32_t ret = proxy_->GetVersion(); return ret; } -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS +} // namespace UserAuth +} // namespace UserIAM +} // namespace OHOS diff --git a/frameworks/kitsimpl/src/userauth_async_stub.cpp b/frameworks/kitsimpl/src/userauth_async_stub.cpp index fde0fd8..0ed216e 100644 --- a/frameworks/kitsimpl/src/userauth_async_stub.cpp +++ b/frameworks/kitsimpl/src/userauth_async_stub.cpp @@ -23,17 +23,14 @@ namespace OHOS { namespace UserIAM { namespace UserAuth { -UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr& impl) +UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr &impl) : authCallback_(impl) { - authCallback_ = impl; } -UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr& impl) +UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr &impl) : getPropCallback_(impl) { - getPropCallback_ = impl; } -UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr& impl) +UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr &impl) : setPropCallback_(impl) { - setPropCallback_ = impl; } int32_t UserAuthAsyncStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -142,7 +139,7 @@ int32_t UserAuthAsyncStub::onExecutorPropertyInfoStub(MessageParcel& data, Messa uint64_t authSubType; uint32_t remainTimes; uint32_t freezingTime; - ExecutorProperty executorProperty; + ExecutorProperty executorProperty = {}; if (!data.ReadInt32(result)) { USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadInt32(result)."); diff --git a/frameworks/kitsimpl/src/userauth_proxy.cpp b/frameworks/kitsimpl/src/userauth_proxy.cpp index 5bb26d6..947fe17 100644 --- a/frameworks/kitsimpl/src/userauth_proxy.cpp +++ b/frameworks/kitsimpl/src/userauth_proxy.cpp @@ -12,16 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "userauth_proxy.h" +#include "userauth_hilog_wrapper.h" #include #include #include -#include "userauth_hilog_wrapper.h" -#include "userauth_proxy.h" namespace OHOS { namespace UserIAM { namespace UserAuth { -UserAuthProxy::UserAuthProxy(const sptr &object) : IRemoteProxy(object) {} +UserAuthProxy::UserAuthProxy(const sptr &object) : IRemoteProxy(object) +{ +} int32_t UserAuthProxy::GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel) { @@ -56,7 +58,7 @@ int32_t UserAuthProxy::GetAvailableStatus(const AuthType authType, const AuthTur return result; } -void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptr& callback) +void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptr &callback) { USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy GetProperty is start"); MessageParcel data; @@ -81,14 +83,14 @@ void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptr(IUserAuth::USER_AUTH_GET_PROPERTY), data, reply, option); if (!ret) { - ExecutorProperty result; + ExecutorProperty result = {}; result.result = IPC_ERROR; callback->onExecutorPropertyInfo(result); USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret); return; } } -void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr& callback) +void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr &callback) { USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy SetProperty is start"); MessageParcel data; @@ -124,8 +126,8 @@ void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr& callback) +uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, + sptr &callback) { USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy Auth is start"); const uint64_t invalidContextID = 0; @@ -168,7 +170,7 @@ uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType, } uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType, - const AuthTurstLevel authTurstLevel, sptr& callback) + const AuthTurstLevel authTurstLevel, sptr &callback) { USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy AuthUser is start"); const uint64_t invalidContextID = 0; @@ -273,7 +275,7 @@ bool UserAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParce if (remote == nullptr) { return false; } - + int32_t result = remote->SendRequest(code, data, reply, option); if (result != OHOS::UserIAM::UserAuth::SUCCESS) { USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthProxy SendRequest fail"); @@ -282,5 +284,5 @@ bool UserAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParce return true; } } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS diff --git a/interfaces/innerkits/napi/include/auth_build.h b/interfaces/innerkits/napi/include/auth_build.h index 99e5bc6..2ea9d63 100755 --- a/interfaces/innerkits/napi/include/auth_build.h +++ b/interfaces/innerkits/napi/include/auth_build.h @@ -19,6 +19,8 @@ #include "napi/native_api.h" #include "napi/native_common.h" +#include "nocopyable.h" + #include "auth_common.h" #include "result_convert.h" @@ -27,9 +29,9 @@ namespace UserIAM { namespace UserAuth { class AuthBuild { public: + DISALLOW_COPY_AND_MOVE(AuthBuild); AuthBuild(); - ~AuthBuild(); - ResultConvert convert; + virtual ~AuthBuild(); Napi_SetPropertyRequest SetPropertyRequestBuild(napi_env env, napi_value object); Napi_GetPropertyRequest GetPropertyRequestBuild(napi_env env, napi_value object); bool NapiTypeObject(napi_env env, napi_value value); @@ -38,6 +40,9 @@ public: uint64_t GetUint8ArrayTo64(napi_env env, napi_value value); int NapiGetValueInt(napi_env env, napi_value value); napi_value Uint64ToUint8Array(napi_env env, uint64_t value); + +private: + ResultConvert convert_; }; } // namespace UserAuth } // namespace UserIAM diff --git a/interfaces/innerkits/napi/include/auth_common.h b/interfaces/innerkits/napi/include/auth_common.h index 016ba25..a526213 100755 --- a/interfaces/innerkits/napi/include/auth_common.h +++ b/interfaces/innerkits/napi/include/auth_common.h @@ -53,15 +53,14 @@ namespace UserAuth { #define PARAM10 10 struct CallBackInfo { - napi_env env; - napi_ref callBack = 0; - napi_deferred deferred; + napi_env env {nullptr}; + napi_ref callBack {nullptr}; + napi_deferred deferred {nullptr}; }; struct GetPropertyInfo { - GetPropertyInfo() : result(nullptr) {}; CallBackInfo callBackInfo; - napi_value result; + napi_value result {nullptr}; int32_t authType; std::vector keys; int32_t getResult; @@ -71,10 +70,9 @@ struct GetPropertyInfo { }; struct SetPropertyInfo { - SetPropertyInfo() : asyncWork(nullptr), result(nullptr) {}; CallBackInfo callBackInfo; - napi_async_work asyncWork; - napi_value result; + napi_async_work asyncWork {nullptr}; + napi_value result {nullptr}; int32_t authType; uint32_t key; std::vector setInfo; @@ -93,10 +91,9 @@ struct ExecuteInfo { }; struct AuthInfo { - AuthInfo() : asyncWork(nullptr) {}; CallBackInfo callBackInfo; napi_callback_info info; - napi_async_work asyncWork; + napi_async_work asyncWork {nullptr}; napi_value onResultCallBack; napi_value onAcquireInfoCallBack; napi_ref onResult; @@ -113,10 +110,9 @@ struct AuthInfo { }; struct AuthUserInfo { - AuthUserInfo() : asyncWork(nullptr) {}; CallBackInfo callBackInfo; napi_callback_info info; - napi_async_work asyncWork; + napi_async_work asyncWork {nullptr}; napi_ref onResult; napi_ref onAcquireInfo; napi_value onResultCallBack; diff --git a/interfaces/innerkits/napi/include/result_convert.h b/interfaces/innerkits/napi/include/result_convert.h index ac67a39..2b86cf4 100755 --- a/interfaces/innerkits/napi/include/result_convert.h +++ b/interfaces/innerkits/napi/include/result_convert.h @@ -21,6 +21,7 @@ #include "napi/native_api.h" #include "napi/native_common.h" +#include "nocopyable.h" #include "userauth_info.h" @@ -32,8 +33,9 @@ namespace UserIAM { namespace UserAuth { class ResultConvert { public: + DISALLOW_COPY_AND_MOVE(ResultConvert); ResultConvert(); - ~ResultConvert(); + virtual ~ResultConvert(); napi_value Uint64ToUint8Napi(napi_env env, uint64_t value); std::vector NapiGetValueUint8Array(napi_env env, napi_value jsObject, std::string key); napi_valuetype GetType(napi_env env, napi_value value); diff --git a/interfaces/innerkits/napi/src/auth_build.cpp b/interfaces/innerkits/napi/src/auth_build.cpp index 861b3d5..3972d6c 100755 --- a/interfaces/innerkits/napi/src/auth_build.cpp +++ b/interfaces/innerkits/napi/src/auth_build.cpp @@ -22,12 +22,8 @@ namespace OHOS { namespace UserIAM { namespace UserAuth { -AuthBuild::AuthBuild(void) -{ -} -AuthBuild::~AuthBuild() -{ -} +AuthBuild::AuthBuild() = default; +AuthBuild::~AuthBuild() = default; Napi_SetPropertyRequest AuthBuild::SetPropertyRequestBuild(napi_env env, napi_value object) { @@ -36,9 +32,9 @@ Napi_SetPropertyRequest AuthBuild::SetPropertyRequestBuild(napi_env env, napi_va USERAUTH_HILOGE(MODULE_JS_NAPI, "SetPropertyRequestBuild object is null"); return request; } - request.authType_ = convert.GetInt32ValueByKey(env, object, "authType"); - request.key_ = convert.GetInt32ValueByKey(env, object, "key"); - request.setInfo_ = convert.NapiGetValueUint8Array(env, object, "setInfo"); + request.authType_ = convert_.GetInt32ValueByKey(env, object, "authType"); + request.key_ = convert_.GetInt32ValueByKey(env, object, "key"); + request.setInfo_ = convert_.NapiGetValueUint8Array(env, object, "setInfo"); USERAUTH_HILOGI(MODULE_JS_NAPI, "AuthBuild::SetPropertyRequestBuild authType = %{public}d, key = %{public}d", request.authType_, request.key_); return request; @@ -51,8 +47,8 @@ Napi_GetPropertyRequest AuthBuild::GetPropertyRequestBuild(napi_env env, napi_va USERAUTH_HILOGE(MODULE_JS_NAPI, "GetPropertyRequestBuild object is null"); return request; } - request.authType_ = convert.GetInt32ValueByKey(env, object, "authType"); - request.keys_ = convert.GetInt32ArrayValueByKey(env, object, "keys"); + request.authType_ = convert_.GetInt32ValueByKey(env, object, "authType"); + request.keys_ = convert_.GetInt32ArrayValueByKey(env, object, "keys"); USERAUTH_HILOGI(MODULE_JS_NAPI, "AuthBuild::GetPropertyRequestBuild authType = %{public}d", request.authType_); return request; } @@ -62,7 +58,7 @@ bool AuthBuild::NapiTypeObject(napi_env env, napi_value value) if (value == nullptr) { return false; } - napi_valuetype isObject = convert.GetType(env, value); + napi_valuetype isObject = convert_.GetType(env, value); if (isObject == napi_object) { return true; } @@ -74,7 +70,7 @@ bool AuthBuild::NapiTypeNumber(napi_env env, napi_value value) if (value == nullptr) { return false; } - napi_valuetype isNumber = convert.GetType(env, value); + napi_valuetype isNumber = convert_.GetType(env, value); if (isNumber == napi_number) { return true; } @@ -116,12 +112,12 @@ uint64_t AuthBuild::GetUint8ArrayTo64(napi_env env, napi_value value) int AuthBuild::NapiGetValueInt(napi_env env, napi_value value) { - return convert.NapiGetValueInt(env, value); + return convert_.NapiGetValueInt(env, value); } napi_value AuthBuild::Uint64ToUint8Array(napi_env env, uint64_t value) { - return convert.Uint64ToUint8Napi(env, value); + return convert_.Uint64ToUint8Napi(env, value); } } // namespace UserAuth } // namespace UserIAM diff --git a/interfaces/innerkits/native/include/iuser_auth.h b/interfaces/innerkits/native/include/iuser_auth.h index fcd759a..cd2e536 100755 --- a/interfaces/innerkits/native/include/iuser_auth.h +++ b/interfaces/innerkits/native/include/iuser_auth.h @@ -43,15 +43,15 @@ public: virtual void GetProperty(const GetPropertyRequest request, sptr &callback) = 0; virtual void SetProperty(const SetPropertyRequest request, sptr &callback) = 0; virtual uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, - sptr &callback) = 0; + sptr &callback) = 0; virtual uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType, - const AuthTurstLevel authTurstLevel, sptr &callback) = 0; + const AuthTurstLevel authTurstLevel, sptr &callback) = 0; virtual int32_t CancelAuth(const uint64_t contextId) = 0; virtual int32_t GetVersion() = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.UserAuth.IUserAuth"); }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // IUSERAUTH_H \ No newline at end of file diff --git a/interfaces/innerkits/native/include/iuserauth_callback.h b/interfaces/innerkits/native/include/iuserauth_callback.h index c88a288..7f3989f 100755 --- a/interfaces/innerkits/native/include/iuserauth_callback.h +++ b/interfaces/innerkits/native/include/iuserauth_callback.h @@ -26,7 +26,6 @@ namespace UserIAM { namespace UserAuth { class IUserAuthCallback : public IRemoteBroker { public: - virtual void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) = 0; virtual void onResult(const int32_t result, const AuthResult extraInfo) = 0; virtual void onExecutorPropertyInfo(const ExecutorProperty result) = 0; @@ -35,6 +34,6 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.UserAuth.IUserAuthCallback"); }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // IUSERAUTH_CALLBACK_H diff --git a/interfaces/innerkits/native/include/user_auth.h b/interfaces/innerkits/native/include/user_auth.h index 49348c4..aa3d876 100755 --- a/interfaces/innerkits/native/include/user_auth.h +++ b/interfaces/innerkits/native/include/user_auth.h @@ -16,9 +16,9 @@ #ifndef USERAUTH_CLIENT_H #define USERAUTH_CLIENT_H +#include #include #include -#include #include "iuser_auth.h" #include "userauth_async_stub.h" @@ -28,6 +28,7 @@ namespace UserIAM { namespace UserAuth { class UserAuth : public DelayedRefSingleton { DECLARE_DELAYED_REF_SINGLETON(UserAuth); + public: DISALLOW_COPY_AND_MOVE(UserAuth); @@ -35,9 +36,9 @@ public: void GetProperty(const GetPropertyRequest request, std::shared_ptr callback); void SetProperty(const SetPropertyRequest request, std::shared_ptr callback); uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, - std::shared_ptr callback); + std::shared_ptr callback); uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType, - const AuthTurstLevel authTurstLevel, std::shared_ptr callback); + const AuthTurstLevel authTurstLevel, std::shared_ptr callback); int32_t CancelAuth(const uint64_t contextId); int32_t GetVersion(); @@ -45,13 +46,13 @@ private: class UserAuthDeathRecipient : public IRemoteObject::DeathRecipient { public: UserAuthDeathRecipient() = default; - ~UserAuthDeathRecipient() = default; - void OnRemoteDied(const wptr& remote) override; + ~UserAuthDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override; private: DISALLOW_COPY_AND_MOVE(UserAuthDeathRecipient); }; - void ResetProxy(const wptr& remote); + void ResetProxy(const wptr &remote); sptr GetProxy(); std::mutex mutex_; @@ -59,6 +60,6 @@ private: sptr deathRecipient_ {nullptr}; }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_CLIENT_H diff --git a/interfaces/innerkits/native/include/userauth_async_stub.h b/interfaces/innerkits/native/include/userauth_async_stub.h index 980b29b..2840bd5 100755 --- a/interfaces/innerkits/native/include/userauth_async_stub.h +++ b/interfaces/innerkits/native/include/userauth_async_stub.h @@ -17,6 +17,8 @@ #define USERAUTH_ASYNC_STUB_H #include +#include + #include "iuserauth_callback.h" #include "userauth_callback.h" @@ -25,10 +27,11 @@ namespace UserIAM { namespace UserAuth { class UserAuthAsyncStub : public IRemoteStub { public: + DISALLOW_COPY_AND_MOVE(UserAuthAsyncStub); explicit UserAuthAsyncStub(std::shared_ptr& impl); explicit UserAuthAsyncStub(std::shared_ptr& impl); explicit UserAuthAsyncStub(std::shared_ptr& impl); - ~UserAuthAsyncStub() = default; + ~UserAuthAsyncStub() override = default; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override; diff --git a/interfaces/innerkits/native/include/userauth_callback.h b/interfaces/innerkits/native/include/userauth_callback.h index c451c1b..ba96d64 100755 --- a/interfaces/innerkits/native/include/userauth_callback.h +++ b/interfaces/innerkits/native/include/userauth_callback.h @@ -35,6 +35,6 @@ public: virtual void onSetProperty(const int32_t result) = 0; }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // IUSERAUTH_CALLBACK_H diff --git a/interfaces/innerkits/native/include/userauth_info.h b/interfaces/innerkits/native/include/userauth_info.h index 2ea13ab..7a154b4 100644 --- a/interfaces/innerkits/native/include/userauth_info.h +++ b/interfaces/innerkits/native/include/userauth_info.h @@ -18,18 +18,16 @@ #include "parcel.h" -#define SIGN_LEN 32 - namespace OHOS { namespace UserIAM { namespace UserAuth { // Type of authentication (password, face) -enum AuthType: uint32_t { +enum AuthType : uint32_t { PIN = 1, FACE = 2, }; // Authentication subtype (2D face, 3D face...) -enum AuthSubType: uint64_t { +enum AuthSubType : uint64_t { /** * Authentication sub type six number pin. */ @@ -52,7 +50,7 @@ enum AuthSubType: uint64_t { FACE_3D = 20001 }; // Certification result confidence level -enum AuthTurstLevel: uint32_t { +enum AuthTurstLevel : uint32_t { // level 1-4 ATL1 = 10000, ATL2 = 20000, @@ -60,7 +58,7 @@ enum AuthTurstLevel: uint32_t { ATL4 = 40000 }; // Actuator get property list -enum GetPropertyType: uint32_t { +enum GetPropertyType : uint32_t { // Authentication subtype (at this point the authentication type has been confirmed) AUTH_SUB_TYPE = 1, // Remaining authentication times @@ -70,9 +68,9 @@ enum GetPropertyType: uint32_t { }; // get attribute request struct GetPropertyRequest { - AuthType authType; + AuthType authType {0}; // GetPropertyType - std::vector keys; + std::vector keys {}; }; // Actuator properties struct ExecutorProperty { @@ -82,7 +80,7 @@ struct ExecutorProperty { uint32_t freezingTime; }; // Actuator property mode list -enum AuthPropertyMode: uint32_t { +enum AuthPropertyMode : uint32_t { PROPERMODE_DELETE = 0, PROPERMODE_GET = 1, PROPERMODE_SET = 2, @@ -92,27 +90,27 @@ enum AuthPropertyMode: uint32_t { PROPERMODE_RELEASE_ALGORITHM = 6, }; // Actuator property list -enum SetPropertyType: uint32_t { +enum SetPropertyType : uint32_t { INIT_ALGORITHM = 1, FREEZE_TEMPLATE = 2, THAW_TEMPLATE = 3, }; struct SetPropertyRequest { - AuthType authType; - SetPropertyType key; - std::vector setInfo; + AuthType authType {0}; + SetPropertyType key {0}; + std::vector setInfo {}; }; // Authentication Result struct AuthResult { - std::vector token; - uint32_t remainTimes; - uint32_t freezingTime; + std::vector token {}; + uint32_t remainTimes {0}; + uint32_t freezingTime {0}; }; struct CoAuthInfo { - AuthType authType; - uint64_t callerID; - uint64_t contextID; - int32_t userID; + AuthType authType {0}; + uint64_t callerID {0}; + uint64_t contextID {0}; + int32_t userID {0}; std::string pkgName; std::vector sessionIds; }; @@ -125,89 +123,89 @@ struct FreezInfo { }; // Result Code -enum ResultCode: int32_t { +enum ResultCode : int32_t { /** * Indicates that authentication is success or ability is supported. */ SUCCESS = 0, /** - * Indicates the authenticator fails to identify user. - */ + * Indicates the authenticator fails to identify user. + */ FAIL = 1, /** - * Indicates other errors. - */ + * Indicates other errors. + */ GENERAL_ERROR = 2, /** - * Indicates that authentication has been canceled. - */ + * Indicates that authentication has been canceled. + */ CANCELED = 3, /** - * Indicates that authentication has timed out. - */ + * Indicates that authentication has timed out. + */ TIMEOUT = 4, /** - * Indicates that this authentication type is not supported. - */ + * Indicates that this authentication type is not supported. + */ TYPE_NOT_SUPPORT = 5, /** - * Indicates that the authentication trust level is not supported. - */ + * Indicates that the authentication trust level is not supported. + */ TRUST_LEVEL_NOT_SUPPORT = 6, /** - * Indicates that the authentication task is busy. Wait for a few seconds and try again. - */ + * Indicates that the authentication task is busy. Wait for a few seconds and try again. + */ BUSY = 7, /** - * Indicates incorrect parameters. - */ + * Indicates incorrect parameters. + */ INVALID_PARAMETERS = 8, /** - * Indicates that the authenticator is locked. - */ + * Indicates that the authenticator is locked. + */ LOCKED = 9, /** - * Indicates that the user has not enrolled the authenticator. - */ + * Indicates that the user has not enrolled the authenticator. + */ NOT_ENROLLED = 10, /** - * Indicates that IPC communication error. - */ + * Indicates that IPC communication error. + */ IPC_ERROR = 11, /** - * Indicates that invalid contextId. - */ + * Indicates that invalid contextId. + */ INVALID_CONTEXTID = 12, /** - * Indicates that WRITE PARCEL ERROR. - */ + * Indicates that WRITE PARCEL ERROR. + */ E_WRITE_PARCEL_ERROR = 13, /** - * Indicates that READ PARCEL ERROR - */ + * Indicates that READ PARCEL ERROR + */ E_READ_PARCEL_ERROR = 14, /** - * Indicates that POWER SERVICE FAILED - */ + * Indicates that POWER SERVICE FAILED + */ E_GET_POWER_SERVICE_FAILED = 15, /** - * Indicates that executor schudle undone - */ + * Indicates that executor schudle undone + */ E_RET_UNDONE = 16, /** - * Indicates that executor schudle undone - */ + * Indicates that executor schudle undone + */ E_RET_NOSERVER = 17, /** - * Check permission failed. - */ + * Check permission failed. + */ E_CHECK_PERMISSION_FAILED = 18, /** - * ERRORCODE_MAX. - */ + * ERRORCODE_MAX. + */ ERRORCODE_MAX = 19 }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_INFO_H diff --git a/interfaces/innerkits/native/include/userauth_proxy.h b/interfaces/innerkits/native/include/userauth_proxy.h index d4c1f4d..f81a33c 100755 --- a/interfaces/innerkits/native/include/userauth_proxy.h +++ b/interfaces/innerkits/native/include/userauth_proxy.h @@ -17,6 +17,8 @@ #define USERAUTH_PROXY_H #include +#include + #include "iuser_auth.h" namespace OHOS { @@ -24,16 +26,17 @@ namespace UserIAM { namespace UserAuth { class UserAuthProxy : public IRemoteProxy { public: - explicit UserAuthProxy(const sptr &impl); - ~UserAuthProxy() = default; + DISALLOW_COPY_AND_MOVE(UserAuthProxy); + explicit UserAuthProxy(const sptr &object); + ~UserAuthProxy() override = default; int32_t GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel) override; - void GetProperty(const GetPropertyRequest request, sptr& callback) override; - void SetProperty(const SetPropertyRequest request, sptr& callback) override; + void GetProperty(const GetPropertyRequest request, sptr &callback) override; + void SetProperty(const SetPropertyRequest request, sptr &callback) override; uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, - sptr& callback) override; + sptr &callback) override; uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType, - const AuthTurstLevel authTurstLevel, sptr& callback) override; + const AuthTurstLevel authTurstLevel, sptr &callback) override; int32_t CancelAuth(const uint64_t contextId) override; int32_t GetVersion() override; @@ -42,6 +45,6 @@ private: static inline BrokerDelegator delegator_; }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_PROXY_H \ No newline at end of file diff --git a/services/include/context_thread_pool.h b/services/include/context_thread_pool.h index 6693293..8d0468e 100644 --- a/services/include/context_thread_pool.h +++ b/services/include/context_thread_pool.h @@ -15,23 +15,24 @@ #ifndef USERAUTH_THREADPOOL_H #define USERAUTH_THREADPOOL_H -#include +#include #include -#include #include +#include +#include "nocopyable.h" #include "thread_pool.h" -#define THREADPOOLNAME "userauthThreadPool" -#define THREADPOOLMAXSTART 3 -#define THREADPOOLMAXTASK 6 - namespace OHOS { namespace UserIAM { namespace UserAuth { +static constexpr char THREADPOOLNAME[] = "userauthThreadPool"; +static constexpr uint64_t THREADPOOLMAXSTART = 3; +static constexpr uint64_t THREADPOOLMAXTASK = 6; + class ContextThreadPool : ThreadPool { public: - + DISALLOW_COPY_AND_MOVE(ContextThreadPool); static ContextThreadPool &GetInstance(); uint32_t Start(int threadsNum) { @@ -61,9 +62,9 @@ public: return ThreadPool::GetThreadsNum(); } - bool AddTask(const uint64_t context, const ThreadPool::Task& f); + bool AddTask(const uint64_t context, const ThreadPool::Task &f); - void TaskFunction(const uint64_t context, const ThreadPool::Task& f); + void TaskFunction(const uint64_t context, const ThreadPool::Task &f); private: class ContextTask { @@ -73,18 +74,18 @@ private: ThreadPool::Task GetTask(); - void AddTask(const ThreadPool::Task& f); + void AddTask(const ThreadPool::Task &f); + private: std::vector tasks; }; explicit ContextThreadPool(const std::string &name); - ~ContextThreadPool(); -private: + ~ContextThreadPool() override; ThreadPool::Task CheckTask(const uint64_t context); std::map ctMap_; std::mutex taskMutex_; }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif \ No newline at end of file diff --git a/services/include/userauth_adapter.h b/services/include/userauth_adapter.h index d445d59..2c65da5 100644 --- a/services/include/userauth_adapter.h +++ b/services/include/userauth_adapter.h @@ -16,12 +16,12 @@ #ifndef USERAUTH_ADAPTER_H #define USERAUTH_ADAPTER_H -#include "userauth_info.h" -#include "iuserauth_callback.h" -#include "set_prop_callback.h" #include "auth_attributes.h" #include "co_auth.h" #include "context_thread_pool.h" +#include "iuserauth_callback.h" +#include "set_prop_callback.h" +#include "userauth_info.h" #include "userauth_interface.h" #include @@ -36,47 +36,45 @@ public: /* Get the executor authentication properties */ void GetPropAuthInfo(int32_t userID, uint64_t callerUID, std::string pkgName, GetPropertyRequest requset, - sptr& callback); + sptr &callback); /** This method is called to set the executor properties * after the callback of the coAuth is called to obtain the scheduling token * and the authentication result is successful. * */ void CoauthSetPropAuthInfo(int32_t userID, int32_t resultCode, uint64_t callerUID, std::string pkgName, - UserAuthToken authToken, SetPropertyRequest requset, sptr& callback); + UserAuthToken authToken, SetPropertyRequest requset, sptr &callback); /* Set the executor authentication properties for freez or unfreez */ void SetPropAuthInfo(uint64_t callerUID, std::string pkgName, int32_t resultCode, UserAuthToken authToken, - SetPropertyRequest requset, std::vector templateIds, - sptr& callback); + SetPropertyRequest requset, std::vector templateIds, sptr &callback); /* get the executor authentication properties for Coauth */ void GetPropAuthInfoCoauth(int32_t userID, uint64_t callerUID, std::string pkgName, int32_t resultCode, - UserAuthToken authToken, GetPropertyRequest requset, sptr& callback); + UserAuthToken authToken, GetPropertyRequest requset, sptr &callback); int32_t GenerateSolution(AuthSolution param, std::vector &sessionIds); - int32_t RequestAuthResult(uint64_t contextId, std::vector scheduleToken, - UserAuthToken &authToken, std::vector &sessionIds); + int32_t RequestAuthResult(uint64_t contextId, std::vector scheduleToken, UserAuthToken &authToken, + std::vector &sessionIds); int32_t CancelContext(uint64_t contextId, std::vector &sessionIds); int32_t Cancel(uint64_t sessionId); /* get the executor authentication properties */ int32_t GetExecutorProp(uint64_t callerUID, std::string pkgName, uint64_t templateId, GetPropertyRequest requset, - ExecutorProperty &result); + ExecutorProperty &result); /* Set the executor authentication properties */ int32_t SetExecutorProp(uint64_t callerUID, std::string pkgName, SetPropertyRequest requset, - sptr& callback); + sptr &callback); int32_t GetVersion(); - int32_t coAuth(CoAuthInfo coAuthInfo, sptr& callback); + int32_t coAuth(CoAuthInfo coAuthInfo, sptr &callback); private: UserAuthAdapter() = default; ~UserAuthAdapter() = default; int32_t GetEachExecutorProp(GetPropertyRequest &requset, ExecutorProperty &result, uint32_t &value, std::shared_ptr pAuthAttributes); - int32_t SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttributes &authAttributes, - uint64_t callerUID, std::string pkgName, - SetPropertyRequest requset, std::vector templateIds, - std::shared_ptr &setPropCallback); + int32_t SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttributes &authAttributes, uint64_t callerUID, + std::string pkgName, SetPropertyRequest requset, std::vector templateIds, + std::shared_ptr &setPropCallback); }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_ADAPTER_H diff --git a/services/include/userauth_async_proxy.h b/services/include/userauth_async_proxy.h index f34f67f..57485f1 100755 --- a/services/include/userauth_async_proxy.h +++ b/services/include/userauth_async_proxy.h @@ -18,17 +18,19 @@ #include -#include "useridm_callback.h" #include "iuserauth_callback.h" +#include "useridm_callback.h" namespace OHOS { namespace UserIAM { namespace UserAuth { class UserAuthAsyncProxy : public IRemoteProxy { public: - explicit UserAuthAsyncProxy(const sptr &object) - : IRemoteProxy(object) {} - ~UserAuthAsyncProxy() = default; + DISALLOW_COPY_AND_MOVE(UserAuthAsyncProxy); + explicit UserAuthAsyncProxy(const sptr &object) : IRemoteProxy(object) + { + } + ~UserAuthAsyncProxy() override = default; void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override; void onResult(const int32_t result, const AuthResult extraInfo) override; @@ -37,11 +39,9 @@ public: private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - -private: static inline BrokerDelegator delegator_; }; -} // namespace UserAuth -} // namespace UserIAM -} // namespace OHOS +} // namespace UserAuth +} // namespace UserIAM +} // namespace OHOS #endif // USERAUTH_ASYNC_PROXY_H diff --git a/services/include/userauth_controller.h b/services/include/userauth_controller.h index b258933..856aa69 100644 --- a/services/include/userauth_controller.h +++ b/services/include/userauth_controller.h @@ -16,9 +16,9 @@ #ifndef USERAUTH_CONTROLLER_H #define USERAUTH_CONTROLLER_H -#include "userauth_info.h" -#include "userauth_adapter.h" #include "iuserauth_callback.h" +#include "userauth_adapter.h" +#include "userauth_info.h" #include "userauth_interface.h" namespace OHOS { @@ -28,20 +28,20 @@ class UserAuthController { public: int32_t GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel); void GetPropAuthInfo(int32_t userID, std::string pkgName, uint64_t callerUID, GetPropertyRequest getPropertyRequest, - sptr& callback); + sptr &callback); int32_t SetExecutorProp(uint64_t callerUID, std::string pkgName, SetPropertyRequest setPropertyrequest, - sptr& callback); + sptr &callback); int32_t AddContextID(uint64_t contextID); int32_t IsContextIDExist(uint64_t contextID); int32_t GenerateContextID(uint64_t &contextID); int32_t DeleteContextID(uint64_t contextID); int32_t GenerateSolution(AuthSolution param, std::vector &sessionIds); - int32_t coAuth(CoAuthInfo coAuthInfo, sptr& callback); + int32_t coAuth(CoAuthInfo coAuthInfo, sptr &callback); int32_t CancelContext(uint64_t contextId, std::vector &sessionIds); int32_t Cancel(uint64_t sessionId); int32_t GetVersion(); }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_CONTROLLER_H diff --git a/services/include/userauth_datamgr.h b/services/include/userauth_datamgr.h index 6c6094f..d3b477d 100755 --- a/services/include/userauth_datamgr.h +++ b/services/include/userauth_datamgr.h @@ -18,16 +18,20 @@ #include #include + +#include "nocopyable.h" + #include "iuserauth_callback.h" #include "userauth_adapter.h" -#include "singleton.h" -#define OPENSSLSUCCESS 1 namespace OHOS { namespace UserIAM { namespace UserAuth { + +constexpr int32_t OPENSSLSUCCESS = 1; class UserAuthDataMgr { public: + DISALLOW_COPY_AND_MOVE(UserAuthDataMgr); static UserAuthDataMgr &GetInstance(); int32_t AddContextID(uint64_t contextID); int32_t IsContextIDExist(uint64_t contextID); @@ -41,6 +45,6 @@ private: std::set contextIDs_; }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_DATAMGR_H diff --git a/services/include/userauth_service.h b/services/include/userauth_service.h index d1e63d0..130a83d 100644 --- a/services/include/userauth_service.h +++ b/services/include/userauth_service.h @@ -17,53 +17,54 @@ #define USERAUTH_SERVICE_H #include +#include +#include #include #include -#include -#include "userauth_stub.h" -#include "userauth_controller.h" #include "iuser_auth.h" +#include "userauth_controller.h" +#include "userauth_stub.h" namespace OHOS { namespace UserIAM { namespace UserAuth { class UserAuthService : public UserAuthStub, public SystemAbility { public: + DISALLOW_COPY_AND_MOVE(UserAuthService); DECLARE_SYSTEM_ABILITY(UserAuthService); explicit UserAuthService(int32_t systemAbilityId, bool runOnCreate = false); ~UserAuthService() override; void OnStart() override; void OnStop() override; int32_t GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel) override; - void GetProperty(const GetPropertyRequest request, sptr& callback) override; - void SetProperty(const SetPropertyRequest request, sptr& callback) override; + void GetProperty(const GetPropertyRequest request, sptr &callback) override; + void SetProperty(const SetPropertyRequest request, sptr &callback) override; uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, - sptr& callback) override; + sptr &callback) override; uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType, - const AuthTurstLevel authTurstLevel, sptr& callback) override; + const AuthTurstLevel authTurstLevel, sptr &callback) override; int32_t CancelAuth(const uint64_t contextId) override; int32_t GetVersion() override; private: int32_t GetCallingUserID(int32_t &userID); bool CheckPermission(const std::string &permission); - int32_t GetControllerData(sptr& callback, AuthResult &extraInfo, - const AuthTurstLevel authTurstLevel, uint64_t &callerID, - std::string &callerName, uint64_t &contextID); + int32_t GetControllerData(sptr &callback, AuthResult &extraInfo, + const AuthTurstLevel authTurstLevel, uint64_t &callerID, std::string &callerName, uint64_t &contextID); class UserAuthServiceCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: - UserAuthServiceCallbackDeathRecipient(sptr& impl); - ~UserAuthServiceCallbackDeathRecipient() = default; - void OnRemoteDied(const wptr& remote) override; + explicit UserAuthServiceCallbackDeathRecipient(sptr &impl); + ~UserAuthServiceCallbackDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override; private: - sptr callback_ { nullptr }; + sptr callback_ {nullptr}; DISALLOW_COPY_AND_MOVE(UserAuthServiceCallbackDeathRecipient); }; UserAuthController userauthController_; }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_SERVICE_H diff --git a/services/include/userauth_stub.h b/services/include/userauth_stub.h index 5feac61..94bf545 100755 --- a/services/include/userauth_stub.h +++ b/services/include/userauth_stub.h @@ -16,8 +16,8 @@ #ifndef USERAUTH_STUB_H #define USERAUTH_STUB_H -#include #include "iuser_auth.h" +#include namespace OHOS { namespace UserIAM { @@ -27,15 +27,15 @@ public: int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: - int32_t GetAvailableStatusStub(MessageParcel& data, MessageParcel& reply); - int32_t GetPropertyStub(MessageParcel& data, MessageParcel& reply); - int32_t SetPropertyStub(MessageParcel& data, MessageParcel& reply); - int32_t AuthStub(MessageParcel& data, MessageParcel& reply); - int32_t AuthUserStub(MessageParcel& data, MessageParcel& reply); - int32_t CancelAuthStub(MessageParcel& data, MessageParcel& reply); - int32_t GetVersionStub(MessageParcel& data, MessageParcel& reply); + int32_t GetAvailableStatusStub(MessageParcel &data, MessageParcel &reply); + int32_t GetPropertyStub(MessageParcel &data, MessageParcel &reply); + int32_t SetPropertyStub(MessageParcel &data, MessageParcel &reply); + int32_t AuthStub(MessageParcel &data, MessageParcel &reply); + int32_t AuthUserStub(MessageParcel &data, MessageParcel &reply); + int32_t CancelAuthStub(MessageParcel &data, MessageParcel &reply); + int32_t GetVersionStub(MessageParcel &data, MessageParcel &reply); }; } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS #endif // USERAUTH_STUB_H \ No newline at end of file diff --git a/services/src/userauth_adapter.cpp b/services/src/userauth_adapter.cpp index f6a4121..188ea1a 100644 --- a/services/src/userauth_adapter.cpp +++ b/services/src/userauth_adapter.cpp @@ -14,15 +14,15 @@ */ #include -#include "userauth_hilog_wrapper.h" -#include "userauth_info.h" #include "auth_attributes.h" #include "co_auth.h" -#include "useridm_client.h" -#include "useridm_info.h" +#include "userauth_adapter.h" #include "userauth_datamgr.h" #include "userauth_excallback_impl.h" -#include "userauth_adapter.h" +#include "userauth_hilog_wrapper.h" +#include "userauth_info.h" +#include "useridm_client.h" +#include "useridm_info.h" namespace OHOS { namespace UserIAM { @@ -46,14 +46,14 @@ int32_t UserAuthAdapter::GetAuthTrustLevel(int32_t userId, uint32_t authType, ui } void UserAuthAdapter::GetPropAuthInfo(int32_t userID, uint64_t callerUID, std::string pkgName, - GetPropertyRequest requset, sptr& callback) + GetPropertyRequest requset, sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetPropAuthInfo is start!"); using namespace UserIDM; std::shared_ptr getInfoCallback = std::make_shared(callback, requset, callerUID, pkgName); - int32_t ret = UserIDMClient::GetInstance().GetAuthInfo(userID, - static_cast(requset.authType), getInfoCallback); + int32_t ret = UserIDMClient::GetInstance().GetAuthInfo(userID, static_cast(requset.authType), + getInfoCallback); if (ret != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GetPropAuthInfo ERROR!"); } @@ -61,9 +61,8 @@ void UserAuthAdapter::GetPropAuthInfo(int32_t userID, uint64_t callerUID, std::s } void UserAuthAdapter::SetPropAuthInfo(uint64_t callerUID, std::string pkgName, int32_t resultCode, - UserAuthToken authToken, SetPropertyRequest requset, - std::vector templateIds, - sptr& callback) + UserAuthToken authToken, SetPropertyRequest requset, std::vector templateIds, + sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth SetPropAuthInfo is start!"); using namespace AuthResPool; @@ -84,9 +83,8 @@ void UserAuthAdapter::SetPropAuthInfo(uint64_t callerUID, std::string pkgName, i USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth SetPropAuthInfo is end!"); } int32_t UserAuthAdapter::SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttributes &authAttributes, - uint64_t callerUID, std::string pkgName, - SetPropertyRequest requset, std::vector templateIds, - std::shared_ptr &setPropCallback) + uint64_t callerUID, std::string pkgName, SetPropertyRequest requset, std::vector templateIds, + std::shared_ptr &setPropCallback) { uint32_t value; int32_t ret = authAttributes.SetUint32Value(AUTH_TYPE, requset.authType); @@ -96,9 +94,9 @@ int32_t UserAuthAdapter::SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttr setPropCallback->OnResult(ret, extraInfo); return ret; } - value = requset.key == SetPropertyType::FREEZE_TEMPLATE ? - static_cast(AuthPropertyMode::PROPERMODE_FREEZE) - : static_cast(AuthPropertyMode::PROPERMODE_UNFREEZE); + value = requset.key == SetPropertyType::FREEZE_TEMPLATE + ? static_cast(AuthPropertyMode::PROPERMODE_FREEZE) + : static_cast(AuthPropertyMode::PROPERMODE_UNFREEZE); ret = authAttributes.SetUint32Value(AUTH_PROPERTY_MODE, value); if (ret != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_PROPERTY_MODE ERROR!"); @@ -134,16 +132,14 @@ int32_t UserAuthAdapter::SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttr return ret; } void UserAuthAdapter::GetPropAuthInfoCoauth(int32_t userID, uint64_t callerUID, std::string pkgName, int32_t resultCode, - UserAuthToken authToken, GetPropertyRequest requset, - sptr& callback) + UserAuthToken authToken, GetPropertyRequest requset, sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetPropAuthInfoCoauth is start!"); using namespace UserIDM; - std::shared_ptr getInfoCallback = - std::make_shared(callback, callerUID, pkgName, resultCode, - authToken, requset); - int32_t ret = UserIDMClient::GetInstance().GetAuthInfo(userID, - static_cast(requset.authType), getInfoCallback); + std::shared_ptr getInfoCallback = std::make_shared(callback, + callerUID, pkgName, resultCode, authToken, requset); + int32_t ret = UserIDMClient::GetInstance().GetAuthInfo(userID, static_cast(requset.authType), + getInfoCallback); if (ret != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GetPropAuthInfoCoauth ERROR!"); } @@ -151,16 +147,14 @@ void UserAuthAdapter::GetPropAuthInfoCoauth(int32_t userID, uint64_t callerUID, } void UserAuthAdapter::CoauthSetPropAuthInfo(int32_t userID, int32_t resultCode, uint64_t callerUID, std::string pkgName, - UserAuthToken authToken, SetPropertyRequest requset, - sptr& callback) + UserAuthToken authToken, SetPropertyRequest requset, sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth CoauthSetPropAuthInfo is start!"); using namespace UserIDM; - std::shared_ptr setPropCallback = - std::make_shared(callback, callerUID, pkgName, resultCode, - authToken, requset); - int32_t ret = UserIDMClient::GetInstance().GetAuthInfo(userID, - static_cast(requset.authType), setPropCallback); + std::shared_ptr setPropCallback = std::make_shared( + callback, callerUID, pkgName, resultCode, authToken, requset); + int32_t ret = UserIDMClient::GetInstance().GetAuthInfo(userID, static_cast(requset.authType), + setPropCallback); if (ret != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth CoauthSetPropAuthInfo ERROR!"); } @@ -178,7 +172,7 @@ int32_t UserAuthAdapter::GenerateSolution(AuthSolution param, std::vector scheduleToken, - UserAuthToken &authToken, std::vector &sessionIds) + UserAuthToken &authToken, std::vector &sessionIds) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth RequestAuthResult is start!"); int32_t ret = OHOS::UserIAM::UserAuth::RequestAuthResult(contextId, scheduleToken, authToken, sessionIds); @@ -218,13 +212,13 @@ int32_t UserAuthAdapter::GetVersion() } int32_t UserAuthAdapter::GetExecutorProp(uint64_t callerUID, std::string pkgName, uint64_t templateId, - GetPropertyRequest requset, ExecutorProperty &result) + GetPropertyRequest requset, ExecutorProperty &result) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetExecutorProp is start!"); using namespace AuthResPool; uint32_t value; - auto pAuthAttributes (std::make_shared()); + auto pAuthAttributes(std::make_shared()); AuthAttributes cAuthAttributes; int32_t ret = cAuthAttributes.SetUint32Value(AUTH_TYPE, requset.authType); if (ret != SUCCESS) { @@ -319,7 +313,7 @@ int32_t UserAuthAdapter::GetEachExecutorProp(GetPropertyRequest &requset, Execut } int32_t UserAuthAdapter::SetExecutorProp(uint64_t callerUID, std::string pkgName, SetPropertyRequest requset, - sptr& callback) + sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth SetExecutorProp is start!"); using namespace AuthResPool; @@ -327,9 +321,9 @@ int32_t UserAuthAdapter::SetExecutorProp(uint64_t callerUID, std::string pkgName std::shared_ptr setPropCallback = std::make_shared(callback); AuthAttributes pAuthAttributes; - value = requset.key == SetPropertyType::INIT_ALGORITHM ? - static_cast(AuthPropertyMode::PROPERMODE_INIT_ALGORITHM) - : static_cast(AuthPropertyMode::PROPERMODE_RELEASE_ALGORITHM); + value = requset.key == SetPropertyType::INIT_ALGORITHM + ? static_cast(AuthPropertyMode::PROPERMODE_INIT_ALGORITHM) + : static_cast(AuthPropertyMode::PROPERMODE_RELEASE_ALGORITHM); int32_t ret = pAuthAttributes.SetUint32Value(AUTH_PROPERTY_MODE, value); if (ret != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value SET_AUTH_PROPERTY_MODE ERROR!"); @@ -363,7 +357,7 @@ int32_t UserAuthAdapter::SetExecutorProp(uint64_t callerUID, std::string pkgName return ret; } -int32_t UserAuthAdapter::coAuth(CoAuthInfo coAuthInfo, sptr& callback) +int32_t UserAuthAdapter::coAuth(CoAuthInfo coAuthInfo, sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth coAuth is start!"); @@ -393,5 +387,5 @@ int32_t UserAuthAdapter::coAuth(CoAuthInfo coAuthInfo, sptr& return SUCCESS; } } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS diff --git a/services/src/userauth_async_proxy.cpp b/services/src/userauth_async_proxy.cpp index 30660bb..a36b3d1 100755 --- a/services/src/userauth_async_proxy.cpp +++ b/services/src/userauth_async_proxy.cpp @@ -49,7 +49,6 @@ void UserAuthAsyncProxy::onAcquireInfo(const int32_t module, const uint32_t acqu int32_t result = reply.ReadInt32(); USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result); } - return; } void UserAuthAsyncProxy::onResult(const int32_t result, const AuthResult extraInfo) @@ -82,7 +81,6 @@ void UserAuthAsyncProxy::onResult(const int32_t result, const AuthResult extraIn int32_t result = reply.ReadInt32(); USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result); } - return; } void UserAuthAsyncProxy::onExecutorPropertyInfo(const ExecutorProperty result) @@ -115,7 +113,6 @@ void UserAuthAsyncProxy::onExecutorPropertyInfo(const ExecutorProperty result) int32_t result = reply.ReadInt32(); USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result); } - return; } void UserAuthAsyncProxy::onSetExecutorProperty(const int32_t result) @@ -138,8 +135,6 @@ void UserAuthAsyncProxy::onSetExecutorProperty(const int32_t result) int32_t result = reply.ReadInt32(); USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result); } - - return; } bool UserAuthAsyncProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) diff --git a/services/src/userauth_controller.cpp b/services/src/userauth_controller.cpp index 8a28a8e..51b928e 100644 --- a/services/src/userauth_controller.cpp +++ b/services/src/userauth_controller.cpp @@ -24,14 +24,12 @@ int32_t UserAuthController::GetAuthTrustLevel(int32_t userId, uint32_t authType, return UserAuthAdapter::GetInstance().GetAuthTrustLevel(userId, authType, authTrustLevel); } int32_t UserAuthController::SetExecutorProp(uint64_t callerUID, std::string pkgName, - SetPropertyRequest setPropertyrequest, - sptr& callback) + SetPropertyRequest setPropertyrequest, sptr &callback) { return UserAuthAdapter::GetInstance().SetExecutorProp(callerUID, pkgName, setPropertyrequest, callback); } void UserAuthController::GetPropAuthInfo(int32_t userID, std::string pkgName, uint64_t callerUID, - GetPropertyRequest getPropertyRequest, - sptr& callback) + GetPropertyRequest getPropertyRequest, sptr &callback) { UserAuthAdapter::GetInstance().GetPropAuthInfo(userID, callerUID, pkgName, getPropertyRequest, callback); } @@ -39,7 +37,7 @@ int32_t UserAuthController::GenerateSolution(AuthSolution param, std::vector& callback) +int32_t UserAuthController::coAuth(CoAuthInfo coAuthInfo, sptr &callback) { return UserAuthAdapter::GetInstance().coAuth(coAuthInfo, callback); } @@ -72,5 +70,5 @@ int32_t UserAuthController::GetVersion() return UserAuthAdapter::GetInstance().GetVersion(); } } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS diff --git a/services/src/userauth_service.cpp b/services/src/userauth_service.cpp index 0c3e8a2..31e9538 100644 --- a/services/src/userauth_service.cpp +++ b/services/src/userauth_service.cpp @@ -15,10 +15,11 @@ #include #include -#include "userauth_hilog_wrapper.h" -#include "useriam_common.h" + #include "accesstoken_kit.h" +#include "userauth_hilog_wrapper.h" #include "userauth_service.h" +#include "useriam_common.h" namespace OHOS { namespace UserIAM { @@ -35,9 +36,7 @@ UserAuthService::UserAuthService(int32_t systemAbilityId, bool runOnCreate) { } -UserAuthService::~UserAuthService() -{ -} +UserAuthService::~UserAuthService() = default; void UserAuthService::OnStart() { @@ -112,7 +111,7 @@ int32_t UserAuthService::GetAvailableStatus(const AuthType authType, const AuthT return ret; } -void UserAuthService::GetProperty(const GetPropertyRequest request, sptr& callback) +void UserAuthService::GetProperty(const GetPropertyRequest request, sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService GetProperty is start"); uint64_t callerID = 0; @@ -147,12 +146,12 @@ void UserAuthService::GetProperty(const GetPropertyRequest request, sptr& callback) +void UserAuthService::SetProperty(const SetPropertyRequest request, sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService SetProperty is start"); int ret = GENERAL_ERROR; uint64_t callerID = 0; - std::string callerName = ""; + std::string callerName; if (callback == nullptr) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService SetProperty IUserAuthCallback is NULL!"); return; @@ -196,20 +195,19 @@ int32_t UserAuthService::GetCallingUserID(int32_t &userID) USERAUTH_HILOGE(MODULE_SERVICE, "Get hap token info failed."); return TYPE_NOT_SUPPORT; } - userID = (int32_t)hapTokenInfo.userID; + userID = static_cast(hapTokenInfo.userID); USERAUTH_HILOGE(MODULE_SERVICE, "GetCallingUserID is %{public}d", userID); return SUCCESS; } -uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType, - const AuthTurstLevel authTurstLevel, - sptr& callback) +uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel, + sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService Auth is start"); const uint64_t invalidContextID = 0; int32_t userID = 0; uint64_t callerID = 0; - std::string callerName = ""; + std::string callerName; uint64_t contextID = 0; AuthSolution authSolutionParam; CoAuthInfo coAuthInfo; @@ -260,14 +258,13 @@ uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType return contextID; } -uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challenge, - const AuthType authType, const AuthTurstLevel authTurstLevel, - sptr& callback) +uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType, + const AuthTurstLevel authTurstLevel, sptr &callback) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService AuthUser is start"); const uint64_t invalidContextID = 0; uint64_t callerID = 0; - std::string callerName = ""; + std::string callerName; uint64_t contextID = 0; AuthSolution authSolutionParam; CoAuthInfo coAuthInfo; @@ -314,9 +311,8 @@ uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challeng return contextID; } -int32_t UserAuthService::GetControllerData(sptr& callback, AuthResult &extraInfo, - const AuthTurstLevel authTurstLevel, uint64_t &callerID, - std::string &callerName, uint64_t &contextID) +int32_t UserAuthService::GetControllerData(sptr &callback, AuthResult &extraInfo, + const AuthTurstLevel authTurstLevel, uint64_t &callerID, std::string &callerName, uint64_t &contextID) { int ret = SUCCESS; int result = SUCCESS; @@ -356,7 +352,7 @@ int32_t UserAuthService::CancelAuth(const uint64_t contextId) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService CancelAuth is start"); int result = INVALID_CONTEXTID; - std::vector sessionIds; + std::vector sessionIds; if (!CheckPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION) && !CheckPermission(ACCESS_BIOMETRIC_PERMISSION)) { USERAUTH_HILOGE(MODULE_SERVICE, "Permission check failed"); return E_CHECK_PERMISSION_FAILED; @@ -391,7 +387,7 @@ int32_t UserAuthService::GetVersion() return userauthController_.GetVersion(); } UserAuthService::UserAuthServiceCallbackDeathRecipient::UserAuthServiceCallbackDeathRecipient( - sptr& impl) + sptr &impl) { if (impl != nullptr) { callback_ = impl; @@ -399,11 +395,10 @@ UserAuthService::UserAuthServiceCallbackDeathRecipient::UserAuthServiceCallbackD USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthServiceCallbackDeathRecipient is error"); } } -void UserAuthService::UserAuthServiceCallbackDeathRecipient::OnRemoteDied(const wptr& remote) +void UserAuthService::UserAuthServiceCallbackDeathRecipient::OnRemoteDied(const wptr &remote) { if (remote == nullptr) { - USERAUTH_HILOGE(MODULE_SERVICE, - "UserAuthServiceCallbackDeathRecipient OnRemoteDied failed, remote is nullptr"); + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthServiceCallbackDeathRecipient OnRemoteDied failed, remote is nullptr"); return; } callback_ = nullptr; @@ -411,5 +406,5 @@ void UserAuthService::UserAuthServiceCallbackDeathRecipient::OnRemoteDied(const USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthServiceCallbackDeathRecipient::Recv death notice."); } } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS diff --git a/services/src/userauth_stub.cpp b/services/src/userauth_stub.cpp index f5f9253..01f80f4 100644 --- a/services/src/userauth_stub.cpp +++ b/services/src/userauth_stub.cpp @@ -12,23 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include "userauth_hilog_wrapper.h" #include "userauth_stub.h" +#include "userauth_hilog_wrapper.h" +#include namespace OHOS { namespace UserIAM { namespace UserAuth { -int32_t UserAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) +int32_t UserAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub::OnRemoteRequest, cmd = %d, flags= %d", - code, option.GetFlags()); + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags()); std::u16string descripter = UserAuthStub::GetDescriptor(); std::u16string remoteDescripter = data.ReadInterfaceToken(); if (descripter != remoteDescripter) { - USERAUTH_HILOGD(MODULE_SERVICE, - "DisplayMgrStub::OnRemoteRequest failed, descriptor is not matched!"); + USERAUTH_HILOGD(MODULE_SERVICE, "DisplayMgrStub::OnRemoteRequest failed, descriptor is not matched!"); return E_GET_POWER_SERVICE_FAILED; } @@ -52,7 +49,7 @@ int32_t UserAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, } } -int32_t UserAuthStub::GetAvailableStatusStub(MessageParcel& data, MessageParcel& reply) +int32_t UserAuthStub::GetAvailableStatusStub(MessageParcel &data, MessageParcel &reply) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub GetAvailableStatusStub is start"); uint32_t authType; @@ -77,7 +74,7 @@ int32_t UserAuthStub::GetAvailableStatusStub(MessageParcel& data, MessageParcel& return SUCCESS; } -int32_t UserAuthStub::GetPropertyStub(MessageParcel& data, MessageParcel& reply) +int32_t UserAuthStub::GetPropertyStub(MessageParcel &data, MessageParcel &reply) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub GetPropertyStub is start"); GetPropertyRequest getPropertyRequest; @@ -110,7 +107,7 @@ int32_t UserAuthStub::GetPropertyStub(MessageParcel& data, MessageParcel& reply) return SUCCESS; } -int32_t UserAuthStub::SetPropertyStub(MessageParcel& data, MessageParcel& reply) +int32_t UserAuthStub::SetPropertyStub(MessageParcel &data, MessageParcel &reply) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub SetPropertyStub is start"); SetPropertyRequest setPropertyRequest; @@ -131,7 +128,7 @@ int32_t UserAuthStub::SetPropertyStub(MessageParcel& data, MessageParcel& reply) return E_READ_PARCEL_ERROR; } - setPropertyRequest.authType = static_cast(authType); + setPropertyRequest.authType = static_cast(authType); setPropertyRequest.key = static_cast(key); setPropertyRequest.setInfo.assign(setInfo.begin(), setInfo.end()); @@ -149,7 +146,7 @@ int32_t UserAuthStub::SetPropertyStub(MessageParcel& data, MessageParcel& reply) return SUCCESS; } -int32_t UserAuthStub::AuthStub(MessageParcel& data, MessageParcel& reply) +int32_t UserAuthStub::AuthStub(MessageParcel &data, MessageParcel &reply) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub AuthStub is start"); uint64_t challenge; @@ -188,7 +185,7 @@ int32_t UserAuthStub::AuthStub(MessageParcel& data, MessageParcel& reply) return SUCCESS; } -int32_t UserAuthStub::AuthUserStub(MessageParcel& data, MessageParcel& reply) +int32_t UserAuthStub::AuthUserStub(MessageParcel &data, MessageParcel &reply) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub AuthUserStub is start"); int32_t userID; @@ -224,8 +221,8 @@ int32_t UserAuthStub::AuthUserStub(MessageParcel& data, MessageParcel& reply) return FAIL; } - ret = AuthUser(userID, challenge, static_cast(authType), - static_cast(authTurstLevel), callback); + ret = AuthUser(userID, challenge, static_cast(authType), static_cast(authTurstLevel), + callback); if (!reply.WriteUint64(ret)) { USERAUTH_HILOGE(MODULE_SERVICE, "Failed to write AuthUser return value"); return E_WRITE_PARCEL_ERROR; @@ -233,7 +230,7 @@ int32_t UserAuthStub::AuthUserStub(MessageParcel& data, MessageParcel& reply) return SUCCESS; } -int32_t UserAuthStub::GetVersionStub(MessageParcel& data, MessageParcel& reply) +int32_t UserAuthStub::GetVersionStub(MessageParcel &data, MessageParcel &reply) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub GetVersionStub is start"); @@ -245,7 +242,7 @@ int32_t UserAuthStub::GetVersionStub(MessageParcel& data, MessageParcel& reply) return SUCCESS; } -int32_t UserAuthStub::CancelAuthStub(MessageParcel& data, MessageParcel& reply) +int32_t UserAuthStub::CancelAuthStub(MessageParcel &data, MessageParcel &reply) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub CancelAuthStub is start"); uint64_t contextID; @@ -265,5 +262,5 @@ int32_t UserAuthStub::CancelAuthStub(MessageParcel& data, MessageParcel& reply) return SUCCESS; } } // namespace UserAuth -} // namespace UserIam +} // namespace UserIAM } // namespace OHOS