settingsdata告警处理

Signed-off-by: chenlang10 <18577333310@163.com>
This commit is contained in:
chenlang10 2023-06-02 14:22:55 +08:00
parent da3fd7e7a0
commit bb17a49f95
5 changed files with 131 additions and 131 deletions

View File

@ -14,11 +14,11 @@
*/
import { Log } from '../Utils/Log';
import AbilityStage from "@ohos.app.ability.AbilityStage"
import AbilityStage from '@ohos.app.ability.AbilityStage'
export default class DataAbilityStage extends AbilityStage {
onCreate() {
Log.I('DataAbilityStage onCreate');
globalThis.abilityContext = this.context;
}
onCreate() :void{
Log.info('DataAbilityStage onCreate');
globalThis.abilityContext = this.context;
}
}

View File

@ -41,7 +41,7 @@ export default class DataExtAbility extends DataShareExtensionAbility {
}
onInitialized() {
Log.I('onInitialize start');
Log.info('onInitialize start');
let context = globalThis.abilityContext;
if (context != null) {
SettingsDBHelper.getInstance().getRdbStore().then((rdb: any) => {
@ -53,29 +53,29 @@ export default class DataExtAbility extends DataShareExtensionAbility {
let value = requests[i]["value"];
if (opt == "insert") {
rdbStore.insert(SettingsDataConfig.TABLE_NAME, value, function (err, ret) {
Log.I('onInitialized insert ret: ' + ret);
Log.info('onInitialized insert ret: ' + ret);
});
} else if (opt == "query") {
rdbStore.query(predicates, columns, function (err, resultSet) {
Log.I('onInitialized query ret: ' + JSON.stringify(resultSet));
Log.info('onInitialized query ret: ' + JSON.stringify(resultSet));
});
} else if (opt == "update") {
rdbStore.update(value, predicates, function (err, ret) {
Log.I('onInitialized update ret: ' + ret);
Log.info('onInitialized update ret: ' + ret);
});
}
}
}).catch(err => {
Log.E('onInitialize failed:' + JSON.stringify(err));
Log.error('onInitialize failed:' + JSON.stringify(err));
})
} else {
Log.I('onInitialize context error!');
Log.info('onInitialize context error!');
}
Log.I('onInitialize end');
Log.info('onInitialize end');
}
insert(uri, value, callback) {
Log.I('insert keyword = ' + value[SettingsDataConfig.FIELD_KEYWORD] + ' start:' + uri);
Log.info('insert keyword = ' + value[SettingsDataConfig.FIELD_KEYWORD] + ' start:' + uri);
let rdbInsert = (GrantStatus) => {
if (!GrantStatus) {
callback(-1, 0);
@ -86,28 +86,28 @@ export default class DataExtAbility extends DataShareExtensionAbility {
let request = {
"operation": "insert", "columns": null, "predicates": null, value: value
};
Log.I('insert request = ' + JSON.stringify(request));
Log.info('insert request = ' + JSON.stringify(request));
requests.push(request);
callback(-1, 0);
} else {
rdbStore.insert(SettingsDataConfig.TABLE_NAME, value, function (err, ret) {
callback(err, ret);
Log.I('insert result: ' + ret);
Log.info('insert result: ' + ret);
});
}
}
try {
Log.I('Start to verify permissions.');
Log.info('Start to verify permissions.');
this.verifyPermission(value, rdbInsert);
} catch (err) {
Log.E('Insert Data error:' + JSON.stringify(err));
Log.error('Insert Data error:' + JSON.stringify(err));
callback(-1, 0);
}
}
update(uri: string, predicates, value, callback) {
Log.I('update keyword = ' + value[SettingsDataConfig.FIELD_KEYWORD] + ' start:' + uri);
Log.info('update keyword = ' + value[SettingsDataConfig.FIELD_KEYWORD] + ' start:' + uri);
let rdbUpData = (GrantStatus) => {
if (!GrantStatus) {
callback(-1, 0);
@ -118,40 +118,40 @@ export default class DataExtAbility extends DataShareExtensionAbility {
let request = {
"operation": "update", "columns": null, "predicates": predicates, value: value
};
Log.I('update request = ' + JSON.stringify(request));
Log.info('update request = ' + JSON.stringify(request));
requests.push(request);
callback(-1, 0);
} else {
rdbStore.update(SettingsDataConfig.TABLE_NAME, value, predicates, function (err, ret) {
callback(err, ret);
Log.I('update result: ' + ret);
Log.info('update result: ' + ret);
});
}
}
try {
Log.I('Start to verify permissions.');
Log.info('Start to verify permissions.');
this.verifyPermission(value, rdbUpData);
} catch (err) {
Log.E('upData error:' + JSON.stringify(err));
Log.error('upData error:' + JSON.stringify(err));
callback(-1, 0);
}
}
delete(uri: string, predicates, callback) {
Log.I('nothing to do');
Log.info('nothing to do');
}
query(uri: string, predicates, columns: Array<string>, callback) {
Log.I( 'query start uri:' + uri);
Log.info( 'query start uri:' + uri);
if (rdbStore == null) {
let request= {"operation":"query", "columns" : columns, "predicates" : predicates, value:""};
Log.I('query request = '+ JSON.stringify(request));
Log.info('query request = '+ JSON.stringify(request));
requests.push(request);
callback(-1, {"_napiwrapper":{}});
} else {
rdbStore.query(SettingsDataConfig.TABLE_NAME, predicates, columns, function (err, resultSet) {
callback(err, resultSet);
Log.I('query result: '+ JSON.stringify(resultSet.rowCount) +'columnNames'+ JSON.stringify(resultSet.columnNames));
Log.info('query result: '+ JSON.stringify(resultSet.rowCount) +'columnNames'+ JSON.stringify(resultSet.columnNames));
});
}
}
@ -162,34 +162,34 @@ export default class DataExtAbility extends DataShareExtensionAbility {
try {
let volumeType = Audio.AudioVolumeType.RINGTONE;
Audio.getAudioManager().setVolume(volumeType, parseInt(settingsValue)).then(() => {
Log.I('settings Promise returned to indicate a successful RINGTONE setting.')
Log.info('settings Promise returned to indicate a successful RINGTONE setting.')
});
} catch (err) {
Log.I('settings RINGTONE failed error = ' + JSON.stringify(err));
Log.info('settings RINGTONE failed error = ' + JSON.stringify(err));
}
break
case SETTINGS_AUDIO_MEDIA:
try {
let volumeType = Audio.AudioVolumeType.MEDIA;
Audio.getAudioManager().setVolume(volumeType, parseInt(settingsValue)).then(() => {
Log.I('settings Promise returned to indicate a successful MEDIA setting.')
Log.info('settings Promise returned to indicate a successful MEDIA setting.')
});
} catch (err) {
Log.I('settings MEDIA failed error = ' + JSON.stringify(err));
Log.info('settings MEDIA failed error = ' + JSON.stringify(err));
}
break
case SETTINGS_AUDIO_VOICE_CALL:
try {
let volumeType = Audio.AudioVolumeType.VOICE_CALL;
Audio.getAudioManager().setVolume(volumeType, parseInt(settingsValue)).then(() => {
Log.I('settings Promise returned to indicate a successful VOICE_CALL setting.')
Log.info('settings Promise returned to indicate a successful VOICE_CALL setting.')
});
} catch (err) {
Log.I('settings VOICE_CALL failed error = ' + JSON.stringify(err));
Log.info('settings VOICE_CALL failed error = ' + JSON.stringify(err));
}
break
default:
Log.I(settingsKey + ' key is not audio');
Log.info(settingsKey + ' key is not audio');
break
}
}
@ -201,22 +201,22 @@ export default class DataExtAbility extends DataShareExtensionAbility {
}
try {
let tokenID = rpc.IPCSkeleton.getCallingTokenId();
Log.I('tokenID = ' + tokenID);
Log.info('tokenID = ' + tokenID);
let grantStatus = abilityAccessCtrl.createAtManager().verifyAccessToken(tokenID, "ohos.permission.MANAGE_SECURE_SETTINGS");
grantStatus.then(data => {
if (data == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) {
Log.I('MANAGE_SECURE_SETTINGS active');
Log.info('MANAGE_SECURE_SETTINGS active');
callBack(true);
} else {
Log.W('MANAGE_SECURE_SETTINGS grantStatus= ' + JSON.stringify(data));
Log.warn('MANAGE_SECURE_SETTINGS grantStatus= ' + JSON.stringify(data));
callBack(false);
}
}).catch((err) => {
Log.E('tokenID = ' + tokenID + ' verifyAccessToken is failed: ' + JSON.stringify(err));
Log.error('tokenID = ' + tokenID + ' verifyAccessToken is failed: ' + JSON.stringify(err));
callBack(false);
})
} catch (err) {
Log.E('err = ' + JSON.stringify(err));
Log.error('err = ' + JSON.stringify(err));
callBack(false);
}
}

