mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 14:30:21 +00:00
add remote stop extension code
Signed-off-by: xinking129 <xinxin13@huawei.com>
This commit is contained in:
parent
28414a493d
commit
2fffa973db
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -125,6 +125,12 @@ public:
|
||||
const std::string& remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo& formShareInfo) = 0;
|
||||
#endif
|
||||
virtual int32_t GetDistributedComponentList(std::vector<std::string>& distributedComponents) = 0;
|
||||
|
||||
virtual int32_t StopRemoteExtensionAbility(
|
||||
const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType) = 0;
|
||||
virtual int32_t StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
|
||||
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType) = 0;
|
||||
|
||||
enum {
|
||||
START_REMOTE_ABILITY = 1,
|
||||
STOP_REMOTE_ABILITY = 3,
|
||||
@ -181,6 +187,10 @@ public:
|
||||
// form share
|
||||
START_REMOTE_SHARE_FORM = 220,
|
||||
START_SHARE_FORM_FROM_REMOTE = 221,
|
||||
|
||||
// stop externsion ability
|
||||
STOP_REMOTE_EXTERNSION_ABILITY = 225,
|
||||
STOP_EXTERNSION_ABILITY_REMOTE = 226,
|
||||
};
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -86,6 +86,10 @@ public:
|
||||
const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo) override;
|
||||
#endif
|
||||
int32_t GetDistributedComponentList(std::vector<std::string>& distributedComponents) override;
|
||||
virtual int32_t StopRemoteExtensionAbility(
|
||||
const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType) override;
|
||||
virtual int32_t StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
|
||||
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType) override;
|
||||
private:
|
||||
bool CallerInfoMarshalling(const CallerInfo& callerInfo, MessageParcel& data);
|
||||
static inline BrokerDelegator<DistributedSchedProxy> delegator_;
|
||||
|
@ -143,6 +143,10 @@ public:
|
||||
void SetContinuationTimeout(int32_t missionId, int32_t timeout);
|
||||
void RemoveContinuationTimeout(int32_t missionId);
|
||||
std::string GetContinuaitonDevice(int32_t missionId);
|
||||
int32_t StopRemoteExtensionAbility(const OHOS::AAFwk::Want& want, int32_t callerUid,
|
||||
uint32_t accessToken, int32_t extensionType) override;
|
||||
int32_t StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& remoteWant, const CallerInfo& callerInfo,
|
||||
const AccountInfo& accountInfo, int32_t extensionType) override;
|
||||
private:
|
||||
DistributedSchedService();
|
||||
bool Init();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -72,6 +72,10 @@ private:
|
||||
bool EnforceInterfaceToken(MessageParcel& data);
|
||||
bool CallerInfoUnmarshalling(CallerInfo& callerInfo, MessageParcel& data);
|
||||
void SaveExtraInfo(const nlohmann::json& extraInfoJson, CallerInfo& callerInfo);
|
||||
void InitCallBackInnerFirst();
|
||||
|
||||
int32_t StopRemoteExtensionAbilityInner(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t StopExtensionAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);
|
||||
|
||||
using DistributedSchedFunc = int32_t(DistributedSchedStub::*)(MessageParcel& data, MessageParcel& reply);
|
||||
std::map<uint32_t, DistributedSchedFunc> remoteFuncsMap_;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -866,6 +866,55 @@ int32_t DistributedSchedProxy::GetDistributedComponentList(std::vector<std::stri
|
||||
PARCEL_READ_HELPER(reply, StringVector, &distributedComponents);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
int32_t DistributedSchedProxy::StopRemoteExtensionAbility(
|
||||
const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
HILOGE("StopRemoteExtensionAbility remote service null");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
|
||||
HILOGE("StopRemoteExtensionAbility WriteInterfaceToken failed");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
PARCEL_WRITE_HELPER(data, Parcelable, &want);
|
||||
PARCEL_WRITE_HELPER(data, Int32, callerUid);
|
||||
PARCEL_WRITE_HELPER(data, Uint32, accessToken);
|
||||
PARCEL_WRITE_HELPER(data, Int32, extensionType);
|
||||
MessageParcel reply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, STOP_REMOTE_EXTERNSION_ABILITY, data, reply);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedProxy::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
|
||||
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
HILOGE("StopExtensionAbilityFromRemote remote service null");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
|
||||
HILOGE("StopExtensionAbilityFromRemote WriteInterfaceToken failed");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
PARCEL_WRITE_HELPER(data, Parcelable, &want);
|
||||
PARCEL_WRITE_HELPER(data, Int32, extensionType);
|
||||
PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
|
||||
PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
|
||||
PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
|
||||
PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
|
||||
PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
|
||||
nlohmann::json extraInfoJson;
|
||||
extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
|
||||
std::string extraInfo = extraInfoJson.dump();
|
||||
PARCEL_WRITE_HELPER(data, String, extraInfo);
|
||||
MessageParcel reply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, STOP_EXTERNSION_ABILITY_REMOTE, data, reply);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -2052,5 +2052,66 @@ int32_t DistributedSchedService::CheckTargetPermission(const OHOS::AAFwk::Want&
|
||||
HILOGE("CheckTargetPermission denied!!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
int32_t DistributedSchedService::StopRemoteExtensionAbility(const OHOS::AAFwk::Want& want, int32_t callerUid,
|
||||
uint32_t accessToken, int32_t extensionType)
|
||||
{
|
||||
std::string localDeviceId;
|
||||
std::string deviceId = want.GetDeviceId();
|
||||
if(!GetLocalDeviceId(localDeviceId) || !CheckDeviceId(localDeviceId, deviceId)) {
|
||||
HILOGE("CheckDeviceId failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
sptr<IDistributedSched> remoteDms = GetRemoteDms(deviceId);
|
||||
if(remoteDms == nullptr) {
|
||||
HILOGE("GetRemoteDms failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
CallerInfo callerInfo;
|
||||
callerInfo.sourceDeviceId = localDeviceId;
|
||||
callerInfo.uid = callerUid;
|
||||
callerInfo.accessToken = accessToken;
|
||||
if(!BundleManagerInternal::GetCallerAppIdFromBms(callerInfo.uid, callerInfo.callerAppId)) {
|
||||
HILOGE("GetCallerAppIdFromBms failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
if(!BundleManagerInternal::GetBundleNameListFromBms(callerInfo.uid, callerInfo.bundleNames)) {
|
||||
HILOGE("GetBundleNameListFromBms failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
AccountInfo accountInfo = {};
|
||||
if ((DistributedSchedPermission::GetInstance().GetAccountInfo(deviceId, callerInfo, accountInfo)) != ERR_OK) {
|
||||
HILOGE("GetAccountInfo failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
AAFwk::Want remoteWant = want;
|
||||
remoteWant.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
|
||||
return remoteDms->StopExtensionAbilityFromRemote(remoteWant, callerInfo, accountInfo, extensionType);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedService::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& remoteWant,
|
||||
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType)
|
||||
{
|
||||
std::string deviceId = remoteWant.GetElement().GetDeviceID();
|
||||
std::string localDeviceId;
|
||||
std::string destinationDeviceId = remoteWant.GetElement().GetDeviceID();
|
||||
if (!GetLocalDeviceId(localDeviceId) ||
|
||||
!CheckDeviceIdFromRemote(localDeviceId, destinationDeviceId, callerInfo.sourceDeviceId)) {
|
||||
HILOGE("check deviceId failed");
|
||||
return INVALID_REMOTE_PARAMETERS_ERR;
|
||||
}
|
||||
|
||||
int32_t permissionValid = CheckTargetPermission(remoteWant, callerInfo, accountInfo, CALL_PERMISSION, true);
|
||||
if (permissionValid != ERR_OK) {
|
||||
HILOGE("CheckTargetPermission failed!!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
Want want = remoteWant;
|
||||
want.RemoveParam(DMS_SRC_NETWORK_ID);
|
||||
sptr<IRemoteObject> callerToken = new DmsTokenCallback();
|
||||
|
||||
return AAFwk::AbilityManagerClient::GetInstance()->StopExtensionAbility(
|
||||
want, callerToken, callerInfo.uid, static_cast<AppExecFwk::ExtensionAbilityType>(extensionType));
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -103,6 +103,7 @@ DistributedSchedStub::DistributedSchedStub()
|
||||
remoteFuncsMap_[START_FREE_INSTALL_FROM_REMOTE] = &DistributedSchedStub::StartFreeInstallFromRemoteInner;
|
||||
remoteFuncsMap_[NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE] =
|
||||
&DistributedSchedStub::NotifyCompleteFreeInstallFromRemoteInner;
|
||||
InitCallBackInnerFirst();
|
||||
}
|
||||
|
||||
DistributedSchedStub::~DistributedSchedStub()
|
||||
@ -111,6 +112,14 @@ DistributedSchedStub::~DistributedSchedStub()
|
||||
localFuncsMap_.clear();
|
||||
}
|
||||
|
||||
void DistributedSchedStub::InitCallBackInnerFirst()
|
||||
{
|
||||
localFuncsMap_[STOP_REMOTE_EXTERNSION_ABILITY] =
|
||||
&DistributedSchedStub::StopRemoteExtensionAbilityInner;
|
||||
remoteFuncsMap_[STOP_EXTERNSION_ABILITY_REMOTE] =
|
||||
&DistributedSchedStub::StopExtensionAbilityFromRemoteInner;
|
||||
}
|
||||
|
||||
int32_t DistributedSchedStub::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
@ -1030,5 +1039,70 @@ int32_t DistributedSchedStub::NotifyCompleteFreeInstallFromRemoteInner(MessagePa
|
||||
HILOGI("result = %{public}d", result);
|
||||
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedStub::StopRemoteExtensionAbilityInner(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
|
||||
HILOGW("request DENIED!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
|
||||
if (want == nullptr) {
|
||||
HILOGW("Stop reomte extension ability want readParcelable failed!");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
int32_t callerUid = 0;
|
||||
PARCEL_READ_HELPER(data, Int32, callerUid);
|
||||
uint32_t accessToken = 0;
|
||||
PARCEL_READ_HELPER(data, Uint32, accessToken);
|
||||
int32_t serviceType = static_cast<int32_t>(AppExecFwk::ExtensionAbilityType::SERVICE);
|
||||
PARCEL_READ_HELPER(data, Int32, serviceType);
|
||||
HILOGD("get callerUid = %{private}d, AccessTokenID = %{private}u", callerUid, accessToken);
|
||||
if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
|
||||
PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
|
||||
HILOGE("check data_sync permission failed!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
auto result = StopRemoteExtensionAbility(*want, callerUid, accessToken, serviceType);
|
||||
HILOGD("StartRemoteAbilityInner result = %{public}d", result);
|
||||
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedStub::StopExtensionAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
if (!CheckCallingUid()) {
|
||||
HILOGW("request DENIED!");
|
||||
return DMS_PERMISSION_DENIED;
|
||||
}
|
||||
shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
|
||||
if (want == nullptr) {
|
||||
HILOGW("want readParcelable failed!");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
int32_t serviceType = static_cast<int32_t>(AppExecFwk::ExtensionAbilityType::SERVICE);
|
||||
PARCEL_READ_HELPER(data, Int32, serviceType);
|
||||
CallerInfo callerInfo;
|
||||
PARCEL_READ_HELPER(data, Int32, callerInfo.uid);
|
||||
PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
|
||||
callerInfo.callerType = CALLER_TYPE_HARMONY;
|
||||
AccountInfo accountInfo;
|
||||
accountInfo.accountType = data.ReadInt32();
|
||||
PARCEL_READ_HELPER(data, StringVector, &accountInfo.groupIdList);
|
||||
callerInfo.callerAppId = data.ReadString();
|
||||
std::string extraInfo = data.ReadString();
|
||||
if (extraInfo.empty()) {
|
||||
HILOGD("extra info is empty!");
|
||||
}
|
||||
nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
|
||||
if (!extraInfoJson.is_discarded()) {
|
||||
uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
|
||||
callerInfo.accessToken = accessToken;
|
||||
HILOGD("parse extra info, accessTokenID = %{private}u", accessToken);
|
||||
}
|
||||
auto result = StopExtensionAbilityFromRemote(*want, callerInfo, accountInfo, serviceType);
|
||||
HILOGD("result = %{public}d", result);
|
||||
PARCEL_WRITE_HELPER(reply, Int32, result);
|
||||
return ERR_NONE;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -212,5 +212,15 @@ int32_t MockDistributedSched::StartShareFormFromRemote(
|
||||
return ERR_NONE;
|
||||
}
|
||||
#endif
|
||||
int32_t MockDistributedSched::StopRemoteExtensionAbility(
|
||||
const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType)
|
||||
{
|
||||
return ERR_NONE;
|
||||
}
|
||||
int32_t MockDistributedSched::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
|
||||
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType)
|
||||
{
|
||||
return ERR_NONE;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -85,6 +85,10 @@ public:
|
||||
int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override;
|
||||
int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override;
|
||||
int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode);
|
||||
int32_t StopRemoteExtensionAbility(
|
||||
const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType) override;
|
||||
int32_t StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
|
||||
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType) override;
|
||||
private:
|
||||
bool expectedTrue_ = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user