From c3c5949354662a7177667af62ac411dfebc78950 Mon Sep 17 00:00:00 2001 From: zhouyan Date: Sun, 24 Apr 2022 11:35:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9D=83=E9=99=90=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E5=BA=94=E7=94=A8=E6=8E=92=E5=88=97=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E4=B8=8D=E5=9B=BA=E5=AE=9A=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyan --- .../pages/authority-tertiary-groups.ets | 28 ++++++++-------- .../MainAbility/pages/authority-tertiary.ets | 33 ++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) 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 4a1335120..960f33bcb 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 2f18b7b92..918218835 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)); }) } } -- Gitee