View File

@ -28,7 +28,7 @@ export default class UserChangeStaticSubscriber extends StaticSubscriberExtensio
if (!event) {
return
}
Log.I(TAG + 'onReceiveEvent, event' + JSON.stringify(event))
Log.info(TAG + 'onReceiveEvent, event' + JSON.stringify(event))
let rdb: ohosDataRdb.RdbStore = await SettingsDBHelper.getInstance().getRdbStore();
switch (event.event) {
case commonEventManager.Support.COMMON_EVENT_USER_ADDED:
@ -38,7 +38,7 @@ export default class UserChangeStaticSubscriber extends StaticSubscriberExtensio
try {
let content = await SettingsDBHelper.getInstance().readDefaultFile();
if (!content) {
Log.E("readDefaultFile is failed!");
Log.error("readDefaultFile is failed!");
return
}
for (var index = 0; index < content.settings.length; index++) {
@ -47,7 +47,7 @@ export default class UserChangeStaticSubscriber extends StaticSubscriberExtensio
}
}
} catch (err) {
Log.E("loadDefaultSettingsData failed! err = " + err);
Log.error("loadDefaultSettingsData failed! err = " + err);
}
break
case commonEventManager.Support.COMMON_EVENT_USER_REMOVED:

View File

@ -16,90 +16,90 @@
import hiLog from '@ohos.hilog';
const DOMAIN: number = 0x0500;
const TAG = "SettingsData";
const TAG = 'SettingsData';
/**
* Basic log class
*/
export class Log {
/**
* Outputs info-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static I(format: string, ...args: any[]) {
if (Log.isLoggable(hiLog.LogLevel.INFO)) {
hiLog.info(DOMAIN, TAG, format, args);
}
/**
* Outputs info-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static info(format: string, ...args: string[]): void {
if (Log.isLoggable(hiLog.LogLevel.INFO)) {
hiLog.info(DOMAIN, TAG, format, args);
}
}
/**
* Outputs debug-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static D(format: string, ...args: any[]) {
if (Log.isLoggable(hiLog.LogLevel.DEBUG)) {
hiLog.debug(DOMAIN, TAG, format, args);
}
/**
* Outputs debug-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static debug(format: string, ...args: string[]): void{
if (Log.isLoggable(hiLog.LogLevel.DEBUG)) {
hiLog.debug(DOMAIN, TAG, format, args);
}
}
/**
* Outputs warning-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static W(format: string, ...args: any[]) {
if (Log.isLoggable(hiLog.LogLevel.WARN)) {
hiLog.warn(DOMAIN, TAG, format, args);
}
/**
* Outputs warning-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static warn(format: string, ...args: string[]): void {
if (Log.isLoggable(hiLog.LogLevel.WARN)) {
hiLog.warn(DOMAIN, TAG, format, args);
}
}
/**
* Outputs error-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static E(format: string, ...args: any[]) {
if (Log.isLoggable(hiLog.LogLevel.ERROR)) {
hiLog.error(DOMAIN, TAG, format, args);
}
/**
* Outputs error-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static error(format: string, ...args: string[]): void {
if (Log.isLoggable(hiLog.LogLevel.ERROR)) {
hiLog.error(DOMAIN, TAG, format, args);
}
}
/**
* Outputs fatal-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static F(format: string, ...args: any[]) {
if (Log.isLoggable(hiLog.LogLevel.FATAL)) {
hiLog.fatal(DOMAIN, TAG, format, args);
}
/**
* Outputs fatal-level logs.
*
* @param tag Identifies the log tag.
* @param format Indicates the log format string.
* @param args Indicates the log parameters.
* @since 7
*/
static fatal(format: string, ...args: string[]): void {
if (Log.isLoggable(hiLog.LogLevel.FATAL)) {
hiLog.fatal(DOMAIN, TAG, format, args);
}
}
/**
* Checks whether logs of the specified tag, and level can be printed.
*
* @param tag Identifies the log tag.
* @param level log level
* @since 7
*/
private static isLoggable(level: hiLog.LogLevel): boolean {
return hiLog.isLoggable(DOMAIN, TAG, level);
}
/**
* Checks whether logs of the specified tag, and level can be printed.
*
* @param tag Identifies the log tag.
* @param level log level
* @since 7
*/
private static isLoggable(level: number): boolean {
return hiLog.isLoggable(DOMAIN, TAG, level);
}
}

