1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10export interface Rationale {
11  title: string;
12  message: string;
13  buttonPositive: string;
14  buttonNegative?: string | undefined;
15  buttonNeutral?: string | undefined;
16}
17
18export type Permission =
19  | 'android.permission.READ_CALENDAR'
20  | 'android.permission.WRITE_CALENDAR'
21  | 'android.permission.CAMERA'
22  | 'android.permission.READ_CONTACTS'
23  | 'android.permission.WRITE_CONTACTS'
24  | 'android.permission.GET_ACCOUNTS'
25  | 'android.permission.ACCESS_BACKGROUND_LOCATION'
26  | 'android.permission.ACCESS_FINE_LOCATION'
27  | 'android.permission.ACCESS_COARSE_LOCATION'
28  | 'android.permission.RECORD_AUDIO'
29  | 'android.permission.READ_PHONE_STATE'
30  | 'android.permission.CALL_PHONE'
31  | 'android.permission.READ_CALL_LOG'
32  | 'android.permission.WRITE_CALL_LOG'
33  | 'com.android.voicemail.permission.ADD_VOICEMAIL'
34  | 'com.android.voicemail.permission.READ_VOICEMAIL'
35  | 'com.android.voicemail.permission.WRITE_VOICEMAIL'
36  | 'android.permission.USE_SIP'
37  | 'android.permission.PROCESS_OUTGOING_CALLS'
38  | 'android.permission.BODY_SENSORS'
39  | 'android.permission.BODY_SENSORS_BACKGROUND'
40  | 'android.permission.SEND_SMS'
41  | 'android.permission.RECEIVE_SMS'
42  | 'android.permission.READ_SMS'
43  | 'android.permission.RECEIVE_WAP_PUSH'
44  | 'android.permission.RECEIVE_MMS'
45  | 'android.permission.READ_EXTERNAL_STORAGE'
46  | 'android.permission.READ_MEDIA_IMAGES'
47  | 'android.permission.READ_MEDIA_VIDEO'
48  | 'android.permission.READ_MEDIA_AUDIO'
49  | 'android.permission.WRITE_EXTERNAL_STORAGE'
50  | 'android.permission.BLUETOOTH_CONNECT'
51  | 'android.permission.BLUETOOTH_SCAN'
52  | 'android.permission.BLUETOOTH_ADVERTISE'
53  | 'android.permission.ACCESS_MEDIA_LOCATION'
54  | 'android.permission.ACCEPT_HANDOVER'
55  | 'android.permission.ACTIVITY_RECOGNITION'
56  | 'android.permission.ANSWER_PHONE_CALLS'
57  | 'android.permission.READ_PHONE_NUMBERS'
58  | 'android.permission.UWB_RANGING'
59  | 'android.permission.POST_NOTIFICATIONS'
60  | 'android.permission.NEARBY_WIFI_DEVICES';
61
62export type PermissionStatus = 'granted' | 'denied' | 'never_ask_again';
63
64export interface PermissionsAndroidStatic {
65  /**
66   * A list of permission results that are returned
67   */
68  RESULTS: {[key: string]: PermissionStatus};
69  /**
70   * A list of specified "dangerous" permissions that require prompting the user
71   */
72  PERMISSIONS: {[key: string]: Permission};
73  new (): PermissionsAndroidStatic;
74  /**
75   * @deprecated Use check instead
76   */
77  checkPermission(permission: Permission): Promise<boolean>;
78  /**
79   * Returns a promise resolving to a boolean value as to whether the specified
80   * permissions has been granted
81   */
82  check(permission: Permission): Promise<boolean>;
83  /**
84   * @deprecated Use request instead
85   */
86  requestPermission(
87    permission: Permission,
88    rationale?: Rationale,
89  ): Promise<boolean>;
90  /**
91   * Prompts the user to enable a permission and returns a promise resolving to a
92   * string value indicating whether the user allowed or denied the request
93   *
94   * If the optional rationale argument is included (which is an object with a
95   * title and message), this function checks with the OS whether it is necessary
96   * to show a dialog explaining why the permission is needed
97   * (https://developer.android.com/training/permissions/requesting.html#explain)
98   * and then shows the system permission dialog
99   */
100  request(
101    permission: Permission,
102    rationale?: Rationale,
103  ): Promise<PermissionStatus>;
104  /**
105   * Prompts the user to enable multiple permissions in the same dialog and
106   * returns an object with the permissions as keys and strings as values
107   * indicating whether the user allowed or denied the request
108   */
109  requestMultiple(
110    permissions: Array<Permission>,
111  ): Promise<{[key in Permission]: PermissionStatus}>;
112}
113
114export const PermissionsAndroid: PermissionsAndroidStatic;
115export type PermissionsAndroid = PermissionsAndroidStatic;
116