mirror of
https://gitee.com/openharmony/request_request
synced 2024-11-23 06:49:58 +00:00
commit
7acc437d5b
@ -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,
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user