View File

@ -48,10 +48,10 @@ class SettingsDBHelper {
}
private async firstStartupConfig() : Promise<void> {
Log.I("firstStartupConfig start");
Log.info("firstStartupConfig start");
let storage = await dataStorage.getPreferences(this.context_, SETTINGSDATA_PREFERENCE)
let isFirst = await storage.get('isFirstStartUp', true)
Log.I("firstStartupConfig isFirstStartUp = " + isFirst);
Log.info("firstStartupConfig isFirstStartUp = " + isFirst);
if (isFirst) {
// 创建公共数据表
await this.rdbStore_.executeSql(SettingsDBHelper.SHARED_TABLE_CREATE_PREFIX + SettingsDBHelper.TABLE_CREATE_SUFFIX, []);
@ -61,17 +61,17 @@ class SettingsDBHelper {
await storage.flush();
await this.loadDefaultSettingsData();
}
Log.I("firstStartupConfig end");
Log.info("firstStartupConfig end");
return;
}
public async initRdbStore() {
Log.I('call initRdbStore start');
Log.info('call initRdbStore start');
this.rdbStore_ = await ohosDataRdb.getRdbStore(this.context_, { name: SettingsDataConfig.DB_NAME }, 1);
await this.firstStartupConfig();
Log.I('call initRdbStore end');
Log.info('call initRdbStore end');
return this.rdbStore_;
}
@ -91,31 +91,31 @@ class SettingsDBHelper {
private async loadGlobalSettings(key, value): Promise<void> {
if (!this.rdbStore_) {
Log.E('rdbStore is null!');
Log.error('rdbStore is null!');
return
}
Log.I("key=" + key + " value " + value);
Log.info("key=" + key + " value " + value);
await this.rdbStore_.insert(SettingsDataConfig.TABLE_NAME, { "KEYWORD": key, "VALUE": value }, (err, ret) => {
if (err) {
Log.E("loadGlobalSettings insert error:" + JSON.stringify(err));
Log.error("loadGlobalSettings insert error:" + JSON.stringify(err));
}
Log.I("loadGlobalSettings insert ret = " + ret);
Log.info("loadGlobalSettings insert ret = " + ret);
}
);
}
public async loadUserSettings(key, value, userId: number): Promise<void> {
if (!this.rdbStore_) {
Log.E('rdbStore is null!');
Log.error('rdbStore is null!');
return
}
Log.I("key=" + key + " value " + value + " userid " + userId);
Log.info("key=" + key + " value " + value + " userid " + userId);
await this.rdbStore_.insert(SettingsDataConfig.USER_TABLE_NAME + '_' + userId,
{ "KEYWORD": key, "VALUE": value }, (err, ret) => {
if (err) {
Log.E("loadGlobalSettings insert error:" + JSON.stringify(err));
Log.error("loadGlobalSettings insert error:" + JSON.stringify(err));
}
Log.I("loadGlobalSettings insert ret = " + ret);
Log.info("loadGlobalSettings insert ret = " + ret);
});
}
@ -125,22 +125,22 @@ class SettingsDBHelper {
let content = await this.context_.resourceManager.getRawFile(DEFAULT_JSON_FILE_NAME);
rawStr = String.fromCharCode.apply(null, content);
} catch (err) {
Log.E("readDefaultFile readRawFile err" + err);
Log.error("readDefaultFile readRawFile err" + err);
}
if (rawStr) {
Log.I("readDefaultFile success");
Log.info("readDefaultFile success");
return JSON.parse(rawStr);
}
return rawStr;
}
private async loadDefaultSettingsData() {
Log.I("loadDefaultSettingsData start");
Log.info("loadDefaultSettingsData start");
try {
let content = await this.readDefaultFile();
if (!content) {
Log.E("readDefaultFile is failed!");
Log.error("readDefaultFile is failed!");
return
}
for (var index = 0; index < content.settings.length; index++) {
@ -153,7 +153,7 @@ class SettingsDBHelper {
}
}
} catch (err) {
Log.E("loadDefaultSettingsData catch error! err = " + err);
Log.error("loadDefaultSettingsData catch error! err = " + err);
}
// 初始化设备名称
@ -171,7 +171,7 @@ class SettingsDBHelper {
if (defaultBrightness) {
await this.loadGlobalSettings(settings.display.SCREEN_BRIGHTNESS_STATUS, defaultBrightness);
}
Log.I("loadDefaultSettingsData end");
Log.info("loadDefaultSettingsData end");
}
}