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 bundle from '@ohos.bundle' 17import account from '@ohos.account.osAccount' 18import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit' 19 20const BUNDLE_NAME1 = 'com.example.third1'; 21const BUNDLE_NAME2 = 'com.example.third2'; 22const BUNDLE_NAME4 = 'com.example.third4'; 23const BUNDLE_NAME5 = 'com.example.third5'; 24const BUNDLE_NAME6 = 'com.example.third6'; 25const ABILITIY_NAME1 = "com.example.third5.MainAbilityA"; 26const ABILITIY_NAME2 = "com.example.third5.MainAbilityB"; 27const ABILITIY_NAME3 = "com.example.third2.MainAbilityA"; 28const ABILITIY_NAME4 = "com.example.third4.MainAbility"; 29const ABILITIY_NAME5 = "com.example.third1.MainAbilityA"; 30const ABILITIY_NAME6 = "com.example.third3.MainAbilityA"; 31const NUM_TWO = 2; 32const NUM_THREE = 3; 33const NUM_FOUR = 4; 34const NUM_NINE = 9; 35const DATATRANSFER = 1; 36const AUDIOPLAYBACK = 2; 37const AUDIORECORDING = 4; 38const LOCATION = 8; 39const BLUETOOTHINTERACTION = 16; 40const MULTIDEVICECONNECTION = 32; 41const WIFIINTERACTION = 64; 42const VOIP = 128; 43const TASKKEEPING = 256; 44let userId = 0; 45 46export default function ActsBmsGetBackGroundModes() { 47describe('ActsBmsGetBackGroundModes', function () { 48 49 beforeAll(async function (done) { 50 await account.getAccountManager().getOsAccountLocalIdFromProcess().then(account => { 51 console.info("getOsAccountLocalIdFromProcess userid ==========" + account); 52 userId = account; 53 done(); 54 }).catch(err => { 55 console.info("getOsAccountLocalIdFromProcess err ==========" + JSON.stringify(err)); 56 done(); 57 }) 58 }); 59 60 /* 61 * @tc.number: SUB_BMS_APPINFO_QUERY_0085 62 * @tc.name: getBackgroundModesMultiAbility 63 * @tc.desc: Get the information of the background modes from multi-ability application 64 */ 65 it('getBackgroundModesMultiAbility', 0, async function (done) { 66 let dataInfos = await bundle.queryAbilityByWant({ 67 action: 'action.system.home', 68 entities: ['entity.system.home'], 69 deviceId: '0', 70 bundleName: BUNDLE_NAME5, 71 abilityName: '' 72 }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); 73 expect(dataInfos.length).assertEqual(NUM_FOUR); 74 if (dataInfos.length == NUM_FOUR) { 75 expect(dataInfos[NUM_TWO].name).assertEqual(ABILITIY_NAME1); 76 expect(dataInfos[NUM_TWO].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | 77 LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); 78 expect(dataInfos[NUM_THREE].name).assertEqual(ABILITIY_NAME2); 79 expect(dataInfos[NUM_THREE].backgroundModes).assertEqual(DATATRANSFER | VOIP); 80 } 81 let bundleInfos = await bundle.getAllBundleInfo(bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, userId); 82 for (let i = 0; i < bundleInfos.length; i++) { 83 if (bundleInfos[i].name == BUNDLE_NAME5) { 84 for (let j = 0; j < bundleInfos[i].abilityInfos.length; j++) { 85 if (bundleInfos[i].abilityInfos[j].name == ABILITIY_NAME1) { 86 expect(bundleInfos[i].abilityInfos[j].backgroundModes).assertEqual(DATATRANSFER | 87 AUDIOPLAYBACK | AUDIORECORDING | LOCATION | BLUETOOTHINTERACTION | 88 MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); 89 } else if (bundleInfos[i].abilityInfos[j].name == ABILITIY_NAME2) { 90 expect(bundleInfos[i].abilityInfos[j].backgroundModes).assertEqual(DATATRANSFER | VOIP); 91 } 92 } 93 } 94 } 95 let data3 = await bundle.getBundleInfo(BUNDLE_NAME5, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); 96 expect(data3.abilityInfos[2].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | 97 LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); 98 expect(data3.abilityInfos[3].backgroundModes).assertEqual(DATATRANSFER | VOIP); 99 done(); 100 }); 101 102 /* 103 * @tc.number: SUB_BMS_APPINFO_QUERY_0086 104 * @tc.name: getBackgroundModesAllModes 105 * @tc.desc: Get all background modes information, and each ability of the application 106 * contains one of the background mode 107 */ 108 it('getBackgroundModesAllModes', 0, async function (done) { 109 let dataInfos = await bundle.queryAbilityByWant({ 110 action: 'action.system.home', 111 entities: ['entity.system.home'], 112 deviceId: '0', 113 bundleName: BUNDLE_NAME6, 114 abilityName: '' 115 }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); 116 expect(dataInfos.length).assertEqual(NUM_NINE); 117 for (let i = 0, len = dataInfos.length; i < len; i++) { 118 expect(dataInfos[i].backgroundModes).assertEqual(1 << i); 119 } 120 done(); 121 }); 122 123 /* 124 * @tc.number: SUB_BMS_APPINFO_QUERY_0087 125 * @tc.name: getBackgroundModesInvalidModes 126 * @tc.desc: Read the backgroundModes information of the app's ability and replace invalid attributes 127 */ 128 it('getBackgroundModesInvalidModes', 0, async function (done) { 129 let dataInfos = await bundle.queryAbilityByWant({ 130 action: 'action.system.home', 131 entities: ['entity.system.home'], 132 deviceId: '0', 133 bundleName: BUNDLE_NAME2, 134 abilityName: '' 135 }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); 136 expect(dataInfos.length).assertEqual(NUM_TWO); 137 if (dataInfos.length == NUM_TWO) { 138 expect(dataInfos[1].name).assertEqual(ABILITIY_NAME3) 139 expect(dataInfos[1].backgroundModes).assertEqual(AUDIOPLAYBACK | AUDIORECORDING | LOCATION 140 | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING) 141 } 142 bundle.getAllBundleInfo(bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, userId, (err, bundleInfos) => { 143 for (let i = 0; i < bundleInfos.length; i++) { 144 if (bundleInfos[i].name == BUNDLE_NAME2) { 145 for (let j = 0; j < bundleInfos[i].abilityInfos.length; j++) { 146 if (bundleInfos[i].abilityInfos[j].name == ABILITIY_NAME3) { 147 expect(bundleInfos[i].abilityInfos[j].backgroundModes).assertEqual( 148 AUDIOPLAYBACK | AUDIORECORDING | LOCATION | BLUETOOTHINTERACTION 149 | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); 150 } 151 } 152 } 153 } 154 bundle.getBundleInfo(BUNDLE_NAME2, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, (err, data3) => { 155 expect(data3.abilityInfos[1].backgroundModes).assertEqual(AUDIOPLAYBACK | AUDIORECORDING | LOCATION 156 | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); 157 done(); 158 }); 159 }); 160 }); 161 162 /* 163 * @tc.number: SUB_BMS_APPINFO_QUERY_0088 164 * @tc.name: getBackgroundModesNotModes 165 * @tc.desc: Read the backgroundModes information of the app's ability and replace invalid attributes 166 */ 167 it('getBackgroundModesNotModes', 0, async function (done) { 168 let dataInfos = await bundle.queryAbilityByWant({ 169 action: 'action.system.home', 170 entities: ['entity.system.home'], 171 deviceId: '0', 172 bundleName: BUNDLE_NAME4, 173 abilityName: '' 174 }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); 175 expect(dataInfos.length).assertEqual(1); 176 if (dataInfos.length == 1) { 177 expect(dataInfos[0].name).assertEqual(ABILITIY_NAME4) 178 expect(dataInfos[0].backgroundModes).assertEqual(0) 179 } 180 done(); 181 }); 182 183 /* 184 * @tc.number: SUB_BMS_APPINFO_QUERY_0089 185 * @tc.name: getBackgroundModesMultiHap 186 * @tc.desc: Get the backgroundModes information of the multi-hap package of the application 187 */ 188 it('getBackgroundModesMultiHap', 0, async function (done) { 189 let dataInfos = await bundle.queryAbilityByWant({ 190 action: 'action.system.home', 191 entities: ['entity.system.home'], 192 deviceId: '0', 193 bundleName: BUNDLE_NAME1, 194 abilityName: '' 195 }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); 196 expect(dataInfos.length).assertEqual(NUM_FOUR); 197 if (dataInfos.length == NUM_FOUR) { 198 expect(dataInfos[1].name).assertEqual(ABILITIY_NAME5) 199 expect(dataInfos[1].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | 200 LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING) 201 expect(dataInfos[3].name).assertEqual(ABILITIY_NAME6) 202 expect(dataInfos[3].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | 203 LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING) 204 } 205 done(); 206 }); 207 208})} 209