• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *    http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { paramMock } from "../utils"
17
18export function mockAbilityAccessCtrl() {
19    const GrantStatus = "[PC preview] unknow GrantStatus";
20
21    const AtManager = {
22        verifyAccessToken: function (...args) {
23            console.warn("AtManager.verifyAccessToken interface mocked in the Previewer." +
24                " How this interface works on the Previewer may be different from that on a real device.")
25            return new Promise((resolve, reject) => {
26                resolve(GrantStatus);
27            })
28        },
29        verifyAccessTokenSync: function (...args) {
30            console.warn("AtManager.verifyAccessTokenSync interface mocked in the Previewer." +
31                " How this interface works on the Previewer may be different from that on a real device.")
32            return GrantStatus;
33        },
34        grantUserGrantedPermission: function (...args) {
35            console.warn("AtManager.grantUserGrantedPermission interface mocked in the Previewer." +
36                " How this interface works on the Previewer may be different from that on a real device.")
37            const len = args.length
38            if (len > 0 && typeof args[len - 1] === 'function') {
39                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
40            } else {
41                return new Promise((resolve, reject) => {
42                    resolve(paramMock.paramNumberMock);
43                })
44            }
45        },
46        revokeUserGrantedPermission: function (...args) {
47            console.warn("AtManager.revokeUserGrantedPermission interface mocked in the Previewer." +
48                " How this interface works on the Previewer may be different from that on a real device.")
49            const len = args.length
50            if (len > 0 && typeof args[len - 1] === 'function') {
51                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
52            } else {
53                return new Promise((resolve, reject) => {
54                    resolve(paramMock.paramNumberMock);
55                })
56            }
57        },
58        getPermissionFlags: function (...args) {
59            console.warn("AtManager.getPermissionFlags interface mocked in the Previewer." +
60                " How this interface works on the Previewer may be different from that on a real device.")
61            return new Promise((resolve, reject) => {
62                resolve(paramMock.paramNumberMock);
63            })
64        },
65        getVersion: function (...args) {
66            console.warn("AtManager.getVersion interface mocked in the Previewer." +
67                " How this interface works on the Previewer may be different from that on a real device.")
68            const len = args.length
69            return new Promise((resolve, reject) => {
70                resolve(paramMock.paramNumberMock);
71            })
72        },
73        on: function (...args) {
74            console.warn("AtManager.on interface mocked in the Previewer." +
75                " How this interface works on the Previewer may be different from that on a real device.")
76            const len = args.length
77            if (len > 0 && typeof args[len - 1] === 'function') {
78                args[len - 1].call(this, PermissionStateChangeInfo);
79            }
80        },
81        off: function (...args) {
82            console.warn("AtManager.off interface mocked in the Previewer." +
83                " How this interface works on the Previewer may be different from that on a real device.")
84            const len = args.length
85            if (len > 0 && typeof args[len - 1] === 'function') {
86                args[len - 1].call(this, PermissionStateChangeInfo);
87            }
88        }
89    };
90    const PermissionStateChangeType = {
91        PERMISSION_REVOKED_OPER: 0,
92        PERMISSION_GRANTED_OPER: 1
93    };
94
95    const PermissionStateChangeInfo = {
96        change: PermissionStateChangeType,
97        tokenID: '[PC Preview] unknown tokenID',
98        permissionName: '[PC Preview] unknown permissionName',
99
100    };
101    const abilityAccessCtrl = {
102        createAtManager : function (...args) {
103            console.warn("abilityAccessCtrl.createAtManager interface mocked in the Previewer." +
104                " How this interface works on the Previewer may be different from that on a real device.")
105            return AtManager;
106        },
107    };
108
109    return abilityAccessCtrl;
110}
111