1/** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import BaseModel from './BaseModel'; 17import common from '../data/commonData' 18import HiLog from '../utils/HiLog'; 19import MmsPreferences from '../utils/MmsPreferences'; 20import telephonySMS from '@ohos.telephony.sms'; 21import LooseObject from '../data/LooseObject' 22 23const TAG = 'SettingModel'; 24 25export default class SettingModel extends BaseModel { 26 setOnSettingValueListener(callback) { 27 let data: LooseObject = {}; 28 data.integrationSwitch = MmsPreferences.getInstance().getValueOfIntegrationSwitch(); 29 data.maliciousWebSwitch = MmsPreferences.getInstance().getValueOfMaliciousWebSwitch(); 30 data.showContactSwitch = MmsPreferences.getInstance().getValueOfShowContactSwitch(); 31 callback(data); 32 } 33 34 getSettingValue(callback) { 35 let settingValues: LooseObject = {}; 36 settingValues.hasAggregate = MmsPreferences.getInstance().getValueOfIntegrationSwitch(); 37 settingValues.isShowContactHeadIcon = MmsPreferences.getInstance().getValueOfShowContactSwitch(); 38 settingValues.recallMessagesFlag = MmsPreferences.getInstance().getValueOfRecallMessageSwitch(); 39 callback(this.encapsulateReturnResult(common.int.SUCCESS, settingValues)); 40 } 41 42 getAdvancedPageSwitchValue(callback) { 43 let result: LooseObject = { 44 'deliveryReportSwitch': false, 45 'autoRetrieveMmsSwitch': false, 46 'recallMessageSwitch': false, 47 'autoDeleteInfoSwitch': false 48 }; 49 result.deliveryReportSwitch = MmsPreferences.getInstance().getValueOfDeliveryReportSwitch(); 50 result.autoRetrieveMmsSwitch = MmsPreferences.getInstance().getValueOfAutoRetrieveMmsSwitch(); 51 if (MmsPreferences.getInstance().getValueOfRecallMessageSwitch() == common.bool.TRUE) { 52 result.recallMessageSwitch = true; 53 } 54 if (MmsPreferences.getInstance().getValueOfAutoDeleteInfoSwitch() == common.bool.TRUE) { 55 result.autoDeleteInfoSwitch = true; 56 } 57 callback(this.encapsulateReturnResult(common.int.SUCCESS, result)); 58 } 59 60 updateSmscNumber(actionData, callback) { 61 let index = actionData.index - 1; 62 let newTelNum = actionData.number; 63 telephonySMS.setSmscAddr(index, newTelNum).then( value => { 64 // If card 1 65 if (index == common.int.SIM_ONE) { 66 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_NEW_SIM_0_SMSC, newTelNum); 67 } else if (index == common.int.SIM_TWO) { 68 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_NEW_SIM_1_SMSC, newTelNum); 69 } 70 return this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS) 71 }).catch((error) => { 72 HiLog.e(TAG, 'updateSmscNumber, setSmscAddr, error: ' + JSON.stringify(error.message)); 73 return this.encapsulateReturnCode(common.int.FAILURE); 74 }); 75 } 76 77 shareSmsEnterSelectedText(actionData, callback) { 78 // The sharing API is not provided. 79 callback(this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS)); 80 } 81 82 updateSwitchValue(keyOfSwitch, valueOfSwitch, callback) { 83 MmsPreferences.getInstance().setValueForSwitch(keyOfSwitch, valueOfSwitch); 84 callback(this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS)); 85 } 86 87 restoreSwitchValueToDefault(callback) { 88 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_INTEGRATION_SWITCH, common.bool.TRUE); 89 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_MALICIOUS_WEB_SWITCH, common.bool.FALSE); 90 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_SHOW_CONTACT_SWITCH, common.bool.TRUE); 91 MmsPreferences.getInstance() 92 .setValueForSwitch(common.string.KEY_OF_DELIVERY_REPORT_SWITCH, common.DELIVERY_REPORTS.DISABLED); 93 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_AUTO_RETRIEVE_SWITCH, 94 common.AUTO_RETRIEVE_MMS.NOT_WHEN_ROAMING); 95 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_RECALL_MESSAGE_SWITCH, common.bool.FALSE); 96 MmsPreferences.getInstance().setValueForSwitch(common.string.KEY_OF_AUTO_DELETE_INFO_SWITCH, common.bool.FALSE); 97 callback(this.encapsulateReturnResult(common.int.SUCCESS, common.string.SUCCESS)); 98 } 99}