2021-07-15 02:53:57 +00:00
|
|
|
/*
|
2022-03-12 08:42:08 +00:00
|
|
|
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
2021-07-15 02:53:57 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-07-15 11:38:20 +00:00
|
|
|
#ifndef OHOS_ABILITY_RUNTIME_PENDING_WANT_MANAGER_H
|
|
|
|
#define OHOS_ABILITY_RUNTIME_PENDING_WANT_MANAGER_H
|
2021-07-15 02:53:57 +00:00
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2023-06-26 01:23:17 +00:00
|
|
|
#include "cpp/mutex.h"
|
2021-07-15 02:53:57 +00:00
|
|
|
|
|
|
|
#include "ability_manager_errors.h"
|
|
|
|
#include "ability_record.h"
|
2021-07-27 15:11:04 +00:00
|
|
|
#include "common_event.h"
|
2021-07-15 02:53:57 +00:00
|
|
|
#include "nocopyable.h"
|
|
|
|
#include "pending_want_key.h"
|
|
|
|
#include "pending_want_record.h"
|
|
|
|
#include "pending_want_common_event.h"
|
|
|
|
#include "sender_info.h"
|
2024-11-01 09:16:42 +00:00
|
|
|
#include "task_handler_wrap.h"
|
2021-07-15 02:53:57 +00:00
|
|
|
#include "want_sender_info.h"
|
|
|
|
|
|
|
|
namespace OHOS {
|
|
|
|
namespace AAFwk {
|
|
|
|
enum class OperationType {
|
|
|
|
/**
|
|
|
|
* Unknown operation.
|
|
|
|
*/
|
|
|
|
UNKNOWN_TYPE,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts an ability with a UI.
|
|
|
|
*/
|
|
|
|
START_ABILITY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts multiple abilities.
|
|
|
|
*/
|
|
|
|
START_ABILITIES,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts an ability without a UI.
|
|
|
|
*/
|
|
|
|
START_SERVICE,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a common event.
|
|
|
|
*/
|
|
|
|
SEND_COMMON_EVENT,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a foreground ability without a UI.
|
|
|
|
*/
|
2024-08-06 02:10:52 +00:00
|
|
|
START_FOREGROUND_SERVICE,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a service extension.
|
|
|
|
*/
|
|
|
|
START_SERVICE_EXTENSION
|
2021-07-15 02:53:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class Flags {
|
|
|
|
/**
|
|
|
|
* Indicates that the {@link WantAgent} can be used only once.
|
|
|
|
*/
|
|
|
|
ONE_TIME_FLAG = 1 << 30,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that {@code null} is returned if the {@link WantAgent} does not exist.
|
|
|
|
*/
|
|
|
|
NO_BUILD_FLAG = 1 << 29,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the existing {@link WantAgent} should be canceled before the new object is generated.
|
|
|
|
*/
|
|
|
|
CANCEL_PRESENT_FLAG = 1 << 28,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the system only replaces the extra data of the existing {@link WantAgent}
|
|
|
|
* with that of the new object.
|
|
|
|
*/
|
|
|
|
UPDATE_PRESENT_FLAG = 1 << 27,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the created {@link WantAgent} should be immutable.
|
|
|
|
*/
|
|
|
|
CONSTANT_FLAG = 1 << 26,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the current value of {@code element} can be replaced
|
|
|
|
* when the {@link WantAgent} is triggered.
|
|
|
|
*/
|
|
|
|
REPLACE_ELEMENT,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the current value of {@code action} can be replaced
|
|
|
|
* when the {@link WantAgent} is triggered.
|
|
|
|
*/
|
|
|
|
REPLACE_ACTION,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the current value of {@code uri} can be replaced when the {@link WantAgent} is triggered.
|
|
|
|
*/
|
|
|
|
REPLACE_URI,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the current value of {@code entities} can be replaced
|
|
|
|
* when the {@link WantAgent} is triggered.
|
|
|
|
*/
|
|
|
|
REPLACE_ENTITIES,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the current value of {@code bundleName} can be replaced
|
|
|
|
* when the {@link WantAgent} is triggered.
|
|
|
|
*/
|
|
|
|
REPLACE_BUNDLE
|
|
|
|
};
|
|
|
|
|
|
|
|
class PendingWantManager : public std::enable_shared_from_this<PendingWantManager>, public NoCopyable {
|
|
|
|
public:
|
|
|
|
PendingWantManager();
|
2021-12-11 09:52:41 +00:00
|
|
|
explicit PendingWantManager(const std::shared_ptr<PendingWantManager> &manager) {};
|
2021-07-15 02:53:57 +00:00
|
|
|
virtual ~PendingWantManager();
|
|
|
|
|
|
|
|
public:
|
2023-09-20 09:17:11 +00:00
|
|
|
sptr<IWantSender> GetWantSender(int32_t callingUid, int32_t uid, const bool isSystemApp,
|
2024-05-25 01:30:04 +00:00
|
|
|
const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken, int32_t appIndex = 0);
|
2023-11-15 06:08:15 +00:00
|
|
|
int32_t SendWantSender(sptr<IWantSender> target, const SenderInfo &senderInfo);
|
2023-09-20 09:17:11 +00:00
|
|
|
void CancelWantSender(const bool isSystemApp, const sptr<IWantSender> &sender);
|
2021-07-15 02:53:57 +00:00
|
|
|
|
|
|
|
int32_t GetPendingWantUid(const sptr<IWantSender> &target);
|
|
|
|
int32_t GetPendingWantUserId(const sptr<IWantSender> &target);
|
|
|
|
std::string GetPendingWantBundleName(const sptr<IWantSender> &target);
|
|
|
|
int32_t GetPendingWantCode(const sptr<IWantSender> &target);
|
|
|
|
int32_t GetPendingWantType(const sptr<IWantSender> &target);
|
|
|
|
void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &recevier);
|
|
|
|
void UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &recevier);
|
|
|
|
int32_t GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want);
|
2022-01-07 18:38:44 +00:00
|
|
|
int32_t GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info);
|
2021-07-15 02:53:57 +00:00
|
|
|
|
|
|
|
void CancelWantSenderLocked(PendingWantRecord &record, bool cleanAbility);
|
2024-04-25 12:55:03 +00:00
|
|
|
int32_t PendingWantStartAbility(const Want &want, const sptr<StartOptions> &startOptions,
|
|
|
|
const sptr<IRemoteObject> &callerToken, int32_t requestCode, const int32_t callerUid, int32_t callerTokenId);
|
2024-08-06 02:10:52 +00:00
|
|
|
int32_t PendingWantStartServiceExtension(Want &want, const sptr<IRemoteObject> &callerToken);
|
2024-04-25 12:55:03 +00:00
|
|
|
int32_t PendingWantStartAbilitys(const std::vector<WantsInfo> &wantsInfo, const sptr<StartOptions> &startOptions,
|
|
|
|
const sptr<IRemoteObject> &callerToken, int32_t requestCode, const int32_t callerUid, int32_t callerTokenId);
|
|
|
|
int32_t DeviceIdDetermine(const Want &want, const sptr<StartOptions> &startOptions,
|
|
|
|
const sptr<IRemoteObject> &callerToken, int32_t requestCode, const int32_t callerUid, int32_t callerTokenId);
|
2023-01-09 09:11:25 +00:00
|
|
|
int32_t PendingWantPublishCommonEvent(const Want &want, const SenderInfo &senderInfo, int32_t callerUid,
|
|
|
|
int32_t callerTokenId);
|
2022-03-05 08:50:24 +00:00
|
|
|
void ClearPendingWantRecord(const std::string &bundleName, int32_t uid);
|
2021-07-15 02:53:57 +00:00
|
|
|
|
2022-01-27 09:41:26 +00:00
|
|
|
void Dump(std::vector<std::string> &info);
|
2022-02-17 13:43:42 +00:00
|
|
|
void DumpByRecordId(std::vector<std::string> &info, const std::string &args);
|
2024-09-19 10:21:43 +00:00
|
|
|
int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, std::vector<std::string> &appKey);
|
2022-01-27 09:41:26 +00:00
|
|
|
|
2021-07-15 02:53:57 +00:00
|
|
|
private:
|
|
|
|
sptr<IWantSender> GetWantSenderLocked(const int32_t callingUid, const int32_t uid, const int32_t userId,
|
2024-05-25 01:30:04 +00:00
|
|
|
WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken, int32_t appIndex = 0);
|
2021-07-15 02:53:57 +00:00
|
|
|
void MakeWantSenderCanceledLocked(PendingWantRecord &record);
|
|
|
|
|
|
|
|
sptr<PendingWantRecord> GetPendingWantRecordByKey(const std::shared_ptr<PendingWantKey> &key);
|
|
|
|
bool CheckPendingWantRecordByKey(
|
|
|
|
const std::shared_ptr<PendingWantKey> &inputKey, const std::shared_ptr<PendingWantKey> &key);
|
|
|
|
|
|
|
|
sptr<PendingWantRecord> GetPendingWantRecordByCode(int32_t code);
|
|
|
|
static int32_t PendingRecordIdCreate();
|
2022-03-05 08:50:24 +00:00
|
|
|
void ClearPendingWantRecordTask(const std::string &bundleName, int32_t uid);
|
2021-07-15 02:53:57 +00:00
|
|
|
|
2024-07-11 08:19:07 +00:00
|
|
|
bool CheckCallerPermission();
|
|
|
|
|
2024-08-30 02:21:25 +00:00
|
|
|
bool CheckWindowState(int32_t pid);
|
|
|
|
|
2021-07-15 02:53:57 +00:00
|
|
|
private:
|
2024-11-01 09:16:42 +00:00
|
|
|
std::shared_ptr<TaskHandlerWrap> taskHandler_;
|
2021-07-15 02:53:57 +00:00
|
|
|
std::map<std::shared_ptr<PendingWantKey>, sptr<PendingWantRecord>> wantRecords_;
|
2023-06-26 01:23:17 +00:00
|
|
|
ffrt::mutex mutex_;
|
2021-07-15 02:53:57 +00:00
|
|
|
};
|
|
|
|
} // namespace AAFwk
|
|
|
|
} // namespace OHOS
|
|
|
|
|
2022-07-15 11:38:20 +00:00
|
|
|
#endif // OHOS_ABILITY_RUNTIME_PENDING_WANT_MANAGER_H
|