From ad9cb4ecb5be75902d9994815d96a7d123e9bcab Mon Sep 17 00:00:00 2001 From: zwx1066281 Date: Mon, 14 Mar 2022 19:50:34 +0800 Subject: [PATCH] =?UTF-8?q?fixed=205995699=20from=20https://gitee.com/zwx1?= =?UTF-8?q?066281/security=5Faccess=5Ftoken/pulls/148=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E5=BC=B9=E7=AA=97=E6=A6=82=E7=8E=87=E7=99=BD?= =?UTF-8?q?=E5=B1=8F=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: zwx1066281 --- .../com.ohos.permissionmanager/build.gradle | 3 +- .../entry/build.gradle | 9 +- frameworks/com.ohos.permissionmanager/gradlew | 208 +++++++++--------- .../com.ohos.permissionmanager/gradlew.bat | 4 +- .../permissionmanager/build.gradle | 9 +- .../permissionmanager/src/main/config.json | 6 +- .../GrantAbility/common/components/dialog.ets | 58 ++--- 7 files changed, 147 insertions(+), 150 deletions(-) diff --git a/frameworks/com.ohos.permissionmanager/build.gradle b/frameworks/com.ohos.permissionmanager/build.gradle index 924a888a1..f1b1a556a 100644 --- a/frameworks/com.ohos.permissionmanager/build.gradle +++ b/frameworks/com.ohos.permissionmanager/build.gradle @@ -3,7 +3,8 @@ apply plugin: 'com.huawei.ohos.app' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 + supportSystem "standard" } buildscript { diff --git a/frameworks/com.ohos.permissionmanager/entry/build.gradle b/frameworks/com.ohos.permissionmanager/entry/build.gradle index 0f0156791..05a33cd3a 100644 --- a/frameworks/com.ohos.permissionmanager/entry/build.gradle +++ b/frameworks/com.ohos.permissionmanager/entry/build.gradle @@ -1,10 +1,9 @@ apply plugin: 'com.huawei.ohos.hap' -apply plugin: 'com.huawei.ohos.decctest' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 7 + compatibleSdkVersion 8 } buildTypes { release { @@ -19,8 +18,4 @@ ohos { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testImplementation 'junit:junit:4.13.1' - ohosTestImplementation 'com.huawei.ohos.testkit:runner:2.0.0.200' -} -decc { - supportType = ['html','xml'] } diff --git a/frameworks/com.ohos.permissionmanager/gradlew b/frameworks/com.ohos.permissionmanager/gradlew index aa815eb87..319ea8401 100644 --- a/frameworks/com.ohos.permissionmanager/gradlew +++ b/frameworks/com.ohos.permissionmanager/gradlew @@ -1,13 +1,13 @@ #!/usr/bin/env sh # -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -26,22 +26,22 @@ # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. -while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then - PRG="$link" - else - PRG=$(dirname "$PRG")"/$link" - fi +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi done -SAVED="$(pwd)" -cd "$(dirname \"$PRG\")/" >/dev/null -APP_HOME="$(pwd -P)" +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null APP_NAME="Gradle" -APP_BASE_NAME=$(basename "$0") +APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -49,15 +49,15 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn() { - echo "$*" +warn () { + echo "$*" } -die() { - echo - echo "$*" - echo - exit 1 +die () { + echo + echo "$*" + echo + exit 1 } # OS specific support (must be 'true' or 'false'). @@ -65,117 +65,117 @@ cygwin=false msys=false darwin=false nonstop=false -case "$(uname)" in -CYGWIN*) - cygwin=true - ;; -Darwin*) - darwin=true - ;; -MINGW*) - msys=true - ;; -NONSTOP*) - nonstop=true - ;; +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ]; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then - MAX_FD_LIMIT=$(ulimit -H -n) - if [ $? -eq 0 ]; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ]; then - warn "Could not set maximum file descriptor limit: $MAX_FD" +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ]; then - APP_HOME=$(cygpath --path --mixed "$APP_HOME") - CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") - JAVACMD=$(cygpath --unix "$JAVACMD") - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null) - SEP="" - for dir in $ROOTDIRSRAW; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ]; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@"; do - CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -) - CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ]; then ### Added a condition - eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg") - else - eval $(echo args$i)="\"$arg\"" +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi - i=$(expr $i + 1) - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac fi # Escape application args -save() { - for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done - echo " " +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" diff --git a/frameworks/com.ohos.permissionmanager/gradlew.bat b/frameworks/com.ohos.permissionmanager/gradlew.bat index 9db1ef2e2..df2e73f25 100644 --- a/frameworks/com.ohos.permissionmanager/gradlew.bat +++ b/frameworks/com.ohos.permissionmanager/gradlew.bat @@ -1,11 +1,11 @@ @rem -@rem Copyright (c) 2021-2022 Huawei Device Co., Ltd. +@rem Copyright (c) 2021-2022 the original author or authors. @rem @rem Licensed under the Apache License, Version 2.0 (the "License"); @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem https://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/build.gradle b/frameworks/com.ohos.permissionmanager/permissionmanager/build.gradle index f6df7ecdb..a59c134a1 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/build.gradle +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/build.gradle @@ -1,10 +1,9 @@ apply plugin: 'com.huawei.ohos.hap' -apply plugin: 'com.huawei.ohos.decctest' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 7 + compatibleSdkVersion 8 } buildTypes { release { @@ -21,8 +20,4 @@ dependencies { entryImplementation project(':entry') implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testImplementation 'junit:junit:4.13.1' - ohosTestImplementation 'com.huawei.ohos.testkit:runner:2.0.0.200' -} -decc { - supportType = ['html','xml'] } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json index 0b23d150f..6e37bca3e 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/config.json @@ -52,11 +52,11 @@ "pages": [ "pages/authority-management", "pages/application-secondary", + "pages/application-tertiary", "pages/authority-secondary", "pages/authority-tertiary", - "pages/application-tertiary", - "pages/other-permissions", - "pages/authority-tertiary-groups" + "pages/authority-tertiary-groups", + "pages/other-permissions" ], "name": ".MainAbility", "window": { diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets index 451678bfa..c5475146e 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets @@ -21,7 +21,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' import Resmgr from '@ohos.resourceManager' -var TAG = "PermissionManager_GrantAbility" +var TAG = "PermissionManager_GrantAbility:" @Extend(Button) function customizeButton() { .backgroundColor($r('app.color.default_background_color')) @@ -110,10 +110,29 @@ export struct privacyDialog { .height(Constants.DIALOG_HEIGHT) .width(Constants.DIALOG_WIDTH) } + + answerRequest() { + var ret: number = Constants.RESULT_SUCCESS + if (this.initStatus == Constants.INIT_NEED_TO_TERMINATED) { + ret = Constants.RESULT_FAILURE + } + console.log(TAG + "code:" + ret + ", result=" + JSON.stringify(this.result)) + featureAbility.terminateSelfWithResult({ + resultCode: ret, + want: { + parameters: { + "ohos.user.grant.permission": this.reqPerms, + "ohos.user.grant.permission.result": this.result + } + } + }) + } + verify() { if((this.initStatus == Constants.INIT_NEED_TO_TERMINATED) || (this.count >= this.grantGroups.length)) { this.controller.close() - this.aboutToDisappear() + this.answerRequest() + this.initStatus = Constants.INIT_NEED_TO_WAIT return false } return true @@ -121,8 +140,8 @@ export struct privacyDialog { getApplicationName(uid) { bundle.getNameForUid(uid).then((data) => { - console.log(TAG + "GrantAbility getApplicationName bundleName:" + data) - console.log(TAG + "GrantAbility getApplicationName userId:" + Math.floor(uid/200000)) + console.log(TAG + "getApplicationName bundleName:" + data) + console.log(TAG + "getApplicationName userId:" + Math.floor(uid/200000)) bundle.getApplicationInfo(data, BundleFlag.GET_BUNDLE_DEFAULT, Math.floor(uid/200000)).then(applicationInfo => { Resmgr.getResourceManager(data).then(item => { item.getString(applicationInfo.labelId, (err, value) => { @@ -131,15 +150,15 @@ export struct privacyDialog { } else { this.appName = value } - console.log(TAG + "GrantAbility hap label:" + applicationInfo.label + ", value:"+this.appName) + console.log(TAG + "hap label:" + applicationInfo.label + ", value:"+this.appName) }) }) }).catch(err => { - console.log(TAG + "GrantAbility applicationInfo error :" + err) + console.log(TAG + "applicationInfo error :" + err) this.initStatus = Constants.INIT_NEED_TO_TERMINATED }) }).catch(err => { - console.log(TAG + "GrantAbility getNameForUid error :" + JSON.stringify(err)) + console.log(TAG + "getNameForUid error :" + JSON.stringify(err)) this.initStatus = Constants.INIT_NEED_TO_TERMINATED }) } @@ -150,7 +169,7 @@ export struct privacyDialog { this.reqPerms.forEach(async (permission, idx) => { var flag = await acManager.getPermissionFlags(this.accessTokenId, permission) if(flag == this.userFixedFlag) { - console.log(TAG + "GrantAbility permission has been fixed:" + permission) + console.log(TAG + "permission has been fixed:" + permission) var ret = await acManager.verifyAccessToken(this.accessTokenId, permission) if(ret == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { this.result[idx] = abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; @@ -158,7 +177,7 @@ export struct privacyDialog { }else { var group = getPermissionGroup(permission) if(!group) { - console.log(TAG + "GrantAbility permission not find:" + permission) + console.log(TAG + "permission not find:" + permission) }else { var exist = this.grantGroups.find(grantGroup => grantGroup.name == group.name) if(!exist) { @@ -183,18 +202,18 @@ export struct privacyDialog { this.result = [] featureAbility.getWant((err, want) => { if (err.code != 0) { - console.log(TAG + "GrantAbility featureAbility.getWant err:" + err) + console.log(TAG + "featureAbility.getWant err:" + err) this.initStatus = Constants.INIT_NEED_TO_TERMINATED return } this.reqPerms = want.parameters['ohos.user.grant.permission'] this.accessTokenId = want.parameters['ohos.aafwk.param.callerToken'] if (this.reqPerms == undefined || this.accessTokenId == undefined || this.reqPerms.length == 0) { - console.log(TAG + "GrantAbility invalid parameters") + console.log(TAG + "invalid parameters") this.initStatus = Constants.INIT_NEED_TO_TERMINATED return } - console.log(TAG + "GrantAbility request permission=" + JSON.stringify(this.reqPerms) + ", tokenId = " + this.accessTokenId) + console.log(TAG + "request permission=" + JSON.stringify(this.reqPerms) + ", tokenId = " + this.accessTokenId) this.result = new Array(this.reqPerms.length).fill(-1); this.getgrantGroups(); this.getApplicationName(want.parameters['ohos.aafwk.param.callerUid']) @@ -202,19 +221,6 @@ export struct privacyDialog { } aboutToDisappear() { - var ret: number = Constants.RESULT_SUCCESS - if (this.initStatus == Constants.INIT_NEED_TO_TERMINATED) { - ret = Constants.RESULT_FAILURE - } - console.log(TAG + "GrantAbility code:" + ret + ", result=" + JSON.stringify(this.result)) - featureAbility.terminateSelfWithResult({ - resultCode: ret, - want: { - parameters: { - "ohos.user.grant.permission": this.reqPerms, - "ohos.user.grant.permission.result": this.result - } - } - }) + console.log(TAG + "aboutToDisappear") } } -- Gitee