mirror of
https://gitee.com/openharmony/resourceschedule_background_task_mgr
synced 2025-03-07 06:58:14 +00:00
使用string代理int
Signed-off-by: lipengfei <lipengfei53@huawei.com>
This commit is contained in:
parent
82bfe8575f
commit
fea0868bac
@ -41,7 +41,6 @@ struct ContinuousTaskParam : public Parcelable {
|
||||
const sptr<IRemoteObject> abilityToken, const std::string &appName, bool isBatchApi = 0, const std::vector<uint32_t> bgModeIds = {})
|
||||
: isNewApi_(isNewApi), bgModeId_(bgModeId), wantAgent_(wantAgent), abilityName_(abilityName), abilityToken_(abilityToken),
|
||||
appName_(appName), isBatchApi_(isBatchApi), bgModeIds_(bgModeIds) {}
|
||||
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
static ContinuousTaskParam *Unmarshalling(Parcel &parcel);
|
||||
|
@ -23,10 +23,10 @@
|
||||
namespace OHOS {
|
||||
namespace BackgroundTaskMgr {
|
||||
ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo() {}
|
||||
ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo(uint32_t typeId, int32_t creatorUid, pid_t creatorPid, std::string abilityName,
|
||||
bool isFromWebview, bool isBatchApi, std::vector<uint32_t> typeIds, int32_t abilityId) : typeId_(typeId), creatorUid_(creatorUid),
|
||||
creatorPid_(creatorPid), abilityName_(abilityName), isFromWebview_(isFromWebview),
|
||||
isBatchApi_(isBatchApi), typeIds_(typeIds), abilityId_(abilityId) {}
|
||||
ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo(uint32_t typeId, int32_t creatorUid,
|
||||
pid_t creatorPid, std::string abilityName, bool isFromWebview, bool isBatchApi, std::vector<uint32_t> typeIds, int32_t abilityId) :
|
||||
typeId_(typeId), creatorUid_(creatorUid), creatorPid_(creatorPid), abilityName_(abilityName),
|
||||
isFromWebview_(isFromWebview), isBatchApi_(isBatchApi), typeIds_(typeIds), abilityId_(abilityId) {}
|
||||
|
||||
uint32_t ContinuousTaskCallbackInfo::GetTypeId() const
|
||||
{
|
||||
|
@ -40,6 +40,17 @@ static constexpr uint32_t MAX_STOP_BG_RUNNING_PARAMS = 2;
|
||||
static constexpr uint32_t CALLBACK_RESULT_PARAMS_NUM = 2;
|
||||
static constexpr uint32_t BG_MODE_ID_BEGIN = 1;
|
||||
static constexpr uint32_t BG_MODE_ID_END = 9;
|
||||
static std::vector<std::string> g_backgroundModes = {
|
||||
"dataTransfer",
|
||||
"audioPlayback",
|
||||
"audioRecording",
|
||||
"location",
|
||||
"bluetoothInteraction",
|
||||
"multiDeviceConnection",
|
||||
"wifiInteraction",
|
||||
"voip",
|
||||
"taskKeeping"
|
||||
};
|
||||
}
|
||||
|
||||
struct AsyncCallbackInfo : public AsyncWorkData {
|
||||
@ -214,7 +225,7 @@ void UpdateBackgroundRunningExecuteCB(napi_env env, void *data)
|
||||
return;
|
||||
}
|
||||
const std::shared_ptr<AppExecFwk::AbilityInfo> info = asyncCallbackInfo->abilityContext->GetAbilityInfo();
|
||||
ContinuousTaskParam taskParam = ContinuousTaskParam(true, asyncCallbackInfo->bgMode, nullptr, info->name,
|
||||
ContinuousTaskParam taskParam = ContinuousTaskParam(true, asyncCallbackInfo->bgMode, nullptr, info->name,
|
||||
asyncCallbackInfo->abilityContext->GetToken(), GetMainAbilityLabel(info->bundleName), true, asyncCallbackInfo->bgModes);
|
||||
BGTASK_LOGD("StartBackgroundRunningExecuteCB %{public}d, %{public}u", taskParam.isBatchApi_, static_cast<uint32_t>(taskParam.bgModeIds_.size()));
|
||||
asyncCallbackInfo->errCode = BackgroundTaskMgrHelper::RequestUpdateBackgroundRunning(taskParam);
|
||||
@ -383,7 +394,6 @@ bool CheckTypeForNapiValue(napi_env env, napi_value param, napi_valuetype expect
|
||||
|
||||
napi_value GetBackgroundMode(const napi_env &env, const napi_value &value, AsyncCallbackInfo *asyncCallbackInfo)
|
||||
{
|
||||
BGTASK_LOGI("lpf interface");
|
||||
bool isArray = false;
|
||||
if (napi_is_array(env, value, &isArray) != napi_ok || isArray == false) {
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
@ -397,11 +407,10 @@ napi_value GetBackgroundMode(const napi_env &env, const napi_value &value, Async
|
||||
BGTASK_LOGI("get bgmode info: %{public}u", asyncCallbackInfo->bgMode);
|
||||
return WrapVoidToJS(env);
|
||||
} else {
|
||||
BGTASK_LOGI("use new interface");
|
||||
uint32_t arrayLen = 0;
|
||||
napi_get_array_length(env, value, &arrayLen);
|
||||
BGTASK_LOGI("get bgModes arraylen: %{public}u", arrayLen);
|
||||
if (arrayLen == 0) {
|
||||
if (arrayLen == 0 ) {
|
||||
Common::HandleParamErr(env, ERR_BGMODE_NULL_OR_TYPE_ERR, true);
|
||||
return nullptr;
|
||||
}
|
||||
@ -409,14 +418,25 @@ napi_value GetBackgroundMode(const napi_env &env, const napi_value &value, Async
|
||||
for (uint32_t i = 0; i < arrayLen; i++) {
|
||||
napi_value mode = nullptr;
|
||||
napi_get_element(env, value, i, &mode);
|
||||
int32_t result = 0;
|
||||
if (Common::GetInt32NumberValue(env, mode, result) == nullptr) {
|
||||
std::string result;
|
||||
if (Common::GetStringValue(env, mode, result) == nullptr) {
|
||||
BGTASK_LOGE("GetBackgroundMode failed.");
|
||||
Common::HandleParamErr(env, ERR_BGMODE_NULL_OR_TYPE_ERR, true);
|
||||
return nullptr;
|
||||
}
|
||||
BGTASK_LOGI("GetBackgroundMode %{public}d.", result);
|
||||
asyncCallbackInfo->bgModes.push_back(result);
|
||||
BGTASK_LOGI("GetBackgroundMode %{public}s.", result.c_str());
|
||||
auto it = std::find(g_backgroundModes.begin(), g_backgroundModes.end(), result);
|
||||
if (it != g_backgroundModes.end()) {
|
||||
auto index = std::distance(g_backgroundModes.begin(), it);
|
||||
auto modeIter = std::find(asyncCallbackInfo->bgModes.begin(), asyncCallbackInfo->bgModes.end(), index + 1);
|
||||
if (modeIter == asyncCallbackInfo->bgModes.end()) {
|
||||
asyncCallbackInfo->bgModes.push_back(index + 1);
|
||||
}
|
||||
} else {
|
||||
BGTASK_LOGE("mode string is invalid");
|
||||
Common::HandleParamErr(env, ERR_BGMODE_NULL_OR_TYPE_ERR, true);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return WrapVoidToJS(env);
|
||||
}
|
||||
@ -434,7 +454,7 @@ napi_value GetWantAgent(const napi_env &env, const napi_value &value,
|
||||
}
|
||||
napi_unwrap(env, value, (void **)&wantAgentPtr);
|
||||
wantAgent = std::make_shared<AbilityRuntime::WantAgent::WantAgent>(*wantAgentPtr);
|
||||
|
||||
|
||||
return WrapVoidToJS(env);
|
||||
}
|
||||
|
||||
@ -480,7 +500,7 @@ napi_value UpdateBackgroundRunning(napi_env env, napi_callback_info info, bool i
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
|
||||
if (argc > 2) {
|
||||
if (argc != 2) {
|
||||
BGTASK_LOGE("wrong param nums");
|
||||
Common::HandleParamErr(env, ERR_PARAM_NUMBER_ERR, isThrow);
|
||||
return WrapVoidToJS(env);
|
||||
|
@ -579,12 +579,6 @@ ErrCode BgContinuousTaskMgr::StartBackgroundRunning(const sptr<ContinuousTaskPar
|
||||
if (!CheckTaskParam(taskParam)) {
|
||||
return ERR_BGTASK_CHECK_TASK_PARAM;
|
||||
}
|
||||
if (taskParam->isBatchApi_) {
|
||||
BGTASK_LOGI("new mode size %{public}u", static_cast<uint32_t>(taskParam->bgModeIds_.size()));
|
||||
for (auto mode : taskParam->bgModeIds_) {
|
||||
BGTASK_LOGI("mode %{public}u", mode);
|
||||
}
|
||||
}
|
||||
ErrCode result = ERR_OK;
|
||||
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
@ -633,7 +627,6 @@ ErrCode BgContinuousTaskMgr::StartBackgroundRunning(const sptr<ContinuousTaskPar
|
||||
|
||||
ErrCode BgContinuousTaskMgr::UpdateBackgroundRunning(const sptr<ContinuousTaskParam> &taskParam)
|
||||
{
|
||||
BGTASK_LOGW("UpdateBackgroundRunning");
|
||||
if (!isSysReady_.load()) {
|
||||
BGTASK_LOGW("manager is not ready");
|
||||
return ERR_BGTASK_SYS_NOT_READY;
|
||||
@ -663,8 +656,14 @@ ErrCode BgContinuousTaskMgr::UpdateBackgroundRunningInner(const std::string task
|
||||
BGTASK_LOGW("continuous task is not exist: %{public}s, use start befor update", taskInfoMapKey.c_str());
|
||||
return ERR_BGTASK_OBJECT_EXISTS;
|
||||
}
|
||||
|
||||
auto continuousTaskRecord = iter->second;
|
||||
auto oldModes = continuousTaskRecord->bgModeIds_;
|
||||
BGTASK_LOGI("continuous task mode %{public}d, old modes: %{public}s, new modes %{public}s, isBatchApi %{public}d",
|
||||
continuousTaskRecord->bgModeId_,
|
||||
continuousTaskRecord->ToString(continuousTaskRecord->bgModeIds_).c_str(),
|
||||
continuousTaskRecord->ToString(updateModes).c_str(),
|
||||
continuousTaskRecord->isBatchApi_);
|
||||
// todo diff compare old and new
|
||||
uint32_t configuredBgMode = GetBackgroundModeInfo(continuousTaskRecord->uid_, continuousTaskRecord->abilityName_);
|
||||
for (auto it = updateModes.begin(); it != updateModes.end(); it++) {
|
||||
@ -692,6 +691,8 @@ ErrCode BgContinuousTaskMgr::UpdateBackgroundRunningInner(const std::string task
|
||||
|
||||
ErrCode BgContinuousTaskMgr::StartBackgroundRunningInner(std::shared_ptr<ContinuousTaskRecord> &continuousTaskRecord)
|
||||
{
|
||||
BGTASK_LOGI("continuous task mode: %{public}u, modes %{public}s, isBatchApi %{public}d", continuousTaskRecord->bgModeId_,
|
||||
continuousTaskRecord->ToString(continuousTaskRecord->bgModeIds_).c_str(), continuousTaskRecord->isBatchApi_);
|
||||
std::string taskInfoMapKey = std::to_string(continuousTaskRecord->uid_) + SEPARATOR
|
||||
+ continuousTaskRecord->abilityName_;
|
||||
if (continuousTaskInfosMap_.find(taskInfoMapKey) != continuousTaskInfosMap_.end()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user