!86 修改KvManager引起的crash

Merge pull request !86 from 李婷婷/master
This commit is contained in:
openharmony_ci 2023-04-07 03:02:04 +00:00 committed by Gitee
commit bbdb235a43
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 0 additions and 323 deletions

View File

@ -1,7 +1,6 @@
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import LogUtils from '../common/utils/LogUtils'
import { closeKVStore } from '../common/utils/KvManager'
const TAG = "MainAbility";
@ -12,7 +11,6 @@ export default class MainAbility extends Ability {
}
onDestroy() {
closeKVStore();
LogUtils.i(TAG, "onDestroy")
}

View File

@ -25,7 +25,6 @@ import {
disableImsSwitchCardOne,
disableImsSwitchCardTwo
} from '../../../model/mobileDataStatus';
import { setCache } from '../../utils/KvManager';
import LogUtils from '../../utils/LogUtils'
const TAG = "ListItem"
@ -115,9 +114,6 @@ export default struct listItem {
.onChange((isOn: boolean) => {
this.controlSwitch = !this.controlSwitch;
LogUtils.i(TAG, 'onclick cardType is :' + JSON.stringify(this.cardType) + 'switcher is:' + JSON.stringify(this.isCon) + "Switch status:" + this.controlSwitch);
if (this.isCon === 1) {
setCache(this.radio_state_enable5g, isOn);
}
if (this.controlSwitch && this.isCon === 0) {
this.dialogTitle = this.title;
this.recordTypeDialog.open();

View File

@ -1,140 +0,0 @@
/*
* Copyright (c) 2023 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.
*/
import distributedKVStore from '@ohos.data.distributedKVStore'
import LogUtils from '../utils/LogUtils'
const TAG = "KVManager"
/**
* Distributed database Basic configuration
*/
let kvManager: any = AppStorage.Get("kvManager")
const options = {
createIfMissing: true,
encrypt: false,
backup: false,
autoSync: true,
kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
securityLevel: distributedKVStore.SecurityLevel.S2,
};
/**
* Distributed database Basic configuration
*/
const kvManagerConfig = {
context: globalThis.settingsAbilityContext,
bundleName: 'com.example.callui',
userInfo: {
userId: '0',
userType: 0
}
};
function createKVManager() {
try {
LogUtils.i(TAG, "succeeded in creating KVManager")
kvManager = distributedKVStore.createKVManager(kvManagerConfig);
AppStorage.SetOrCreate("kvManager", kvManager)
} catch(e) {
LogUtils.i(TAG, "Failed to create KVManager.code is " + JSON.stringify(e.code) + " message is : " + JSON.stringify(e.message))
}
}
/**
* Create a database instance
*
* @param {Function} callback - Callback
*/
function getKVStore(callback) {
if (kvManager == undefined) {
createKVManager();
}
kvManager.getKVStore('storeId', options).then((store) => {
callback(store);
});
}
/**
* Distributed database Set up storage
*
* @param {string} key - storage key
* @param {string} value - storage value
*/
export function setCache(key, value) {
getKVStore(
(store) => {
store.put(key, value).then((data) => {
LogUtils.i(TAG, `put success key ${key}, value: ${value}:` + JSON.stringify(data))
if (key === 'pinRemainingTime') {
getCache(key, (data) => {
LogUtils.i(TAG, `getCache success key ${key}: ` + JSON.stringify(data))
});
}
}).catch((err) => {
LogUtils.i(TAG, 'put err: ' + JSON.stringify(err));
});
}
);
}
/**
* Distributed database Get up storage
*
* @param {string} key - storage key
* @param {Function} callback - Callback
*/
export function getCache(key, callback) {
getKVStore((store) => {
store.get(key).then((data) => {
callback(data);
}).catch((err) => {
LogUtils.i(TAG, 'getCache err: ' + JSON.stringify(err));
callback(null, err);
});
});
}
/**
* Distributed database Get up storage
*
* @param {string} key - storage key
* @param {Function} callback - Callback
*/
export function deleteCache(key, callback) {
getKVStore((store) => {
store.delete(key).then((data) => {
callback(data);
}).catch((err) => {
callback(null, err);
});
});
}
/**
* Distributed database close storage
*/
export function closeKVStore() {
getKVStore((store) => {
kvManager.closeKVStore("appId", "storeId", function (err, data) {
if (err != undefined) {
LogUtils.e(TAG, `Fail to close KVStore code is ${err.code}, message is ${err.message} `)
}
})
})
}

View File

@ -1,7 +1,6 @@
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import LogUtils from '../common/utils/LogUtils'
import { closeKVStore } from '../common/utils/KvManager'
const TAG = "MainAbility";
@ -13,7 +12,6 @@ export default class MainAbility extends Ability {
onDestroy() {
LogUtils.i(TAG, "onDestroy");
closeKVStore();
}
onWindowStageCreate(windowStage: Window.WindowStage) {

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { setCache, getCache, deleteCache } from '../utils/KvManager'
import UpdataInfo from './dialog/upDataInfo'
import StopSim from './dialog/stopSim'
import EditSimInfo from './dialog/editSimInfo'
@ -137,7 +136,6 @@ export default struct eSimSet {
action: (stop) => {
this.defaultSetString = $r('app.string.sim_null_character');
if (this.curEditList.id === 0) {
setCache(this.SIM_CARD_Change, 1);
this.setSimActive(0, false)
this.list[0].name = $r('app.string.sim_not_enabled');
this.isStop1 = false;

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { setCache, getCache } from '../../utils/KvManager'
import simServiceProxy from '../../../model/simServiceProxy'
import LogUtils from '../../../common/utils/LogUtils'
@ -182,10 +181,8 @@ export default struct DefaultDialCard {
}
}.height(64)
.onClick(() => {
setCache(this.SIM_CARD_DEFAULT, '+8618851354122');
this.action($r('app.string.sim_card_two_no_space'));
this.changeCard1 = false;
setCache(this.SIM_CARD_KEYWORD, 2)
this.setDefaultVoiceSlotId(1)
this.changeCard2 = true;
this.changeDefault = false;

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { setCache } from '../../utils/KvManager'
import { getString } from '../../utils/Utils'
@CustomDialog
@ -57,7 +56,6 @@ export default struct StopSim {
Text($r('app.string.stop_use'))
.fontSize('16vp')
.onClick(() => {
setCache(this.SIM_CARD_DEFAULT, '不设置');
this.isChange = false;
this.controller.close();
this.action(false);

View File

@ -1,137 +0,0 @@
/*
* Copyright (c) 2023 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.
*/
import distributedKVStore from '@ohos.data.distributedKVStore'
import LogUtils from '../utils/LogUtils'
const TAG = "KVManager"
let kvManager: any = AppStorage.Get("kvManager");
/**
* Distributed database Basic configuration
*/
const options = {
createIfMissing: true,
encrypt: false,
backup: false,
autoSync: true,
kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
securityLevel: distributedKVStore.SecurityLevel.S2,
};
/**
* Distributed database Basic configuration
*/
const kvManagerConfig = {
context: globalThis.simCardAbilityContext,
bundleName: 'com.example.callui',
userInfo: {
userId: '0',
userType: 0
}
};
function createKVManager() {
try {
LogUtils.i(TAG, "succeeded in creating KVManager")
kvManager = distributedKVStore.createKVManager(kvManagerConfig);
AppStorage.SetOrCreate("kvManager", kvManager)
} catch(e) {
LogUtils.i(TAG, "Failed to create KVManager.code is " + JSON.stringify(e.code) + " message is : " + JSON.stringify(e.message))
}
}
/**
* Create a database instance
*
* @param {Function} callback - Callback
*/
function getKVStore(callback) {
if (kvManager == undefined) {
createKVManager();
}
kvManager.getKVStore('storeId', options).then((store) => {
callback(store);
});
}
/**
* Distributed database Set up storage
*
* @param {string} key - storage key
* @param {string} value - storage value
*/
export function setCache(key, value) {
getKVStore(
(store) => {
store.put(key, value).then((data) => {
LogUtils.i(TAG, `put success key ${key}, value: ${value}:` + JSON.stringify(data))
if (key === 'pinRemainingTime') {
getCache(key, (data) => {
LogUtils.i(TAG, `getCache success key ${key}: ` + JSON.stringify(data))
});
}
}).catch((err) => {
LogUtils.i(TAG, 'put err: ' + JSON.stringify(err));
});
}
);
}
/**
* Distributed database Get up storage
*
* @param {string} key - storage key
* @param {Function} callback - Callback
*/
export function getCache(key, callback) {
getKVStore((store) => {
store.get(key).then((data) => {
callback(data);
}).catch((err) => {
LogUtils.i(TAG, 'getCache err: ' + JSON.stringify(err));
callback(null, err);
});
});
}
/**
* Distributed database Get up storage
*
* @param {string} key - storage key
* @param {Function} callback - Callback
*/
export function deleteCache(key, callback) {
getKVStore((store) => {
store.delete(key).then((data) => {
callback(data);
}).catch((err) => {
callback(null, err);
});
});
}
/**
* Distributed database close storage
*/
export function closeKVStore() {
getKVStore((store) => {
kvManager.closeKVStore("appId", "storeId", function (err, data) {
if (err != undefined) {
LogUtils.e(TAG, `Fail to close KVStore code is ${err.code}, message is ${err.message} `)
}
})
})
}

View File

@ -20,7 +20,6 @@ import CardSetData from '../common/config/cardSetData';
import SetFlowLimit from '../common/components/dialog/setFlowLimit'
import DefaultDialCard from '../common/components/dialog/defalutDialing'
import cardInfoData from '../common/config/cardInfoData';
import { setCache, getCache } from '../common/utils/KvManager'
import dataServiceProxy from '../model/dataServiceProxy';
import simServiceProxy from '../model/simServiceProxy'
import DefaultCard from '../common/components/defaultCard'
@ -134,13 +133,6 @@ struct Index {
aboutToAppear() {
LogUtils.i(TAG, "aboutToAppear")
getCache(this.SHOW_CHANGE, (data) => {
if (data == 0) {
this.isShow = false;
} else {
this.isShow = true;
};
});
}
getDefaultDataSlotId() {
@ -159,28 +151,6 @@ struct Index {
this.getShowNumber(1);
this.getDefaultVoiceSlotld();
this.getDefaultDataSlotId();
getCache(this.SIM_CARD_Change, (data) => {
if (data == null) {
setCache(this.SIM_CARD_Change, 0);
} else {
if (data == 0) {
this.defaultDataChange = true;
} else {
this.defaultDataChange = false;
};
};
});
getCache(this.SIM_CARD_STOP, (data) => {
if (data != null) {
this.isStop = data;
}
;
});
getCache(this.SIM_CARD_DEFAULT, (data) => {
this.defaultset = data.replace('\'', '').replace('\'', '');
});
LogUtils.i(TAG, "onPageShow end ")
}
@ -226,7 +196,6 @@ struct Index {
.opacity(this.isStop ? 1 : 0.4)
.onClick(() => {
LogUtils.i(TAG, "onclick defaultcard card one")
setCache(this.SIM_CARD_Change, 0);
this.setDefaultDataSlotId(0)
this.defaultDataChange = !this.defaultDataChange;
})