!258 添加全局任务中心接口

Merge pull request !258 from 曦阳/majiajun
This commit is contained in:
openharmony_ci 2022-01-08 10:22:00 +00:00 committed by Gitee
commit c214543d2f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
17 changed files with 290 additions and 10 deletions

View File

@ -196,6 +196,16 @@ public:
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
enum RequestCode {
E_STATE_INITIAL = 0,
E_STATE_INACTIVE,

View File

@ -163,6 +163,16 @@ public:
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
AbilityLifeCycleState curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL;
sptr<IAbilityScheduler> abilityScheduler_; // kit interface used to schedule ability life
Want want_;

View File

@ -180,6 +180,14 @@ public:
{
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
sptr<IAbilityScheduler> abilityScheduler_ = nullptr; // kit interface used to schedule ability life
Want want_;

View File

@ -556,6 +556,21 @@ public:
*/
ErrCode MoveMissionToFront(int32_t missionId);
/**
* Start synchronizing remote device mission
* @param devId, deviceId.
* @param fixConflict, resolve synchronizing conflicts flag.
* @param tag, call tag.
* @return Returns ERR_OK on success, others on failure.
*/
ErrCode StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag);
/**
* Stop synchronizing remote device mission
* @param devId, deviceId.
* @return Returns ERR_OK on success, others on failure.
*/
ErrCode StopSyncRemoteMissions(const std::string& devId);
private:
static std::mutex mutex_;
static std::shared_ptr<AbilityManagerClient> instance_;

View File

@ -532,6 +532,22 @@ public:
virtual int StopUser(int userId, const sptr<IStopUserCallback> &callback) = 0;
/**
* Start synchronizing remote device mission
* @param devId, deviceId.
* @param fixConflict, resolve synchronizing conflicts flag.
* @param tag, call tag.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) = 0;
/**
* Stop synchronizing remote device mission
* @param devId, deviceId.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int StopSyncRemoteMissions(const std::string& devId) = 0;
enum {
// ipc id 1-1000 for kit
// ipc id for terminating ability (1)
@ -741,6 +757,12 @@ public:
NOTIFY_CONTINUATION_RESULT = 1102,
// ipc id for mission manager(1110)
REGISTER_REMOTE_MISSION_LISTENER = 1110,
UNREGISTER_REMOTE_MISSION_LISTENER = 1111,
START_SYNC_MISSIONS = 1112,
STOP_SYNC_MISSIONS = 1113,
// ipc id 2001-3000 for tools
// ipc id for dumping state (2001)
DUMP_STATE = 2001,

View File

@ -490,6 +490,10 @@ public:
virtual int NotifyContinuationResult(const sptr<IRemoteObject> &abilityToken, const int32_t result) override;
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override;
virtual int StopSyncRemoteMissions(const std::string& devId) override;
virtual int LockMissionForCleanup(int32_t missionId) override;
virtual int UnlockMissionForCleanup(int32_t missionId) override;

View File

@ -583,6 +583,10 @@ public:
virtual int MoveMissionToFront(int32_t missionId) override;
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override;
virtual int StopSyncRemoteMissions(const std::string& devId) override;
/**
* Get system memory information.
* @param SystemMemoryAttr, memory information.
@ -783,6 +787,10 @@ private:
void RequestPermission(const Want *resultWant);
bool CheckIsRemote(const std::string& deviceId);
int GetRemoteMissionInfos(const std::string& deviceId, int32_t numMax,
std::vector<MissionInfo> &missionInfos);
int GetRemoteMissionInfo(const std::string& deviceId, int32_t missionId,
MissionInfo &missionInfo);
void DumpInner(const std::string &args, std::vector<std::string> &info);
void DumpStackListInner(const std::string &args, std::vector<std::string> &info);

View File

@ -121,6 +121,9 @@ private:
int StartUserInner(MessageParcel &data, MessageParcel &reply);
int StopUserInner(MessageParcel &data, MessageParcel &reply);
int StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply);
int StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply);
using RequestFuncType = int (AbilityManagerStub::*)(MessageParcel &data, MessageParcel &reply);
std::map<uint32_t, RequestFuncType> requestFuncMap_;
};

View File

@ -722,5 +722,31 @@ ErrCode AbilityManagerClient::MoveMissionToFront(int32_t missionId)
sptr<IAbilityManager> abms = iface_cast<IAbilityManager>(remoteObject_);
return abms->MoveMissionToFront(missionId);
}
/**
* Start synchronizing remote device mission
* @param devId, deviceId.
* @param fixConflict, resolve synchronizing conflicts flag.
* @param tag, call tag.
* @return Returns ERR_OK on success, others on failure.
*/
ErrCode AbilityManagerClient::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
{
CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED);
auto abms = iface_cast<IAbilityManager>(remoteObject_);
return abms->StartSyncRemoteMissions(devId, fixConflict, tag);
}
/**
* Stop synchronizing remote device mission
* @param devId, deviceId.
* @return Returns ERR_OK on success, others on failure.
*/
ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string& devId)
{
CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED);
auto abms = iface_cast<IAbilityManager>(remoteObject_);
return abms->StopSyncRemoteMissions(devId);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -1830,5 +1830,62 @@ int AbilityManagerProxy::StopUser(int userId, const sptr<IStopUserCallback> &cal
}
return reply.ReadInt32();
}
int AbilityManagerProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
{
HILOG_INFO("called");
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("WriteInterfaceToken faild");
return ERR_INVALID_VALUE;
}
if (!data.WriteString(devId)) {
HILOG_ERROR("write deviceId fail.");
return ERR_INVALID_VALUE;
}
if (!data.WriteBool(fixConflict)) {
HILOG_ERROR("WriteBool fail.");
return ERR_INVALID_VALUE;
}
if (!data.WriteInt64(tag)) {
HILOG_ERROR("WriteInt64 fail.");
return ERR_INVALID_VALUE;
}
auto error = Remote()->SendRequest(IAbilityManager::START_SYNC_MISSIONS, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Send request error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
int32_t AbilityManagerProxy::StopSyncRemoteMissions(const std::string& devId)
{
HILOG_INFO("called");
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("WriteInterfaceToken faild");
return ERR_INVALID_VALUE;
}
if (!data.WriteString(devId)) {
HILOG_ERROR("write deviceId fail.");
return ERR_INVALID_VALUE;
}
auto error = Remote()->SendRequest(IAbilityManager::STOP_SYNC_MISSIONS, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Send request error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
} // namespace AAFwk
} // namespace OHOS
} // namespace OHOS

