• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2021 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 { AsyncCallback } from '../basic';
17import { ApplicationInfo } from '../bundle/applicationInfo';
18import { ProcessInfo } from './processInfo';
19import { ElementName } from '../bundle/elementName';
20
21/**
22 * The context of an ability or an application.  It allows access to
23 * application-specific resources, request and verification permissions.
24 * Can only be obtained through the ability.
25 *
26 * @since 6
27 * @SysCap SystemCapability.Appexecfwk
28 * @devices phone, tablet, tv, wearable, car
29 * @import import abilityManager from 'app/context'
30 * @permission N/A
31 */
32export interface Context {
33
34    /**
35    * Get the local root dir of an app. If it is the first call, the dir
36    * will be created.
37    * @note If in the context of the ability, return the root dir of
38    * the ability; if in the context of the application, return the
39    * root dir of the application.
40    * @since 7
41    * @sysCap SystemCapability.Appexecfwk
42    * @devices phone, tablet, tv, wearable, car
43    * @return the root dir
44    */
45    getOrCreateLocalDir(): Promise<string>;
46    getOrCreateLocalDir(callback: AsyncCallback<string>): void;
47    /**
48    * Verify whether the specified permission is allowed for a particular
49    * pid and uid running in the system.
50    * @param permission The name of the specified permission
51    * @param pid process id
52    * @param uid user id
53    * @note Pid and uid are optional. If you do not pass in pid and uid,
54    * it will check your own permission.
55    * @since 7
56    * @sysCap SystemCapability.Appexecfwk
57    * @devices phone, tablet, tv, wearable, car
58    * @return asynchronous callback with {@code 0} if the PID
59    *         and UID have the permission; callback with {@code -1} otherwise.
60    */
61    verifyPermission(permission: string, options?: PermissionOptions): Promise<number>;
62    verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback<number>): void;
63    verifyPermission(permission: string, callback: AsyncCallback<number>): void;
64
65    /**
66    * Requests certain permissions from the system.
67    * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
68    * @param requestCode Indicates the request code to be passed to the PermissionRequestResult
69    * @since 7
70    * @sysCap SystemCapability.Appexecfwk
71    * @devices phone, tablet, tv, wearable, car
72    */
73    requestPermissionsFromUser(permissions: Array<string>, requestCode: number, resultCallback: AsyncCallback<PermissionRequestResult>): void;
74
75    /**
76    * Obtains information about the current application.
77    * @since 7
78    * @sysCap SystemCapability.Appexecfwk
79    * @devices phone, tablet, tv, wearable
80    */
81    getApplicationInfo(callback: AsyncCallback<ApplicationInfo>): void
82    getApplicationInfo(): Promise<ApplicationInfo>;
83
84    /**
85    * Obtains the bundle name of the current ability.
86    * @since 7
87    * @sysCap SystemCapability.Appexecfwk
88    * @devices phone, tablet, tv, wearable
89    */
90    getBundleName(callback: AsyncCallback<string>): void
91    getBundleName(): Promise<string>;
92
93    /**
94    * Obtains information about the current process, including the process ID and name.
95    * @since 7
96    * @sysCap SystemCapability.Appexecfwk
97    * @devices phone, tablet, tv, wearable
98    */
99    getProcessInfo(callback: AsyncCallback<ProcessInfo>): void
100    getProcessInfo(): Promise<ProcessInfo>;
101
102    /**
103    * Obtains the ohos.bundle.ElementName object of the current ability. This method is available only to Page abilities.
104    * @since 7
105    * @sysCap SystemCapability.Appexecfwk
106    * @devices phone, tablet, tv, wearable
107    */
108    getElementName(callback: AsyncCallback<ElementName>): void
109    getElementName(): Promise<ElementName>;
110
111    /**
112    * Obtains the name of the current process.
113    * @since 7
114    * @sysCap SystemCapability.Appexecfwk
115    * @devices phone, tablet, tv, wearable
116    */
117    getProcessName(callback: AsyncCallback<string>): void
118    getProcessName(): Promise<string>;
119
120    /**
121    * Obtains the bundle name of the ability that called the current ability.
122    * @since 7
123    * @sysCap SystemCapability.Appexecfwk
124    * @devices phone, tablet, tv, wearable
125    */
126    getCallingBundle(callback: AsyncCallback<string>): void
127    getCallingBundle(): Promise<string>;
128}
129
130/**
131 * @name the result of requestPermissionsFromUser with asynchronous callback
132 * @since 7
133 * @SysCap SystemCapability.Appexecfwk
134 * @permission N/A
135 * @devices phone, tablet, tv, wearable, car
136 */
137interface PermissionRequestResult {
138    /**
139    * @default The request code passed in by the user
140    * @since 7
141    * @SysCap SystemCapability.Appexecfwk
142    */
143    requestCode: number;
144
145    /**
146    * @default The permissions passed in by the user
147    * @since 7
148    * @SysCap SystemCapability.Appexecfwk
149    */
150    permissions: Array<string>;
151
152    /**
153    * @default The results for the corresponding request permissions
154    * @since 7
155    * @SysCap SystemCapability.Appexecfwk
156    */
157    authResults: Array<number>;
158}
159
160interface PermissionOptions {
161 /**
162  * @default The process id
163  * @since 7
164  * @SysCap SystemCapability.Appexecfwk
165  */
166 pid?: number;
167
168 /**
169  * @default The user id
170  * @since 7
171  * @SysCap SystemCapability.Appexecfwk
172  */
173 uid?: number;
174}