diff --git a/interfaces/kits/js/app_control/js_app_control.cpp b/interfaces/kits/js/app_control/js_app_control.cpp index b649f3a515f54e936a4c1a0638291dd45b18ed60..2319eaca1f83bf6064139242d4780ca96341793d 100644 --- a/interfaces/kits/js/app_control/js_app_control.cpp +++ b/interfaces/kits/js/app_control/js_app_control.cpp @@ -37,6 +37,9 @@ const std::string PERMISSION_DISPOSED_STATUS = "ohos.permission.MANAGE_DISPOSED_ const std::string SET_DISPOSED_STATUS = "SetDisposedStatus"; const std::string GET_DISPOSED_STATUS = "GetDisposedStatus"; const std::string DELETE_DISPOSED_STATUS = "DeleteDisposedStatus"; +const std::string SET_DISPOSED_STATUS_SYNC = "SetDisposedStatusSync"; +const std::string DELETE_DISPOSED_STATUS_SYNC = "DeleteDisposedStatusSync"; +const std::string GET_DISPOSED_STATUS_SYNC = "GetDisposedStatusSync"; const std::string APP_ID = "appId"; const std::string DISPOSED_WANT = "disposedWant"; } @@ -183,6 +186,49 @@ napi_value SetDisposedStatus(napi_env env, napi_callback_info info) return promise; } +napi_value SetDisposedStatusSync(napi_env env, napi_callback_info info) +{ + APP_LOGD("begin to SetDisposedStatusSync"); + NapiArg args(env, info); + napi_value nRet; + napi_get_undefined(env, &nRet); + if (!args.Init(ARGS_SIZE_TWO, ARGS_SIZE_TWO)) { + APP_LOGE("Napi func init failed"); + BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR); + return nRet; + } + std::string appId; + if (!CommonFunc::ParseString(env, args[ARGS_POS_ZERO], appId)) { + APP_LOGE("appId %{public}s invalid!", appId.c_str()); + BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return nRet; + } + OHOS::AAFwk::Want want; + if (!CommonFunc::ParseWantWithoutVerification(env, args[ARGS_POS_ONE], want)) { + APP_LOGE("want invalid!"); + BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, DISPOSED_WANT, TYPE_WANT); + return nRet; + } + auto appControlProxy = GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("AppControlProxy is null."); + napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + SET_DISPOSED_STATUS_SYNC); + napi_throw(env, error); + return nRet; + } + ErrCode ret = appControlProxy->SetDisposedStatus(appId, want); + ret = CommonFunc::ConvertErrCode(ret); + if (ret != NO_ERROR) { + APP_LOGE("SetDisposedStatusSync err = %{public}d", ret); + napi_value businessError = BusinessError::CreateCommonError( + env, ret, SET_DISPOSED_STATUS_SYNC, PERMISSION_DISPOSED_STATUS); + napi_throw(env, businessError); + } + APP_LOGD("call SetDisposedStatusSync done."); + return nRet; +} + void DeleteDisposedStatusExec(napi_env env, void *data) { DisposedStatus *asyncCallbackInfo = reinterpret_cast(data); @@ -273,6 +319,43 @@ napi_value DeleteDisposedStatus(napi_env env, napi_callback_info info) return promise; } +napi_value DeleteDisposedStatusSync(napi_env env, napi_callback_info info) +{ + APP_LOGD("begin to DeleteDisposedStatusSync."); + NapiArg args(env, info); + napi_value nRet; + napi_get_undefined(env, &nRet); + if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_ONE)) { + APP_LOGE("param count invalid."); + BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR); + return nRet; + } + std::string appId; + if (!CommonFunc::ParseString(env, args[ARGS_POS_ZERO], appId)) { + APP_LOGE("appId %{public}s invalid!", appId.c_str()); + BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return nRet; + } + auto appControlProxy = GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("AppControlProxy is null"); + napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + DELETE_DISPOSED_STATUS_SYNC); + napi_throw(env, error); + return nRet; + } + ErrCode ret = appControlProxy->DeleteDisposedStatus(appId); + ret = CommonFunc::ConvertErrCode(ret); + if (ret != NO_ERROR) { + APP_LOGE("DeleteDisposedStatusSync err = %{public}d", ret); + napi_value businessError = BusinessError::CreateCommonError( + env, ret, DELETE_DISPOSED_STATUS_SYNC, PERMISSION_DISPOSED_STATUS); + napi_throw(env, businessError); + } + APP_LOGD("call DeleteDisposedStatusSync done."); + return nRet; +} + void GetDisposedStatusExec(napi_env env, void *data) { DisposedStatus *asyncCallbackInfo = reinterpret_cast(data); @@ -382,8 +465,9 @@ napi_value GetDisposedStatusSync(napi_env env, napi_callback_info info) } auto appControlProxy = GetAppControlProxy(); if (appControlProxy == nullptr) { + APP_LOGE("AppControlProxy is null"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, - GET_DISPOSED_STATUS); + GET_DISPOSED_STATUS_SYNC); napi_throw(env, error); return nullptr; } @@ -393,11 +477,12 @@ napi_value GetDisposedStatusSync(napi_env env, napi_callback_info info) if (ret != ERR_OK) { APP_LOGE("GetDisposedStatusSync failed"); napi_value businessError = BusinessError::CreateCommonError( - env, ret, GET_DISPOSED_STATUS, PERMISSION_DISPOSED_STATUS); + env, ret, GET_DISPOSED_STATUS_SYNC, PERMISSION_DISPOSED_STATUS); napi_throw(env, businessError); return nullptr; } napi_value nWant = nullptr; + NAPI_CALL(env, napi_create_object(env, &nWant)); CommonFunc::ConvertWantInfo(env, nWant, disposedWant); APP_LOGD("call GetDisposedStatusSync done."); return nWant; diff --git a/interfaces/kits/js/app_control/js_app_control.h b/interfaces/kits/js/app_control/js_app_control.h index 036b26cfc6d64c88128aea2f994fa5aebfe141fe..c256ba5df9165bc832c860104feebd8c8614c841 100644 --- a/interfaces/kits/js/app_control/js_app_control.h +++ b/interfaces/kits/js/app_control/js_app_control.h @@ -35,6 +35,8 @@ napi_value GetDisposedStatus(napi_env env, napi_callback_info info); napi_value SetDisposedStatus(napi_env env, napi_callback_info info); napi_value DeleteDisposedStatus(napi_env env, napi_callback_info info); napi_value GetDisposedStatusSync(napi_env env, napi_callback_info info); +napi_value SetDisposedStatusSync(napi_env env, napi_callback_info info); +napi_value DeleteDisposedStatusSync(napi_env env, napi_callback_info info); } // namespace AppExecFwk } // namespace OHOS #endif /* JS_APP_CONTROL_H */ \ No newline at end of file diff --git a/interfaces/kits/js/app_control/js_app_control_unsupported.cpp b/interfaces/kits/js/app_control/js_app_control_unsupported.cpp index bfa68480aa40874c5e170cb552073131a5270f96..cb5bc6c8e8cb1d1021e84f58a50847b819c05d20 100644 --- a/interfaces/kits/js/app_control/js_app_control_unsupported.cpp +++ b/interfaces/kits/js/app_control/js_app_control_unsupported.cpp @@ -59,5 +59,23 @@ napi_value GetDisposedStatusSync(napi_env env, napi_callback_info info) napi_throw(env, error); return nullptr; } + +napi_value SetDisposedStatusSync(napi_env env, napi_callback_info info) +{ + APP_LOGE("SystemCapability.BundleManager.BundleFramework.AppControl not supported."); + napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + "setDisposedStatusSync"); + napi_throw(env, error); + return nullptr; +} + +napi_value DeleteDisposedStatusSync(napi_env env, napi_callback_info info) +{ + APP_LOGE("SystemCapability.BundleManager.BundleFramework.AppControl not supported."); + napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + "deleteDisposedStatusSync"); + napi_throw(env, error); + return nullptr; +} } // AppExecFwk } // OHOS diff --git a/interfaces/kits/js/app_control/native_module.cpp b/interfaces/kits/js/app_control/native_module.cpp index 0f7e6de66a80fdb5bfde2ef68c3dbfcce66c1751..62cb539ee9ff7509b3c60eff4d6b9d792e52011a 100644 --- a/interfaces/kits/js/app_control/native_module.cpp +++ b/interfaces/kits/js/app_control/native_module.cpp @@ -33,6 +33,8 @@ static napi_value AppControlExport(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("setDisposedStatus", SetDisposedStatus), DECLARE_NAPI_FUNCTION("deleteDisposedStatus", DeleteDisposedStatus), DECLARE_NAPI_FUNCTION("getDisposedStatusSync", GetDisposedStatusSync), + DECLARE_NAPI_FUNCTION("setDisposedStatusSync", SetDisposedStatusSync), + DECLARE_NAPI_FUNCTION("deleteDisposedStatusSync", DeleteDisposedStatusSync), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));