/* * 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_CALL_RECORD_H #define OHOS_ABILITY_RUNTIME_CALL_RECORD_H #include "ability_connect_callback_interface.h" #include "nocopyable.h" namespace OHOS { namespace AAFwk { class AbilityRecord; /** * @class AbilityCallRecipient * AbilityCallRecipient notices IRemoteBroker died. */ class AbilityCallRecipient : public IRemoteObject::DeathRecipient { public: using RemoteDiedHandler = std::function &)>; explicit AbilityCallRecipient(RemoteDiedHandler handler) : handler_(handler) {}; virtual ~AbilityCallRecipient() = default; void OnRemoteDied(const wptr &__attribute__((unused)) remote) override { if (handler_) { handler_(remote); } }; private: RemoteDiedHandler handler_; }; /** * @enum CallState * CallState defines the state of calling ability. */ enum class CallState { INIT, REQUESTING, REQUESTED }; /** * @class CallRecord * CallRecord,This class is used to record information about a connection of calling ability. */ class CallRecord : public std::enable_shared_from_this { public: CallRecord(const int32_t callerUid, const std::shared_ptr &targetService, const sptr &connCallback, const sptr &callToken); virtual ~CallRecord(); static std::shared_ptr CreateCallRecord(const int32_t callerUid, const std::shared_ptr &targetService, const sptr &connCallback, const sptr &callToken); void SetCallStub(const sptr &call); sptr GetCallStub(); void SetConCallBack(const sptr &connCallback); sptr GetConCallBack() const; void Dump(std::vector &info) const; bool SchedulerConnectDone(); bool SchedulerDisconnectDone(); void OnCallStubDied(const wptr &remote); int32_t GetCallerUid() const; bool IsCallState(const CallState &state) const; void SetCallState(const CallState &state); int32_t GetCallRecordId() const; AppExecFwk::ElementName GetTargetServiceName() const; sptr GetCallerToken() const; private: static int64_t callRecordId; int recordId_; // record id int32_t callerUid_; // caller uid CallState state_; // call state sptr callRemoteObject_ = nullptr; sptr callDeathRecipient_ = nullptr; std::weak_ptr service_; // target:service need to be called sptr connCallback_ = nullptr; // service connect callback sptr callerToken_ = nullptr; // caller token int64_t startTime_ = 0; // records first time of ability start DISALLOW_COPY_AND_MOVE(CallRecord); }; } // namespace AAFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_CALL_RECORD_H