未验证 提交 e816c810 编写于 作者: O openharmony_ci 提交者: Gitee

!23776 访问控制ArkTS告警信息整改-3.2release挑单

Merge pull request !23776 from zhouyan/3.2release
......@@ -7,7 +7,7 @@
## 导入模块
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
```
......@@ -28,8 +28,8 @@ createAtManager(): AtManager
**示例:**
```js
let atManager = abilityAccessCtrl.createAtManager();
```ts
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
```
## AtManager
......@@ -67,15 +67,16 @@ checkAccessToken(tokenID: number, permissionName: Permissions): Promise<Grant
**示例:**
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
try {
atManager.checkAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
atManager.checkAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data: abilityAccessCtrl.GrantStatus) => {
console.log(`checkAccessToken success, data->${JSON.stringify(data)}`);
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`checkAccessToken fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -114,10 +115,12 @@ verifyAccessTokenSync(tokenID: number, permissionName: Permissions): GrantStatus
**示例:**
```js
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let data = atManager.verifyAccessTokenSync(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let data: abilityAccessCtrl.GrantStatus = atManager.verifyAccessTokenSync(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
console.log(`data->${JSON.stringify(data)}`);
```
......@@ -161,16 +164,17 @@ grantUserGrantedPermission(tokenID: number, permissionName: Permissions, permiss
**示例:**
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags = 1;
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags: number = 1;
try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags).then(() => {
console.log('grantUserGrantedPermission success');
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -213,14 +217,15 @@ grantUserGrantedPermission(tokenID: number, permissionName: Permissions, permiss
**示例:**
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags = 1;
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags: number = 1;
try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err, data) => {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err: BusinessError, data: void) => {
if (err) {
console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -272,16 +277,17 @@ revokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permis
**示例:**
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags = 1;
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags: number = 1;
try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags).then(() => {
console.log('revokeUserGrantedPermission success');
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -324,14 +330,15 @@ revokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permis
**示例:**
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags = 1;
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionFlags: number = 1;
try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err, data) => {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err: BusinessError, data: void) => {
if (err) {
console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -382,15 +389,16 @@ getPermissionFlags(tokenID: number, permissionName: Permissions): Promise<num
**示例:**
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
try {
atManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
atManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data: number) => {
console.log(`getPermissionFlags success, data->${JSON.stringify(data)}`);
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`getPermissionFlags fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -416,10 +424,12 @@ getVersion(): Promise<number>
**示例:**
```js
let atManager = abilityAccessCtrl.createAtManager();
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let promise = atManager.getVersion();
promise.then(data => {
promise.then((data: number) => {
console.log(`promise: data->${JSON.stringify(data)}`);
});
```
......@@ -459,16 +469,16 @@ on(type: 'permissionStateChange', tokenIDList: Array<number>, permissionLi
**示例:**
```js
import {Permissions} from '@ohos.abilityAccessCtrl';
```ts
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
import bundleManager from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager();
let appInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100);
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let appInfo: bundleManager.ApplicationInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try {
atManager.on('permissionStateChange', tokenIDList, permissionList, (data) => {
atManager.on('permissionStateChange', tokenIDList, permissionList, (data: abilityAccessCtrl.PermissionStateChangeInfo) => {
console.debug("receive permission state change, data:" + JSON.stringify(data));
});
} catch(err) {
......@@ -510,12 +520,12 @@ off(type: 'permissionStateChange', tokenIDList: Array&lt;number&gt;, permissionL
**示例:**
```js
import {Permissions} from '@ohos.abilityAccessCtrl';
```ts
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
import bundleManager from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager();
let appInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100);
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let appInfo: bundleManager.ApplicationInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try {
......@@ -552,15 +562,22 @@ verifyAccessToken(tokenID: number, permissionName: Permissions): Promise&lt;Gran
**示例:**
```js
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
```ts
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let promise = atManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
promise.then(data => {
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let permissionName: Permissions = 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS';
try {
atManager.verifyAccessToken(tokenID, permissionName).then((data: abilityAccessCtrl.GrantStatus) => {
console.log(`promise: data->${JSON.stringify(data)}`);
});
}).catch((err: BusinessError) => {
console.log(`verifyAccessToken fail, err->${JSON.stringify(err)}`);
});
}catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
```
### requestPermissionsFromUser<sup>9+</sup>
......@@ -594,19 +611,67 @@ requestPermissionsFromUser(context: Context, permissionList: Array&lt;Permission
**示例:**
```js
ArkTS语法不支持直接使用globalThis,需要通过一个单例的map来做中转。开发者需要:
a. 在EntryAbility.ets中导入构建的单例对象GlobalThis。
```ts
import { GlobalThis } from '../utils/globalThis'; // 需要根据globalThis.ets的路径自行适配
```
b. 在onCreate中添加:
```ts
GlobalThis.getInstance().setContext('context', this.context);
```
> **说明:**
>
> 由于在ts中引入ets文件会有告警提示,需要将EntryAbility.ts的文件后缀修改为EntryAbility.ets,并在module.json5中同步修改。
**globalThis.ets示例代码如下:**
```ts
import common from '@ohos.app.ability.common';
// 构造单例对象
export class GlobalThis {
private constructor() {}
private static instance: GlobalThis;
private _uiContexts = new Map<string, common.UIAbilityContext>();
public static getInstance(): GlobalThis {
if (!GlobalThis.instance) {
GlobalThis.instance = new GlobalThis();
}
return GlobalThis.instance;
}
getContext(key: string): common.UIAbilityContext | undefined {
return this._uiContexts.get(key);
}
setContext(key: string, value: common.UIAbilityContext): void {
this._uiContexts.set(key, value);
}
// 其他需要传递的内容依此扩展
}
```
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
import { BusinessError } from '@ohos.base';
import common from '@ohos.app.ability.common';
import { GlobalThis } from '../utils/globalThis';
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(this.context, ["ohos.permission.CAMERA"], (err, data)=>{
console.info("data:" + JSON.stringify(data));
console.info("data permissions:" + data.permissions);
console.info("data authResults:" + data.authResults);
});
let context: common.UIAbilityContext = GlobalThis.getInstance().getContext('context');
atManager.requestPermissionsFromUser(context, ['ohos.permission.CAMERA'], (err: BusinessError, data)=>{
console.info('data:' + JSON.stringify(data));
console.info('data permissions:' + data.permissions);
console.info('data authResults:' + data.authResults);
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
```
```
### requestPermissionsFromUser<sup>9+</sup>
......@@ -645,21 +710,28 @@ requestPermissionsFromUser(context: Context, permissionList: Array&lt;Permission
**示例:**
```js
修改EntryAbility.ets和导入GlobalThis等步骤同上,此处不再重复
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
import { BusinessError } from '@ohos.base';
import common from '@ohos.app.ability.common';
import { GlobalThis } from '../utils/globalThis';
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(this.context, ["ohos.permission.CAMERA"]).then((data) => {
let context: common.UIAbilityContext = GlobalThis.getInstance().getContext('context');
atManager.requestPermissionsFromUser(context, ['ohos.permission.CAMERA']).then((data) => {
console.info("data:" + JSON.stringify(data));
console.info("data permissions:" + data.permissions);
console.info("data authResults:" + data.authResults);
}).catch((err) => {
}).catch((err: BusinessError) => {
console.info("data:" + JSON.stringify(err));
})
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
```
```
### verifyAccessToken<sup>(deprecated)</sup>
......@@ -688,15 +760,21 @@ verifyAccessToken(tokenID: number, permissionName: string): Promise&lt;GrantStat
**示例:**
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
let promise = atManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
promise.then(data => {
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
let tokenID: number = 0; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取
try {
atManager.verifyAccessToken(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS').then((data: abilityAccessCtrl.GrantStatus) => {
console.log(`promise: data->${JSON.stringify(data)}`);
});
}).catch((err: BusinessError) => {
console.log(`verifyAccessToken fail, err->${JSON.stringify(err)}`);
});
}catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
```
### GrantStatus
......
......@@ -8,7 +8,7 @@
## 导入模块
```js
```ts
import privacyManager from '@ohos.privacyManager';
```
......@@ -53,14 +53,15 @@ addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCou
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let tokenID = 0; // 可以通过getApplicationInfo获取accessTokenId
let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
try {
privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0).then(() => {
console.log('addPermissionUsedRecord success');
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -103,12 +104,13 @@ addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCou
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let tokenID = 0; // 可以通过getApplicationInfo获取accessTokenId
let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
try {
privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0, (err, data) => {
privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0, (err: BusinessError, data: void) => {
if (err) {
console.log(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
} else {
......@@ -156,10 +158,11 @@ getPermissionUsedRecord(request: PermissionUsedRequest): Promise&lt;PermissionUs
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let request = {
let request: privacyManager.PermissionUsedRequest = {
"tokenId": 1,
"isRemote": false,
"deviceId": "device",
......@@ -172,7 +175,7 @@ let request = {
try {
privacyManager.getPermissionUsedRecord(request).then((data) => {
console.log(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -211,10 +214,11 @@ getPermissionUsedRecord(request: PermissionUsedRequest, callback: AsyncCallback&
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let request = {
let request: privacyManager.PermissionUsedRequest = {
"tokenId": 1,
"isRemote": false,
"deviceId": "device",
......@@ -225,7 +229,7 @@ let request = {
"flag":privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
};
try {
privacyManager.getPermissionUsedRecord(request, (err, data) => {
privacyManager.getPermissionUsedRecord(request, (err: BusinessError, data: privacyManager.PermissionUsedResponse) => {
if (err) {
console.log(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
} else {
......@@ -275,14 +279,15 @@ startUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;v
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let tokenID = 0; // 可以通过getApplicationInfo获取accessTokenId
let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
try {
privacyManager.startUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS").then(() => {
console.log('startUsingPermission success');
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`startUsingPermission fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -323,12 +328,13 @@ startUsingPermission(tokenID: number, permissionName: Permissions, callback: Asy
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let tokenID = 0; // 可以通过getApplicationInfo获取accessTokenId
let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
try {
privacyManager.startUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS", (err, data) => {
privacyManager.startUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS", (err: BusinessError, data: void) => {
if (err) {
console.log(`startUsingPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -378,14 +384,15 @@ stopUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;vo
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let tokenID = 0; // 可以通过getApplicationInfo获取accessTokenId
let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
try {
privacyManager.stopUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS").then(() => {
console.log('stopUsingPermission success');
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -426,12 +433,13 @@ stopUsingPermission(tokenID: number, permissionName: Permissions, callback: Asyn
**示例:**
```js
```ts
import privacyManager from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let tokenID = 0; // 可以通过getApplicationInfo获取accessTokenId
let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
try {
privacyManager.stopUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS", (err, data) => {
privacyManager.stopUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS", (err: BusinessError, data: void) => {
if (err) {
console.log(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -475,12 +483,13 @@ on(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback
**示例:**
```js
import privacyManager from '@ohos.privacyManager';
```ts
import privacyManager, { Permissions } from '@ohos.privacyManager';
import { BusinessError } from '@ohos.base';
let permissionList = [];
let permissionList: Array<Permissions> = [];
try {
privacyManager.on('activeStateChange', permissionList, (data) => {
privacyManager.on('activeStateChange', permissionList, (data: privacyManager.ActiveChangeResponse) => {
console.debug("receive permission state change, data:" + JSON.stringify(data));
});
} catch(err) {
......@@ -519,10 +528,10 @@ off(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callbac
**示例:**
```js
import privacyManager from '@ohos.privacyManager';
```ts
import privacyManager, { Permissions } from '@ohos.privacyManager';
let permissionList = [];
let permissionList: Array<Permissions> = [];
try {
privacyManager.off('activeStateChange', permissionList);
}catch(err) {
......
......@@ -27,19 +27,20 @@ checkAccessToken(tokenID: number, permissionName: Permissions): Promise&lt;Grant
3. 使用checkAccessToken接口对当前调用者进行权限校验。
4. 根据权限校验结果采取对应的措施。
```js
```ts
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import { BusinessError } from '@ohos.base';
import rpc from '@ohos.rpc'
class Stub extends rpc.RemoteObject {
onRemoteRequest(code, data, reply, option) {
let callerTokenId = rpc.IPCSkeleton.getCallingTokenId();
onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption) {
let callerTokenId: number = rpc.IPCSkeleton.getCallingTokenId();
console.log("RpcServer: getCallingTokenId result: " + callerTokenId);
var atManager = abilityAccessCtrl.createAtManager();
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
try {
atManager.checkAccessToken(callerTokenId, "ohos.permission.ACCELEROMETER").then((data) => {
atManager.checkAccessToken(callerTokenId, "ohos.permission.ACCELEROMETER").then((data: abilityAccessCtrl.GrantStatus) => {
console.log(`checkAccessToken success, data->${JSON.stringify(data)}`);
}).catch((err) => {
}).catch((err: BusinessError) => {
console.log(`checkAccessToken fail, err->${JSON.stringify(err)}`);
});
} catch(err) {
......@@ -48,5 +49,4 @@ checkAccessToken(tokenID: number, permissionName: Permissions): Promise&lt;Grant
return true;
}
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册