mirror of
https://gitee.com/openharmony/security_asset
synced 2024-11-23 15:59:42 +00:00
fix cpp calback mem
Signed-off-by: zhangwenzhi <zhangwenzhi3@huawei.com>
This commit is contained in:
parent
134e72f638
commit
1ebb2065be
@ -85,10 +85,8 @@ pub(crate) extern "C" fn on_package_removed(user_id: i32, owner: *const u8, owne
|
||||
app_index: i32) {
|
||||
delete_data_by_owner(user_id, owner, owner_size);
|
||||
|
||||
let bundle_name = bundle_name.clone();
|
||||
|
||||
let c_str = unsafe { CStr::from_ptr(bundle_name) };
|
||||
let bundle_name = c_str.to_string_lossy().into_owned();
|
||||
let bundle_name = c_str.to_str().clone();
|
||||
|
||||
logi!("[INFO]On app -{}-{}-{}- removed.", user_id, bundle_name, app_index);
|
||||
|
||||
@ -129,10 +127,9 @@ pub(crate) extern "C" fn backup_db() {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) extern "C" fn on_app_restore(user_id: i32, bundle_name: *const u8) {
|
||||
let bundle_name = bundle_name.clone();
|
||||
pub(crate) extern "C" fn on_app_restore(user_id: i32, bundle_name: *const u8, app_index: i32) {
|
||||
let c_str = unsafe { CStr::from_ptr(bundle_name) };
|
||||
let bundle_name = c_str.to_string_lossy().into_owned();
|
||||
let bundle_name = c_str.to_str().clone();
|
||||
logi!("[INFO]On app -{}-{}- restore.", user_id, bundle_name);
|
||||
|
||||
let arc_asset_plugin = AssetPlugin::get_instance();
|
||||
@ -141,6 +138,7 @@ pub(crate) extern "C" fn on_app_restore(user_id: i32, bundle_name: *const u8) {
|
||||
let mut params = ExtDbMap::new();
|
||||
params.insert(PARAM_NAME_USER_ID, Value::Number(user_id as u32));
|
||||
params.insert(PARAM_NAME_BUNDLE_NAME, Value::Bytes(bundle_name.as_bytes().to_vec()));
|
||||
params.insert(PARAM_NAME_APP_INDEX, Value::Number(app_index as u32));
|
||||
match load.process_event(EventType::OnAppRestore, ¶ms) {
|
||||
Ok(()) => logi!("process app restore event success."),
|
||||
Err(code) => loge!("process app restore event failed, code: {}", code),
|
||||
@ -191,7 +189,7 @@ struct EventCallBack {
|
||||
on_user_removed: extern "C" fn(i32),
|
||||
on_screen_off: extern "C" fn(),
|
||||
on_charging: extern "C" fn(),
|
||||
on_app_restore: extern "C" fn(i32, *const u8),
|
||||
on_app_restore: extern "C" fn(i32, *const u8, i32),
|
||||
on_user_unlocked: extern "C" fn(i32),
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,21 @@ pub(crate) fn handle_common_event(reason: SystemAbilityOnDemandReason) {
|
||||
};
|
||||
let mut bundle_name = bundle_name.clone();
|
||||
bundle_name.push('\0');
|
||||
listener::on_app_restore(user_id, bundle_name.as_ptr());
|
||||
|
||||
let app_index = match want.get(SANDBOX_APP_INDEX) {
|
||||
Some(v) => match v.parse::<i32>() {
|
||||
Ok(parsed_value) => parsed_value,
|
||||
Err(_) => {
|
||||
loge!("[FATAL]Get restore app info failed, failed to parse appIndex");
|
||||
return;
|
||||
},
|
||||
},
|
||||
None => {
|
||||
loge!("[FATIL]Get restore app info failed, get appIndex fail");
|
||||
return;
|
||||
},
|
||||
};
|
||||
listener::on_app_restore(user_id, bundle_name.as_ptr(), app_index);
|
||||
} else if reason_name == "usual.event.USER_UNLOCKED" {
|
||||
listener::on_user_unlocked(reason.extra_data.code);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ typedef void (*OnPackageRemoved)(int32_t, const uint8_t *, uint32_t, const uint8
|
||||
typedef void (*OnUserRemoved)(int32_t);
|
||||
typedef void (*OnScreenOff)(void);
|
||||
typedef void (*OnCharging)(void);
|
||||
typedef void (*OnAppRestore)(int32_t, const uint8_t *);
|
||||
typedef void (*OnAppRestore)(int32_t, const uint8_t *, int32_t);
|
||||
typedef void (*OnUserUnlocked)(int32_t);
|
||||
|
||||
typedef struct {
|
||||
|
@ -88,7 +88,15 @@ public:
|
||||
int userId = data.GetCode();
|
||||
std::string bundleName = want.GetStringParam(BUNDLE_NAME);
|
||||
|
||||
this->eventCallBack->onAppRestore(userId, reinterpret_cast<const uint8_t *>(bundleName.c_str()));
|
||||
int appIndex = want.GetIntParam(SANDBOX_APP_INDEX, -1) : 0;
|
||||
if (appIndex == -1) {
|
||||
LOGE("[FATAL]Get app restore info failed, userId=%{public}d, appIndex=%{public}d",
|
||||
userId, appIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
this->eventCallBack->onAppRestore(userId,
|
||||
reinterpret_cast<const uint8_t *>(bundleName.c_str()), appIndex);
|
||||
}
|
||||
LOGI("[INFO]Receive event: RESTORE_START, start_time: %{public}ld", startTime);
|
||||
} else if (action == CommonEventSupport::COMMON_EVENT_USER_UNLOCKED) {
|
||||
|
Loading…
Reference in New Issue
Block a user