diff --git a/entry/src/main/ets/DataAbility/DataExtAbility.ets b/entry/src/main/ets/DataAbility/DataExtAbility.ets index a018224ce3036af7f78c5cc1a12871f8189579b0..d9eb8c3f89a10c0c077dceb070a4ab0e3e2ffba5 100644 --- a/entry/src/main/ets/DataAbility/DataExtAbility.ets +++ b/entry/src/main/ets/DataAbility/DataExtAbility.ets @@ -28,6 +28,7 @@ import SettingsDataConfig from '../Utils/SettingsDataConfig'; import SettingsDBHelper from '../Utils/SettingsDBHelper'; import { Log } from '../Utils/Log'; import { GlobalContext} from '../Utils/GlobalContext'; +import contextConstant from '@ohos.app.ability.contextConstant'; interface IRequest { @@ -51,18 +52,26 @@ let err:BusinessError = {'code':-1} as BusinessError; export default class DataExtAbility extends DataShareExtensionAbility { onCreate(want: Want) { - GlobalContext.thisContext = this.context; + GlobalContext.getContext().setObject('abilityContext', this.context); + // database move to DE area; + this.context.area = contextConstant.AreaMode.EL2; + this.context.area = SettingsDBHelper.getInstance().getArea(); this.onInitialized(); Log.info('onCreate context' + JSON.stringify(this.context)); } onInitialized() { Log.info('onInitialize start'); - let context = GlobalContext.thisContext as common.Context; + let context = GlobalContext.getContext().getObject('abilityContext') as Context; Log.info('onInitialize start context: ' + JSON.stringify(this.context)); - if (context !== undefined) { + if (context !== null) { SettingsDBHelper.getInstance().getRdbStore().then((rdb: relationalStore.RdbStore|undefined) => { rdbStore = rdb; + if (!rdbStore) { + Log.error('onInitialized: get rdb store failed!'); + return; + } + Log.info('onInitialized: get rdb store succeed!'); for (let i = 0; i < requests.length; i++) { let opt: string = requests[i].operation; let columns: string[] = requests[i].columns; diff --git a/entry/src/main/ets/StaticSubscriber/UserChangeStaticSubscriber.ets b/entry/src/main/ets/StaticSubscriber/UserChangeStaticSubscriber.ets index 98a83d833035cf45379baeae1204839e209e6ec1..554c849a6583ba7ea92af71bf52d666fbaf64d3f 100644 --- a/entry/src/main/ets/StaticSubscriber/UserChangeStaticSubscriber.ets +++ b/entry/src/main/ets/StaticSubscriber/UserChangeStaticSubscriber.ets @@ -69,7 +69,7 @@ export default class UserChangeStaticSubscriber extends StaticSubscriberExtensio } break case commonEventManager.Support.COMMON_EVENT_USER_REMOVED: - // 删除对应用户的数据表 + // 删除对应用户数据表 rdb?.executeSql(CURRENT_USER_TABLE_DROP + event.code, []); rdb?.executeSql(CURRENT_SECURE_USER_TABLE_DROP + event.code, []); break