diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 15029413d67a853029e95624cdd13673bfbe1c36..99694ee87f60b50c2c4a4e2666580ab141a2135b 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -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", diff --git a/interfaces/inner_api/app_manager/include/appmgr/ability_info_callback_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ability_info_callback_proxy.h new file mode 100755 index 0000000000000000000000000000000000000000..35408dce53c5e7ab8123388c31220b8b664a3621 --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/ability_info_callback_proxy.h @@ -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 { +public: + explicit AbilityInfoCallbackProxy(const sptr &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 token, const Want &want) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + static inline BrokerDelegator delegator_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif diff --git a/interfaces/inner_api/app_manager/include/appmgr/ability_info_callback_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ability_info_callback_stub.h new file mode 100755 index 0000000000000000000000000000000000000000..ff41b555b52f2b519d6b785c57700532e5e535ad --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/ability_info_callback_stub.h @@ -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 { +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 token, const Want &want) override; + +private: + int32_t HandleNotifyAbilityToken(MessageParcel &data, MessageParcel &reply); + + using AbilityInfoCallbackFunc = int32_t (AbilityInfoCallbackStub::*)(MessageParcel &data, + MessageParcel &reply); + std::map memberFuncMap_; + + DISALLOW_COPY_AND_MOVE(AbilityInfoCallbackStub); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ABILITY_INFO_CALLBACK_STUB_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/iability_info_callback.h b/interfaces/inner_api/app_manager/include/appmgr/iability_info_callback.h new file mode 100755 index 0000000000000000000000000000000000000000..bdc9f723560408b5aa6ffef2606baa92b0bbb19b --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/iability_info_callback.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 token, const Want &want) = 0; + + enum { + Notify_ABILITY_TOKEN = 1, + }; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_IABILITY_INFO_CALLBACK_H diff --git a/interfaces/inner_api/app_manager/src/appmgr/ability_info_callback_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ability_info_callback_proxy.cpp new file mode 100755 index 0000000000000000000000000000000000000000..df3fd69a512841a22d2d2c130e5f1f8966ddd37d --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/ability_info_callback_proxy.cpp @@ -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 &impl) : IRemoteProxy(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 token, const Want &want) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + return; + } + + data.WriteRemoteObject(token); + data.WriteParcelable(&want); + sptr 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 diff --git a/interfaces/inner_api/app_manager/src/appmgr/ability_info_callback_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ability_info_callback_stub.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6df0f0f2e022ff4637f783c54de1a59a329a1a81 --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/ability_info_callback_stub.cpp @@ -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( + 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 token, const Want &want) +{ +} + +int32_t AbilityInfoCallbackStub::HandleNotifyAbilityToken(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("AbilityInfoCallbackStub"); + sptr token = data.ReadRemoteObject(); + Want *want = data.ReadParcelable(); + + if (!want) { + HILOG_ERROR("ReadParcelable failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + NotifyAbilityToken(token, *want); + delete want; + return NO_ERROR; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index ddeab4b24aea0e2e7b4b3030358316b1089ba4ba..c13961968e2613aca9ee1910fe61e0e1c60e7c53 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -207,6 +207,7 @@ struct AbilityRequest { std::shared_ptr startSetting = nullptr; std::string specifiedFlag; + sptr abilityInfoCallback = nullptr; AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED; diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index ba68971e2cae6fae26e8676d77ed68f9928ce254..4cf743558d2fb3d3259cbe0fcdd0371992d64d3a 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -29,6 +29,7 @@ #include "snapshot.h" #include "start_options.h" #include "want.h" +#include "iability_info_callback.h" namespace OHOS { namespace AAFwk { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 82affa559aa2b8149040e4217cf1822c695ccbe0..8a87b4f39b95573741334f77d16295e253254de4 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -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."; @@ -3149,6 +3151,13 @@ int AbilityManagerService::GenerateAbilityRequest( request.callerToken = callerToken; request.startSetting = nullptr; + if (IPCSkeleton::GetCallingUid() == SYSTEM_UID) { + sptr 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 diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 7b4b51346710344a4e903efef62d46cf27249485..9faf99d2a30a32ad52cc3007b6570ed4f26509f3 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -315,6 +315,12 @@ int MissionListManager::StartAbilityLocked(const std::shared_ptr } } + sptr abilityInfoCallback + = iface_cast (abilityRequest.abilityInfoCallback); + if (abilityInfoCallback != nullptr) { + abilityInfoCallback->NotifyAbilityToken(targetAbilityRecord->GetToken(), abilityRequest.want); + } + #ifdef SUPPORT_GRAPHICS std::shared_ptr startOptions = nullptr; targetAbilityRecord->ProcessForegroundAbility(false, abilityRequest, startOptions, callerAbility);