* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use ipc::parcel::MsgParcel;
use std::any::Any;
use std::collections::HashMap;
use ylong_runtime::task::JoinHandle;
use std::sync::{Arc, Mutex};
use asset_sdk::{AssetError, Value};
pub type ExtDbMap = HashMap<&'static str, Value>;
#[derive(Default, Hash, PartialEq, Eq, Clone)]
pub enum EventType {
#[default]
Sync = 0,
CleanCloudFlag = 1,
DeleteCloudData,
OnDeviceUpgrade,
OnAppRestore,
OnUserUnlocked,
OnAppCall,
OnPackageClear,
OnUserRemoved,
QuerySyncResult,
WrapData,
IsPermissionEnabled,
UpdateCloudSyncStatus,
ReportHAEvent,
}
pub const PARAM_NAME_BUNDLE_NAME: &str = "BundleName";
pub const PARAM_NAME_USER_ID: &str = "osAccount";
pub const PARAM_NAME_APP_INDEX: &str = "AppIndex";
pub const PARAM_NAME_OWNER_TYPE: &str = "OwnerType";
pub const PARAM_NAME_OWNER_INFO: &str = "OwnerInfo";
pub const PARAM_NAME_CALLER: &str = "caller";
pub const PARAM_NAME_DEVELOPER_ID: &str = "DeveloperId";
pub const PARAM_NAME_GROUP_ID: &str = "asset_group_id";
pub const PARAM_NAME_REQUIRE_ATTR_ENCRYPTED: &str = "asset_require_attr_encrypted";
pub const PARAM_NAME_ACCESSIBILITY: &str = "asset_accessibility";
pub const PARAM_NAME_ERROR_CODE: &str = "error_code";
pub const PARAM_NAME_RESULT_CODE: &str = "ResultCode";
pub const PARAM_NAME_TOTAL_COUNT: &str = "TotalCount";
pub const PARAM_NAME_FAILED_COUNT: &str = "FailedCount";
pub const PARAM_NAME_IS_HAP: &str = "IsHap";
pub const PARAM_NAME_DECRYPT_KEY_ALIAS: &str = "DecryptKeyAlias";
pub const PARAM_NAME_ENCRYPT_KEY_ALIAS: &str = "EncryptKeyAlias";
pub const PARAM_NAME_CIPHER: &str = "Cipher";
pub const PARAM_NAME_AAD: &str = "AAD";
pub const RETURN_OFFSET: &str = "ReturnOffset";
pub const RETURN_LIMIT: &str = "ReturnLimit";
pub const PARAM_NAME_EVENT_ID: &str = "event_id";
pub const PARAM_NAME_FUNCTION_NAME: &str = "function_name";
pub const PARAM_NAME_BEGIN_TIME: &str = "begin_time";
pub const PARAM_NAME_DIFF_TIME: &str = "diff_time";
pub const PARAM_NAME_EXTRA_INFO: &str = "extra_info";
pub const PARAM_NAME_CALL_STACK: &str = "asset_call_stack";
pub const PARAM_NAME_ALIAS: &str = "asset_alias";
pub const PARAM_NAME_SYNC_TYPE: &str = "asset_sync_type";
pub const PARAM_NAME_REQUIRE_PASSWORD_SET: &str = "asset_require_password_set";
pub const PARAM_NAME_AUTH_TYPE: &str = "asset_auth_type";
pub const PARAM_NAME_OP_TYPE: &str = "asset_operation_type";
pub const PARAM_NAME_RETURN_TYPE: &str = "asset_return_type";
pub const PARAM_NAME_WRAP_TYPE: &str = "asset_wrap_type";
pub const PARAM_NAME_IS_PERSISTENT: &str = "asset_is_persistent";
pub const PARAM_NAME_CONFLICT_RESOLUTION: &str = "asset_conflict_resolution";
#[derive(Default, Hash, PartialEq, Eq, Clone)]
pub enum PluginType {
#[default]
Asset = 0,
}
pub trait IAssetPluginCtx: Any + Sync + Send + std::panic::RefUnwindSafe {
fn init(&mut self, user_id: i32) -> Result<(), u32>;
fn create_adapt_cloud_table_for_specific_db(&self, db_info: &ExtDbMap, is_ce: bool) -> Result<(), u32>;
fn add(&self, attributes: &ExtDbMap) -> Result<i32, u32>;
fn ce_add(&self, attributes: &ExtDbMap) -> Result<i32, u32>;
fn add_cloud_adapt_data(
&self,
attributes: &ExtDbMap,
adapt_attributes: &ExtDbMap,
is_ce: bool,
need_lock: bool,
) -> Result<i32, u32>;
fn replace(&self, condition: &ExtDbMap, attributes: &ExtDbMap) -> std::result::Result<(), u32>;
fn ce_replace(&self, condition: &ExtDbMap, attributes: &ExtDbMap) -> std::result::Result<(), u32>;
fn query(&self, attributes: &ExtDbMap) -> Result<Vec<ExtDbMap>, u32>;
fn ce_query(&self, attributes: &ExtDbMap) -> Result<Vec<ExtDbMap>, u32>;
fn query_target_data(
&self,
db_name: &str,
columns: &[&'static str],
sql_where: &str,
limit: u32,
offset: u32,
is_ce: bool,
) -> Result<Vec<ExtDbMap>, u32>;
fn query_certain_db(
&self,
db_info: &ExtDbMap,
attributes: &ExtDbMap,
query_options: &ExtDbMap,
is_ce: bool,
is_filter_sync: bool,
) -> Result<Vec<ExtDbMap>, u32>;
fn query_certain_db_with_connect_table(
&self,
db_info: &ExtDbMap,
attributes: &ExtDbMap,
is_ce: bool,
need_lock: bool,
) -> Result<Vec<ExtDbMap>, u32>;
fn remove(&self, attributes: &ExtDbMap) -> Result<i32, u32>;
fn ce_remove(&self, attributes: &ExtDbMap) -> Result<i32, u32>;
fn remove_certain_db(&self, db_info: &ExtDbMap, attributes: &ExtDbMap, is_ce: bool) -> Result<i32, u32>;
fn remove_with_specific_cond(&self, specific_cond: &str, condition_value: &[Value]) -> Result<i32, u32>;
fn ce_remove_with_specific_cond(&self, specific_cond: &str, condition_value: &[Value]) -> Result<i32, u32>;
fn remove_cloud_adapt_data(
&self,
db_info: &ExtDbMap,
attributes: Option<&ExtDbMap>,
adapt_attributes: Option<&ExtDbMap>,
is_ce: bool,
need_lock: bool,
) -> Result<i32, u32>;
fn update(&self, attributes: &ExtDbMap, attrs_to_update: &ExtDbMap) -> Result<i32, u32>;
fn ce_update(&self, attributes: &ExtDbMap, attrs_to_update: &ExtDbMap) -> Result<i32, u32>;
fn get_certain_db_lock(
&self,
db_info: &ExtDbMap,
is_ce: bool,
) -> Result<Arc<Mutex<i32>>, u32>;
fn get_storage_path(&self) -> String;
fn increase_count(&self);
fn decrease_count(&self);
fn add_task(&self, handle: JoinHandle<()>);
fn is_ce_upgrade(&self, user_id: i32) -> bool;
fn store_key_value(&self, user_id: i32, column_key: &str, column_value: i32) -> bool;
fn query_value(&self, user_id: i32, column_key: &str) -> Result<i32, AssetError>;
fn is_device_locked(&self) -> Result<bool, u32>;
}
pub trait IAssetPlugin: Any + Sync + Send + std::panic::RefUnwindSafe {
fn init(&self, ctx: Box<dyn IAssetPluginCtx>) -> Result<(), u32>;
fn uninit(&self);
fn process_event(&self, event_type: EventType, params: &mut ExtDbMap) -> Result<(), u32>;
fn redirect_request(&self, code: u32, data: &mut MsgParcel, reply: &mut MsgParcel) -> Result<(), i32>;
fn on_sa_extension(&self, extension: String, data: &mut MsgParcel, reply: &mut MsgParcel) -> Result<(), i32>;
}