interactive non-response dialog

Signed-off-by: ouyangli4 <ouyangli4@huawei.com>
This commit is contained in:
ouyangli4
2026-01-05 20:30:09 +08:00
committed by ouyangli4
parent e16472f20f
commit 2559bf3799
9 changed files with 104 additions and 55 deletions
@@ -61,6 +61,7 @@ public:
static constexpr char BUSSINESS_THREAD_BLOCK_3S[] = "BUSSINESS_THREAD_BLOCK_3S";
static constexpr char BUSSINESS_THREAD_BLOCK_6S[] = "BUSSINESS_THREAD_BLOCK_6S";
static constexpr char BACKGROUND_WARNING[] = "BACKGROUND_WARNING";
static constexpr char BUSINESS_INPUT_BLOCK[] = "BUSINESS_INPUT_BLOCK";
};
/**
* @struct FaultData
@@ -104,6 +104,7 @@ public:
void InitWarningCpuInfo(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo);
bool CheckInBackGround(const FaultData &faultData);
bool CheckAppfreezeHappend(const std::string& key, const std::string& eventName);
bool CheckNeedRecordAppRunningUnquieId(const std::string& eventName);
bool IsBetaVersion();
void InsertKillThread(int32_t state, int32_t pid, int32_t uid, const std::string& bundleName);
bool IsSkipDetect(int32_t pid, int32_t uid, const std::string& bundleName,
+11
View File
@@ -1086,6 +1086,17 @@ bool AppfreezeManager::CheckAppfreezeHappend(const std::string& key, const std::
return result;
}
bool AppfreezeManager::CheckNeedRecordAppRunningUnquieId(const std::string& eventName)
{
if (eventName == AppFreezeType::THREAD_BLOCK_3S || eventName == AppFreezeType::THREAD_BLOCK_6S ||
eventName == AppFreezeType::BUSSINESS_THREAD_BLOCK_3S ||
eventName == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S ||
eventName == AppFreezeType::BUSINESS_INPUT_BLOCK) {
return true;
}
return false;
}
bool AppfreezeManager::IsBetaVersion()
{
return g_betaVersion;
@@ -43,18 +43,16 @@ public:
virtual ~ModalSystemAppFreezeUIExtension();
void ProcessAppFreeze(bool focusFlag, const FaultData &faultData, std::string pid, std::string bundleName,
std::function<void()> callback, bool isDialogExist);
std::function<void()> callback);
private:
bool CreateModalUIExtension(std::string &pid, std::string &bundleName);
bool CreateModalUIExtension(std::string &pid, std::string &bundleName, const FaultData &faultData);
bool CreateSystemDialogWant(
std::string &pid, std::string &bundleName, sptr<IRemoteObject> token, AAFwk::Want &want);
std::string &pid, std::string &bundleName, sptr<IRemoteObject> token, AAFwk::Want &want,
const FaultData &faultData);
private:
bool lastFocusStatus = false;
uint64_t lastFreezeTime = 0;
std::mutex appFreezeResultMutex_;
std::string lastFreezePid;
};
} // namespace AppExecFwk
} // namespace OHOS
@@ -7730,7 +7730,7 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData)
return ERR_OK;
}
if (appRunningManager_ && eventName.find("THREAD_BLOCK_") != std::string::npos) {
if (appRunningManager_ && AppExecFwk::AppfreezeManager::GetInstance()->CheckNeedRecordAppRunningUnquieId(eventName)) {
std::string appRunningUniqueId;
int32_t ret = appRunningManager_->GetAppRunningUniqueIdByPid(pid, appRunningUniqueId);
TAG_LOGI(AAFwkTag::APPDFR, "ret=%{public}d, appRunningUniqueId=%{public}s", ret, appRunningUniqueId.c_str());
@@ -7748,12 +7748,9 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData)
}
#ifdef APP_NO_RESPONSE_DIALOG
// A dialog box is displayed when the PC appfreeze
bool isDialogExist = appRunningManager_ ?
appRunningManager_->CheckAppRunningRecordIsExist(APP_NO_RESPONSE_BUNDLENAME, APP_NO_RESPONSE_ABILITY) : false;
auto killFaultApp = std::bind(&AppMgrServiceInner::KillFaultApp, this, pid, bundleName, faultData, false);
ModalSystemAppFreezeUIExtension::GetInstance().ProcessAppFreeze(appRecord->GetFocusFlag(), faultData,
std::to_string(pid), bundleName, killFaultApp, isDialogExist);
std::to_string(pid), bundleName, killFaultApp);
#else
KillFaultApp(pid, bundleName, faultData);
#endif
@@ -7806,12 +7803,9 @@ void AppMgrServiceInner::TimeoutNotifyApp(int32_t pid, int32_t uid,
bool isNeedExit = (faultData.errorObject.name == AppFreezeType::APP_INPUT_BLOCK) ||
(faultData.errorObject.name == AppFreezeType::LIFECYCLE_TIMEOUT);
#ifdef APP_NO_RESPONSE_DIALOG
bool isDialogExist = appRunningManager_ ?
appRunningManager_->CheckAppRunningRecordIsExist(APP_NO_RESPONSE_BUNDLENAME, APP_NO_RESPONSE_ABILITY) :
false;
auto killFaultApp = std::bind(&AppMgrServiceInner::KillFaultApp, this, pid, bundleName, faultData, isNeedExit);
ModalSystemAppFreezeUIExtension::GetInstance().ProcessAppFreeze(true, faultData, std::to_string(pid),
bundleName, killFaultApp, isDialogExist);
bundleName, killFaultApp);
#else
KillFaultApp(pid, bundleName, faultData, isNeedExit);
#endif
@@ -34,13 +34,15 @@ namespace OHOS {
namespace AppExecFwk {
const std::string UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType";
const std::string UIEXTENSION_SYS_COMMON_UI = "sysDialog/common";
const std::string APP_FREEZE_PID = "APP_FREEZE_PID";
const std::string APP_FREEZE_PID = "pid";
const std::string FREEZE_WINDOW_POSX = "FREEZE_WINDOW_POSX";
const std::string FREEZE_WINDOW_POSY = "FREEZE_WINDOW_POSY";
const std::string FREEZE_WINDOW_WIDTH = "FREEZE_WINDOW_WIDTH";
const std::string FREEZE_WINDOW_HEIGHT = "FREEZE_WINDOW_HEIGHT";
const std::string START_BUNDLE_NAME = "startBundleName";
const std::string APP_FREEZE_TOKEN = "freezeToken";
const std::string APP_FREEZE_EVENT_NAME = "eventName";
const std::string APP_FREEZE_RUNNING_UNIQUE_ID = "appRunningUniqueId";
constexpr int32_t INVALID_USERID = -1;
constexpr int32_t MESSAGE_PARCEL_KEY_SIZE = 3;
constexpr uint32_t COMMAND_START_DIALOG = 1;
@@ -57,7 +59,7 @@ ModalSystemAppFreezeUIExtension::~ModalSystemAppFreezeUIExtension()
{}
void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const FaultData &faultData, std::string pid,
std::string bundleName, std::function<void()> callback, bool isDialogExist)
std::string bundleName, std::function<void()> callback)
{
const std::string SCENE_BAOARD_NAME = "com.ohos.sceneboard";
if ((bundleName == SCENE_BAOARD_NAME || faultData.waitSaveState) && callback) {
@@ -66,39 +68,29 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau
}
FaultDataType faultType = faultData.faultType;
std::string name = faultData.errorObject.name;
bool isAppFreezeDialog = name == AppFreezeType::THREAD_BLOCK_6S || name == AppFreezeType::APP_INPUT_BLOCK ||
name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S;
uint64_t now =
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch())
.count();
bool timeout = now - lastFreezeTime > TIMEOUT_INTERVAL_MS;
TAG_LOGI(AAFwkTag::ABILITYMGR,
"%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s", bundleName.c_str(),
focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str());
bool isPullUpBox =
isAppFreezeDialog && (pid != lastFreezePid || (pid == lastFreezePid && timeout && !isDialogExist));
bool updateTypeName = name == AppFreezeType::THREAD_BLOCK_6S || name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S;
if (pid == lastFreezePid && updateTypeName) {
lastFreezeTime = now;
if (name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S) {
return;
}
if (focusFlag && isPullUpBox) {
CreateModalUIExtension(pid, bundleName);
bool isAppFreezeDialog = name == AppFreezeType::THREAD_BLOCK_6S ||
name == AppFreezeType::APP_INPUT_BLOCK || name == AppFreezeType::BUSINESS_INPUT_BLOCK;
TAG_LOGI(AAFwkTag::ABILITYMGR,
"ProcessAppFreeze %{public}s is %{public}s pid:%{public}s eventName:%{public}s", bundleName.c_str(),
focusFlag ? "focus" : "not focus", pid.c_str(), name.c_str());
if (focusFlag && isAppFreezeDialog) {
CreateModalUIExtension(pid, bundleName, faultData);
} else if (callback && (faultType != FaultDataType::APP_FREEZE || !isAppFreezeDialog)) {
callback();
}
if (!isDialogExist && !focusFlag && lastFreezePid == pid) {
lastFreezePid = INVALID_PID;
lastFocusStatus = false;
}
}
bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string& pid, std::string& bundleName)
bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string& pid, std::string& bundleName,
const FaultData &faultData)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Create Modal UIExtension Called");
sptr<IRemoteObject> token;
AAFwk::Want want;
std::unique_lock<std::mutex> lockAssertResult(appFreezeResultMutex_);
if (!CreateSystemDialogWant(pid, bundleName, token, want)) {
if (!CreateSystemDialogWant(pid, bundleName, token, want, faultData)) {
return false;
}
auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance();
@@ -111,21 +103,20 @@ bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string& pid, s
TAG_LOGE(AAFwkTag::ABILITYMGR, "StartExtensionAbility failed, result = %{public}d", result);
return false;
}
lastFreezePid = pid;
lastFocusStatus = true;
lastFreezeTime = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count();
TAG_LOGI(AAFwkTag::ABILITYMGR, "success, result = %{public}d", result);
return true;
}
bool ModalSystemAppFreezeUIExtension::CreateSystemDialogWant(
std::string& pid, std::string& bundleName, sptr<IRemoteObject> token, AAFwk::Want &want)
std::string& pid, std::string& bundleName, sptr<IRemoteObject> token, AAFwk::Want &want,
const FaultData &faultData)
{
want.SetElementName(APP_NO_RESPONSE_BUNDLENAME, APP_NO_RESPONSE_ABILITY);
want.SetParam(UIEXTENSION_TYPE_KEY, UIEXTENSION_SYS_COMMON_UI);
want.SetParam(APP_FREEZE_PID, pid);
want.SetParam(START_BUNDLE_NAME, bundleName);
want.SetParam(APP_FREEZE_EVENT_NAME, faultData.errorObject.name);
want.SetParam(APP_FREEZE_RUNNING_UNIQUE_ID, faultData.appRunningUniqueId);
auto sceneSessionManager = Rosen::SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy();
if (!sceneSessionManager) {
@@ -151,15 +142,13 @@ bool ModalSystemAppFreezeUIExtension::CreateSystemDialogWant(
uint32_t height = 10;
int32_t focusPid = -1;
for (const auto &info : infos) {
if (info != nullptr) {
if (info->IsFocused()) {
posX = info->rect_.posX_;
posY = info->rect_.posY_;
width = info->rect_.width_;
height = info->rect_.height_;
focusPid = info->pid_;
break;
}
if (info != nullptr && info->IsFocused()) {
posX = info->rect_.posX_;
posY = info->rect_.posY_;
width = info->rect_.width_;
height = info->rect_.height_;
focusPid = info->pid_;
break;
}
}
if ((focusPid == -1) || (std::to_string(focusPid) != pid)) {
@@ -507,5 +507,32 @@ HWTEST_F(AppfreezeEventReportTest, SendAppfreezeEvent_Test_013, TestSize.Level1)
OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, eventInfo);
EXPECT_EQ(ret, 0);
}
/**
* @tc.number: SendAppfreezeEvent_Test_011
* @tc.desc: add testcase
* @tc.type: FUNC
*/
HWTEST_F(AppfreezeEventReportTest, SendAppfreezeEvent_Test_014, TestSize.Level1)
{
std::string eventName = "BUSINESS_INPUT_BLOCK";
std::string testName = "SendAppfreezeEvent_Test_014";
AppfreezeEventInfo eventInfo;
eventInfo.eventId = 14; // test value
eventInfo.bundleName = testName;
eventInfo.processName = testName;
eventInfo.binderInfo = testName;
eventInfo.freezeMemory = testName;
eventInfo.appRunningUniqueId = testName;
eventInfo.errorStack = testName;
eventInfo.errorName = testName;
eventInfo.errorMessage = testName;
eventInfo.freezeInfoFile = testName;
eventInfo.hitraceInfo = testName;
eventInfo.foregroundState = false;
int ret = AppfreezeEventReport::SendAppfreezeEvent(eventName,
OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, eventInfo);
EXPECT_EQ(ret, 0);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -612,5 +612,26 @@ HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_CheckThreadKilled_Test001, T
result = appfreezeManager->CheckThreadKilled(pid, uid, bundleName);
EXPECT_EQ(result, false);
}
/**
* @tc.number: AppfreezeManagerTest CheckNeedRecordAppRunningUnquieId Test
* @tc.desc: add testcase
* @tc.type: FUNC
*/
HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_CheckNeedRecordAppRunningUnquieId_Test001, TestSize.Level1)
{
bool result = appfreezeManager->CheckNeedRecordAppRunningUnquieId("THREAD_BLOCK_3S");
EXPECT_EQ(result, true);
result = appfreezeManager->CheckNeedRecordAppRunningUnquieId("THREAD_BLOCK_6S");
EXPECT_EQ(result, true);
result = appfreezeManager->CheckNeedRecordAppRunningUnquieId("BUSSINESS_THREAD_BLOCK_3S");
EXPECT_EQ(result, true);
result = appfreezeManager->CheckNeedRecordAppRunningUnquieId("BUSSINESS_THREAD_BLOCK_6S");
EXPECT_EQ(result, true);
result = appfreezeManager->CheckNeedRecordAppRunningUnquieId("BUSINESS_INPUT_BLOCK");
EXPECT_EQ(result, true);
result = appfreezeManager->CheckNeedRecordAppRunningUnquieId("TEST");
EXPECT_EQ(result, false);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -67,7 +67,10 @@ HWTEST_F(ModalSystemAppFreezeUiextensionTest, CreateModalUIExtension_001, TestSi
{
std::string pid = "1";
std::string bundleName = "Test";
bool ret = ModalSystemAppFreezeUIExtension::GetInstance().CreateModalUIExtension(pid, bundleName);
FaultData faultData;
faultData.errorObject.name = "Test";
faultData.appRunningUniqueId = "1";
bool ret = ModalSystemAppFreezeUIExtension::GetInstance().CreateModalUIExtension(pid, bundleName, faultData);
EXPECT_NE(ret, true);
}
@@ -84,7 +87,11 @@ HWTEST_F(ModalSystemAppFreezeUiextensionTest, CreateSystemDialogWant_001, TestSi
AAFwk::Want want;
std::string pid = "1";
std::string bundleName = "Test";
bool ret = ModalSystemAppFreezeUIExtension::GetInstance().CreateSystemDialogWant(pid, bundleName, token, want);
FaultData faultData;
faultData.errorObject.name = "Test";
faultData.appRunningUniqueId = "1";
bool ret = ModalSystemAppFreezeUIExtension::GetInstance().CreateSystemDialogWant(
pid, bundleName, token, want, faultData);
EXPECT_NE(ret, true);
}