!912 应用协同适配器

Merge pull request !912 from 仝月姣/master
This commit is contained in:
openharmony_ci 2024-06-02 09:45:38 +00:00 committed by Gitee
commit bbcc53bd1f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
17 changed files with 699 additions and 92 deletions

View File

@ -24,6 +24,7 @@ ohos_shared_library("distributed_sched_utils") {
include_dirs = [
"${dms_path}/common/include",
"${dms_path}/interfaces/innerkits/common/include",
"${dms_path}/services/dtbschedmgr/include",
]

View File

@ -13,9 +13,11 @@
* limitations under the License.
*/
#ifndef OHOS_DMS_UTILS_H
#define OHOS_DMS_UTILS_H
#ifndef OHOS_DISTRIBUTED_SCHED_UTILS_H
#define OHOS_DISTRIBUTED_SCHED_UTILS_H
#include "cJSON.h"
#include <initializer_list>
#include <string>
#include "parcel.h"
@ -36,6 +38,10 @@ std::string Base64Encode(const unsigned char *toEncode, unsigned int len);
std::string Base64Decode(const std::string& basicString);
bool IsBase64(unsigned char c);
std::string GetAnonymStr(const std::string &value);
bool IsInt32(const cJSON *paramValue);
bool IsString(const cJSON *paramValue);
bool CJsonParamCheck(const cJSON *jsonObj, const std::initializer_list<std::string> &keys);
bool GetOsInfoFromDM(const std::string &dmInfoEx, int32_t &osType, std::string &osVersion);
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_SCHED_SERVICE_H
#endif // OHOS_DISTRIBUTED_SCHED_UTILS_H

View File

@ -21,15 +21,17 @@
#include <fstream>
#include <iostream>
#include <vector>
#include "cJSON.h"
#include "ability_manager_client.h"
#include "config_policy_utils.h"
#include "dms_constant.h"
#include "dtbschedmgr_log.h"
namespace OHOS {
namespace DistributedSchedule {
using namespace OHOS::DistributedSchedule::Constants;
const std::string TAG = "DistributedSchedUtils";
const std::string CONTINUE_CONFIG_RELATIVE_PATH = "etc/distributedhardware/dms/continue_config.json";
const std::string ALLOW_APP_LIST_KEY = "allow_applist";
@ -57,6 +59,12 @@ static std::string g_continueCfgFullPath = "";
static std::vector<std::string> g_allowAppList;
std::mutex g_allowAppListMtx;
using JsonTypeCheckFunc = bool (*)(const cJSON *paramValue);
std::map<std::string, JsonTypeCheckFunc> jsonTypeCheckMap = {
std::map<std::string, JsonTypeCheckFunc>::value_type(PARAM_KEY_OS_TYPE, &DistributedSchedule::IsInt32),
std::map<std::string, JsonTypeCheckFunc>::value_type(PARAM_KEY_OS_VERSION, &DistributedSchedule::IsString),
};
bool IsValidPath(const std::string &inFilePath, std::string &realFilePath)
{
char path[PATH_MAX + 1] = { 0 };
@ -350,5 +358,95 @@ std::string GetAnonymStr(const std::string &value)
return res;
}
bool IsInt32(const cJSON *paramValue)
{
if (paramValue == nullptr || !cJSON_IsObject(paramValue)) {
HILOGE("JSON parameter is invalid.");
return false;
}
if (!cJSON_IsNumber(paramValue)) {
HILOGE("JSON parameter is not number.");
return false;
}
int32_t value = paramValue->valueint;
if (!(INT32_MIN <= value && value <= INT32_MAX)) {
HILOGE("JSON parameter number is outside the int32_t range.");
return false;
}
return true;
}
bool IsString(const cJSON *paramValue)
{
if (paramValue == nullptr || !cJSON_IsObject(paramValue)) {
HILOGE("JSON parameter is invalid.");
return false;
}
if (cJSON_IsString(paramValue)) {
HILOGE("JSON parameter is not string.");
return false;
}
return true;
}
bool CJsonParamCheck(const cJSON *jsonObj, const std::initializer_list<std::string> &keys)
{
if (jsonObj == nullptr || !cJSON_IsObject(jsonObj)) {
HILOGE("JSON parameter is invalid.");
return false;
}
for (auto it = keys.begin(); it != keys.end(); it++) {
cJSON *paramValue = cJSON_GetObjectItemCaseSensitive(jsonObj, (*it).c_str());
if (paramValue == nullptr) {
HILOGE("JSON parameter does not contain key: %{public}s", (*it).c_str());
return false;
}
auto iter = jsonTypeCheckMap.find(*it);
if (iter == jsonTypeCheckMap.end()) {
HILOGE("Check is not supported yet, key %{public}s.", (*it).c_str());
return false;
}
JsonTypeCheckFunc &func = iter->second;
bool res = (*func)(paramValue);
if (!res) {
HILOGE("The key %{public}s value format in JSON is illegal.", (*it).c_str());
return false;
}
}
return true;
}
bool GetOsInfoFromDM(const std::string &dmInfoEx, int32_t &osType, std::string &osVersion)
{
cJSON *dataJson = nullptr;
bool isSuccess = false;
do {
dataJson = cJSON_Parse(dmInfoEx.c_str());
if (dataJson == nullptr) {
HILOGE("Parse device info extra data to json fail.");
break;
}
if (!CJsonParamCheck(dataJson, {PARAM_KEY_OS_TYPE, PARAM_KEY_OS_VERSION})) {
HILOGE("Check OS type and version from device extra data json fail.");
break;
}
osType = cJSON_GetObjectItemCaseSensitive(dataJson, PARAM_KEY_OS_TYPE)->valueint;
osVersion = std::string(cJSON_GetObjectItemCaseSensitive(dataJson, PARAM_KEY_OS_VERSION)->valuestring);
isSuccess = true;
} while (false);
if (dataJson != nullptr) {
cJSON_Delete(dataJson);
dataJson = nullptr;
}
return isSuccess;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -13,12 +13,17 @@
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_DMS_CONSTANT_H
#define OHOS_DISTRIBUTED_DMS_CONSTANT_H
#ifndef OHOS_DMS_CONSTANT_H
#define OHOS_DMS_CONSTANT_H
namespace OHOS {
namespace DistributedSchedule {
namespace Constants {
constexpr int32_t OH_OS_TYPE = 10;
constexpr int32_t HO_OS_TYPE = 11;
constexpr const char* PARAM_KEY_OS_TYPE = "OS_TYPE";
constexpr const char* PARAM_KEY_OS_VERSION = "OS_VERSION";
constexpr const char* DMS_NAME = "dmsfwk";
constexpr const char* DMS_VERSION = "5.0.0";
constexpr const char* DMS_SERVICE_ID = "dmsfwk_svr_id";
@ -29,4 +34,4 @@ constexpr const char* DMS_SERVICE_TYPE = "appInfo";
} // Constants
} // DistributedSchedule
} // OHOS
#endif
#endif // OHOS_DMS_CONSTANT_H

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 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 OHOS_IDMS_INTERACTIVE_ADAPTER_H
#define OHOS_IDMS_INTERACTIVE_ADAPTER_H
#include <string>
#include "caller_info.h"
#include "message_parcel.h"
#include "want.h"
namespace OHOS {
namespace DistributedSchedule {
typedef struct {
int32_t (*StartRemoteAbilityAdapter)(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
uint32_t accessToken);
int32_t (*StartAbilityFromRemoteAdapter)(MessageParcel& data, MessageParcel& reply);
int32_t (*StopAbilityFromRemoteAdapter)(MessageParcel& data, MessageParcel& reply);
int32_t (*ConnectRemoteAbilityAdapter)(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
int32_t callerUid, int32_t callerPid, uint32_t accessToken);
int32_t (*ConnectAbilityFromRemoteAdapter)(MessageParcel& data, MessageParcel& reply);
int32_t (*DisconnectRemoteAbilityAdapter)(const sptr<IRemoteObject>& connect, int32_t callerUid,
uint32_t accessToken);
int32_t (*DisconnectAbilityFromRemoteAdapter)(MessageParcel& data, MessageParcel& reply);
int32_t (*NotifyAbilityLifecycleChangedFromRemoteAdapter)(MessageParcel& data, MessageParcel& reply);
} IDmsInteractiveAdapter;
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_IDMS_INTERACTIVE_ADAPTER_H

View File

@ -12,13 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DMS_STATIC_CAPABILITY_H
#define DMS_STATIC_CAPABILITY_H
#include "single_instance.h"
#include "i_static_capability_collector.h"
#ifndef API_EXPORT
#define API_EXPORT __attribute__((visibility("default")))
#endif

View File

@ -74,7 +74,10 @@ ohos_shared_library("distributedschedsvr") {
install_enable = true
if (!dmsfwk_softbus_adapter_common) {
cflags = [ "-DDMSFWK_SAME_ACCOUNT" ]
cflags = [
"-DDMSFWK_SAME_ACCOUNT",
"-DDMSFWK_INTERACTIVE_ADAPTER",
]
}
sources = [

View File

@ -21,6 +21,8 @@
#include "parcel.h"
#include "dms_constant.h"
namespace OHOS {
namespace DistributedSchedule {
enum {
@ -35,15 +37,18 @@ enum {
class DmsDeviceInfo : public Parcelable {
public:
DmsDeviceInfo(const std::string& deviceName, int32_t deviceType,
const std::string& networkId, int32_t deviceState = ONLINE)
: deviceName_(deviceName), deviceType_(deviceType), networkId_(networkId), deviceState_(deviceState) {}
DmsDeviceInfo(const std::string& deviceName, int32_t deviceType, const std::string& networkId,
int32_t deviceState = ONLINE, int32_t osType = Constants::OH_OS_TYPE, std::string osVersion = "")
: deviceName_(deviceName), deviceType_(deviceType), networkId_(networkId), deviceState_(deviceState),
osType_(osType), osVersion_(osVersion) {}
~DmsDeviceInfo() = default;
const std::string& GetDeviceName() const;
const std::string& GetNetworkId() const;
int32_t GetDeviceType() const;
int32_t GetDeviceState() const;
int32_t GetDeviceOSType() const;
const std::string& GetGetDeviceOSVersion() const;
bool Marshalling(Parcel& parcel) const override;
private:
@ -51,6 +56,8 @@ private:
int32_t deviceType_ = UNKNOWN_TYPE;
std::string networkId_;
int32_t deviceState_ = UNKNOWN_STATE;
int32_t osType_ = Constants::OH_OS_TYPE;
std::string osVersion_ = "";
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -21,6 +21,13 @@
#include <set>
#include <unordered_map>
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
#include "form_mgr_interface.h"
#endif
#include "iremote_object.h"
#include "iremote_proxy.h"
#include "system_ability.h"
#include "app_mgr_interface.h"
#include "app_state_observer.h"
#include "datashare_manager.h"
@ -28,17 +35,12 @@
#include "distributed_sched_continuation.h"
#include "dms_callback_task.h"
#include "dsched_collaborate_callback_mgr.h"
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
#include "form_mgr_interface.h"
#endif
#include "iremote_object.h"
#include "iremote_proxy.h"
#include "idms_interactive_adapter.h"
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
#include "mission/distributed_mission_info.h"
#include "nocopyable.h"
#endif
#include "single_instance.h"
#include "system_ability.h"
namespace OHOS {
namespace DistributedSchedule {
@ -196,10 +198,21 @@ public:
const AccountInfo& accountInfo, int32_t flag, bool needQueryExtension);
ErrCode QueryOsAccount(int32_t& activeAccountId);
#ifdef DMSFWK_INTERACTIVE_ADAPTER
bool CheckRemoteOsType(const std::string& netwokId) override;
int32_t StartAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
int32_t StopAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
int32_t ConnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
int32_t DisconnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
int32_t NotifyAbilityLifecycleChangedFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
#endif
private:
DistributedSchedService();
bool Init();
void InitCommonEventListener();
int32_t GetCallerInfo(const std::string &localDeviceId, int32_t callerUid, uint32_t accessToken,
CallerInfo &callerInfo);
void RemoteConnectAbilityMappingLocked(const sptr<IRemoteObject>& connect, const std::string& localDeviceId,
const std::string& remoteDeviceId, const AppExecFwk::ElementName& element, const CallerInfo& callerInfo,
TargetComponent targetComponent);
@ -225,7 +238,6 @@ private:
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
sptr<AppExecFwk::IFormMgr> GetFormMgrProxy();
#endif
int32_t CleanMission(int32_t missionId);
int32_t SetCallerInfo(int32_t callerUid, std::string localDeviceId, uint32_t accessToken, CallerInfo& callerInfo);
int32_t SetWantForContinuation(AAFwk::Want& newWant, int32_t missionId);
int32_t ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
@ -277,6 +289,16 @@ private:
DSchedEventState state, int32_t ret);
bool CheckCallingUid();
#ifdef DMSFWK_INTERACTIVE_ADAPTER
int32_t GetDmsInteractiveAdapterProxy();
int32_t StartRemoteAbilityAdapter(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
uint32_t accessToken);
int32_t ConnectRemoteAbilityAdapter(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
int32_t callerUid, int32_t callerPid, uint32_t accessToken);
int32_t DisconnectRemoteAbilityAdapter(const sptr<IRemoteObject>& connect, int32_t callerUid,
uint32_t accessToken);
#endif
private:
std::shared_ptr<DSchedContinuation> dschedContinuation_;
std::shared_ptr<DSchedCollaborationCallbackMgr> collaborateCbMgr_;
@ -308,6 +330,11 @@ private:
std::atomic<int32_t> token_ {0};
std::map<std::string, sptr<AppStateObserver>> bundleNameMap_;
DataShareManager dataShareManager_;
#ifdef DMSFWK_INTERACTIVE_ADAPTER
std::mutex dmsAdapetrLock_;
IDmsInteractiveAdapter dmsAdapetr_;
#endif
};
class ConnectAbilitySession {

View File

@ -31,9 +31,19 @@ public:
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option) override;
#ifdef DMSFWK_INTERACTIVE_ADAPTER
virtual bool CheckRemoteOsType(const std::string& netwokId) = 0;
virtual int32_t StartAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0;
virtual int32_t StopAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0;
virtual int32_t ConnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0;
virtual int32_t DisconnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0;
virtual int32_t NotifyAbilityLifecycleChangedFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0;
#endif
private:
int32_t StartRemoteAbilityInner(MessageParcel& data, MessageParcel& reply);
int32_t StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);
int32_t StopAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);
int32_t SendResultFromRemoteInner(MessageParcel& data, MessageParcel& reply);
int32_t ContinueMissionInner(MessageParcel& data, MessageParcel& reply);
int32_t ContinueMissionOfBundleNameInner(MessageParcel& data, MessageParcel& reply);
@ -44,9 +54,18 @@ private:
int32_t ConnectRemoteAbilityInner(MessageParcel& data, MessageParcel& reply);
int32_t DisconnectRemoteAbilityInner(MessageParcel& data, MessageParcel& reply);
int32_t ConnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);
int32_t ReadDataForConnect(MessageParcel& data, CallerInfo& callerInfo, AccountInfo& accountInfo);
int32_t DisconnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);
int32_t NotifyProcessDiedFromRemoteInner(MessageParcel& data, MessageParcel& reply);
#ifdef DMSFWK_INTERACTIVE_ADAPTER
bool CheckDmsExtensionCallingUid();
int32_t StartAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply);
int32_t StopAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply);
int32_t ConnectAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply);
int32_t DisconnectAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply);
int32_t NotifyAbilityLifecycleChangedFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply);
#endif
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
int32_t GetMissionInfosInner(MessageParcel& data, MessageParcel& reply);
int32_t GetRemoteMissionSnapshotInfoInner(MessageParcel& data, MessageParcel& reply);
@ -92,12 +111,19 @@ private:
void InitLocalFuncsInner();
void InitLocalMissionManagerInner();
void InitRemoteFuncsInner();
std::shared_ptr<AAFwk::Want> ReadDistributedWant(MessageParcel& data);
int32_t GetEncodeDSchedEventNotify(const EventNotify& event, MessageParcel& reply);
int32_t StopRemoteExtensionAbilityInner(MessageParcel& data, MessageParcel& reply);
int32_t StopExtensionAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);
std::shared_ptr<AAFwk::Want> ReadDistributedWant(MessageParcel& data);
int32_t GetEncodeDSchedEventNotify(const EventNotify& event, MessageParcel& reply);
int32_t ReadDataForConnect(MessageParcel& data, CallerInfo& callerInfo, AccountInfo& accountInfo);
int32_t GetStartAbilityFromRemoteExParam(MessageParcel& data, OHOS::AppExecFwk::AbilityInfo& abilityInfo,
int32_t& requestCode, CallerInfo& callerInfo, AccountInfo& accountInfo);
int32_t GetConnectAbilityFromRemoteExParam(MessageParcel& data, AppExecFwk::AbilityInfo& abilityInfo,
sptr<IRemoteObject>& connect, CallerInfo& callerInfo, AccountInfo& accountInfo);
private:
using DistributedSchedFunc = int32_t(DistributedSchedStub::*)(MessageParcel& data, MessageParcel& reply);
std::map<uint32_t, DistributedSchedFunc> remoteFuncsMap_;
std::map<uint32_t, DistributedSchedFunc> localFuncsMap_;

View File

@ -45,6 +45,10 @@ enum class IDSchedInterfaceCode : uint32_t {
START_FREE_INSTALL_FROM_REMOTE = 51,
NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE = 52,
#ifdef DMSFWK_INTERACTIVE_ADAPTER
NOTIFY_ABILITY_LIFECYCLE_CHANGED_FROM_REMOTE = 66,
#endif
// request code for mission
GET_MISSION_INFOS = 80,
REGISTER_MISSION_LISTENER = 84,
@ -73,7 +77,7 @@ enum class IDSchedInterfaceCode : uint32_t {
// request code for upload distributed component info
GET_DISTRIBUTED_COMPONENT_LIST = 161,
START_REMOTE_FREE_INSTALL = 200,
// form share
START_REMOTE_SHARE_FORM = 220,

View File

@ -425,7 +425,7 @@ void DSchedContinue::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
HILOGI("process event %{public}d with state %{public}d", eventId, stateMachine_->GetStateType());
int32_t ret = stateMachine_->Execute(event);
if (ret != ERR_OK) {
HILOGE("event %{public}d excute failed, ret %{public}d", eventId, ret);
HILOGE("event %{public}d execute failed, ret %{public}d", eventId, ret);
OnContinueEnd(ret);
}
return;

View File

@ -43,12 +43,24 @@ int32_t DmsDeviceInfo::GetDeviceState() const
return deviceState_;
}
int32_t DmsDeviceInfo::GetDeviceOSType() const
{
return osType_;
}
const std::string& DmsDeviceInfo::GetGetDeviceOSVersion() const
{
return osVersion_;
}
bool DmsDeviceInfo::Marshalling(Parcel& parcel) const
{
PARCEL_WRITE_HELPER_RET(parcel, String16, Str8ToStr16(networkId_), false);
PARCEL_WRITE_HELPER_RET(parcel, String16, Str8ToStr16(deviceName_), false);
PARCEL_WRITE_HELPER_RET(parcel, Int32, deviceType_, false);
PARCEL_WRITE_HELPER_RET(parcel, Int32, deviceState_, false);
PARCEL_WRITE_HELPER_RET(parcel, Int32, osType_, false);
PARCEL_WRITE_HELPER_RET(parcel, String16, Str8ToStr16(osVersion_), false);
return true;
}
} // namespace DistributedSchedule

View File

@ -19,6 +19,7 @@
#include <string>
#include "deviceManager/dms_device_info.h"
#include "distributed_sched_utils.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "mission/dms_continue_send_manager.h"
@ -30,8 +31,14 @@ const std::string TAG = "DistributedDeviceNodeListener";
}
void DistributedDeviceNodeListener::OnDeviceOnline(const DistributedHardware::DmDeviceInfo& deviceInfo)
{
auto dmsDeviceInfo = std::make_shared<DmsDeviceInfo>(
deviceInfo.deviceName, deviceInfo.deviceTypeId, deviceInfo.networkId);
int32_t osType = Constants::OH_OS_TYPE;
std::string osVersion = "";
if (GetOsInfoFromDM(deviceInfo.extraData, osType, osVersion)) {
HILOGE("Get Os info from DM device info fail, extraData %{public}s.", deviceInfo.extraData.c_str());
}
auto dmsDeviceInfo = std::make_shared<DmsDeviceInfo>(deviceInfo.deviceName, deviceInfo.deviceTypeId,
deviceInfo.networkId, ONLINE, osType, osVersion);
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(dmsDeviceInfo);
DMSContinueSendMgr::GetInstance().NotifyDeviceOnline();
}

View File

@ -17,6 +17,7 @@
#include <algorithm>
#include <cinttypes>
#include <dlfcn.h>
#include <unistd.h>
#include "ability_manager_client.h"
@ -168,6 +169,14 @@ void DistributedSchedService::OnStart()
dschedContinuation_->Init(continuationCallback);
collaborateCbMgr_->Init();
dmsCallbackTask_->Init(freeCallback);
#ifdef DMSFWK_INTERACTIVE_ADAPTER
int32_t ret = GetDmsInteractiveAdapterProxy();
if (ret != ERR_OK) {
HILOGE("Get remote dms interactive adapter proxy fail, ret %{public}d.", ret);
}
#endif
HILOGI("OnStart start service success.");
Publish(this);
}
@ -312,22 +321,190 @@ void DistributedSchedService::DurationStart(const std::string srcDeviceId, const
DmsContinueTime::GetInstance().SetNetWorkId(srcDeviceId, dstDeviceId);
}
int32_t DistributedSchedService::StartRemoteAbility(const OHOS::AAFwk::Want& want,
#ifdef DMSFWK_INTERACTIVE_ADAPTER
bool DistributedSchedService::CheckRemoteOsType(const std::string& netwokId)
{
auto devInfo = DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceInfoById(netwokId);
if (devInfo == nullptr) {
HILOGE("GetDeviceInfoById failed, netwokId: %{public}s.", GetAnonymStr(netwokId).c_str());
return false;
}
HILOGI("Remote device OsType %{public}d, netwokId: %{public}s.", devInfo->GetDeviceOSType(),
GetAnonymStr(netwokId).c_str());
return (devInfo->GetDeviceOSType() == Constants::HO_OS_TYPE);
}
int32_t DistributedSchedService::GetDmsInteractiveAdapterProxy()
{
HILOGI("Get remote dms interactive adapter proxy.");
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
#if (defined(__aarch64__) || defined(__x86_64__))
char resolvedPath[100] = "/system/lib64/libdms_interactive_adapter.z.so";
#else
char resolvedPath[100] = "/system/lib/libdms_interactive_adapter.z.so";
#endif
int32_t (*GetDmsInterActiveAdapetr)(const sptr<IRemoteObject> &callerToken,
IDmsInteractiveAdapter &dmsAdpHandle) = nullptr;
void *dllHandle = dlopen(resolvedPath, RTLD_LAZY);
if (dllHandle == nullptr) {
HILOGE("Open dms interactive adapter shared object fail, resolvedPath [%{public}s].", resolvedPath);
return NOT_FIND_SERVICE_REGISTRY;
}
int32_t ret = ERR_OK;
do {
GetDmsInterActiveAdapetr = reinterpret_cast<int32_t (*)(const sptr<IRemoteObject> &callerToken,
IDmsInteractiveAdapter &dmsAdpHandle)>(dlsym(dllHandle, "GetDmsInterActiveAdapetr"));
if (GetDmsInterActiveAdapetr == nullptr) {
HILOGE("Link the GetDmsInterActiveAdapetr symbol in dms interactive adapter fail.");
ret = NOT_FIND_SERVICE_REGISTRY;
break;
}
int32_t ret = GetDmsInterActiveAdapetr(this, dmsAdapetr_);
if (ret == ERR_OK) {
HILOGE("Init remote dms interactive adapter proxy fail, ret %{public}d.", ret);
ret = INVALID_PARAMETERS_ERR;
break;
}
HILOGI("Init remote dms interactive adapter proxy success.");
ret = ERR_OK;
} while (false);
dlclose(dllHandle);
return ret;
}
int32_t DistributedSchedService::StartRemoteAbilityAdapter(const OHOS::AAFwk::Want& want,
int32_t callerUid, int32_t requestCode, uint32_t accessToken)
{
std::string localDeviceId;
std::string deviceId = want.GetElement().GetDeviceID();
if (!GetLocalDeviceId(localDeviceId) || !CheckDeviceId(localDeviceId, deviceId)) {
HILOGE("check deviceId failed");
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.StartRemoteAbilityAdapter == nullptr) {
HILOGE("Dms interactive start remote ability adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
sptr<IDistributedSched> remoteDms = GetRemoteDms(deviceId);
if (remoteDms == nullptr) {
HILOGE("get remoteDms failed");
int32_t ret = dmsAdapetr_.StartRemoteAbilityAdapter(want, callerUid, requestCode, accessToken);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter start remote ability adapter fail, ret %{public}d.", ret);
}
return ret;
}
int32_t DistributedSchedService::ConnectRemoteAbilityAdapter(const OHOS::AAFwk::Want& want,
const sptr<IRemoteObject>& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken)
{
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.ConnectRemoteAbilityAdapter == nullptr) {
HILOGE("Dms interactive connect remote ability adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
AppExecFwk::AbilityInfo abilityInfo;
CallerInfo callerInfo;
int32_t ret = dmsAdapetr_.ConnectRemoteAbilityAdapter(want, connect, callerUid, callerPid, accessToken);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter connect remote ability adapter fail, ret %{public}d.", ret);
}
return ret;
}
int32_t DistributedSchedService::DisconnectRemoteAbilityAdapter(const sptr<IRemoteObject>& connect, int32_t callerUid,
uint32_t accessToken)
{
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.DisconnectRemoteAbilityAdapter == nullptr) {
HILOGE("Dms interactive disconnect remote ability adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = dmsAdapetr_.DisconnectRemoteAbilityAdapter(connect, callerUid, accessToken);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter disconnect remote ability adapter fail, ret %{public}d.", ret);
}
return ret;
}
int32_t DistributedSchedService::StartAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply)
{
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.StartAbilityFromRemoteAdapter == nullptr) {
HILOGE("Dms interactive start ability from remote adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = dmsAdapetr_.StartAbilityFromRemoteAdapter(data, reply);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter start ability from remote adapter fail, ret %{public}d.", ret);
}
return ret;
}
int32_t DistributedSchedService::StopAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply)
{
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.StopAbilityFromRemoteAdapter == nullptr) {
HILOGE("Dms interactive stop ability from remote adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = dmsAdapetr_.StopAbilityFromRemoteAdapter(data, reply);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter stop ability from remote adapter fail, ret %{public}d.", ret);
}
return ret;
}
int32_t DistributedSchedService::ConnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply)
{
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.ConnectAbilityFromRemoteAdapter == nullptr) {
HILOGE("Dms interactive connect ability from remote adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = dmsAdapetr_.ConnectAbilityFromRemoteAdapter(data, reply);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter connect ability from remote adapter fail, ret %{public}d.", ret);
}
return ret;
}
int32_t DistributedSchedService::DisconnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply)
{
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.DisconnectAbilityFromRemoteAdapter == nullptr) {
HILOGE("Dms interactive disconnect ability from remote adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = dmsAdapetr_.DisconnectAbilityFromRemoteAdapter(data, reply);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter disconnect ability from remote adapter fail, ret %{public}d.", ret);
}
return ret;
}
int32_t DistributedSchedService::NotifyAbilityLifecycleChangedFromRemoteAdapter(MessageParcel& data,
MessageParcel& reply)
{
std::lock_guard<std::mutex> autoLock(dmsAdapetrLock_);
if (dmsAdapetr_.NotifyAbilityLifecycleChangedFromRemoteAdapter == nullptr) {
HILOGE("Dms interactive disconnect ability from remote adapter dllHandle is null.");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = dmsAdapetr_.NotifyAbilityLifecycleChangedFromRemoteAdapter(data, reply);
if (ret != ERR_OK) {
HILOGE("Dms interactive adapter disconnect ability from remote adapter fail, ret %{public}d.", ret);
}
return ret;
}
#endif // DMSFWK_INTERACTIVE_ADAPTER
int32_t DistributedSchedService::GetCallerInfo(const std::string &localDeviceId, int32_t callerUid,
uint32_t accessToken, CallerInfo &callerInfo)
{
callerInfo.sourceDeviceId = localDeviceId;
callerInfo.uid = callerUid;
callerInfo.accessToken = accessToken;
@ -340,14 +517,45 @@ int32_t DistributedSchedService::StartRemoteAbility(const OHOS::AAFwk::Want& wan
return INVALID_PARAMETERS_ERR;
}
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
AccountInfo accountInfo;
int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(deviceId, callerInfo, accountInfo);
return ERR_OK;
}
int32_t DistributedSchedService::StartRemoteAbility(const OHOS::AAFwk::Want& want,
int32_t callerUid, int32_t requestCode, uint32_t accessToken)
{
std::string localDeviceId;
std::string deviceId = want.GetElement().GetDeviceID();
if (!GetLocalDeviceId(localDeviceId) || !CheckDeviceId(localDeviceId, deviceId)) {
HILOGE("check deviceId failed");
return INVALID_PARAMETERS_ERR;
}
#ifdef DMSFWK_INTERACTIVE_ADAPTER
if (CheckRemoteOsType(deviceId)) {
return StartRemoteAbilityAdapter(want, callerUid, requestCode, accessToken);
}
#endif // DMSFWK_INTERACTIVE_ADAPTER
CallerInfo callerInfo;
int32_t ret = GetCallerInfo(localDeviceId, callerUid, accessToken, callerInfo);
if (ret != ERR_OK) {
HILOGE("GetAccountInfo failed");
HILOGE("Get local device caller info fail, ret: %{public}d.", ret);
return ret;
}
AccountInfo accountInfo;
ret = DistributedSchedPermission::GetInstance().GetAccountInfo(deviceId, callerInfo, accountInfo);
if (ret != ERR_OK) {
HILOGE("GetAccountInfo fail, ret: %{public}d.", ret);
return ret;
}
AAFwk::Want* newWant = const_cast<Want*>(&want);
newWant->SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
AppExecFwk::AbilityInfo abilityInfo;
sptr<IDistributedSched> remoteDms = GetRemoteDms(deviceId);
if (remoteDms == nullptr) {
HILOGE("get remoteDms failed");
return INVALID_PARAMETERS_ERR;
}
HILOGI("[PerformanceTest] StartRemoteAbility transact begin");
if (!DmsContinueTime::GetInstance().GetPull()) {
int64_t begin = GetTickCount();
@ -1163,6 +1371,13 @@ int32_t DistributedSchedService::ConnectRemoteAbility(const OHOS::AAFwk::Want& w
HILOGE("ConnectRemoteAbility check deviceId failed");
return INVALID_PARAMETERS_ERR;
}
#ifdef DMSFWK_INTERACTIVE_ADAPTER
if (CheckRemoteOsType(remoteDeviceId)) {
return ConnectRemoteAbilityAdapter(want, connect, callerUid, callerPid, accessToken);
}
#endif // DMSFWK_INTERACTIVE_ADAPTER
CallerInfo callerInfo = { callerUid, callerPid, CALLER_TYPE_HARMONY, localDeviceId };
callerInfo.accessToken = accessToken;
{
@ -2021,6 +2236,13 @@ int32_t DistributedSchedService::DisconnectRemoteAbility(const sptr<IRemoteObjec
HILOGE("DisconnectRemoteAbility connect is null");
return INVALID_PARAMETERS_ERR;
}
#ifdef DMSFWK_INTERACTIVE_ADAPTER
if (distributedConnectAbilityMap_.find(connect) == distributedConnectAbilityMap_.end()) {
return DisconnectRemoteAbilityAdapter(connect, callerUid, accessToken);
}
#endif // DMSFWK_INTERACTIVE_ADAPTER
std::list<ConnectAbilitySession> sessionsList;
{
std::lock_guard<std::mutex> autoLock(distributedLock_);

View File

@ -161,6 +161,8 @@ void DistributedSchedStub::InitRemoteFuncsInner()
{
remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_ABILITY_FROM_REMOTE)] =
&DistributedSchedStub::StartAbilityFromRemoteInner;
remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::STOP_ABILITY_FROM_REMOTE)] =
&DistributedSchedStub::StopAbilityFromRemoteInner;
remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::SEND_RESULT_FROM_REMOTE)] =
&DistributedSchedStub::SendResultFromRemoteInner;
remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_CONTINUATION_RESULT_FROM_REMOTE)] =
@ -192,6 +194,12 @@ void DistributedSchedStub::InitRemoteFuncsInner()
&DistributedSchedStub::ReleaseAbilityFromRemoteInner;
remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_STATE_CHANGED_FROM_REMOTE)] =
&DistributedSchedStub::NotifyStateChangedFromRemoteInner;
#ifdef DMSFWK_INTERACTIVE_ADAPTER
remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_STATE_CHANGED_FROM_REMOTE)] =
&DistributedSchedStub::NotifyAbilityLifecycleChangedFromRemoteAdapterInner;
#endif
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_SHARE_FORM_FROM_REMOTE)] =
&DistributedSchedStub::StartShareFormFromRemoteInner;
@ -292,36 +300,26 @@ shared_ptr<AAFwk::Want> DistributedSchedStub::ReadDistributedWant(MessageParcel&
return want;
}
int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
int32_t DistributedSchedStub::GetStartAbilityFromRemoteExParam(MessageParcel& data,
OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t& requestCode,
CallerInfo& callerInfo, AccountInfo& accountInfo)
{
if (!CheckCallingUid()) {
HILOGW("request DENIED!");
return DMS_PERMISSION_DENIED;
}
shared_ptr<AAFwk::Want> want = ReadDistributedWant(data);
if (want == nullptr) {
HILOGW("want readParcelable failed!");
return ERR_NULL_OBJECT;
}
unique_ptr<CompatibleAbilityInfo> cmpAbilityInfo(data.ReadParcelable<CompatibleAbilityInfo>());
if (cmpAbilityInfo == nullptr) {
HILOGW("AbilityInfo readParcelable failed!");
HILOGE("AbilityInfo readParcelable failed!");
return ERR_NULL_OBJECT;
}
AbilityInfo abilityInfo;
cmpAbilityInfo->ConvertToAbilityInfo(abilityInfo);
std::string package = abilityInfo.bundleName;
std::string deviceId = abilityInfo.deviceId;
int64_t begin = GetTickCount();
int32_t requestCode = 0;
PARCEL_READ_HELPER(data, Int32, requestCode);
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()) {
@ -331,6 +329,70 @@ int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, M
HILOGD("parse extra info");
}
}
return ERR_OK;
}
int32_t DistributedSchedStub::GetConnectAbilityFromRemoteExParam(MessageParcel& data,
AppExecFwk::AbilityInfo& abilityInfo, sptr<IRemoteObject>& connect,
CallerInfo& callerInfo, AccountInfo& accountInfo)
{
unique_ptr<CompatibleAbilityInfo> cmpAbilityInfo(data.ReadParcelable<CompatibleAbilityInfo>());
if (cmpAbilityInfo == nullptr) {
HILOGE("abilityInfo readParcelable failed!");
return ERR_NULL_OBJECT;
}
cmpAbilityInfo->ConvertToAbilityInfo(abilityInfo);
connect = data.ReadRemoteObject();
int32_t result = ReadDataForConnect(data, callerInfo, accountInfo);
if (result != ERR_NONE) {
HILOGD("Read callerInfo and accountInfo for connect fail, ret %{public}d.", result);
return result;
}
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()) {
SaveExtraInfo(extraInfoJson, callerInfo);
HILOGD("parse extra info");
}
return ERR_OK;
}
int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
{
#ifdef DMSFWK_INTERACTIVE_ADAPTER
if (CheckRemoteOsType(IPCSkeleton::GetCallingDeviceID())) {
return StartAbilityFromRemoteAdapterInner(data, reply);
}
#endif
if (!CheckCallingUid()) {
HILOGW("request DENIED!");
return DMS_PERMISSION_DENIED;
}
int64_t begin = GetTickCount();
shared_ptr<AAFwk::Want> want = ReadDistributedWant(data);
if (want == nullptr) {
HILOGW("want readParcelable failed!");
return ERR_NULL_OBJECT;
}
AbilityInfo abilityInfo;
int32_t requestCode = 0;
CallerInfo callerInfo;
AccountInfo accountInfo;
if (GetStartAbilityFromRemoteExParam(data, abilityInfo, requestCode, callerInfo, accountInfo) != ERR_OK) {
HILOGE("Get start ability from remote exParam fail!");
return INVALID_PARAMETERS_ERR;
}
std::string package = abilityInfo.bundleName;
std::string deviceId = abilityInfo.deviceId;
int32_t result = StartAbilityFromRemote(*want, abilityInfo, requestCode, callerInfo, accountInfo);
BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::START_REMOTE_ABILITY, result,
want->GetElement().GetBundleName(), want->GetElement().GetAbilityName(), callerInfo.uid };
@ -344,6 +406,17 @@ int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, M
return ERR_NONE;
}
int32_t DistributedSchedStub::StopAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
{
#ifdef DMSFWK_INTERACTIVE_ADAPTER
if (CheckRemoteOsType(IPCSkeleton::GetCallingDeviceID())) {
return StopAbilityFromRemoteAdapterInner(data, reply);
}
#endif
int32_t result = ERR_OK;
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
}
void DistributedSchedStub::SaveExtraInfo(const nlohmann::json& extraInfoJson, CallerInfo& callerInfo)
{
if (extraInfoJson.find(EXTRO_INFO_JSON_KEY_ACCESS_TOKEN) != extraInfoJson.end() &&
@ -679,42 +752,36 @@ int32_t DistributedSchedStub::ReadDataForConnect(MessageParcel& data, CallerInfo
int32_t DistributedSchedStub::ConnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
{
#ifdef DMSFWK_INTERACTIVE_ADAPTER
if (CheckRemoteOsType(IPCSkeleton::GetCallingDeviceID())) {
return ConnectAbilityFromRemoteAdapterInner(data, reply);
}
#endif
if (!CheckCallingUid()) {
HILOGW("request DENIED!");
return DMS_PERMISSION_DENIED;
}
shared_ptr<AAFwk::Want> want = ReadDistributedWant(data);
if (want == nullptr) {
HILOGW("want readParcelable failed!");
return ERR_NULL_OBJECT;
}
unique_ptr<CompatibleAbilityInfo> cmpAbilityInfo(data.ReadParcelable<CompatibleAbilityInfo>());
if (cmpAbilityInfo == nullptr) {
HILOGW("abilityInfo readParcelable failed!");
return ERR_NULL_OBJECT;
}
AbilityInfo abilityInfo;
cmpAbilityInfo->ConvertToAbilityInfo(abilityInfo);
sptr<IRemoteObject> connect = data.ReadRemoteObject();
sptr<IRemoteObject> connect = nullptr;
CallerInfo callerInfo;
AccountInfo accountInfo;
int32_t result = ReadDataForConnect(data, callerInfo, accountInfo);
if (result != ERR_NONE) {
return result;
}
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()) {
SaveExtraInfo(extraInfoJson, callerInfo);
HILOGD("parse extra info");
if (GetConnectAbilityFromRemoteExParam(data, abilityInfo, connect, callerInfo, accountInfo) != ERR_OK) {
HILOGE("Get connect ability from remote exParam fail!");
return INVALID_PARAMETERS_ERR;
}
std::string package = abilityInfo.bundleName;
std::string deviceId = abilityInfo.deviceId;
int64_t begin = GetTickCount();
result = ConnectAbilityFromRemote(*want, abilityInfo, connect, callerInfo, accountInfo);
int32_t result = ConnectAbilityFromRemote(*want, abilityInfo, connect, callerInfo, accountInfo);
BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::CONNECT_REMOTE_ABILITY, result,
want->GetElement().GetBundleName(), want->GetElement().GetAbilityName(), callerInfo.uid };
DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
@ -729,6 +796,12 @@ int32_t DistributedSchedStub::ConnectAbilityFromRemoteInner(MessageParcel& data,
int32_t DistributedSchedStub::DisconnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
{
#ifdef DMSFWK_INTERACTIVE_ADAPTER
if (CheckRemoteOsType(IPCSkeleton::GetCallingDeviceID())) {
return DisconnectAbilityFromRemoteAdapterInner(data, reply);
}
#endif
if (!CheckCallingUid()) {
HILOGW("request DENIED!");
return DMS_PERMISSION_DENIED;
@ -1528,5 +1601,78 @@ int32_t DistributedSchedStub::StopExtensionAbilityFromRemoteInner(MessageParcel&
PARCEL_WRITE_HELPER(reply, Int32, result);
return ERR_NONE;
}
#ifdef DMSFWK_INTERACTIVE_ADAPTER
bool DistributedSchedStub::CheckDmsExtensionCallingUid()
{
// never allow non-system uid for distributed request
constexpr int32_t MULTIUSER_HAP_PER_USER_RANGE_EXT = 100000;
constexpr int32_t HID_HAP_EXT = 10000;
auto callingUid = IPCSkeleton::GetCallingUid();
auto uid = callingUid % MULTIUSER_HAP_PER_USER_RANGE_EXT;
return uid < HID_HAP_EXT;
}
int32_t DistributedSchedStub::StartAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply)
{
if (!CheckDmsExtensionCallingUid()) {
HILOGW("Start ability from remote adapter request DENIED!");
return DMS_PERMISSION_DENIED;
}
int32_t result = StartAbilityFromRemoteAdapter(data, reply);
HILOGI("Start ability from remote adapter result = %{public}d", result);
return result;
}
int32_t DistributedSchedStub::StopAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply)
{
if (!CheckDmsExtensionCallingUid()) {
HILOGW("Stop ability from remote adapter request DENIED!");
return DMS_PERMISSION_DENIED;
}
int32_t result = StopAbilityFromRemoteAdapter(data, reply);
HILOGI("Stop ability from remote adapter result = %{public}d", result);
return ERR_OK;
}
int32_t DistributedSchedStub::ConnectAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply)
{
if (!CheckDmsExtensionCallingUid()) {
HILOGW("Connect ability from remote adapter request DENIED!");
return DMS_PERMISSION_DENIED;
}
int32_t result = ConnectAbilityFromRemoteAdapter(data, reply);
HILOGI("Connect ability from remote adapter result = %{public}d", result);
return ERR_OK;
}
int32_t DistributedSchedStub::DisconnectAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply)
{
if (!CheckDmsExtensionCallingUid()) {
HILOGW("Disconnect ability from remote adapter request DENIED!");
return DMS_PERMISSION_DENIED;
}
int32_t result = DisconnectAbilityFromRemoteAdapter(data, reply);
HILOGI("Disconnect ability from remote adapter result = %{public}d", result);
return ERR_OK;
}
int32_t DistributedSchedStub::NotifyAbilityLifecycleChangedFromRemoteAdapterInner(MessageParcel& data,
MessageParcel& reply)
{
if (!CheckDmsExtensionCallingUid()) {
HILOGW("Disconnect ability from remote adapter request DENIED!");
return DMS_PERMISSION_DENIED;
}
int32_t result = NotifyAbilityLifecycleChangedFromRemoteAdapter(data, reply);
HILOGI("Disconnect ability from remote adapter result = %{public}d", result);
return ERR_OK;
}
#endif
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -186,8 +186,13 @@ bool DtbschedmgrDeviceInfoStorage::UpdateDeviceInfoStorage()
return false;
}
for (const auto& dmDeviceInfo : dmDeviceInfoList) {
auto deviceInfo = std::make_shared<DmsDeviceInfo>(
dmDeviceInfo.deviceName, dmDeviceInfo.deviceTypeId, dmDeviceInfo.networkId);
int32_t osType = Constants::OH_OS_TYPE;
std::string osVersion = "";
if (GetOsInfoFromDM(dmDeviceInfo.extraData, osType, osVersion)) {
HILOGE("Get Os info from DM device info fail, extraData %{public}s.", dmDeviceInfo.extraData.c_str());
}
auto deviceInfo = std::make_shared<DmsDeviceInfo>(dmDeviceInfo.deviceName, dmDeviceInfo.deviceTypeId,
dmDeviceInfo.networkId, ONLINE, osType, osVersion);
std::string networkId = deviceInfo->GetNetworkId();
RegisterUuidNetworkIdMap(networkId);
{
@ -201,16 +206,6 @@ bool DtbschedmgrDeviceInfoStorage::UpdateDeviceInfoStorage()
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceId(std::string& networkId)
{
return GetLocalDeviceFromDnet(networkId);
}
bool DtbschedmgrDeviceInfoStorage::GetLocalUdid(std::string& udid)
{
return GetLocalDeviceUdid(udid);
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceFromDnet(std::string& networkId)
{
auto dnetworkAdapter = DnetworkAdapter::GetInstance();
if (dnetworkAdapter == nullptr) {
@ -227,7 +222,7 @@ bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceFromDnet(std::string& networkId
return true;
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceUdid(std::string& udid)
bool DtbschedmgrDeviceInfoStorage::GetLocalUdid(std::string& udid)
{
auto dnetworkAdapter = DnetworkAdapter::GetInstance();
if (dnetworkAdapter == nullptr) {
@ -327,6 +322,7 @@ std::string DtbschedmgrDeviceInfoStorage::GetNetworkIdByUuid(const std::string&
return "";
}
}
void DtbschedmgrDeviceInfoStorage::DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo)
{
if (devInfo == nullptr) {
@ -342,8 +338,9 @@ void DtbschedmgrDeviceInfoStorage::DeviceOnlineNotify(const std::shared_ptr<DmsD
std::string networkId = devInfo->GetNetworkId();
RegisterUuidNetworkIdMap(networkId);
std::string uuid = GetUuidByNetworkId(networkId);
HILOGI("networkId: %{public}s, uuid: %{public}s, deviceName: %{public}s", GetAnonymStr(networkId).c_str(),
GetAnonymStr(uuid).c_str(), devInfo->GetDeviceName().c_str());
HILOGI("networkId: %{public}s, uuid: %{public}s, deviceName: %{public}s, osType: %{public}d, "
"osVersion: %{public}s.", GetAnonymStr(networkId).c_str(), GetAnonymStr(uuid).c_str(),
devInfo->GetDeviceName().c_str(), devInfo->GetDeviceOSType(), devInfo->GetGetDeviceOSVersion().c_str());
{
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_[networkId] = devInfo;