mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
@@ -105,11 +105,15 @@ private:
|
||||
return;
|
||||
}
|
||||
auto observer = observerWptr.lock();
|
||||
if (observer && observer->RemoveJsObserverObject(observerId)) {
|
||||
bool isEmpty = false;
|
||||
if (observer && observer->RemoveJsObserverObject(observerId, isEmpty)) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE, "observer is not exist!"));
|
||||
}
|
||||
if (isEmpty) {
|
||||
AppExecFwk::ApplicationDataManager::GetInstance().RemoveErrorObserver();
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
|
||||
|
||||
@@ -80,9 +80,11 @@ void JsErrorObserver::AddJsObserverObject(int32_t observerId, NativeValue* jsObs
|
||||
observerId, std::shared_ptr<NativeReference>(engine_.CreateReference(jsObserverObject, 1)));
|
||||
}
|
||||
|
||||
bool JsErrorObserver::RemoveJsObserverObject(int32_t observerId)
|
||||
bool JsErrorObserver::RemoveJsObserverObject(int32_t observerId, bool &isEmpty)
|
||||
{
|
||||
return jsObserverObjectMap_.erase(observerId) == 1;
|
||||
bool result = (jsObserverObjectMap_.erase(observerId) == 1);
|
||||
isEmpty = jsObserverObjectMap_.empty();
|
||||
return result;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
~JsErrorObserver();
|
||||
void OnUnhandledException(std::string errMsg) override;
|
||||
void AddJsObserverObject(int32_t observerId, NativeValue* jsObserverObject);
|
||||
bool RemoveJsObserverObject(int32_t observerId);
|
||||
bool RemoveJsObserverObject(int32_t observerId, bool &isEmpty);
|
||||
|
||||
private:
|
||||
void CallJsFunction(NativeValue* value, const char* methodName, NativeValue* const* argv, size_t argc);
|
||||
|
||||
@@ -34,13 +34,21 @@ void ApplicationDataManager::AddErrorObserver(const std::shared_ptr<IErrorObserv
|
||||
errorObserver_ = observer;
|
||||
}
|
||||
|
||||
void ApplicationDataManager::NotifyUnhandledException(const std::string &errMsg)
|
||||
bool ApplicationDataManager::NotifyUnhandledException(const std::string &errMsg)
|
||||
{
|
||||
HILOG_DEBUG("Notify error observer come.");
|
||||
std::shared_ptr<IErrorObserver> observer = errorObserver_.lock();
|
||||
if (observer) {
|
||||
observer->OnUnhandledException(errMsg);
|
||||
if (errorObserver_) {
|
||||
errorObserver_->OnUnhandledException(errMsg);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ApplicationDataManager::RemoveErrorObserver()
|
||||
{
|
||||
HILOG_DEBUG("Remove error observer come.");
|
||||
errorObserver_ = nullptr;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -68,7 +68,6 @@ namespace {
|
||||
constexpr int32_t DELIVERY_TIME = 200;
|
||||
constexpr int32_t DISTRIBUTE_TIME = 100;
|
||||
constexpr int32_t UNSPECIFIED_USERID = -2;
|
||||
constexpr int32_t JS_CRASH_DELAY_TIME = 3000;
|
||||
constexpr int SIGNAL_JS_HEAP = 39;
|
||||
constexpr int SIGNAL_JS_HEAP_PRIV = 40;
|
||||
|
||||
@@ -410,31 +409,20 @@ void MainThread::ScheduleMemoryLevel(const int level)
|
||||
*/
|
||||
void MainThread::ScheduleProcessSecurityExit()
|
||||
{
|
||||
PostProcessSecurityExitTask(false);
|
||||
}
|
||||
|
||||
void MainThread::PostProcessSecurityExitTask(bool delay)
|
||||
{
|
||||
HILOG_DEBUG("PostProcessSecurityExitTask called start");
|
||||
HILOG_DEBUG("ScheduleProcessSecurityExit called");
|
||||
wptr<MainThread> weak = this;
|
||||
auto task = [weak]() {
|
||||
auto appThread = weak.promote();
|
||||
if (appThread == nullptr) {
|
||||
HILOG_ERROR("appThread is nullptr, PostProcessSecurityExitTask failed.");
|
||||
HILOG_ERROR("appThread is nullptr, ScheduleProcessSecurityExit failed.");
|
||||
return;
|
||||
}
|
||||
appThread->HandleProcessSecurityExit();
|
||||
};
|
||||
bool result;
|
||||
if (delay) {
|
||||
result = mainHandler_->PostTask(task, JS_CRASH_DELAY_TIME);
|
||||
} else {
|
||||
result = mainHandler_->PostTask(task);
|
||||
}
|
||||
bool result = mainHandler_->PostTask(task);
|
||||
if (!result) {
|
||||
HILOG_ERROR("PostProcessSecurityExitTask post task failed");
|
||||
HILOG_ERROR("ScheduleProcessSecurityExit post task failed");
|
||||
}
|
||||
HILOG_DEBUG("PostProcessSecurityExitTask called end");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -964,7 +952,6 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
std::string errorName = GetNativeStrFromJsTaggedObj(obj, "name");
|
||||
std::string errorStack = GetNativeStrFromJsTaggedObj(obj, "stack");
|
||||
std::string summary = "Error message:" + errorMsg + "\nStacktrace:\n" + errorStack;
|
||||
ApplicationDataManager::GetInstance().NotifyUnhandledException(summary);
|
||||
time_t timet;
|
||||
time(&timet);
|
||||
OHOS::HiviewDFX::HiSysEvent::Write(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, "JS_ERROR",
|
||||
@@ -976,6 +963,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
EVENT_KEY_REASON, errorName,
|
||||
EVENT_KEY_JSVM, JSVM_TYPE,
|
||||
EVENT_KEY_SUMMARY, summary);
|
||||
if (ApplicationDataManager::GetInstance().NotifyUnhandledException(summary)) {
|
||||
return;
|
||||
}
|
||||
auto appThread = weak.promote();
|
||||
if (appThread == nullptr) {
|
||||
HILOG_ERROR("appThread is nullptr, HandleLaunchApplication failed.");
|
||||
@@ -984,7 +974,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
// if app's callback has been registered, let app decide whether exit or not.
|
||||
HILOG_ERROR("\n%{public}s is about to exit due to RuntimeError\nError type:%{public}s\n%{public}s",
|
||||
bundleName.c_str(), errorName.c_str(), summary.c_str());
|
||||
appThread->PostProcessSecurityExitTask(true);
|
||||
appThread->ScheduleProcessSecurityExit();
|
||||
};
|
||||
jsEngine.RegisterUncaughtExceptionHandler(uncaughtTask);
|
||||
application_->SetRuntime(std::move(runtime));
|
||||
|
||||
@@ -27,13 +27,14 @@ class ApplicationDataManager {
|
||||
public:
|
||||
static ApplicationDataManager &GetInstance();
|
||||
void AddErrorObserver(const std::shared_ptr<IErrorObserver> &observer);
|
||||
void NotifyUnhandledException(const std::string &errMsg);
|
||||
bool NotifyUnhandledException(const std::string &errMsg);
|
||||
void RemoveErrorObserver();
|
||||
|
||||
private:
|
||||
ApplicationDataManager();
|
||||
~ApplicationDataManager();
|
||||
DISALLOW_COPY_AND_MOVE(ApplicationDataManager);
|
||||
std::weak_ptr<IErrorObserver> errorObserver_;
|
||||
std::shared_ptr<IErrorObserver> errorObserver_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -419,8 +419,6 @@ private:
|
||||
bool PrepareAbilityDelegator(const std::shared_ptr<UserTestRecord> &record, bool isStageBased,
|
||||
BundleInfo& bundleInfo);
|
||||
|
||||
void PostProcessSecurityExitTask(bool delay);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief The handle of application not response process.
|
||||
|
||||
Reference in New Issue
Block a user