!1010 foundation拉起后重新添加回调。

Merge pull request !1010 from fqwert/ee
This commit is contained in:
openharmony_ci 2024-10-05 09:51:56 +00:00 committed by Gitee
commit 7acc437d5b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 28 additions and 7 deletions

View File

@ -17,6 +17,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use hisysevent::{build_number_param, write, EventType};
use samgr::definition::APP_MGR_SERVICE_ID;
use samgr::manage::SystemAbilityManager;
use system_ability_fwk::ability::{Ability, Handler};
use crate::manage::app_state::AppStateListener;
@ -92,6 +94,17 @@ impl RequestAbility {
AppStateListener::init(client_manger.clone(), task_manager.clone());
SystemAbilityManager::subscribe_system_ability(
APP_MGR_SERVICE_ID,
|_, _| {
info!("app manager service init");
AppStateListener::register();
},
|_, _| {
error!("app Manager service died");
},
);
let stub = RequestServiceStub::new(
handler.clone(),
task_manager,

View File

@ -12,6 +12,7 @@
// limitations under the License.
use std::mem::MaybeUninit;
use std::sync::Once;
use super::task_manager::TaskManagerTx;
use crate::manage::events::{StateEvent, TaskManagerEvent};
@ -24,22 +25,29 @@ pub(crate) struct AppStateListener {
}
static mut APP_STATE_LISTENER: MaybeUninit<AppStateListener> = MaybeUninit::uninit();
static ONCE: Once = Once::new();
impl AppStateListener {
pub(crate) fn init(client_manager: ClientManagerEntry, task_manager: TaskManagerTx) {
info!("AppStateListener init");
unsafe {
APP_STATE_LISTENER.write(AppStateListener {
client_manager,
task_manager,
ONCE.call_once(|| {
APP_STATE_LISTENER.write(AppStateListener {
client_manager,
task_manager,
});
});
#[cfg(feature = "oh")]
{
RegisterAPPStateCallback(app_state_change_callback);
RegisterProcessStateCallback(process_state_change_callback);
}
}
pub(crate) fn register() {
if ONCE.is_completed() {
unsafe {
RegisterAPPStateCallback(app_state_change_callback);
RegisterProcessStateCallback(process_state_change_callback);
}
}
info!("AppStateListener init ok");
}
}