1/* 2 * Copyright (c) 2024 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 file from '@system.file'; 17import storage from '@system.storage'; 18let strData = ''; 19export const saveTxtData = function (obj, str) { 20 21 console.info('saveTxtData key= ' + obj.title + ', str= ' + str); 22 let keyStr = obj.title; 23 storage.set({ 24 key: keyStr, 25 value: str, 26 success: function () { 27 console.info('storage set success, key= ' + keyStr + 'value= ' + str); 28 }, 29 fail: function () { 30 console.info('storage set fail, key= ' + keyStr + 'value= ' + str); 31 }, 32 complete: function () { 33 console.info('storage set call complete'); 34 } 35 }); 36 37}; 38 39export const getTxtData = function () { 40 let keyList = [ 41 'chart(bar)', 42 'chart(line)', 43 'image-animator', 44 'input', 45 'list-item', 46 'longpress', 47 'marquee', 48 'opacity', 49 'picker-view', 50 'progress', 51 'qrcode', 52 'slider', 53 'swipe', 54 'swiper', 55 'switch', 56 'transition', 57 'app', 58 'configuration', 59 'timer(timeout)', 60 'timer(interval)', 61 'storage', 62 'file', 63 'vibrator', 64 'stepCounter', 65 'barometer', 66 'heartRate', 67 'onBodyState', 68 'accelerometer', 69 'gyroscope', 70 'location(info)', 71 'location(subscribe)', 72 'deviceInfo', 73 'brightness(value)', 74 'brightness(mode)', 75 'battery', 76 'nfc' 77 ]; 78 79 for (let index = 0; index < keyList.length; index++) { 80 const element = keyList[index]; 81 getStorageData(element, index, keyList.length); 82 } 83}; 84 85export const getStorageData = function (element, index, totalLength) { 86 87 storage.get({ 88 key: element, 89 success: function (data) { 90 console.info('storage get call success, key= ' + element + ', value= ' + data); 91 if (data !== '') { 92 strData += element + ':' + data; 93 } 94 if (index === totalLength - 1) { 95 console.info('get data complete strData= ' + strData); 96 saveTxtFile(strData); 97 } 98 }, 99 fail: function (data, code) { 100 console.info('storage get call fail, key= ' + element); 101 }, 102 complete: function () { 103 console.info('storage get call complete'); 104 }, 105 }); 106}; 107 108export const saveTxtFile = function (str) { 109 console.info('write str= ' + str); 110 file.writeText({ 111 uri: 'internal://app/summary_report.json', 112 text: str, 113 success: function() { 114 console.log('call writeText success.'); 115 }, 116 fail: function(data, code) { 117 console.error('write call fail callback fail, code: ' + code + ', data: ' + data); 118 }, 119 }); 120};