* Copyright (c) 2022-2026 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 FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_CONTINUOUS_TASK_COMMON_UTILS_H
#define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_CONTINUOUS_TASK_COMMON_UTILS_H
#include <regex>
#include <set>
#include "nlohmann/json.hpp"
#include "background_mode.h"
namespace OHOS {
namespace BackgroundTaskMgr {
namespace {
static constexpr uint32_t NOTIFICATION_TEXT_MEDIA_PROCESS_INDEX = 1;
static constexpr uint32_t NOTIFICATION_TEXT_VIDEO_BROADCAST_INDEX = 2;
static constexpr uint32_t NOTIFICATION_TEXT_WORK_OUT_INDEX = 3;
static constexpr uint32_t BGMODE_AUDIO_PLAYBACK = 2;
static constexpr uint32_t BGMODE_AUDIO_RECORDING = 4;
static constexpr uint32_t BGMODE_VOIP = 128;
static constexpr char BANNER_NOTIFICATION_PREFIX[] = "bgbanner";
static constexpr int32_t BGTASK_BANNER_NOTIFICATION_BTN_ALLOW_TIME = 0;
static constexpr int32_t BGTASK_BANNER_NOTIFICATION_BTN_ALLOW_ALLOWED = 1;
static constexpr char BGTASK_BANNER_NOTIFICATION_ACTION_NAME[] = "bgtask_banner_notification_action_name";
static constexpr char BGTASK_BANNER_NOTIFICATION_ACTION_PARAM_BTN[] = "bgtask_banner_notificaiton_action_param_btn";
static constexpr char BGTASK_BANNER_NOTIFICATION_ACTION_PARAM_UID[] = "bgtask_banner_notificaiton_action_param_uid";
static constexpr char BGTASK_BANNER_NOTIFICATION_ACTION_LABEL[] = "bgtask_banner_notificaiton_action_label";
static constexpr uint32_t SUBSCRIBER_BACKGROUND_TASK_STATE = 1 << 3;
static constexpr char BGTASK_AUTH_DIALOG_EVENT_NAME[] = "OnBgTaskServiceDialogClicked";
static constexpr char BGTASK_BUNDLE_NAME[] = "com.ohos.backgroundtaskmgr.resources";
}
class CommonUtils {
public:
static bool CheckJsonValue(const nlohmann::json &value, std::initializer_list<std::string> params);
static bool CheckExistMode(const std::vector<uint32_t> &bgModeIds, uint32_t bgMode);
static bool CheckExistNotification(const std::vector<int32_t> ¬ificationIds, const int32_t notificationId);
static bool CheckModesSame(const std::vector<uint32_t> &oldBgModeIds, const std::vector<uint32_t> &newBgModeIds);
static std::string ModesToString(const std::vector<uint32_t> &bgmodes);
static bool CheckApplyMode(const std::vector<uint32_t> &applyBgModeIds,
const std::vector<uint32_t> &checkBgModeIds);
static bool CheckExistOtherMode(const std::vector<uint32_t> &bgModeIds, uint32_t bgMode,
const std::set<uint32_t> &liveViewTypes);
static bool CheckStrToNum(const std::string &value);
static void SortMode(std::vector<uint32_t> &bgModeIds);
public:
static constexpr int32_t jsonFormat_ = 4;
};
}
}
#endif