1048147e0Sopenharmony_ci/** 2048147e0Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3048147e0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4048147e0Sopenharmony_ci * you may not use this file except in compliance with the License. 5048147e0Sopenharmony_ci * You may obtain a copy of the License at 6048147e0Sopenharmony_ci * 7048147e0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8048147e0Sopenharmony_ci * 9048147e0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10048147e0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11048147e0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12048147e0Sopenharmony_ci * See the License for the specific language governing permissions and 13048147e0Sopenharmony_ci * limitations under the License. 14048147e0Sopenharmony_ci */ 15048147e0Sopenharmony_ci 16048147e0Sopenharmony_ciimport BaseModel from './BaseModel'; 17048147e0Sopenharmony_ciimport common from '../data/commonData' 18048147e0Sopenharmony_ciimport HiLog from '../utils/HiLog'; 19048147e0Sopenharmony_ciimport MmsPreferences from '../utils/MmsPreferences'; 20048147e0Sopenharmony_ciimport telephonySMS from '@ohos.telephony.sms'; 21048147e0Sopenharmony_ciimport LooseObject from '../data/LooseObject' 22048147e0Sopenharmony_ci 23048147e0Sopenharmony_ciconst TAG = 'SettingModel'; 24048147e0Sopenharmony_ci 25048147e0Sopenharmony_ciexport default class SettingModel extends BaseModel { 26048147e0Sopenharmony_ci setOnSettingValueListener(callback) { 27048147e0Sopenharmony_ci let data: LooseObject = {}; 28048147e0Sopenharmony_ci data.integrationSwitch = MmsPreferences.getInstance().getValueOfIntegrationSwitch(); 29048147e0Sopenharmony_ci data.maliciousWebSwitch = MmsPreferences.getInstance().getValueOfMaliciousWebSwitch(); 30048147e0Sopenharmony_ci data.showContactSwitch = MmsPreferences.getInstance().getValueOfShowContactSwitch(); 31048147e0Sopenharmony_ci callback(data); 32048147e0Sopenharmony_ci } 33048147e0Sopenharmony_ci 34048147e0Sopenharmony_ci getSettingValue(callback) { 35048147e0Sopenharmony_ci let settingValues: LooseObject = {}; 36048147e0Sopenharmony_ci settingValues.hasAggregate = MmsPreferences.getInstance().getValueOfIntegrationSwitch(); 37048147e0Sopenharmony_ci settingValues.isShowContactHeadIcon = MmsPreferences.getInstance().getValueOfShowContactSwitch(); 38048147e0Sopenharmony_ci settingValues.recallMessagesFlag = MmsPreferences.getInstance().getValueOfRecallMessageSwitch(); 39048147e0Sopenharmony_ci callback(this.encapsulateReturnResult(common.int.SUCCESS, settingValues)); 40048147e0Sopenharmony_ci } 41048147e0Sopenharmony_ci 42048147e0Sopenharmony_ci getAdvancedPageSwitchValue(callback) { 43048147e0Sopenharmony_ci let result: LooseObject = { 44048147e0Sopenharmony_ci 'deliveryReportSwitch': false, 45048147e0Sopenharmony_ci 'autoRetrieveMmsSwitch': false, 46048147e0Sopenharmony_ci 'recallMessageSwitch': false, 47048147e0Sopenharmony_ci 'autoDeleteInfoSwitch': false 48048147e0Sopenharmony_ci }; 49048147e0Sopenharmony_ci result.deliveryReportSwitch = MmsPreferences.getInstance().getValueOfDeliveryReportSwitch(); 50048147e0Sopenharmony_ci result.autoRetrieveMmsSwitch = MmsPreferences.getInstance().getValueOfAutoRetrieveMmsSwitch(); 51048147e0Sopenharmony_ci if (MmsPreferences.getInstance().getValueOfRecallMessageSwitch() == common.bool.TRUE) { 52048147e0Sopenharmony_ci result.recallMessageSwitch = true; 53048147e0Sopenharmony_ci } 54048147e0Sopenharmony_ci if (MmsPreferences.getInstance().getValueOfAutoDeleteInfoSwitch() == common.bool.TRUE) { 55048147e0Sopenharmony_ci result.autoDeleteInfoSwitch = true; 56048147e0Sopenharmony_ci } 57048147e0Sopenharmony_ci callback(this.encapsulateReturnResult(common.int.SUCCESS, result)); 58048147e0Sopenharmony_ci } 59048147e0Sopenharmony_ci 60048147e0Sopenharmony_ci updateSmscNumber(actionData, callback) { 61048147e0Sopenharmony_ci let index = actionData.index - 1; 62048147e0Sopenharmony_ci let newTelNum = actionData.number; 63048147e0Sopenharmony_ci telephonySMS.setSmscAddr(index, newTelNum).then( value => { 64048147e0Sopenharmony_ci // If card 1 65048147e0Sopenharmony_ci if (index == common.int.SIM_ONE) { 66048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_NEW_SIM_0_SMSC, newTelNum); 67048147e0Sopenharmony_ci } else if (index == common.int.SIM_TWO) { 68048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_NEW_SIM_1_SMSC, newTelNum); 69048147e0Sopenharmony_ci } 70048147e0Sopenharmony_ci return this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS) 71048147e0Sopenharmony_ci }).catch((error) => { 72048147e0Sopenharmony_ci HiLog.e(TAG, 'updateSmscNumber, setSmscAddr, error: ' + JSON.stringify(error.message)); 73048147e0Sopenharmony_ci return this.encapsulateReturnCode(common.int.FAILURE); 74048147e0Sopenharmony_ci }); 75048147e0Sopenharmony_ci } 76048147e0Sopenharmony_ci 77048147e0Sopenharmony_ci shareSmsEnterSelectedText(actionData, callback) { 78048147e0Sopenharmony_ci // The sharing API is not provided. 79048147e0Sopenharmony_ci callback(this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS)); 80048147e0Sopenharmony_ci } 81048147e0Sopenharmony_ci 82048147e0Sopenharmony_ci updateSwitchValue(keyOfSwitch, valueOfSwitch, callback) { 83048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(keyOfSwitch, valueOfSwitch); 84048147e0Sopenharmony_ci callback(this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS)); 85048147e0Sopenharmony_ci } 86048147e0Sopenharmony_ci 87048147e0Sopenharmony_ci restoreSwitchValueToDefault(callback) { 88048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_INTEGRATION_SWITCH, common.bool.TRUE); 89048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_MALICIOUS_WEB_SWITCH, common.bool.FALSE); 90048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_SHOW_CONTACT_SWITCH, common.bool.TRUE); 91048147e0Sopenharmony_ci MmsPreferences.getInstance() 92048147e0Sopenharmony_ci .setValueForSwitch(common.string.KEY_OF_DELIVERY_REPORT_SWITCH, common.DELIVERY_REPORTS.DISABLED); 93048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_AUTO_RETRIEVE_SWITCH, 94048147e0Sopenharmony_ci common.AUTO_RETRIEVE_MMS.NOT_WHEN_ROAMING); 95048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_RECALL_MESSAGE_SWITCH, common.bool.FALSE); 96048147e0Sopenharmony_ci MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_AUTO_DELETE_INFO_SWITCH, common.bool.FALSE); 97048147e0Sopenharmony_ci callback(this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS)); 98048147e0Sopenharmony_ci } 99048147e0Sopenharmony_ci}