flet-permission-handler 0.1.0.dev1__py3-none-any.whl → 0.70.0.dev6611__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet-permission-handler might be problematic. Click here for more details.

@@ -1,5 +1,8 @@
1
- from flet_permission_handler.permission_handler import (
2
- PermissionHandler,
3
- PermissionStatus,
4
- PermissionType,
5
- )
1
+ from flet_permission_handler.permission_handler import PermissionHandler
2
+ from flet_permission_handler.types import Permission, PermissionStatus
3
+
4
+ __all__ = [
5
+ "Permission",
6
+ "PermissionHandler",
7
+ "PermissionStatus",
8
+ ]
@@ -1,143 +1,82 @@
1
- from enum import Enum
2
- from typing import Any, Optional
3
-
4
- from flet.core.control import Control
5
- from flet.core.ref import Ref
6
-
7
-
8
- class PermissionStatus(Enum):
9
- GRANTED = "granted"
10
- DENIED = "denied"
11
- PERMANENTLY_DENIED = "permanentlyDenied"
12
- LIMITED = "limited"
13
- PROVISIONAL = "provisional"
14
- RESTRICTED = "restricted"
15
-
16
-
17
- class PermissionType(Enum):
18
- ACCESS_MEDIA_LOCATION = "accessMediaLocation"
19
- ACCESS_NOTIFICATION_POLICY = "accessNotificationPolicy"
20
- ACTIVITY_RECOGNITION = "activityRecognition"
21
- APP_TRACKING_TRANSPARENCY = "appTrackingTransparency"
22
- ASSISTANT = "assistant"
23
- AUDIO = "audio"
24
- BACKGROUND_REFRESH = "backgroundRefresh"
25
- BLUETOOTH = "bluetooth"
26
- BLUETOOTH_ADVERTISE = "bluetoothAdvertise"
27
- BLUETOOTH_CONNECT = "bluetoothConnect"
28
- BLUETOOTH_SCAN = "bluetoothScan"
29
- CALENDAR_FULL_ACCESS = "calendarFullAccess"
30
- CALENDAR_WRITE_ONLY = "calendarWriteOnly"
31
- CAMERA = "camera"
32
- CONTACTS = "contacts"
33
- CRITICAL_ALERTS = "criticalAlerts"
34
- IGNORE_BATTERY_OPTIMIZATIONS = "ignoreBatteryOptimizations"
35
- LOCATION = "location"
36
- LOCATION_ALWAYS = "locationAlways"
37
- LOCATION_WHEN_IN_USE = "locationWhenInUse"
38
- MANAGE_EXTERNAL_STORAGE = "manageExternalStorage"
39
- MEDIA_LIBRARY = "mediaLibrary"
40
- MICROPHONE = "microphone"
41
- NEARBY_WIFI_DEVICES = "nearbyWifiDevices"
42
- NOTIFICATION = "notification"
43
- PHONE = "phone"
44
- PHOTOS = "photos"
45
- PHOTOS_ADD_ONLY = "photosAddOnly"
46
- REMINDERS = "reminders"
47
- REQUEST_INSTALL_PACKAGES = "requestInstallPackages"
48
- SCHEDULE_EXACT_ALARM = "scheduleExactAlarm"
49
- SENSORS = "sensors"
50
- SENSORS_ALWAYS = "sensorsAlways"
51
- SMS = "sms"
52
- SPEECH = "speech"
53
- STORAGE = "storage"
54
- SYSTEM_ALERT_WINDOW = "systemAlertWindow"
55
- UNKNOWN = "unknown"
56
- VIDEOS = "videos"
57
-
58
-
59
- class PermissionHandler(Control):
60
- """
61
- A control that allows you check and request permission from your device.
62
- This control is non-visual and should be added to `page.overlay` list.
1
+ from typing import Optional
2
+
3
+ import flet as ft
4
+ from flet_permission_handler.types import Permission, PermissionStatus
5
+
6
+ __all__ = ["PermissionHandler"]
63
7
 
64
- -----
65
8
 
66
- Online docs: https://flet.dev/docs/controls/permissionhandler
9
+ @ft.control("PermissionHandler")
10
+ class PermissionHandler(ft.Service):
67
11
  """
