Signed-off-by: wanchengzhen <wanchengzhen@huawei.com>
This commit is contained in:
wanchengzhen 2022-02-17 13:43:42 +00:00
parent 1feed74e91
commit 57a5f7f44d
26 changed files with 911 additions and 480 deletions

View File

@ -32,6 +32,7 @@ namespace OHOS {
namespace AbilityRuntime {
using RuntimeTask = std::function<void(int, const AAFwk::Want&)>;
using PermissionRequestTask = std::function<void(const std::vector<std::string>&, const std::vector<int>&)>;
class LocalCallContainer;
class AbilityContext : public Context {
public:
virtual ~AbilityContext() = default;
@ -229,6 +230,13 @@ public:
*/
virtual ErrCode SetMissionLabel(const std::string &label) = 0;
/**
* @brief Get LocalCallContainer.
*
* @return Returns the LocalCallContainer.
*/
virtual sptr<LocalCallContainer> GetLocalCallContainer() = 0;
virtual void SetConfiguration(const std::shared_ptr<AppExecFwk::Configuration> &config) = 0;
virtual std::shared_ptr<AppExecFwk::Configuration> GetConfiguration() const = 0;

View File

@ -117,6 +117,16 @@ public:
return contentStorage_;
}
/**
* @brief Get LocalCallContainer.
*
* @return Returns the LocalCallContainer.
*/
sptr<LocalCallContainer> GetLocalCallContainer() override
{
return localCallContainer_;
}
void SetConfiguration(const std::shared_ptr<AppExecFwk::Configuration> &config) override;
std::shared_ptr<AppExecFwk::Configuration> GetConfiguration() const override;

View File

@ -39,6 +39,8 @@ public:
void InvokeCallBack() const;
AppExecFwk::ElementName GetElementName() const;
bool IsExistCallBack() const;
int GetRecordId();
std::vector<std::shared_ptr<CallerCallBack>> GetCallers();
private:
static int64_t callRecordId;

View File

@ -119,6 +119,31 @@ int LocalCallContainer::Release(const std::shared_ptr<CallerCallBack>& callback)
void LocalCallContainer::DumpCalls(std::vector<std::string> &info) const
{
HILOG_DEBUG("LocalCallContainer::DumpCalls called.");
info.emplace_back(" caller connections:");
for (auto iter = callProxyRecords_.begin(); iter != callProxyRecords_.end(); iter++) {
std::string tempstr = " LocalCallRecord";
tempstr += " ID #" + std::to_string (iter->second->GetRecordId()) + "\n";
tempstr += " callee";
tempstr += " uri[" + iter->first + "]" + "\n";
tempstr += " callers #" + std::to_string (iter->second->GetCallers().size());
bool flag = true;
for (auto &callBack:iter->second->GetCallers()) {
if (callBack && !callBack->IsCallBack()) {
HILOG_INFO("%{public}s call back is not called.", __func__);
flag = false;
break;
}
}
if (flag) {
HILOG_INFO("%{public}s state is REQUESTEND.", __func__);
tempstr += " state #REQUESTEND";
} else {
HILOG_INFO("%{public}s state is REQUESTING.", __func__);
tempstr += " state #REQUESTING";
}
info.emplace_back(tempstr);
}
return;
}
void LocalCallContainer::OnAbilityConnectDone(

View File

@ -113,5 +113,15 @@ bool LocalCallRecord::IsExistCallBack() const
{
return (callers_.size() > 0);
}
int LocalCallRecord::GetRecordId()
{
return recordId_;
}
std::vector<std::shared_ptr<CallerCallBack>> LocalCallRecord::GetCallers()
{
return callers_;
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -1581,7 +1581,7 @@ void AbilityThread::DumpAbilityInfo(const std::vector<std::string> &params, std:
return;
}
std::string dumpInfo = " event:";
std::string dumpInfo = " event:";
info.push_back(dumpInfo);
if (!abilityHandler_) {
@ -1598,6 +1598,25 @@ void AbilityThread::DumpAbilityInfo(const std::vector<std::string> &params, std:
runner->DumpRunnerInfo(dumpInfo);
info.push_back(dumpInfo);
if (!currentAbility_) {
APP_LOGI("currentAbility is nullptr.");
return;
}
const auto ablityContext = currentAbility_->GetAbilityContext();
if (!ablityContext) {
APP_LOGI("current ability context is nullptr.");
return;
}
const auto localCallContainer = ablityContext->GetLocalCallContainer();
if (!localCallContainer) {
APP_LOGI("current ability context locall call container is nullptr.");
return;
}
localCallContainer->DumpCalls(info);
APP_LOGI("localCallContainer need to get calls info.");
}

View File

@ -913,6 +913,8 @@ public:
KEY_DUMPSYS_SERVICE,
KEY_DUMPSYS_PENDING,
KEY_DUMPSYS_PROCESS,
KEY_DUMPSYS_DATA,
KEY_DUMPSYS_SYSTEM_UI,
};
friend class AbilityStackManager;
@ -1071,17 +1073,21 @@ private:
*/
void DumpSysFuncInit();
void DumpSysInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId);
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void DumpSysMissionListInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId);
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void DumpSysAbilityInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId);
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void DumpSysStateInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId);
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void DumpSysPendingInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId);
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void DumpSysProcess(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId);
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void DataDumpSysStateInner(
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void SystemDumpSysStateInner(
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
void InitConnectManager(int32_t userId, bool switchUser);
void InitDataAbilityManager(int32_t userId, bool switchUser);

View File

@ -666,6 +666,10 @@ public:
*/
void Dump(std::vector<std::string> &info);
void DumpSys(std::vector<std::string> &info, bool isClient = false);
void DumpClientInfo(std::vector<std::string> &info, bool isClient = false);
/**
* dump ability state info.
*
@ -866,7 +870,7 @@ private:
std::weak_ptr<Mission> mission_;
int32_t missionId_ = -1;
bool isSwitchingPause_ = false;
// new version
std::shared_ptr<CallContainer> callContainer_ = nullptr;
bool isStartedByCall_ = false;

View File

@ -1,65 +1,65 @@
/*
* Copyright (c) 2021 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_AAFWK_CALL_CONTAINER_H
#define OHOS_AAFWK_CALL_CONTAINER_H
#include <map>
#include <string>
#include <mutex>
#include "ability_connect_callback_interface.h"
#include "call_record.h"
#include "element_name.h"
#include "iremote_object.h"
#include "nocopyable.h"
namespace OHOS {
namespace AAFwk {
class CallRecord;
/**
* @class CallContainer
* CallContainer provides a facility for managing the call records of ability.
*/
class CallContainer : public std::enable_shared_from_this<CallContainer> {
public:
using CallMapType = std::map<sptr<IRemoteObject>, std::shared_ptr<CallRecord>>;
using RecipientMapType = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>;
CallContainer();
virtual ~CallContainer();
void AddCallRecord(const sptr<IAbilityConnection> & connect, const std::shared_ptr<CallRecord>& callRecord);
std::shared_ptr<CallRecord> GetCallRecord(const sptr<IAbilityConnection> & connect) const;
bool RemoveCallRecord(const sptr<IAbilityConnection> & connect);
bool CallRequestDone(const sptr<IRemoteObject> & callStub);
void Dump(std::vector<std::string> &info, const std::string &args = "") const;
bool IsNeedToCallRequest() const;
private:
void RemoveConnectDeathRecipient(const sptr<IAbilityConnection> &connect);
void AddConnectDeathRecipient(const sptr<IAbilityConnection> &connect);
void OnConnectionDied(const wptr<IRemoteObject> & remote);
private:
CallMapType callRecordMap_;
RecipientMapType deathRecipientMap_;
DISALLOW_COPY_AND_MOVE(CallContainer);
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_AAFWK_CALL_CONTAINER_H
/*
* Copyright (c) 2021 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_AAFWK_CALL_CONTAINER_H
#define OHOS_AAFWK_CALL_CONTAINER_H
#include <map>
#include <string>
#include <mutex>
#include "ability_connect_callback_interface.h"
#include "call_record.h"
#include "element_name.h"
#include "iremote_object.h"
#include "nocopyable.h"
namespace OHOS {
namespace AAFwk {
class CallRecord;
/**
* @class CallContainer
* CallContainer provides a facility for managing the call records of ability.
*/
class CallContainer : public std::enable_shared_from_this<CallContainer> {
public:
using CallMapType = std::map<sptr<IRemoteObject>, std::shared_ptr<CallRecord>>;
using RecipientMapType = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>;
CallContainer();
virtual ~CallContainer();
void AddCallRecord(const sptr<IAbilityConnection> & connect, const std::shared_ptr<CallRecord>& callRecord);
std::shared_ptr<CallRecord> GetCallRecord(const sptr<IAbilityConnection> & connect) const;
bool RemoveCallRecord(const sptr<IAbilityConnection> & connect);
bool CallRequestDone(const sptr<IRemoteObject> & callStub);
void Dump(std::vector<std::string> &info) const;
bool IsNeedToCallRequest() const;
private:
void RemoveConnectDeathRecipient(const sptr<IAbilityConnection> &connect);
void AddConnectDeathRecipient(const sptr<IAbilityConnection> &connect);
void OnConnectionDied(const wptr<IRemoteObject> & remote);
private:
CallMapType callRecordMap_;
RecipientMapType deathRecipientMap_;
DISALLOW_COPY_AND_MOVE(CallContainer);
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_AAFWK_CALL_CONTAINER_H

View File

@ -47,6 +47,7 @@ public:
std::shared_ptr<AbilityRecord> GetAbilityRecordByScheduler(const sptr<IAbilityScheduler> &scheduler);
void Dump(const char *func, int line);
void DumpState(std::vector<std::string> &info, const std::string &args = "") const;
void DumpSysState(std::vector<std::string> &info, bool isClient = false, const std::string &args = "") const;
void GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info);
private:

View File

@ -79,6 +79,8 @@ public:
void DumpState(std::vector<std::string> &info);
void DumpSysState(std::vector<std::string> &info, bool isClient);
void OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord);
void OnTimeOut(uint32_t msgId, int64_t eventId);

View File

@ -79,6 +79,8 @@ public:
void DumpState(std::vector<std::string> &info);
void DumpSysState(std::vector<std::string> &info, bool isClient = false);
void OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord);
void OnTimeOut(uint32_t msgId, int64_t eventId);

View File

@ -81,6 +81,8 @@ public:
*/
void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state);
void OnAppStateChanged(const AppInfo &info);
/**
* attach ability thread ipc object.
*

View File

@ -159,6 +159,7 @@ public:
void ClearPendingWantRecord(const std::string &bundleName);
void Dump(std::vector<std::string> &info);
void DumpByRecordId(std::vector<std::string> &info, const std::string &args);
private:
sptr<IWantSender> GetWantSenderLocked(const int32_t callingUid, const int32_t uid, const int32_t userId,

View File

@ -112,6 +112,10 @@ const std::map<std::string, AbilityManagerService::DumpsysKey> AbilityManagerSer
std::map<std::string, AbilityManagerService::DumpsysKey>::value_type("-p", KEY_DUMPSYS_PENDING),
std::map<std::string, AbilityManagerService::DumpsysKey>::value_type("--process", KEY_DUMPSYS_PROCESS),
std::map<std::string, AbilityManagerService::DumpsysKey>::value_type("-r", KEY_DUMPSYS_PROCESS),
std::map<std::string, AbilityManagerService::DumpsysKey>::value_type("--data", KEY_DUMPSYS_DATA),
std::map<std::string, AbilityManagerService::DumpsysKey>::value_type("-d", KEY_DUMPSYS_DATA),
std::map<std::string, AbilityManagerService::DumpsysKey>::value_type("--ui", KEY_DUMPSYS_SYSTEM_UI),
std::map<std::string, AbilityManagerService::DumpsysKey>::value_type("-k", KEY_DUMPSYS_SYSTEM_UI),
};
const bool REGISTER_RESULT =
@ -1657,6 +1661,8 @@ void AbilityManagerService::DumpSysFuncInit()
dumpsysFuncMap_[KEY_DUMPSYS_SERVICE] = &AbilityManagerService::DumpSysStateInner;
dumpsysFuncMap_[KEY_DUMPSYS_PENDING] = &AbilityManagerService::DumpSysPendingInner;
dumpsysFuncMap_[KEY_DUMPSYS_PROCESS] = &AbilityManagerService::DumpSysProcess;
dumpsysFuncMap_[KEY_DUMPSYS_DATA] = &AbilityManagerService::DataDumpSysStateInner;
dumpsysFuncMap_[KEY_DUMPSYS_SYSTEM_UI] = &AbilityManagerService::SystemDumpSysStateInner;
}
void AbilityManagerService::DumpSysInner(
@ -1674,7 +1680,7 @@ void AbilityManagerService::DumpSysInner(
}
void AbilityManagerService::DumpSysMissionListInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId)
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId)
{
std::shared_ptr<MissionListManager> targetManager;
if (isUserID) {
@ -1705,7 +1711,7 @@ void AbilityManagerService::DumpSysMissionListInner(
}
}
void AbilityManagerService::DumpSysAbilityInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId)
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId)
{
std::shared_ptr<MissionListManager> targetManager;
if (isUserID) {
@ -1771,18 +1777,33 @@ void AbilityManagerService::DumpSysStateInner(
void AbilityManagerService::DumpSysPendingInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId)
{
std::shared_ptr<PendingWantManager> targetManager;
if (isUserID) {
auto it = pendingWantManagers_.find(userId);
if (it != pendingWantManagers_.end()) {
it->second->Dump(info);
if (it == pendingWantManagers_.end()) {
info.push_back("error: No user found'.");
return;
}
info.push_back("error: No user found'.");
targetManager = it->second;
} else {
targetManager = pendingWantManager_;
}
CHECK_POINTER(targetManager);
std::vector<std::string> argList;
SplitStr(args, " ", argList);
if (argList.empty()) {
return;
}
CHECK_POINTER(pendingWantManager_);
pendingWantManager_->Dump(info);
if (argList.size() == MIN_DUMP_ARGUMENT_NUM) {
targetManager->DumpByRecordId(info, argList[1]);
} else if (argList.size() < MIN_DUMP_ARGUMENT_NUM) {
targetManager->Dump(info);
} else {
info.emplace_back("error: invalid argument, please see 'ability dumpsys -h'.");
}
}
void AbilityManagerService::DumpSysProcess(
@ -1830,6 +1851,47 @@ void AbilityManagerService::DumpSysProcess(
}
}
void AbilityManagerService::DataDumpSysStateInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId)
{
std::shared_ptr<DataAbilityManager> targetManager;
if (isUserID) {
auto it = dataAbilityManagers_.find(userId);
if (it == dataAbilityManagers_.end()) {
info.push_back("error: No user found'.");
return;
}
targetManager = it->second;
} else {
targetManager = dataAbilityManager_;
}
CHECK_POINTER(targetManager);
std::vector<std::string> argList;
SplitStr(args, " ", argList);
if (argList.empty()) {
return;
}
if (argList.size() == MIN_DUMP_ARGUMENT_NUM) {
targetManager->DumpSysState(info, isClient, argList[1]);
} else if (argList.size() < MIN_DUMP_ARGUMENT_NUM) {
targetManager->DumpSysState(info, isClient);
} else {
info.emplace_back("error: invalid argument, please see 'ability dump -h'.");
}
}
void AbilityManagerService::SystemDumpSysStateInner(
const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int userId)
{
if (useNewMission_) {
kernalAbilityManager_->DumpSysState(info, isClient);
} else {
systemAppManager_->DumpSysState(info, isClient);
}
}
void AbilityManagerService::DumpInner(const std::string &args, std::vector<std::string> &info)
{
if (useNewMission_) {
@ -2227,11 +2289,12 @@ void AbilityManagerService::OnAbilityRequestDone(const sptr<IRemoteObject> &toke
void AbilityManagerService::OnAppStateChanged(const AppInfo &info)
{
HILOG_INFO("On app state changed.");
currentStackManager_->OnAppStateChanged(info);
connectManager_->OnAppStateChanged(info);
if (useNewMission_) {
currentMissionListManager_->OnAppStateChanged(info);
kernalAbilityManager_->OnAppStateChanged(info);
} else {
currentStackManager_->OnAppStateChanged(info);
systemAppManager_->OnAppStateChanged(info);
}
dataAbilityManager_->OnAppStateChanged(info);

View File

@ -947,6 +947,11 @@ void AbilityRecord::DumpAbilityState(
dumpInfo = " ready #" + std::to_string(isReady_) + " window attached #" +
std::to_string(isWindowAttached_) + " launcher #" + std::to_string(isLauncherAbility_);
info.push_back(dumpInfo);
dumpInfo = " callee connections: ";
info.push_back(dumpInfo);
if (callContainer_) {
callContainer_->Dump(info);
}
if (isLauncherRoot_ && IsNewVersion()) {
dumpInfo = " can restart num #" + std::to_string(restartCount_);
@ -1562,5 +1567,67 @@ bool AbilityRecord::IsSwitchingPause()
{
return isSwitchingPause_;
}
void AbilityRecord::DumpSys(std::vector<std::string> &info, bool isClient)
{
std::string dumpInfo = " AbilityRecord ID #" + std::to_string(recordId_);
info.push_back(dumpInfo);
dumpInfo = " app name [" + GetAbilityInfo().applicationName + "]";
info.push_back(dumpInfo);
dumpInfo = " main name [" + GetAbilityInfo().name + "]";
info.push_back(dumpInfo);
dumpInfo = " bundle name [" + GetAbilityInfo().bundleName + "]";
info.push_back(dumpInfo);
std::string typeStr;
GetAbilityTypeString(typeStr);
dumpInfo = " ability type [" + typeStr + "]";
info.push_back(dumpInfo);
std::shared_ptr<AbilityRecord> preAbility = GetPreAbilityRecord();
if (preAbility == nullptr) {
dumpInfo = " previous ability app name [NULL]" + LINE_SEPARATOR;
dumpInfo += " previous ability file name [NULL]";
} else {
dumpInfo =
" previous ability app name [" + preAbility->GetAbilityInfo().applicationName + "]" + LINE_SEPARATOR;
dumpInfo += " previous ability file name [" + preAbility->GetAbilityInfo().name + "]";
}
info.push_back(dumpInfo);
std::shared_ptr<AbilityRecord> nextAbility = GetNextAbilityRecord();
if (nextAbility == nullptr) {
dumpInfo = " next ability app name [NULL]" + LINE_SEPARATOR;
dumpInfo += " next ability file name [NULL]";
} else {
dumpInfo =
" next ability app name [" + nextAbility->GetAbilityInfo().applicationName + "]" + LINE_SEPARATOR;
dumpInfo += " next ability main name [" + nextAbility->GetAbilityInfo().name + "]";
}
info.push_back(dumpInfo);
dumpInfo = " state #" + AbilityRecord::ConvertAbilityState(GetAbilityState()) + " start time [" +
std::to_string(startTime_) + "]";
info.push_back(dumpInfo);
dumpInfo = " app state #" + AbilityRecord::ConvertAppState(appState_);
info.push_back(dumpInfo);
dumpInfo = " ready #" + std::to_string(isReady_) + " window attached #" +
std::to_string(isWindowAttached_) + " launcher #" + std::to_string(isLauncherAbility_);
info.push_back(dumpInfo);
if (isLauncherRoot_ && IsNewVersion()) {
dumpInfo = " can restart num #" + std::to_string(restartCount_);
info.push_back(dumpInfo);
}
DumpClientInfo(info, isClient);
}
void AbilityRecord::DumpClientInfo(std::vector<std::string> &info, bool isClient)
{
if (isClient && scheduler_ && isReady_) {
std::vector<std::string> params;
scheduler_->DumpAbilityInfo(params, info);
AppExecFwk::Configuration config;
if (DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config) == ERR_OK) {
info.emplace_back(" configuration: " + config.GetName());
}
}
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -1,189 +1,195 @@
/*
* Copyright (c) 2021 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 "call_container.h"
#include "hilog_wrapper.h"
#include "ability_manager_errors.h"
#include "ability_connect_callback_stub.h"
#include "ability_util.h"
#include "ability_event_handler.h"
#include "ability_manager_service.h"
namespace OHOS {
namespace AAFwk {
CallContainer::CallContainer()
{}
CallContainer::~CallContainer()
{
std::for_each(deathRecipientMap_.begin(),
deathRecipientMap_.end(),
[&](RecipientMapType::reference recipient) {
recipient.first->RemoveDeathRecipient(recipient.second);
});
deathRecipientMap_.clear();
callRecordMap_.clear();
}
void CallContainer::AddCallRecord(const sptr<IAbilityConnection> & connect,
const std::shared_ptr<CallRecord>& callRecord)
{
CHECK_POINTER(callRecord);
CHECK_POINTER(connect);
CHECK_POINTER(connect->AsObject());
auto iter = callRecordMap_.find(connect->AsObject());
if (iter != callRecordMap_.end()) {
RemoveConnectDeathRecipient(connect);
callRecordMap_.erase(callRecordMap_.find(connect->AsObject()));
}
AddConnectDeathRecipient(connect);
callRecord->SetConCallBack(connect);
callRecordMap_.emplace(connect->AsObject(), callRecord);
HILOG_DEBUG("Add call record to callcontainer, target: %{public}s",
callRecord->GetTargetServiceName().GetURI().c_str());
}
std::shared_ptr<CallRecord> CallContainer::GetCallRecord(const sptr<IAbilityConnection> & connect) const
{
CHECK_POINTER_AND_RETURN(connect, nullptr);
CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr);
auto mapIter = callRecordMap_.find(connect->AsObject());
if (mapIter != callRecordMap_.end()) {
return mapIter->second;
}
return nullptr;
}
bool CallContainer::RemoveCallRecord(const sptr<IAbilityConnection> & connect)
{
HILOG_DEBUG("call container release call record by callback.");
CHECK_POINTER_AND_RETURN(connect, nullptr);
CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr);
auto iter = callRecordMap_.find(connect->AsObject());
if (iter != callRecordMap_.end()) {
auto callrecord = iter->second;
if (callrecord) {
callrecord->SchedulerDisConnectDone();
}
RemoveConnectDeathRecipient(connect);
callRecordMap_.erase(callRecordMap_.find(connect->AsObject()));
HILOG_DEBUG("remove call record is success.");
return true;
}
if (callRecordMap_.empty()) {
// notify soft resouce service.
HILOG_DEBUG("this ability has no callrecord.");
}
HILOG_WARN("remove call record is not exist.");
return false;
}
void CallContainer::OnConnectionDied(const wptr<IRemoteObject> & remote)
{
HILOG_WARN("Call back is died.");
auto object = remote.promote();
CHECK_POINTER(object);
std::shared_ptr<CallRecord> callRecord = nullptr;
auto mapIter = callRecordMap_.find(object);
if (mapIter != callRecordMap_.end()) {
callRecord = mapIter->second;
}
auto abilityManagerService = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER(abilityManagerService);
auto handler = abilityManagerService->GetEventHandler();
CHECK_POINTER(handler);
auto task = [abilityManagerService, callRecord]() {
abilityManagerService->OnCallConnectDied(callRecord);
};
handler->PostTask(task);
}
bool CallContainer::CallRequestDone(const sptr<IRemoteObject> & callStub)
{
HILOG_INFO("Call Request Done start.");
CHECK_POINTER_AND_RETURN(callStub, false);
std::for_each(callRecordMap_.begin(),
callRecordMap_.end(),
[&callStub](CallMapType::reference service) {
std::shared_ptr<CallRecord> callRecord = service.second;
if (callRecord && callRecord->IsCallState(CallState::REQUESTING)) {
callRecord->SetCallStub(callStub);
callRecord->SchedulerConnectDone();
}
});
HILOG_INFO("Call Request Done end.");
return true;
}
void CallContainer::Dump(std::vector<std::string> &info, const std::string &args) const
{
HILOG_INFO("Dump call records.");
}
bool CallContainer::IsNeedToCallRequest() const
{
for (auto &iter : callRecordMap_) {
auto callRecord = iter.second;
if (callRecord && !callRecord->IsCallState(CallState::REQUESTED)) {
return true;
}
}
return false;
}
void CallContainer::AddConnectDeathRecipient(const sptr<IAbilityConnection> &connect)
{
CHECK_POINTER(connect);
CHECK_POINTER(connect->AsObject());
auto it = deathRecipientMap_.find(connect->AsObject());
if (it != deathRecipientMap_.end()) {
HILOG_ERROR("This death recipient has been added.");
return;
} else {
sptr<IRemoteObject::DeathRecipient> deathRecipient = new AbilityConnectCallbackRecipient(
std::bind(&CallContainer::OnConnectionDied, this, std::placeholders::_1));
connect->AsObject()->AddDeathRecipient(deathRecipient);
deathRecipientMap_.emplace(connect->AsObject(), deathRecipient);
}
}
void CallContainer::RemoveConnectDeathRecipient(const sptr<IAbilityConnection> &connect)
{
CHECK_POINTER(connect);
CHECK_POINTER(connect->AsObject());
auto it = deathRecipientMap_.find(connect->AsObject());
if (it != deathRecipientMap_.end()) {
it->first->RemoveDeathRecipient(it->second);
deathRecipientMap_.erase(it);
return;
}
}
} // namespace AAFwk
} // namesspace OHOS
/*
* Copyright (c) 2021 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 "call_container.h"
#include "hilog_wrapper.h"
#include "ability_manager_errors.h"
#include "ability_connect_callback_stub.h"
#include "ability_util.h"
#include "ability_event_handler.h"
#include "ability_manager_service.h"
namespace OHOS {
namespace AAFwk {
CallContainer::CallContainer()
{}
CallContainer::~CallContainer()
{
std::for_each(deathRecipientMap_.begin(),
deathRecipientMap_.end(),
[&](RecipientMapType::reference recipient) {
recipient.first->RemoveDeathRecipient(recipient.second);
});
deathRecipientMap_.clear();
callRecordMap_.clear();
}
void CallContainer::AddCallRecord(const sptr<IAbilityConnection> & connect,
const std::shared_ptr<CallRecord>& callRecord)
{
CHECK_POINTER(callRecord);
CHECK_POINTER(connect);
CHECK_POINTER(connect->AsObject());
auto iter = callRecordMap_.find(connect->AsObject());
if (iter != callRecordMap_.end()) {
RemoveConnectDeathRecipient(connect);
callRecordMap_.erase(callRecordMap_.find(connect->AsObject()));
}
AddConnectDeathRecipient(connect);
callRecord->SetConCallBack(connect);
callRecordMap_.emplace(connect->AsObject(), callRecord);
HILOG_DEBUG("Add call record to callcontainer, target: %{public}s",
callRecord->GetTargetServiceName().GetURI().c_str());
}
std::shared_ptr<CallRecord> CallContainer::GetCallRecord(const sptr<IAbilityConnection> & connect) const
{
CHECK_POINTER_AND_RETURN(connect, nullptr);
CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr);
auto mapIter = callRecordMap_.find(connect->AsObject());
if (mapIter != callRecordMap_.end()) {
return mapIter->second;
}
return nullptr;
}
bool CallContainer::RemoveCallRecord(const sptr<IAbilityConnection> & connect)
{
HILOG_DEBUG("call container release call record by callback.");
CHECK_POINTER_AND_RETURN(connect, nullptr);
CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr);
auto iter = callRecordMap_.find(connect->AsObject());
if (iter != callRecordMap_.end()) {
auto callrecord = iter->second;
if (callrecord) {
callrecord->SchedulerDisConnectDone();
}
RemoveConnectDeathRecipient(connect);
callRecordMap_.erase(callRecordMap_.find(connect->AsObject()));
HILOG_DEBUG("remove call record is success.");
return true;
}
if (callRecordMap_.empty()) {
// notify soft resouce service.
HILOG_DEBUG("this ability has no callrecord.");
}
HILOG_WARN("remove call record is not exist.");
return false;
}
void CallContainer::OnConnectionDied(const wptr<IRemoteObject> & remote)
{
HILOG_WARN("Call back is died.");
auto object = remote.promote();
CHECK_POINTER(object);
std::shared_ptr<CallRecord> callRecord = nullptr;
auto mapIter = callRecordMap_.find(object);
if (mapIter != callRecordMap_.end()) {
callRecord = mapIter->second;
}
auto abilityManagerService = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER(abilityManagerService);
auto handler = abilityManagerService->GetEventHandler();
CHECK_POINTER(handler);
auto task = [abilityManagerService, callRecord]() {
abilityManagerService->OnCallConnectDied(callRecord);
};
handler->PostTask(task);
}
bool CallContainer::CallRequestDone(const sptr<IRemoteObject> & callStub)
{
HILOG_INFO("Call Request Done start.");
CHECK_POINTER_AND_RETURN(callStub, false);
std::for_each(callRecordMap_.begin(),
callRecordMap_.end(),
[&callStub](CallMapType::reference service) {
std::shared_ptr<CallRecord> callRecord = service.second;
if (callRecord && callRecord->IsCallState(CallState::REQUESTING)) {
callRecord->SetCallStub(callStub);
callRecord->SchedulerConnectDone();
}
});
HILOG_INFO("Call Request Done end.");
return true;
}
void CallContainer::Dump(std::vector<std::string> &info) const
{
HILOG_INFO("Dump call records.");
for (auto &iter : callRecordMap_) {
auto callRecord = iter.second;
if (callRecord) {
callRecord->Dump(info);
}
}
}
bool CallContainer::IsNeedToCallRequest() const
{
for (auto &iter : callRecordMap_) {
auto callRecord = iter.second;
if (callRecord && !callRecord->IsCallState(CallState::REQUESTED)) {
return true;
}
}
return false;
}
void CallContainer::AddConnectDeathRecipient(const sptr<IAbilityConnection> &connect)
{
CHECK_POINTER(connect);
CHECK_POINTER(connect->AsObject());
auto it = deathRecipientMap_.find(connect->AsObject());
if (it != deathRecipientMap_.end()) {
HILOG_ERROR("This death recipient has been added.");
return;
} else {
sptr<IRemoteObject::DeathRecipient> deathRecipient = new AbilityConnectCallbackRecipient(
std::bind(&CallContainer::OnConnectionDied, this, std::placeholders::_1));
connect->AsObject()->AddDeathRecipient(deathRecipient);
deathRecipientMap_.emplace(connect->AsObject(), deathRecipient);
}
}
void CallContainer::RemoveConnectDeathRecipient(const sptr<IAbilityConnection> &connect)
{
CHECK_POINTER(connect);
CHECK_POINTER(connect->AsObject());
auto it = deathRecipientMap_.find(connect->AsObject());
if (it != deathRecipientMap_.end()) {
it->first->RemoveDeathRecipient(it->second);
deathRecipientMap_.erase(it);
return;
}
}
} // namespace AAFwk
} // namesspace OHOS

View File

@ -1,181 +1,199 @@
/*
* Copyright (c) 2021 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 "call_record.h"
#include "hilog_wrapper.h"
#include "ability_util.h"
#include "ability_event_handler.h"
#include "ability_manager_service.h"
#include "ability_record.h"
#include "element_name.h"
namespace OHOS {
namespace AAFwk {
int64_t CallRecord::callRecordId = 0;
CallRecord::CallRecord(const int32_t callerUid, const std::shared_ptr<AbilityRecord> &targetService,
const sptr<IAbilityConnection> &connCallback, const sptr<IRemoteObject> &callToken)
: callerUid_(callerUid),
state_(CallState::INIT),
service_(targetService),
connCallback_(connCallback),
callerToken_(callToken)
{
recordId_ = callRecordId++;
startTime_ = AbilityUtil::SystemTimeMillis();
}
CallRecord::~CallRecord()
{
if (callRemoteObject_ && callDeathRecipient_) {
callRemoteObject_->RemoveDeathRecipient(callDeathRecipient_);
}
}
std::shared_ptr<CallRecord> CallRecord::CreateCallRecord(const int32_t callerUid,
const std::shared_ptr<AbilityRecord> &targetService, const sptr<IAbilityConnection> &connCallback,
const sptr<IRemoteObject> &callToken)
{
auto callRecord = std::make_shared<CallRecord>(callerUid, targetService, connCallback, callToken);
CHECK_POINTER_AND_RETURN(callRecord, nullptr);
callRecord->SetCallState(CallState::INIT);
return callRecord;
}
void CallRecord::SetCallStub(const sptr<IRemoteObject> & call)
{
CHECK_POINTER(call);
callRemoteObject_ = call;
HILOG_DEBUG("SetCallStub complete.");
if (callDeathRecipient_ == nullptr) {
callDeathRecipient_ =
new AbilityCallRecipient(std::bind(&CallRecord::OnCallStubDied, this, std::placeholders::_1));
}
callRemoteObject_->AddDeathRecipient(callDeathRecipient_);
}
sptr<IRemoteObject> CallRecord::GetCallStub()
{
return callRemoteObject_;
}
void CallRecord::SetConCallBack(const sptr<IAbilityConnection> &connCallback)
{
connCallback_ = connCallback;
}
sptr<IAbilityConnection> CallRecord::GetConCallBack() const
{
return connCallback_;
}
AppExecFwk::ElementName CallRecord::GetTargetServiceName() const
{
std::shared_ptr<AbilityRecord> tmpService = service_.lock();
if (tmpService) {
const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo();
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name);
return element;
}
return AppExecFwk::ElementName();
}
sptr<IRemoteObject> CallRecord::GetCallerToken() const
{
return callerToken_;
}
bool CallRecord::SchedulerConnectDone()
{
HILOG_DEBUG("Scheduler Connect Done by callback. id:%{public}d", recordId_);
std::shared_ptr<AbilityRecord> tmpService = service_.lock();
if (!callRemoteObject_ || !connCallback_ || !tmpService) {
HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done.");
return false;
}
const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo();
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name);
connCallback_->OnAbilityConnectDone(element, callRemoteObject_, ERR_OK);
state_ = CallState::REQUESTED;
HILOG_DEBUG("element: %{public}s, result: %{public}d. connectstate:%{public}d.", element.GetURI().c_str(),
ERR_OK, state_);
return true;
}
bool CallRecord::SchedulerDisConnectDone()
{
HILOG_DEBUG("Scheduler disconnect Done by callback. id:%{public}d", recordId_);
std::shared_ptr<AbilityRecord> tmpService = service_.lock();
if (!connCallback_ || !tmpService) {
HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done.");
return false;
}
const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo();
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name);
connCallback_->OnAbilityDisconnectDone(element, ERR_OK);
return true;
}
void CallRecord::OnCallStubDied(const wptr<IRemoteObject> & remote)
{
HILOG_WARN("callstub is died. id:%{public}d", recordId_);
auto object = remote.promote();
CHECK_POINTER(object);
auto abilityManagerService = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER(abilityManagerService);
auto handler = abilityManagerService->GetEventHandler();
CHECK_POINTER(handler);
auto task = [abilityManagerService, callRecord = shared_from_this()]() {
abilityManagerService->OnCallConnectDied(callRecord);
};
handler->PostTask(task);
}
void CallRecord::Dump(std::vector<std::string> &info) const
{
HILOG_DEBUG("CallRecord::Dump is called");
}
int32_t CallRecord::GetCallerUid() const
{
return callerUid_;
}
bool CallRecord::IsCallState(const CallState& state) const
{
return (state_ == state);
}
void CallRecord::SetCallState(const CallState& state)
{
state_ = state;
}
int CallRecord::GetCallRecordId() const
{
return recordId_;
}
} // namespace AAFwk
/*
* Copyright (c) 2021 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 "call_record.h"
#include "hilog_wrapper.h"
#include "ability_util.h"
#include "ability_event_handler.h"
#include "ability_manager_service.h"
#include "ability_record.h"
#include "element_name.h"
namespace OHOS {
namespace AAFwk {
int64_t CallRecord::callRecordId = 0;
CallRecord::CallRecord(const int32_t callerUid, const std::shared_ptr<AbilityRecord> &targetService,
const sptr<IAbilityConnection> &connCallback, const sptr<IRemoteObject> &callToken)
: callerUid_(callerUid),
state_(CallState::INIT),
service_(targetService),
connCallback_(connCallback),
callerToken_(callToken)
{
recordId_ = callRecordId++;
startTime_ = AbilityUtil::SystemTimeMillis();
}
CallRecord::~CallRecord()
{
if (callRemoteObject_ && callDeathRecipient_) {
callRemoteObject_->RemoveDeathRecipient(callDeathRecipient_);
}
}
std::shared_ptr<CallRecord> CallRecord::CreateCallRecord(const int32_t callerUid,
const std::shared_ptr<AbilityRecord> &targetService, const sptr<IAbilityConnection> &connCallback,
const sptr<IRemoteObject> &callToken)
{
auto callRecord = std::make_shared<CallRecord>(callerUid, targetService, connCallback, callToken);
CHECK_POINTER_AND_RETURN(callRecord, nullptr);
callRecord->SetCallState(CallState::INIT);
return callRecord;
}
void CallRecord::SetCallStub(const sptr<IRemoteObject> & call)
{
CHECK_POINTER(call);
callRemoteObject_ = call;
HILOG_DEBUG("SetCallStub complete.");
if (callDeathRecipient_ == nullptr) {
callDeathRecipient_ =
new AbilityCallRecipient(std::bind(&CallRecord::OnCallStubDied, this, std::placeholders::_1));
}
callRemoteObject_->AddDeathRecipient(callDeathRecipient_);
}
sptr<IRemoteObject> CallRecord::GetCallStub()
{
return callRemoteObject_;
}
void CallRecord::SetConCallBack(const sptr<IAbilityConnection> &connCallback)
{
connCallback_ = connCallback;
}
sptr<IAbilityConnection> CallRecord::GetConCallBack() const
{
return connCallback_;
}
AppExecFwk::ElementName CallRecord::GetTargetServiceName() const
{
std::shared_ptr<AbilityRecord> tmpService = service_.lock();
if (tmpService) {
const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo();
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name);
return element;
}
return AppExecFwk::ElementName();
}
sptr<IRemoteObject> CallRecord::GetCallerToken() const
{
return callerToken_;
}
bool CallRecord::SchedulerConnectDone()
{
HILOG_DEBUG("Scheduler Connect Done by callback. id:%{public}d", recordId_);
std::shared_ptr<AbilityRecord> tmpService = service_.lock();
if (!callRemoteObject_ || !connCallback_ || !tmpService) {
HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done.");
return false;
}
const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo();
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name);
connCallback_->OnAbilityConnectDone(element, callRemoteObject_, ERR_OK);
state_ = CallState::REQUESTED;
HILOG_DEBUG("element: %{public}s, result: %{public}d. connectstate:%{public}d.", element.GetURI().c_str(),
ERR_OK, state_);
return true;
}
bool CallRecord::SchedulerDisConnectDone()
{
HILOG_DEBUG("Scheduler disconnect Done by callback. id:%{public}d", recordId_);
std::shared_ptr<AbilityRecord> tmpService = service_.lock();
if (!connCallback_ || !tmpService) {
HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done.");
return false;
}
const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo();
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name);
connCallback_->OnAbilityDisconnectDone(element, ERR_OK);
return true;
}
void CallRecord::OnCallStubDied(const wptr<IRemoteObject> & remote)
{
HILOG_WARN("callstub is died. id:%{public}d", recordId_);
auto object = remote.promote();
CHECK_POINTER(object);
auto abilityManagerService = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER(abilityManagerService);
auto handler = abilityManagerService->GetEventHandler();
CHECK_POINTER(handler);
auto task = [abilityManagerService, callRecord = shared_from_this()]() {
abilityManagerService->OnCallConnectDied(callRecord);
};
handler->PostTask(task);
}
void CallRecord::Dump(std::vector<std::string> &info) const
{
HILOG_DEBUG("CallRecord::Dump is called");
std::string tempstr = " CallRecord";
tempstr += " ID #" + std::to_string (recordId_) + "\n";
tempstr += " caller";
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken_);
if (abilityRecord) {
AppExecFwk::ElementName element(
abilityRecord->GetAbilityInfo().deviceId, abilityRecord->GetAbilityInfo().bundleName,
abilityRecord->GetAbilityInfo().name);
tempstr += " uri [" + element.GetURI() + "]" + "\n";
}
std::string state = (state_ == CallState::INIT ? "INIT" :
state_ == CallState::REQUESTING ? "REQUESTING" : "REQUESTED");
tempstr += " state #" + state;
tempstr += " start time [" + std::to_string (startTime_) + "]";
info.emplace_back(tempstr);
HILOG_DEBUG("CallRecord::Dump is called1");
}
int32_t CallRecord::GetCallerUid() const
{
return callerUid_;
}
bool CallRecord::IsCallState(const CallState& state) const
{
return (state_ == state);
}
void CallRecord::SetCallState(const CallState& state)
{
state_ = state;
}
int CallRecord::GetCallRecordId() const
{
return recordId_;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -495,6 +495,48 @@ void DataAbilityManager::DumpState(std::vector<std::string> &info, const std::st
return;
}
void DataAbilityManager::DumpSysState(std::vector<std::string> &info, bool isClient, const std::string &args) const
{
if (!args.empty()) {
auto it = std::find_if(dataAbilityRecordsLoaded_.begin(),
dataAbilityRecordsLoaded_.end(),
[&args](const auto &dataAbilityRecord) { return dataAbilityRecord.first.compare(args) == 0; });
if (it != dataAbilityRecordsLoaded_.end()) {
info.emplace_back("AbilityName [ " + it->first + " ]");
it->second->Dump(info);
// add dump client info
if (isClient && it->second->GetScheduler() && it->second->GetAbilityRecord()->IsReady()) {
std::vector<std::string> params;
it->second->GetScheduler()->DumpAbilityInfo(params, info);
AppExecFwk::Configuration config;
if (DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config) == ERR_OK) {
info.emplace_back(" configuration: " + config.GetName());
}
}
} else {
info.emplace_back(args + ": Nothing to dump.");
}
} else {
info.emplace_back(" dataAbilityRecords:");
for (auto &&dataAbilityRecord : dataAbilityRecordsLoaded_) {
info.emplace_back(" uri [" + dataAbilityRecord.first + "]");
dataAbilityRecord.second->Dump(info);
dataAbilityRecord.second->GetScheduler();
// add dump client info
if (isClient && dataAbilityRecord.second->GetScheduler()
&& dataAbilityRecord.second->GetAbilityRecord()->IsReady()) {
std::vector<std::string> params;
dataAbilityRecord.second->GetScheduler()->DumpAbilityInfo(params, info);
AppExecFwk::Configuration config;
if (DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config) == ERR_OK) {
info.emplace_back(" configuration: " + config.GetName());
}
}
}
}
return;
}
void DataAbilityManager::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info)
{
HILOG_INFO("Get ability running infos");

View File

@ -306,6 +306,14 @@ void KernalAbilityManager::DumpState(std::vector<std::string> &info)
}
}
void KernalAbilityManager::DumpSysState(std::vector<std::string>& info, bool isClient)
{
info.emplace_back("SystemUIRecords:");
for (auto &ability : abilities_) {
ability->DumpSys(info, isClient);
}
}
void KernalAbilityManager::OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord)
{
std::lock_guard<std::recursive_mutex> guard(stackLock_);

View File

@ -321,6 +321,13 @@ void KernalSystemAppManager::DumpState(std::vector<std::string> &info)
ability->Dump(info);
}
}
void KernalSystemAppManager::DumpSysState(std::vector<std::string> &info, bool isClient)
{
info.emplace_back("SystemUIRecords:");
for (auto &ability : abilities_) {
ability->DumpSys(info, isClient);
}
}
void KernalSystemAppManager::OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord)
{

View File

@ -239,7 +239,7 @@ std::string MissionList::GetTypeName()
return "NORMAL";
}
case MissionListType::DEFAULT_STANDARD: {
return "DEFAULT_STAND";
return "DEFAULT_STANDARD";
}
case MissionListType::DEFAULT_SINGLE: {
return "DEFAULT_SINGLE";
@ -282,12 +282,12 @@ void MissionList::DumpStateByRecordId(
}
void MissionList::DumpList(std::vector<std::string> &info, bool isClient)
{
std::string dumpInfo = " MissionList Type #" + GetTypeName();
std::string dumpInfo = " MissionList Type #" + GetTypeName();
info.push_back(dumpInfo);
for (const auto& mission : missions_) {
if (mission) {
dumpInfo = " Mission ID #" + std::to_string(mission->GetMissionId());
dumpInfo = " Mission ID #" + std::to_string(mission->GetMissionId());
dumpInfo += " mission name #[" + mission->GetMissionName() + "]" +
" lockedState #" + std::to_string(mission->IsLockedState());
info.push_back(dumpInfo);

View File

@ -592,6 +592,63 @@ void MissionListManager::OnAbilityRequestDone(const sptr<IRemoteObject> &token,
}
}
void MissionListManager::OnAppStateChanged(const AppInfo &info)
{
std::lock_guard<std::recursive_mutex> guard(managerLock_);
if (info.state == AppState::TERMINATED || info.state == AppState::END) {
for (const auto& abilityRecord : terminateAbilityList_) {
if (!abilityRecord) {
HILOG_ERROR("abilityRecord is nullptr.");
continue;
}
if (info.processName == abilityRecord->GetAbilityInfo().process ||
info.processName == abilityRecord->GetApplicationInfo().bundleName) {
abilityRecord->SetAppState(info.state);
}
}
} else {
for (const auto& missionList : currentMissionLists_) {
auto missions = missionList->GetAllMissions();
for (const auto& missionInfo : missions) {
if (!missionInfo) {
HILOG_ERROR("missionInfo is nullptr.");
continue;
}
auto abilityRecord = missionInfo->GetAbilityRecord();
if (info.processName == abilityRecord->GetAbilityInfo().process ||
info.processName == abilityRecord->GetApplicationInfo().bundleName) {
abilityRecord->SetAppState(info.state);
}
}
}
auto defaultStandardListmissions = defaultStandardList_->GetAllMissions();
for (const auto& missionInfo : defaultStandardListmissions) {
if (!missionInfo) {
HILOG_ERROR("defaultStandardListmissions is nullptr.");
continue;
}
auto abilityRecord = missionInfo->GetAbilityRecord();
if (info.processName == abilityRecord->GetAbilityInfo().process ||
info.processName == abilityRecord->GetApplicationInfo().bundleName) {
abilityRecord->SetAppState(info.state);
}
}
auto defaultSingleListmissions = defaultSingleList_->GetAllMissions();
for (const auto& missionInfo : defaultSingleListmissions) {
if (!missionInfo) {
HILOG_ERROR("defaultSingleListmissions is nullptr.");
continue;
}
auto abilityRecord = missionInfo->GetAbilityRecord();
if (info.processName == abilityRecord->GetAbilityInfo().process ||
info.processName == abilityRecord->GetApplicationInfo().bundleName) {
abilityRecord->SetAppState(info.state);
}
}
}
}
std::shared_ptr<AbilityRecord> MissionListManager::GetAbilityRecordByToken(
const sptr<IRemoteObject> &token) const
{
@ -1609,47 +1666,49 @@ void MissionListManager::DumpMissionListByRecordId(
void MissionListManager::DumpMissionList(std::vector<std::string> &info, bool isClient, const std::string &args)
{
std::lock_guard<std::recursive_mutex> guard(managerLock_);
if (args.size() != 0 &&
args != "NORMAL" &&
args != "DEFAULT_STANDARD" &&
args != "DEFAULT_SINGLE" &&
args != "LAUNCHER") {
info.emplace_back("MissionList Type NORMAL|DEFAULT_STANDARD|DEFAULT_SINGLE|LAUNCHER");
return;
}
std::string dumpInfo = "User ID #" + std::to_string(userId_);
info.push_back(dumpInfo);
if (args.size() == 0 || args == "NORMAL") {
dumpInfo = " current mission lists:{";
dumpInfo = " Current mission lists:";
info.push_back(dumpInfo);
for (const auto& missionList : currentMissionLists_) {
if (missionList) {
missionList->DumpList(info, isClient);
}
}
dumpInfo = " }";
info.push_back(dumpInfo);
}
if (args.size() == 0 || args == "DEFAULT_STANDARD") {
dumpInfo = " default stand mission list:{";
dumpInfo = " default stand mission list:";
info.push_back(dumpInfo);
if (defaultStandardList_) {
defaultStandardList_->DumpList(info, isClient);
}
dumpInfo = " }";
info.push_back(dumpInfo);
}
if (args.size() == 0 || args == "DEFAULT_SINGLE") {
dumpInfo = " default single mission list:{";
dumpInfo = " default single mission list:";
info.push_back(dumpInfo);
if (defaultSingleList_) {
defaultSingleList_->DumpList(info, isClient);
}
dumpInfo = " }";
info.push_back(dumpInfo);
}
if (args.size() == 0 || args == "LAUNCHER") {
dumpInfo = " launcher mission list:{";
dumpInfo = " launcher mission list:";
info.push_back(dumpInfo);
if (launcherList_) {
launcherList_->DumpList(info, isClient);
}
dumpInfo = " }";
info.push_back(dumpInfo);
}
}

View File

@ -524,7 +524,7 @@ void PendingWantManager::Dump(std::vector<std::string> &info)
for (const auto &item : wantRecords_) {
const auto &pendingKey = item.first;
dumpInfo = " PendWantRecord ID #" + std::to_string(pendingKey->GetUserId()) +
dumpInfo = " PendWantRecord ID #" + std::to_string(pendingKey->GetCode()) +
" type #" + std::to_string(pendingKey->GetType());
info.push_back(dumpInfo);
dumpInfo = " bundle name [" + pendingKey->GetBundleName() + "]";
@ -548,5 +548,38 @@ void PendingWantManager::Dump(std::vector<std::string> &info)
}
}
}
void PendingWantManager::DumpByRecordId(std::vector<std::string> &info, const std::string &args)
{
std::string dumpInfo = " PendingWantRecords:";
info.push_back(dumpInfo);
for (const auto &item : wantRecords_) {
const auto &pendingKey = item.first;
if (args == std::to_string(pendingKey->GetCode())) {
dumpInfo = " PendWantRecord ID #" + std::to_string(pendingKey->GetCode()) +
" type #" + std::to_string(pendingKey->GetType());
info.push_back(dumpInfo);
dumpInfo = " bundle name [" + pendingKey->GetBundleName() + "]";
info.push_back(dumpInfo);
dumpInfo = " result who [" + pendingKey->GetRequestWho() + "]";
info.push_back(dumpInfo);
dumpInfo = " request code #" + std::to_string(pendingKey->GetRequestCode()) +
" flags #" + std::to_string(pendingKey->GetFlags());
info.push_back(dumpInfo);
dumpInfo = " resolved type [" + pendingKey->GetRequestResolvedType() + "]";
info.push_back(dumpInfo);
dumpInfo = " Wants:";
info.push_back(dumpInfo);
auto Wants = pendingKey->GetAllWantsInfos();
for (const auto& Want : Wants) {
dumpInfo = " uri [" + Want.want.GetElement().GetDeviceID() + "//" +
Want.want.GetElement().GetBundleName() + "/" + Want.want.GetElement().GetAbilityName() + "]";
info.push_back(dumpInfo);
dumpInfo = " resolved types [" + Want.resolvedTypes + "]";
info.push_back(dumpInfo);
}
}
}
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -29,8 +29,7 @@ const std::string HELP_MSG = "usage: aa <command> <options>\n"
" help list available commands\n"
" start start ability with options\n"
" stop-service stop service with options\n"
" dump dump the ability stack info\n"
" dumpsys dump the ability info\n"
" dump dump the ability info\n"
" force-stop <bundle-name> force stop the process with bundle name\n"
" test start the test framework with options\n";
@ -63,17 +62,24 @@ const std::string HELP_MSG_DUMP = "usage: aa dump <options>\n"
" -e, --serv dump the service abilities\n"
" -d, --data dump the data abilities\n";
const std::string HELP_MSG_DUMPSYS = "usage: aa dumpsys <options>\n"
const std::string HELP_MSG_DUMPSYS = "usage: aa dump <options>\n"
"options list:\n"
" -h, --help list available commands\n"
" -a, --all dump all abilities\n"
" -l, --mission-list dump mission list\n"
" -i, --ability dump abilityRecordId\n"
" -e, --extension dump elementName\n"
" -e, --extension dump elementName (API7 ExtensionRecords,"
"API8 serviceAbilityRecords)\n"
" -p, --pending dump pendingWantRecordId\n"
" -r, --process dump process\n"
" -d, --data dump the data abilities\n"
" -k, --ui dump the kenarl ability list ui stack\n"
" -u, --userId userId\n"
" -c, --client client\n";
" -c, --client client\n"
" -c, -u are auxiliary parameters and cannot be used alone\n"
" The original -s parameter is invalid\n"
" The original -m parameter is invalid\n";
const std::string HELP_MSG_TEST =
"usage: aa test <options>\n"
@ -133,8 +139,6 @@ private:
ErrCode RunAsDumpCommandOptopt();
ErrCode MakeWantFromCmd(Want &want, std::string &windowMode);
ErrCode RunAsDumpSysCommandOptopt();
ErrCode RunAsTestCommand();
bool IsTestCommandIntegrity(const std::map<std::string, std::string> &params);
ErrCode TestCommandError(const std::string &info);

View File

@ -53,7 +53,7 @@ const struct option LONG_OPTIONS_DUMP[] = {
{"mission-infos", no_argument, nullptr, 'S'},
{nullptr, 0, nullptr, 0},
};
const std::string SHORT_OPTIONS_DUMPSYS = "hal::i:e::p::r::u:c";
const std::string SHORT_OPTIONS_DUMPSYS = "hal::i:e::p::r::kd::u:c";
const struct option LONG_OPTIONS_DUMPSYS[] = {
{"help", no_argument, nullptr, 'h'},
{"all", no_argument, nullptr, 'a'},
@ -62,6 +62,8 @@ const struct option LONG_OPTIONS_DUMPSYS[] = {
{"extension", no_argument, nullptr, 'e'},
{"pending", no_argument, nullptr, 'p'},
{"process", no_argument, nullptr, 'r'},
{"data", no_argument, nullptr, 'd'},
{"ui", no_argument, nullptr, 'k'},
{"userId", required_argument, nullptr, 'u'},
{"client", no_argument, nullptr, 'c'},
{nullptr, 0, nullptr, 0},
@ -82,8 +84,7 @@ ErrCode AbilityManagerShellCommand::CreateCommandMap()
{"screen", std::bind(&AbilityManagerShellCommand::RunAsScreenCommand, this)},
{"start", std::bind(&AbilityManagerShellCommand::RunAsStartAbility, this)},
{"stop-service", std::bind(&AbilityManagerShellCommand::RunAsStopService, this)},
{"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpCommand, this)},
{"dumpsys", std::bind(&AbilityManagerShellCommand::RunAsDumpsysCommand, this)},
{"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpsysCommand, this)},
{"force-stop", std::bind(&AbilityManagerShellCommand::RunAsForceStop, this)},
{"test", std::bind(&AbilityManagerShellCommand::RunAsTestCommand, this)},
};
@ -626,7 +627,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand()
break;
}
case 'l': {
if (isfirstCommand == false) {
if (isfirstCommand == false && optarg == nullptr) {
isfirstCommand = true;
} else {
// 'aa dumpsys -i 10 -element -lastpage'
@ -664,7 +665,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand()
break;
}
case 'e': {
if (isfirstCommand == false) {
if (isfirstCommand == false && optarg == nullptr) {
isfirstCommand = true;
} else {
// 'aa dumpsys -i 10 -element'
@ -679,7 +680,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand()
break;
}
case 'p': {
if (isfirstCommand == false) {
if (isfirstCommand == false && optarg == nullptr) {
isfirstCommand = true;
} else {
result = OHOS::ERR_INVALID_VALUE;
@ -691,7 +692,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand()
break;
}
case 'r': {
if (isfirstCommand == false) {
if (isfirstCommand == false && optarg == nullptr) {
isfirstCommand = true;
} else {
// 'aa dumpsys -i 10 -render'
@ -705,6 +706,36 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand()
// 'aa dumpsys --process'
break;
}
case 'd': {
if (isfirstCommand == false && optarg == nullptr) {
isfirstCommand = true;
} else {
result = OHOS::ERR_INVALID_VALUE;
resultReceiver_.append(HELP_MSG_DUMPSYS);
return result;
}
// 'aa dumpsys -d'
// 'aa dumpsys --data'
break;
}
case 'k': {
if (isfirstCommand == false) {
isfirstCommand = true;
if (isUserID == true) {
result = OHOS::ERR_INVALID_VALUE;
resultReceiver_.append("-k is no userID option\n");
resultReceiver_.append(HELP_MSG_DUMPSYS);
return result;
}
} else {
result = OHOS::ERR_INVALID_VALUE;
resultReceiver_.append(HELP_MSG_DUMPSYS);
return result;
}
// 'aa dumpsys -k'
// 'aa dumpsys --UI'
break;
}
case 'u': {
// 'aa dumpsys -u'
// 'aa dumpsys --userId'
@ -740,6 +771,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand()
} else {
if (isfirstCommand != true) {
result = OHOS::ERR_INVALID_VALUE;
resultReceiver_.append(HELP_MSG_NO_OPTION);
resultReceiver_.append(HELP_MSG_DUMPSYS);
return result;
}