1/* 2 * Copyright (c) 2021 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 LocationService from './LocationService'; 17import LogUtil from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil'; 18import ConfigData from '../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData'; 19 20export const LocationServiceOpenStatusKey = "LocationServiceStatus"; 21 22export class LocationVM { 23 mIsStart: boolean = false; 24 25 initViewModel() { 26 if (this.mIsStart) { 27 return; 28 } 29 LogUtil.info(ConfigData.TAG + 'init location view model') 30 this.mIsStart = true; 31 LocationService.registerListener(this); 32 LocationService.startService(); 33 } 34 35 updateServiceState(state) { 36 LogUtil.info(ConfigData.TAG + `update location service state, state: ${state} `) 37 AppStorage.SetOrCreate(LocationServiceOpenStatusKey, state); 38 } 39 40 enableLocation() { 41 LogUtil.info(ConfigData.TAG + 'enable location') 42 LocationService.enableLocation(); 43 } 44 45 disableLocation() { 46 LogUtil.info(ConfigData.TAG + 'disable location') 47 LocationService.disableLocation(); 48 } 49} 50 51let locationVM = new LocationVM(); 52 53export default locationVM as LocationVM; 54