View File

@ -35,6 +35,7 @@
#include "iservice_registry.h"
#include "locale_config.h"
#include "lock_screen_white_list.h"
#include "mission/mission_info_converter.h"
#include "sa_mgr_client.h"
#include "softbus_bus_center.h"
#include "string_ex.h"
@ -49,6 +50,7 @@ static const int EXPERIENCE_MEM_THRESHOLD = 20;
constexpr auto DATA_ABILITY_START_TIMEOUT = 5s;
constexpr int32_t NON_ANONYMIZE_LENGTH = 6;
const int32_t EXTENSION_SUPPORT_API_VERSION = 8;
const int32_t MAX_NUMBER_OF_DISTRIBUTED_MISSIONS = 20;
const std::string EMPTY_DEVICE_ID = "";
const std::string PKG_NAME = "ohos.distributedhardware.devicemanager";
const std::map<std::string, AbilityManagerService::DumpKey> AbilityManagerService::dumpMap = {
@ -472,10 +474,10 @@ sptr<DistributedSchedule::IDistributedSched> AbilityManagerService::GetDmsProxy(
return nullptr;
}
HILOG_INFO("get dms proxy success.");
sptr<DistributedSchedule::IDistributedSched> iDistributedSchedule =
sptr<DistributedSchedule::IDistributedSched> dmsProxy =
iface_cast<DistributedSchedule::IDistributedSched>(remoteObject);
HILOG_INFO("%{public}s end.", __func__);
return iDistributedSchedule;
return dmsProxy;
}
bool AbilityManagerService::GetLocalDeviceId(std::string& localDeviceId)
@ -854,6 +856,26 @@ int AbilityManagerService::NotifyContinuationResult(const sptr<IRemoteObject> &a
return ERR_OK;
}
int AbilityManagerService::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
{
sptr<DistributedSchedule::IDistributedSched> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOG_ERROR("AbilityManagerService::StartSyncRemoteMissions failed to get dms.");
return ERR_INVALID_VALUE;
}
return dmsProxy->StartSyncRemoteMissions(devId, fixConflict, tag);
}
int AbilityManagerService::StopSyncRemoteMissions(const std::string& devId)
{
sptr<DistributedSchedule::IDistributedSched> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOG_ERROR("AbilityManagerService::StopSyncRemoteMissions failed to get dms.");
return ERR_INVALID_VALUE;
}
return dmsProxy->StopSyncRemoteMissions(devId);
}
void AbilityManagerService::RemoveAllServiceRecord()
{
connectManager_->RemoveAll();
@ -1094,13 +1116,30 @@ int AbilityManagerService::GetMissionInfos(const std::string& deviceId, int32_t
}
if (CheckIsRemote(deviceId)) {
HILOG_ERROR("get remote missioninfos not support yet.");
return -1;
return GetRemoteMissionInfos(deviceId, numMax, missionInfos);
}
return currentMissionListManager_->GetMissionInfos(numMax, missionInfos);
}
int AbilityManagerService::GetRemoteMissionInfos(const std::string& deviceId, int32_t numMax,
std::vector<MissionInfo> &missionInfos)
{
HILOG_INFO("GetRemoteMissionInfos begin");
sptr<DistributedSchedule::IDistributedSched> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOG_ERROR("GetRemoteMissionInfos failed to get dms.");
return ERR_INVALID_VALUE;
}
std::vector<DistributedSchedule::DstbMissionInfo> dstbMissionInfos;
int result = dmsProxy->GetMissionInfos(deviceId, numMax, dstbMissionInfos);
if (result != ERR_OK) {
HILOG_ERROR("GetRemoteMissionInfos failed, result = %{public}d", result);
return result;
}
return DistributedSchedule::MissionInfoConverter::ConvertToMissionInfos(dstbMissionInfos, missionInfos);
}
int AbilityManagerService::GetMissionInfo(const std::string& deviceId, int32_t missionId,
MissionInfo &missionInfo)
{
@ -1114,13 +1153,31 @@ int AbilityManagerService::GetMissionInfo(const std::string& deviceId, int32_t m
}
if (CheckIsRemote(deviceId)) {
HILOG_ERROR("get remote mission not support yet.");
return -1;
return GetRemoteMissionInfo(deviceId, missionId, missionInfo);
}
return currentMissionListManager_->GetMissionInfo(missionId, missionInfo);
}
int AbilityManagerService::GetRemoteMissionInfo(const std::string& deviceId, int32_t missionId,
MissionInfo &missionInfo)
{
HILOG_INFO("GetMissionInfoFromDms begin");
std::vector<MissionInfo> missionVector;
int result = GetRemoteMissionInfos(deviceId, MAX_NUMBER_OF_DISTRIBUTED_MISSIONS, missionVector);
if (result != ERR_OK) {
return result;
}
for (auto iter = missionVector.begin(); iter != missionVector.end(); iter++) {
if (iter->id == missionId) {
missionInfo = *iter;
return ERR_OK;
}
}
HILOG_WARN("missionId not found");
return ERR_INVALID_VALUE;
}
int AbilityManagerService::CleanMission(int32_t missionId)
{
HILOG_INFO("request CleanMission, missionId:%{public}d", missionId);

View File

@ -1077,5 +1077,28 @@ int AbilityManagerStub::StopUserInner(MessageParcel &data, MessageParcel &reply)
}
return NO_ERROR;
}
int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply)
{
std::string deviceId = data.ReadString();
bool fixConflict = data.ReadBool();
int64_t tag = data.ReadInt64();
int result = StartSyncRemoteMissions(deviceId, fixConflict, tag);
if (!reply.WriteInt32(result)) {
HILOG_ERROR("StartSyncRemoteMissionsInner failed.");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}
int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply)
{
int result = StopSyncRemoteMissions(data.ReadString());
if (!reply.WriteInt32(result)) {
HILOG_ERROR("StopSyncRemoteMissionsInner failed.");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -308,7 +308,14 @@ public:
{
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr<IRemoteObject> &callerToken, int requestCode));
MOCK_METHOD3(StartAbility, int(const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode));
MOCK_METHOD2(

View File

@ -351,6 +351,14 @@ public:
{
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -106,6 +106,14 @@ public:
{
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -114,7 +114,14 @@ public:
{
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
void Wait()
{
sem_.Wait();

View File

@ -139,7 +139,14 @@ public:
{
return 0;
}
virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
{
return 0;
}
virtual int StopSyncRemoteMissions(const std::string& devId) override
{
return 0;
}
public:
std::string powerState_;
};