12
+ Manages permissions for the application.
68
13
 
69
- def __init__(
70
- self,
71
- # Control
72
- #
73
- ref: Optional[Ref] = None,
74
- data: Any = None,
75
- ):
76
- Control.__init__(
77
- self,
78
- ref=ref,
79
- data=data,
80
- )
14
+ Danger: Platform support
15
+ Currently only supported on Android, iOS, Windows, and Web platforms.
81
16
 
82
- def _get_control_name(self):
83
- return "permission_handler"
84
-
85
- def check_permission(
86
- self, of: PermissionType, wait_timeout: Optional[float] = 25
87
- ) -> Optional[PermissionStatus]:
88
- out = self.invoke_method(
89
- "check_permission",
90
- {"of": of.value if isinstance(of, PermissionType) else of},
91
- wait_for_result=True,
92
- wait_timeout=wait_timeout,
93
- )
94
- return PermissionStatus(out) if out is not None else None
95
-
96
- async def check_permission_async(
97
- self, of: PermissionType, wait_timeout: Optional[float] = 25
98
- ) -> Optional[PermissionStatus]:
99
- out = await self.invoke_method_async(
100
- "check_permission",
101
- {"of": of.value if isinstance(of, PermissionType) else of},
102
- wait_for_result=True,
103
- wait_timeout=wait_timeout,
104
- )
105
- return PermissionStatus(out) if out is not None else None
106
-
107
- def request_permission(
108
- self, of: PermissionType, wait_timeout: Optional[float] = 25
109
- ) -> Optional[PermissionStatus]:
110
- out = self.invoke_method(
111
- "request_permission",
112
- {"of": of.value if isinstance(of, PermissionType) else of},
113
- wait_for_result=True,
114
- wait_timeout=wait_timeout,
17
+ Raises:
18
+ FletUnsupportedPlatformException: If the platform is not supported.
19
+ """
20
+
21
+ def before_update(self):
22
+ super().before_update()
23
+
24
+ # validate platform
25
+ if not (
26
+ self.page.web
27
+ or self.page.platform
28
+ in [
29
+ ft.PagePlatform.ANDROID,
30
+ ft.PagePlatform.IOS,
31
+ ft.PagePlatform.WINDOWS,
32
+ ]
33
+ ):
34
+ raise ft.FletUnsupportedPlatformException(
35
+ "PermissionHandler is currently only supported on Android, iOS, "
36
+ "Windows, and Web platforms."
37
+ )
38
+
39
+ async def get_status(self, permission: Permission) -> Optional[PermissionStatus]:
40
+ """
41
+ Gets the current status of the given `permission`.
42
+
43
+ Args:
44
+ permission: The `Permission` to check the status for.
45
+
46
+ Returns:
47
+ A `PermissionStatus` if the status is known, otherwise `None`.
48
+ """
49
+ status = await self._invoke_method(
50
+ method_name="get_status",
51
+ arguments={"permission": permission},
115
52
  )
116
- return PermissionStatus(out) if out is not None else None
117
-
118
- async def request_permission_async(
119
- self, of: PermissionType, wait_timeout: Optional[float] = 25
120
- ) -> Optional[PermissionStatus]:
121
- out = await self.invoke_method_async(
122
- "request_permission",
123
- {"of": of.value if isinstance(of, PermissionType) else of},
124
- wait_for_result=True,
125
- wait_timeout=wait_timeout,
53
+ return PermissionStatus(status) if status is not None else None
54
+
55
+ async def request(self, permission: Permission) -> Optional[PermissionStatus]:
56
+ """
57
+ Request the user for access to the `permission` if access hasn't already been
58
+ granted access before.
59
+
60
+ Args:
61
+ permission: The `Permission` to request.
62
+
63
+ Returns:
64
+ The new `PermissionStatus` after the request, or `None` if the request
65
+ was not successful.
66
+ """
67
+ r = await self._invoke_method(
68
+ method_name="request",
69
+ arguments={"permission": permission},
126
70
  )
127
- return PermissionStatus(out) if out is not None else None
71
+ return PermissionStatus(r) if r is not None else None
128
72
 
129
- def open_app_settings(self, wait_timeout: Optional[float] = 10) -> bool:
130
- opened = self.invoke_method(
131
- "open_app_settings",
132
- wait_for_result=True,
133
- wait_timeout=wait_timeout,
134
- )
135
- return opened == "true"
73
+ async def open_app_settings(self) -> bool:
74
+ """
75
+ Opens the app settings page.
136
76
 
137
- async def open_app_settings_async(self, wait_timeout: Optional[float] = 10) -> bool:
138
- opened = await self.invoke_method_async(
139
- "open_app_settings",
140
- wait_for_result=True,
141
- wait_timeout=wait_timeout,
77
+ Returns:
78
+ `True` if the app settings page could be opened, otherwise `False`.
79
+ """
80
+ return await self._invoke_method(
81
+ method_name="open_app_settings",
142
82
  )
143
- return opened == "true"
@@ -0,0 +1,425 @@
1
+ from enum import Enum
2
+
3
+ __all__ = [
4
+ "Permission",
5
+ "PermissionStatus",
6
+ ]
7
+
8
+
9
+ class PermissionStatus(Enum):
10
+ """Defines the state of a [`Permission`][(p).]."""
11
+
12
+ GRANTED = "granted"
13
+ """
14
+ The user granted access to the requested feature.
15
+ """
16
+
17
+ DENIED = "denied"
18
+ """
19
+ The user denied access to the requested feature, permission needs to be asked first.
20
+ """
21
+
22
+ PERMANENTLY_DENIED = "permanentlyDenied"
23
+ """
24
+ Permission to the requested feature is permanently denied,
25
+ the permission dialog will not be shown when requesting this permission.
26
+ The user may still change the permission status in the settings.
27
+
28
+ Note:
29
+ - On Android:
30
+ - Android 11+ (API 30+): whether the user denied the permission
31
+ for a second time.
32
+ - Below Android 11 (API 30): whether the user denied access
33
+ to the requested feature and selected to never again show a request.
34
+ - On iOS: If the user has denied access to the requested feature.
35
+ """
36
+
37
+ LIMITED = "limited"
38
+ """
39
+ The user has authorized this application for limited access.
40
+ So far this is only relevant for the Photo Library picker.
41
+
42
+ Note:
43
+ Only supported on iOS (iOS14+) and Android (Android 14+).
44
+ """
45
+
46
+ PROVISIONAL = "provisional"
47
+ """
48
+ The application is provisionally authorized to post non-interruptive
49
+ user notifications.
50
+
51
+ Note:
52
+ Only supported on iOS (iOS 12+).
53
+ """
54
+
55
+ RESTRICTED = "restricted"
56
+ """
57
+ The OS denied access to the requested feature. The user cannot change
58
+ this app's status, possibly due to active restrictions such as parental
59
+ controls being in place.
60
+
61
+ Note:
62
+ Only supported on iOS.
63
+ """
64
+
65
+
66
+ # todo: show how pyproject config for each could look like for each permission
67
+ # (what exactly is needed in manifest, plist, etc.)
68
+
69
+
70
+ class Permission(Enum):
71
+ """Defines the permissions which can be checked and requested."""
72
+
73
+ ACCESS_MEDIA_LOCATION = "accessMediaLocation"
74
+ """
75
+ Permission for accessing the device's media library.
76
+
77
+ Allows an application to access any geographic locations persisted in the
78
+ user's shared collection.
79
+
80
+ Note:
81
+ Only supported on Android 10+ (API 29+) only.
82
+ """
83
+
84
+ ACCESS_NOTIFICATION_POLICY = "accessNotificationPolicy"
85
+ """
86
+ Permission for accessing the device's notification policy.
87
+
88
+ Allows the user to access the notification policy of the phone.
89
+ Example: Allows app to turn on and off do-not-disturb.
90
+
91
+ Note:
92
+ Only supported on Android Marshmallow+ (API 23+) only.
93
+ """
94
+
95
+ ACTIVITY_RECOGNITION = "activityRecognition"
96
+ """
97
+ Permission for accessing the activity recognition.
98
+
99
+ Note:
100
+ Only supported on Android 10+ (API 29+) only.
101
+ """
102
+
103
+ APP_TRACKING_TRANSPARENCY = "appTrackingTransparency"
104
+ """
105
+ Permission for accessing the device's tracking state.
106
+ Allows user to accept that your app collects data about end users and
107
+ shares it with other companies for purposes of tracking across apps and
108
+ websites.
109
+
110
+ Note:
111
+ Only supported on iOS only.
112
+ """
113
+
114
+ ASSISTANT = "assistant"
115
+ """
116
+ Info:
117
+ - Android: Nothing
118
+ - iOS: SiriKit
119
+ """
120
+
121
+ AUDIO = "audio"
122
+ """
123
+ Permission for accessing the device's audio files from external storage.
124
+
125
+ Note:
126
+ Only supported on Android 13+ (API 33+) only.
127
+ """
128
+
129
+ BACKGROUND_REFRESH = "backgroundRefresh"
130
+ """
131
+ Permission for reading the current background refresh status.
132
+
133
+ Note:
134
+ Only supported on iOS only.
135
+ """
136
+
137
+ BLUETOOTH = "bluetooth"
138
+ """
139
+ Permission for accessing the device's bluetooth adapter state.
140
+
141
+ Depending on the platform and version, the requirements are slightly different:
142
+
143
+ Info:
144
+ - Android: always allowed.
145
+ - iOS:
146
+ - 13 and above: The authorization state of Core Bluetooth manager.
147
+ - below 13: always allowed.
148
+ """
149
+
150
+ BLUETOOTH_ADVERTISE = "bluetoothAdvertise"
151
+ """
152
+ Permission for advertising Bluetooth devices
153
+ Allows the user to make this device discoverable to other Bluetooth devices.
154
+
155
+ Note:
156
+ Only supported on Android 12+ (API 31+) only.
157
+ """
158
+
159
+ BLUETOOTH_CONNECT = "bluetoothConnect"
160
+ """
161
+ Permission for connecting to Bluetooth devices.
162
+ Allows the user to connect with already paired Bluetooth devices.
163
+
164
+ Note:
165
+ Only supported on Android 12+ (API 31+) only.
166
+ """
167
+
168
+ BLUETOOTH_SCAN = "bluetoothScan"
169
+ """
170
+ Permission for scanning for Bluetooth devices.
171
+
172
+ Note:
173
+ Only supported on Android 12+ (API 31+) only.
174
+ """
175
+
176
+ CALENDAR_FULL_ACCESS = "calendarFullAccess"
177
+ """
178
+ Permission for reading from and writing to the device's calendar.
179
+ """
180
+
181
+ CALENDAR_WRITE_ONLY = "calendarWriteOnly"
182
+ """
183
+ Permission for writing to the device's calendar.
184
+
185
+ On iOS 16 and lower, this permission is identical to
186
+ [`CALENDAR_FULL_ACCESS`][(c).].
187
+ """
188
+
189
+ CAMERA = "camera"
190
+ """
191
+ Permission for accessing the device's camera.
192
+
193
+ Info:
194
+ - Android: Camera
195
+ - iOS: Photos (Camera Roll and Camera)
196
+ """
197
+
198
+ CONTACTS = "contacts"
199
+ """
200
+ Permission for accessing the device's contacts.
201
+
202
+ Info:
203
+ - Android: Contacts
204
+ - iOS: AddressBook
205
+ """
206
+
207
+ CRITICAL_ALERTS = "criticalAlerts"
208
+ """
209
+ Permission for sending critical alerts.
210
+ Allow for sending notifications that override the ringer.
211
+
212
+ Note:
213
+ Only supported on iOS only.
214
+ """
215
+
216
+ IGNORE_BATTERY_OPTIMIZATIONS = "ignoreBatteryOptimizations"
217
+ """
218
+ Permission for accessing ignore battery optimizations.
219
+
220
+ Note:
221
+ Only supported on Android only.
222
+ """
223
+
224
+ LOCATION = "location"
225
+ """
226
+ Permission for accessing the device's location.
227
+
228
+ Info:
229
+ - Android: Fine and Coarse Location
230
+ - iOS: CoreLocation (Always and WhenInUse)
231
+ """
232
+
233
+ LOCATION_ALWAYS = "locationAlways"
234
+ """
235
+ Info:
236
+ iOS: CoreLocation (Always)
237
+ """
238
+
239
+ LOCATION_WHEN_IN_USE = "locationWhenInUse"
240
+ """
241
+ Permission for accessing the device's location when the app is
242
+ running in the foreground.
243
+
244
+ Info:
245
+ - Android: Fine and Coarse Location
246
+ - iOS: CoreLocation - WhenInUse
247
+ """
248
+
249
+ MANAGE_EXTERNAL_STORAGE = "manageExternalStorage"
250
+ """
251
+ Permission for accessing the device's external storage.
252
+ Allows an application a broad access to external storage in scoped storage.
253
+
254
+ You should request this permission only when your app cannot
255
+ effectively make use of the more privacy-friendly APIs.
256
+ For more information:
257
+ https://developer.android.com/training/data-storage/manage-all-files
258
+
259
+ Info:
260
+ When the privacy-friendly APIs (i.e. [Storage Access Framework](https://developer.android.com/guide/topics/providers/document-provider)
261
+ or the[MediaStore](https://developer.android.com/training/data-storage/shared/media) APIs)
262
+ is all your app needs, the [PermissionGroup.storage] are the only
263
+ permissions you need to request.
264
+
265
+ If the usage of this permission is needed, you have to fill out
266
+ the Permission Declaration Form upon submitting your app to the
267
+ Google Play Store.
268
+ More details:
269
+ https://support.google.com/googleplay/android-developer/answer/9214102#zippy=
270
+
271
+ Note:
272
+ Only supported on Android 11+ (API 30+) only.
273
+ """ # noqa: E501
274
+
275
+ MEDIA_LIBRARY = "mediaLibrary"
276
+ """
277
+ Permission for accessing the device's media library.
278
+
279
+ Note:
280
+ Only supported on iOS 9.3+ only
281
+ """
282
+
283
+ MICROPHONE = "microphone"
284
+ """
285
+ Permission for accessing the device's microphone.
286
+ """
287
+
288
+ NEARBY_WIFI_DEVICES = "nearbyWifiDevices"
289
+ """
290
+ Permission for connecting to nearby devices via Wi-Fi.
291
+
292
+ Note:
293
+ Only supported on Android 13+ (API 33+) only.
294
+ """
295
+
296
+ NOTIFICATION = "notification"
297
+ """
298
+ Permission for pushing notifications.
299
+ """
300
+
301
+ PHONE = "phone"
302
+ """
303
+ Permission for accessing the device's phone state.
304
+
305
+ Note:
306
+ Only supported on Android only.
307
+ """
308
+
309
+ PHOTOS = "photos"
310
+ """
311
+ Permission for accessing (read & write) the device's photos.
312
+
313
+ If you only want to add photos, you can use
314
+ the `PHOTOS_ADD_ONLY` permission instead (iOS only).
315
+ """
316
+
317
+ PHOTOS_ADD_ONLY = "photosAddOnly"
318
+ """
319
+ Permission for adding photos to the device's photo library (iOS only).
320
+
321
+ If you want to read them as well, use the `Permission.PHOTOS` permission instead.
322
+
323
+ Info:
324
+ iOS: Photos (14+ read & write access level)
325
+ """
326
+
327
+ REMINDERS = "reminders"
328
+ """
329
+ Permission for accessing the device's reminders.
330
+
331
+ Note:
332
+ Only supported on iOS only.
333
+ """
334
+
335
+ REQUEST_INSTALL_PACKAGES = "requestInstallPackages"
336
+ """
337
+ Permission for requesting installing packages.
338
+
339
+ Note:
340
+ Only supported on Android Marshmallow+ (API 23+) only.
341
+ """
342
+
343
+ SCHEDULE_EXACT_ALARM = "scheduleExactAlarm"
344
+ """
345
+ Permission for scheduling exact alarms.
346
+
347
+ Note:
348
+ Only supported on Android 12+ (API 31+) only.
349
+ """
350
+
351
+ SENSORS = "sensors"
352
+ """
353
+ Permission for accessing the device's sensors.
354
+
355
+ Info:
356
+ - Android: Body Sensors
357
+ - iOS: CoreMotion
358
+ """
359
+
360
+ SENSORS_ALWAYS = "sensorsAlways"
361
+ """
362
+ Permission for accessing the device's sensors in background.
363
+
364
+ Note:
365
+ Only supported on Android 13+ (API 33+) only.
366
+ """
367
+
368
+ SMS = "sms"
369
+ """
370
+ Permission for sending and reading SMS messages (Android only).
371
+ """
372
+
373
+ SPEECH = "speech"
374
+ """
375
+ Permission for accessing speech recognition.
376
+
377
+ Info:
378
+ - Android: Requests access to microphone
379
+ (identical to requesting [`MICROPHONE`][(c).]).
380
+ - iOS: Requests speech access (different from requesting
381
+ [`MICROPHONE`][(c).]).
382
+ """
383
+
384
+ STORAGE = "storage"
385
+ """
386
+ Permission for accessing external storage.
387
+
388
+ Depending on the platform and version, the requirements are slightly different:
389
+
390
+ Info:
391
+ - Android:
392
+ - On Android 13 (API 33) and above, this permission is deprecated and
393
+ always returns `PermissionStatus.denied`. Instead use `Permission.PHOTOS`,
394
+ `Permission.VIDEO`, `Permission.AUDIO` or
395
+ `Permission.MANAGE_EXTERNAL_STORAGE`.
396
+ For more information see
397
+ [this](https://pub.dev/packages/permission_handler#faq).
398
+
399
+ - Below Android 13 (API 33), the `READ_EXTERNAL_STORAGE` and
400
+ `WRITE_EXTERNAL_STORAGE` permissions are requested (depending on the
401
+ definitions in the AndroidManifest.xml) file.
402
+ - iOS: Access to folders like `Documents` or `Downloads`. Implicitly granted.
403
+ """
404
+
405
+ SYSTEM_ALERT_WINDOW = "systemAlertWindow"
406
+ """
407
+ Permission for creating system alert window.
408
+ Allows an app to create windows shown on top of all other apps.
409
+
410
+ Note:
411
+ Only supported on Android only.
412
+ """
413
+
414
+ UNKNOWN = "unknown"
415
+ """
416
+ The unknown only used for return type, never requested.
417
+ """
418
+
419
+ VIDEOS = "videos"
420
+ """
421
+ Permission for accessing the device's video files from external storage.
422
+
423
+ Note:
424
+ Only supported on Android 13+ (API 33+) only.
425
+ """