mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
!3984 支持启动ablity事,传入callback
Merge pull request !3984 from wangdengjia/1124master
This commit is contained in:
@@ -49,6 +49,8 @@ ohos_shared_library("app_manager") {
|
||||
sources = [
|
||||
"src/appmgr/ability_controller_proxy.cpp",
|
||||
"src/appmgr/ability_controller_stub.cpp",
|
||||
"src/appmgr/ability_info_callback_proxy.cpp",
|
||||
"src/appmgr/ability_info_callback_stub.cpp",
|
||||
"src/appmgr/ability_state_data.cpp",
|
||||
"src/appmgr/ams_mgr_proxy.cpp",
|
||||
"src/appmgr/ams_mgr_stub.cpp",
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_ABILITY_RUNTIME_ABILITY_INFO_CALLBACK_PROXY_H
|
||||
#define OHOS_ABILITY_RUNTIME_ABILITY_INFO_CALLBACK_PROXY_H
|
||||
|
||||
#include "iability_info_callback.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
/**
|
||||
* @brief Transfer abilityInfo to the initiator.
|
||||
*/
|
||||
class AbilityInfoCallbackProxy : public IRemoteProxy<IAbilityInfoCallback> {
|
||||
public:
|
||||
explicit AbilityInfoCallbackProxy(const sptr<IRemoteObject> &impl);
|
||||
virtual ~AbilityInfoCallbackProxy() = default;
|
||||
|
||||
/**
|
||||
* Notify the initiator of the ability token.
|
||||
*
|
||||
* @param token The token of ability.
|
||||
* @param want The want of ability to start.
|
||||
*/
|
||||
virtual void NotifyAbilityToken(const sptr<IRemoteObject> token, const Want &want) override;
|
||||
|
||||
private:
|
||||
bool WriteInterfaceToken(MessageParcel &data);
|
||||
static inline BrokerDelegator<AbilityInfoCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_ABILITY_RUNTIME_ABILITY_INFO_CALLBACK_STUB_H
|
||||
#define OHOS_ABILITY_RUNTIME_ABILITY_INFO_CALLBACK_STUB_H
|
||||
|
||||
#include "iability_info_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
/**
|
||||
* @brief Transfer abilityInfo to the initiator.
|
||||
*/
|
||||
class AbilityInfoCallbackStub : public IRemoteStub<IAbilityInfoCallback> {
|
||||
public:
|
||||
AbilityInfoCallbackStub();
|
||||
virtual ~AbilityInfoCallbackStub();
|
||||
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
/**
|
||||
* Notify the initiator of the ability token.
|
||||
*
|
||||
* @param token The token of ability.
|
||||
* @param want The want of ability to start.
|
||||
*/
|
||||
virtual void NotifyAbilityToken(const sptr<IRemoteObject> token, const Want &want) override;
|
||||
|
||||
private:
|
||||
int32_t HandleNotifyAbilityToken(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
using AbilityInfoCallbackFunc = int32_t (AbilityInfoCallbackStub::*)(MessageParcel &data,
|
||||
MessageParcel &reply);
|
||||
std::map<uint32_t, AbilityInfoCallbackFunc> memberFuncMap_;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(AbilityInfoCallbackStub);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_ABILITY_INFO_CALLBACK_STUB_H
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_ABILITY_RUNTIME_IABILITY_INFO_CALLBACK_H
|
||||
#define OHOS_ABILITY_RUNTIME_IABILITY_INFO_CALLBACK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using OHOS::AAFwk::Want;
|
||||
/**
|
||||
* @brief Transfer abilityInfo to the initiator.
|
||||
*/
|
||||
class IAbilityInfoCallback : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IAbilityInfoCallback");
|
||||
|
||||
/**
|
||||
* Notify the initiator of the ability token.
|
||||
*
|
||||
* @param token The token of ability.
|
||||
* @param want The want of ability to start.
|
||||
*/
|
||||
virtual void NotifyAbilityToken(const sptr<IRemoteObject> token, const Want &want) = 0;
|
||||
|
||||
enum {
|
||||
Notify_ABILITY_TOKEN = 1,
|
||||
};
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_IABILITY_INFO_CALLBACK_H
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#include "ability_info_callback_proxy.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
AbilityInfoCallbackProxy::AbilityInfoCallbackProxy(
|
||||
const sptr<IRemoteObject> &impl) : IRemoteProxy<IAbilityInfoCallback>(impl)
|
||||
{}
|
||||
|
||||
bool AbilityInfoCallbackProxy::WriteInterfaceToken(MessageParcel &data)
|
||||
{
|
||||
if (!data.WriteInterfaceToken(AbilityInfoCallbackProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("write interface token failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbilityInfoCallbackProxy::NotifyAbilityToken(const sptr<IRemoteObject> token, const Want &want)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.WriteRemoteObject(token);
|
||||
data.WriteParcelable(&want);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
HILOG_ERROR("Remote() is NULL");
|
||||
return;
|
||||
}
|
||||
int32_t ret = remote->SendRequest(IAbilityInfoCallback::Notify_ABILITY_TOKEN, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
HILOG_WARN("SendRequest is failed, error code: %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#include "ability_info_callback_stub.h"
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_types.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
AbilityInfoCallbackStub::AbilityInfoCallbackStub()
|
||||
{
|
||||
memberFuncMap_[static_cast<uint32_t>(
|
||||
IAbilityInfoCallback::Notify_ABILITY_TOKEN)] = &AbilityInfoCallbackStub::HandleNotifyAbilityToken;
|
||||
}
|
||||
|
||||
AbilityInfoCallbackStub::~AbilityInfoCallbackStub()
|
||||
{
|
||||
memberFuncMap_.clear();
|
||||
}
|
||||
|
||||
int AbilityInfoCallbackStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
HILOG_INFO("AbilityInfoCallbackStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
|
||||
std::u16string descriptor = AbilityInfoCallbackStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
HILOG_ERROR("local descriptor is not equal to remote");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto itFunc = memberFuncMap_.find(code);
|
||||
if (itFunc != memberFuncMap_.end()) {
|
||||
auto memberFunc = itFunc->second;
|
||||
if (memberFunc != nullptr) {
|
||||
return (this->*memberFunc)(data, reply);
|
||||
}
|
||||
}
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
void AbilityInfoCallbackStub::NotifyAbilityToken(const sptr<IRemoteObject> token, const Want &want)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t AbilityInfoCallbackStub::HandleNotifyAbilityToken(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_INFO("AbilityInfoCallbackStub");
|
||||
sptr<IRemoteObject> token = data.ReadRemoteObject();
|
||||
Want *want = data.ReadParcelable<Want>();
|
||||
|
||||
if (!want) {
|
||||
HILOG_ERROR("ReadParcelable<Want> failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
NotifyAbilityToken(token, *want);
|
||||
delete want;
|
||||
return NO_ERROR;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -207,6 +207,7 @@ struct AbilityRequest {
|
||||
|
||||
std::shared_ptr<AbilityStartSetting> startSetting = nullptr;
|
||||
std::string specifiedFlag;
|
||||
sptr<IRemoteObject> abilityInfoCallback = nullptr;
|
||||
|
||||
AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED;
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "snapshot.h"
|
||||
#include "start_options.h"
|
||||
#include "want.h"
|
||||
#include "iability_info_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
@@ -78,6 +78,8 @@ using OHOS::Security::AccessToken::AccessTokenKit;
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
const int32_t SYSTEM_UID = 1000;
|
||||
|
||||
const std::string ARGS_USER_ID = "-u";
|
||||
const std::string ARGS_CLIENT = "-c";
|
||||
const std::string ILLEGAL_INFOMATION = "The arguments are illegal and you can enter '-h' for help.";
|
||||
@@ -3022,6 +3024,13 @@ int AbilityManagerService::GenerateAbilityRequest(
|
||||
request.callerToken = callerToken;
|
||||
request.startSetting = nullptr;
|
||||
|
||||
if (IPCSkeleton::GetCallingUid() == SYSTEM_UID) {
|
||||
sptr<IRemoteObject> abilityInfoCallback = want.GetRemoteObject("abilityInfoCallback");
|
||||
if (abilityInfoCallback != nullptr) {
|
||||
request.abilityInfoCallback = abilityInfoCallback;
|
||||
}
|
||||
}
|
||||
|
||||
auto bms = GetBundleManager();
|
||||
CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED);
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
|
||||
@@ -316,6 +316,12 @@ int MissionListManager::StartAbilityLocked(const std::shared_ptr<AbilityRecord>
|
||||
}
|
||||
}
|
||||
|
||||
sptr<AppExecFwk::IAbilityInfoCallback> abilityInfoCallback
|
||||
= iface_cast<AppExecFwk::IAbilityInfoCallback> (abilityRequest.abilityInfoCallback);
|
||||
if (abilityInfoCallback != nullptr) {
|
||||
abilityInfoCallback->NotifyAbilityToken(targetAbilityRecord->GetToken(), abilityRequest.want);
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
std::shared_ptr<StartOptions> startOptions = nullptr;
|
||||
targetAbilityRecord->ProcessForegroundAbility(false, abilityRequest, startOptions, callerAbility);
|
||||
|
||||
Reference in New Issue
Block a user