• 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 mockPrivacyManager() {
19    const PermissionUsedRequestMock = {
20        tokenId: "[PC Preview] unknown tokenId",
21        isRemote: "[PC Preview] unknown isRemote",
22        deviceId: "[PC Preview] unknown deviceId",
23        bundleName: "[PC Preview] unknown bundleName",
24        permissionNames: "[PC Preview] unknown permissionNames",
25        beginTime: "[PC Preview] unknown beginTime",
26        endTime: "[PC Preview] unknown endTime",
27        flag: "[PC Preview] unknown flag",
28    };
29    const UsedRecordDetailMock = {
30        status: "[PC Preview] unknown status",
31        timestamp: "[PC Preview] unknown timestamp",
32        accessDuration: "[PC Preview] unknown accessDuration",
33    };
34    const PermissionUsedRecordMock = {
35        permissionName: "[PC Preview] unknown permissionName",
36        accessCount: "[PC Preview] unknown accessCount",
37        rejectCount: "[PC Preview] unknown rejectCount",
38        lastAccessTime: "[PC Preview] unknown lastAccessTime",
39        lastRejectTime: "[PC Preview] unknown lastRejectTime",
40        lastAccessDuration: "[PC Preview] unknown lastAccessDuration",
41        accessRecords: [UsedRecordDetailMock],
42        rejectRecords: [UsedRecordDetailMock],
43    };
44    const BundleUsedRecordMock = {
45        tokenId: "[PC Preview] unknown tokenId",
46        isRemote: "[PC Preview] unknown isRemote",
47        deviceId: "[PC Preview] unknown deviceId",
48        bundleName: "[PC Preview] unknown bundleName",
49        permissionRecords: [PermissionUsedRecordMock]
50    };
51    const PermissionUsedResponseMock = {
52        beginTime: '[PC preview] unknow beginTime',
53        endTime: '[PC preview] unknow endTime',
54        bundleRecords: [BundleUsedRecordMock],
55    };
56    const PermissionActiveStatus = {
57            PERM_INACTIVE: 0,
58            PERM_ACTIVE_IN_FOREGROUND: 1,
59            PERM_ACTIVE_IN_BACKGROUND: 2,
60    };
61    const ActiveChangeResponse = {
62        tokenId: "[PC Preview] unknown tokenId",
63        permissionName: "[PC Preview] unknown permissionName",
64        deviceId: "[PC Preview] unknown deviceId",
65        activeStatus: PermissionActiveStatus,
66    };
67    const privacyManager = {
68        PermissionActiveStatus,
69        PermissionUsageFlag : {
70            FLAG_PERMISSION_USAGE_SUMMARY: 0,
71            FLAG_PERMISSION_USAGE_DETAIL: 1,
72        },
73
74        addPermissionUsedRecord: function (...args) {
75            console.warn("privacyManager.addPermissionUsedRecord interface mocked in the Previewer. How this interface works on the" +
76                " Previewer may be different from that on a real device.")
77            const len = args.length;
78            if (len > 0 && typeof args[len - 1] === 'function') {
79                  args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
80            } else {
81                return new Promise((resolve, reject) => {
82                    resolve(paramMock.paramNumberMock);
83                });
84            }
85        },
86        getPermissionUsedRecords: function (...args) {
87            console.warn("privacyManager.getPermissionUsedRecords interface mocked in the Previewer. How this interface works on the" +
88                " Previewer may be different from that on a real device.")
89            const len = args.length;
90            if (typeof args[len - 1] === 'function') {
91                args[len - 1].call(this, paramMock.businessErrorMock, PermissionUsedResponseMock)
92            } else {
93                return new Promise((resolve, reject) => {
94                    resolve(PermissionUsedResponseMock);
95                })
96            }
97        },
98        startUsingPermission: function (...args) {
99            console.warn("privacyManager.startUsingPermission interface mocked in the Previewer. How this interface works on the" +
100                " Previewer may be different from that on a real device.")
101            const len = args.length;
102            if (len > 0 && typeof args[len - 1] === 'function') {
103                  args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
104            } else {
105                return new Promise((resolve, reject) => {
106                    resolve(paramMock.paramNumberMock);
107                });
108            }
109        },
110        stopUsingPermission: function (...args) {
111            console.warn("privacyManager.stopUsingPermission interface mocked in the Previewer. How this interface works on the" +
112                " Previewer may be different from that on a real device.")
113            const len = args.length;
114            if (len > 0 && typeof args[len - 1] === 'function') {
115                  args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
116            } else {
117                return new Promise((resolve, reject) => {
118                    resolve(paramMock.paramNumberMock);
119                });
120            }
121        },
122        on: function (...args) {
123            console.warn("privacyManager.on interface mocked in the Previewer. How this interface works on the" +
124                " Previewer may be different from that on a real device.")
125            const len = args.length;
126            if (len > 0 && typeof args[len - 1] === 'function') {
127                  args[len - 1].call(this, ActiveChangeResponse);
128            }
129        },
130        off: function (...args) {
131            console.warn("privacyManager.off interface mocked in the Previewer. How this interface works on the" +
132                " Previewer may be different from that on a real device.")
133            const len = args.length;
134            if (len > 0 && typeof args[len - 1] === 'function') {
135                  args[len - 1].call(this, ActiveChangeResponse);
136            }
137        },
138    };
139    return privacyManager;
140}
141