提交 2133792a 编写于 作者: F fanchenxuan

docs一致性整改

Signed-off-by: Nfanchenxuan <fanchenxuan@huawei.com>
上级 cf842ae8
...@@ -339,8 +339,8 @@ function OnPermissionStateChanged(data){ ...@@ -339,8 +339,8 @@ function OnPermissionStateChanged(data){
} }
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
let type: 'permissionStateChange' = 'permissionStateChange'; let type: 'permissionStateChange' = 'permissionStateChange';
let tokenIDList: Array&lt;number&gt; = []; let tokenIDList: Array<number> = [];
let permissionNameList: Array&lt;string&gt; = []; let permissionNameList: Array<string> = [];
try{ try{
atManager.on(type, tokenIDList, permissionNameList, OnPermissionStateChanged); atManager.on(type, tokenIDList, permissionNameList, OnPermissionStateChanged);
} }
...@@ -377,8 +377,8 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; ...@@ -377,8 +377,8 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
let type: 'permissionStateChange' = 'permissionStateChange'; let type: 'permissionStateChange' = 'permissionStateChange';
let tokenIDList: Array&lt;number&gt; = []; let tokenIDList: Array<number> = [];
let permissionNameList: Array&lt;string&gt; = []; let permissionNameList: Array<string> = [];
try{ try{
atManager.off(type, tokenIDList, permissionNameList); atManager.off(type, tokenIDList, permissionNameList);
} }
......
...@@ -45,13 +45,15 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n ...@@ -45,13 +45,15 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let bundleName = "com.ohos.permissionmanager"; // change to your bundle name async addPermissionUsedRecord() {
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function let bundleName = "com.ohos.permissionmanager"; // change to your bundle name
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function
var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId
privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0).then(data => { var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId
console.log(`promise: data->${JSON.stringify(data)}`); privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0).then(data => {
}); console.log(`promise: data->${JSON.stringify(data)}`);
});
}
``` ```
## privacyManager.addPermissionUsedRecord ## privacyManager.addPermissionUsedRecord
...@@ -81,13 +83,15 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n ...@@ -81,13 +83,15 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let bundleName = "com.ohos.permissionmanager"; // change to your bundle name async addPermissionUsedRecord() {
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function let bundleName = "com.ohos.permissionmanager"; // change to your bundle name
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function
var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId
privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0, (err, data) => { var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId
console.log(`callback: data->${JSON.stringify(data)}`); privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0, (err, data) => {
}); console.log(`callback: data->${JSON.stringify(data)}`);
});
}
``` ```
## privacyManager.getPermissionUsedRecords ## privacyManager.getPermissionUsedRecords
...@@ -194,16 +198,18 @@ startUsingPermission(tokenID: number, permissionName: string): Promise&lt;number ...@@ -194,16 +198,18 @@ startUsingPermission(tokenID: number, permissionName: string): Promise&lt;number
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let bundleName = "com.ohos.permissionmanager"; // change to your bundle name async startUsingPermission() {
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function let bundleName = "com.ohos.permissionmanager"; // change to your bundle name
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function
let tokenID = appInfo.accessTokenId;
let permissionName = "ohos.permission.CAMERA"; let tokenID = appInfo.accessTokenId;
privacyManager.startUsingPermission(tokenID, permissionName).then(data => { let permissionName = "ohos.permission.CAMERA";
console.log(`promise: data->${JSON.stringify(data)}`); privacyManager.startUsingPermission(tokenID, permissionName).then(data => {
}).catch(err => { console.log(`promise: data->${JSON.stringify(data)}`);
console.log(`Error: err->${JSON.stringify(err)}`); }).catch(err => {
}); console.log(`Error: err->${JSON.stringify(err)}`);
});
}
``` ```
## privacyManager.startUsingPermission<sup>9+</sup> ## privacyManager.startUsingPermission<sup>9+</sup>
...@@ -230,18 +236,20 @@ startUsingPermission(tokenID: number, permissionName: string, callback: AsyncCal ...@@ -230,18 +236,20 @@ startUsingPermission(tokenID: number, permissionName: string, callback: AsyncCal
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let bundleName = "com.ohos.permissionmanager"; // change to your bundle name async startUsingPermission() {
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function let bundleName = "com.ohos.permissionmanager"; // change to your bundle name
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function
let tokenID = appInfo.accessTokenId;
let permissionName = "ohos.permission.CAMERA"; let tokenID = appInfo.accessTokenId;
privacyManager.startUsingPermission(tokenID, permissionName, (err, data)=> { let permissionName = "ohos.permission.CAMERA";
if (err) { privacyManager.startUsingPermission(tokenID, permissionName, (err, data)=> {
console.log(`Error: err->${JSON.stringify(err)}`); if (err) {
} else { console.log(`Error: err->${JSON.stringify(err)}`);
console.log(`promise: data->${JSON.stringify(data)}`); } else {
} console.log(`promise: data->${JSON.stringify(data)}`);
}); }
});
}
``` ```
## privacyManager.stopUsingPermission<sup>9+</sup> ## privacyManager.stopUsingPermission<sup>9+</sup>
...@@ -273,16 +281,18 @@ stopUsingPermission(tokenID: number, permissionName: string): Promise&lt;number& ...@@ -273,16 +281,18 @@ stopUsingPermission(tokenID: number, permissionName: string): Promise&lt;number&
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let bundleName = "com.ohos.permissionmanager"; // change to your bundle name async stopUsingPermission() {
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function let bundleName = "com.ohos.permissionmanager"; // change to your bundle name
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function
let tokenID = appInfo.accessTokenId;
let permissionName = "ohos.permission.CAMERA"; let tokenID = appInfo.accessTokenId;
privacyManager.stopUsingPermission(tokenID, permissionName).then(data => { let permissionName = "ohos.permission.CAMERA";
console.log(`promise: data->${JSON.stringify(data)}`); privacyManager.stopUsingPermission(tokenID, permissionName).then(data => {
}).catch(err => { console.log(`promise: data->${JSON.stringify(data)}`);
console.log(`Error: err->${JSON.stringify(err)}`); }).catch(err => {
}); console.log(`Error: err->${JSON.stringify(err)}`);
});
}
``` ```
## privacyManager.stopUsingPermission<sup>9+</sup> ## privacyManager.stopUsingPermission<sup>9+</sup>
...@@ -309,18 +319,20 @@ stopUsingPermission(tokenID: number, permissionName: string, callback: AsyncCall ...@@ -309,18 +319,20 @@ stopUsingPermission(tokenID: number, permissionName: string, callback: AsyncCall
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let bundleName = "com.ohos.permissionmanager"; // change to your bundle name async stopUsingPermission() {
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function let bundleName = "com.ohos.permissionmanager"; // change to your bundle name
let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function
let tokenID = appInfo.accessTokenId;
let permissionName = "ohos.permission.CAMERA"; let tokenID = appInfo.accessTokenId;
privacyManager.privacyManager.stopUsingPermission(tokenID, permissionName, (err, data)=> { let permissionName = "ohos.permission.CAMERA";
if (err) { privacyManager.privacyManager.stopUsingPermission(tokenID, permissionName, (err, data)=> {
console.log(`Error: err->${JSON.stringify(err)}`); if (err) {
} else { console.log(`Error: err->${JSON.stringify(err)}`);
console.log(`promise: data->${JSON.stringify(data)}`); } else {
} console.log(`promise: data->${JSON.stringify(data)}`);
}); }
});
}
``` ```
## privacyManager.on<sup>9+</sup> ## privacyManager.on<sup>9+</sup>
...@@ -352,7 +364,7 @@ function OnPermissionUseStateChanged(data){ ...@@ -352,7 +364,7 @@ function OnPermissionUseStateChanged(data){
console.debug("receive permission state change, data:" + JSON.stringify(data)); console.debug("receive permission state change, data:" + JSON.stringify(data));
} }
let type: 'activeStateChange' = 'activeStateChange'; let type: 'activeStateChange' = 'activeStateChange';
let permissionNameList: Array&lt;string&gt; = []; let permissionNameList: Array<string> = [];
try{ try{
privacyManager.on(type, permissionNameList, OnPermissionUseStateChanged); privacyManager.on(type, permissionNameList, OnPermissionUseStateChanged);
} }
...@@ -387,7 +399,7 @@ off(type: 'activeStateChange', permissionNameList: Array&lt;string&gt;, callback ...@@ -387,7 +399,7 @@ off(type: 'activeStateChange', permissionNameList: Array&lt;string&gt;, callback
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let type: 'activeStateChange' = 'activeStateChange'; let type: 'activeStateChange' = 'activeStateChange';
let permissionNameList: Array&lt;string&gt; = []; let permissionNameList: Array<string> = [];
try{ try{
privacyManager.off(type, permissionNameList); privacyManager.off(type, permissionNameList);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册