diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets index 4a133512091174822aa449d6f63f63d340515880..960f33bcb1e42b988eb4749e9386d18a0f29940a 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets @@ -43,14 +43,14 @@ class ApplicationObj { labelId: string iconId: string index: number - accessTokenId: string + accessTokenId: number permission: string alphabeticalIndex: string constructor( labelId: string, iconId: string, index: number, - accessTokenId: string, + accessTokenId: number, permission: string, alphabeticalIndex: string) { this.labelId = labelId @@ -262,6 +262,15 @@ struct applicationItem { } }) }) + + // initial then fill values when sync return which may cause sync panic + for (let i = 0; i < bundleNames.length; i++) { + this.applicationList.push( + new ApplicationObj('', '', i, 0, '', '')); + this.oldApplicationItem.push( + new ApplicationObj('', '', i, 0, '', '')); + } + for (let i = 0; i < bundleNames.length; i++) { // Get BundleInfo based on bundle name bundle.getBundleInfo(bundleNames[i], Constants.PARMETER_BUNDLE_FLAG).then(res => { @@ -269,7 +278,7 @@ struct applicationItem { getAppIcon(res.appInfo.iconId, res.name) ]) .then((values) => { - this.applicationList.push( + this.applicationList[i] = ( new ApplicationObj( String(values[0]), String(values[1]), @@ -278,7 +287,7 @@ struct applicationItem { routerData[0].permission, makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array ); - this.oldApplicationItem.push( + this.oldApplicationItem[i] = ( new ApplicationObj( String(values[0]), String(values[1]), @@ -287,8 +296,6 @@ struct applicationItem { routerData[0].permission, makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array ); - this.applicationList.sort((a,b) => a.index - b.index) - this.oldApplicationItem.sort((a,b) => a.index - b.index) }); // 0: have permission; -1: no permission var boole = true; @@ -311,13 +318,8 @@ struct applicationItem { } }); } - }).catch(() => { - this.applicationList.push( - new ApplicationObj('', '', 0, '', '', '') - ); - this.oldApplicationItem.push( - new ApplicationObj('', '', 0, '', '', '') - ); + }).catch(error => { + console.log(TAG + bundleNames[i] + "getBundleInfo failed, cause: " + JSON.stringify(error)); }) } } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary.ets index 2f18b7b92bbfe5418fa05bf05a4494146b42f7b7..918218835758300d45f250e06eab24598b3eb16b 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary.ets @@ -38,14 +38,14 @@ class ApplicationObj { labelId: string iconId: string index: number - accessTokenId: string + accessTokenId: number permission: string alphabeticalIndex: string constructor( labelId: string, iconId: string, index: number, - accessTokenId: string, + accessTokenId: number, permission: string, alphabeticalIndex: string) { this.labelId = labelId @@ -234,14 +234,24 @@ struct applicationItem { * Lifecycle function, executed when the page is initialized */ aboutToAppear() { - for (let i = 0; i < routerData[0].bundleNames.length; i++) { + let bundleNames = routerData[0].bundleNames; + + // initial then fill values when sync return which may cause sync panic + for (let i = 0; i < bundleNames.length; i++) { + this.applicationList.push( + new ApplicationObj('', '', i, 0, '', '')); + this.oldApplicationItem.push( + new ApplicationObj('', '', i, 0, '', '')); + } + + for (let i = 0; i < bundleNames.length; i++) { // Get BundleInfo based on bundle name - bundle.getBundleInfo(routerData[0].bundleNames[i], Constants.PARMETER_BUNDLE_FLAG).then(res => { + bundle.getBundleInfo(bundleNames[i], Constants.PARMETER_BUNDLE_FLAG).then(res => { Promise.all([getAppLabel(res.appInfo.labelId, res.name), getAppIcon(res.appInfo.iconId, res.name), verifyAccessToken(res.appInfo.accessTokenId, routerData[0].permission)]) .then((values) => { - this.applicationList.push( + this.applicationList[i] = ( new ApplicationObj( String(values[0]), String(values[1]), @@ -250,7 +260,7 @@ struct applicationItem { routerData[0].permission, makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array ); - this.oldApplicationItem.push( + this.oldApplicationItem[i] = ( new ApplicationObj( String(values[0]), String(values[1]), @@ -259,8 +269,6 @@ struct applicationItem { routerData[0].permission, makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array ); - this.applicationList.sort((a,b) => a.index - b.index) - this.oldApplicationItem.sort((a,b) => a.index - b.index) // 0: have permission; -1: no permission if (values[2] === Constants.PERMISSION_INDEX) { this.toggleIsOn[i] = true; @@ -269,13 +277,8 @@ struct applicationItem { this.toggleIsOn[i] = false; } }); - }).catch(() => { - this.applicationList.push( - new ApplicationObj('', '', 0, '', '', '') - ); - this.oldApplicationItem.push( - new ApplicationObj('', '', 0, '', '', '') - ); + }).catch(error => { + console.log(TAG + bundleNames[i] + "getBundleInfo failed, cause: " + JSON.stringify(error)); }) } }