Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
permission_handler
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
permission_handler
Commits
3227538b
Commit
3227538b
authored
Mar 12, 2021
by
Maurits van Beusekom
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
ffc85b24
11fb8c49
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
169 additions
and
5 deletions
+169
-5
README.md
+4
-0
permission_handler/CHANGELOG.md
+5
-0
permission_handler/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java
+2
-0
permission_handler/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java
+29
-1
permission_handler/android/src/main/java/com/baseflow/permissionhandler/PermissionUtils.java
+4
-0
permission_handler/android/src/main/java/com/baseflow/permissionhandler/ServiceManager.java
+13
-0
permission_handler/example/android/app/src/main/AndroidManifest.xml
+3
-0
permission_handler/ios/Classes/PermissionHandlerEnums.h
+9
-0
permission_handler/ios/Classes/PermissionManager.h
+1
-0
permission_handler/ios/Classes/PermissionManager.m
+2
-0
permission_handler/ios/Classes/strategies/BluetoothPermissionStrategy.h
+25
-0
permission_handler/ios/Classes/strategies/BluetoothPermissionStrategy.m
+58
-0
permission_handler/pubspec.yaml
+2
-2
permission_handler_platform_interface/CHANGELOG.md
+4
-0
permission_handler_platform_interface/lib/src/permissions.dart
+6
-0
permission_handler_platform_interface/pubspec.yaml
+2
-2
No files found.
README.md
View file @
3227538b
...
...
@@ -101,6 +101,9 @@ You can remove permissions you don't use:
## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=0'
## dart: PermissionGroup.bluetooth
# 'PERMISSION_BLUETOOTH=0'
]
end
...
...
@@ -128,6 +131,7 @@ You can remove permissions you don't use:
| PermissionGroup.notification | PermissionGroupNotification | PERMISSION_NOTIFICATIONS |
| PermissionGroup.mediaLibrary | NSAppleMusicUsageDescription, kTCCServiceMediaLibrary | PERMISSION_MEDIA_LIBRARY |
| PermissionGroup.sensors | NSMotionUsageDescription | PERMISSION_SENSORS |
| PermissionGroup.bluetooth | NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription | PERMISSION_BLUETOOTH |
4. Clean & Rebuild
</details>
...
...
permission_handler/CHANGELOG.md
View file @
3227538b
## 6.1.0
*
Added support for bluetooth permissions;
*
Workaround for ignore battery optimizations on pre-M Android devices (see PR
[
#376
](
https://github.com/Baseflow/flutter-permission-handler/pull/376
)
).
## 6.0.1+1
*
Fixed content of the README.md file.
...
...
permission_handler/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java
View file @
3227538b
...
...
@@ -32,6 +32,7 @@ final class PermissionConstants {
static
final
int
PERMISSION_GROUP_ACCESS_MEDIA_LOCATION
=
18
;
static
final
int
PERMISSION_GROUP_ACTIVITY_RECOGNITION
=
19
;
static
final
int
PERMISSION_GROUP_UNKNOWN
=
20
;
static
final
int
PERMISSION_GROUP_BLUETOOTH
=
21
;
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
...
...
@@ -55,6 +56,7 @@ final class PermissionConstants {
PERMISSION_GROUP_ACCESS_MEDIA_LOCATION
,
PERMISSION_GROUP_ACTIVITY_RECOGNITION
,
PERMISSION_GROUP_UNKNOWN
,
PERMISSION_GROUP_BLUETOOTH
,
})
@interface
PermissionGroup
{
}
...
...
permission_handler/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java
View file @
3227538b
...
...
@@ -104,7 +104,13 @@ final class PermissionManager {
// if we can't add as unknown and continue
if
(
names
==
null
||
names
.
isEmpty
())
{
if
(!
requestResults
.
containsKey
(
permission
))
{
requestResults
.
put
(
permission
,
PermissionConstants
.
PERMISSION_STATUS_DENIED
);
// On Android below M, the android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS flag in AndroidManifest.xml
// may be ignored and not visible to the App as it's a new permission setting as a whole.
if
(
permission
==
PermissionConstants
.
PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS
&&
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
M
)
{
requestResults
.
put
(
permission
,
PermissionConstants
.
PERMISSION_STATUS_RESTRICTED
);
}
else
{
requestResults
.
put
(
permission
,
PermissionConstants
.
PERMISSION_STATUS_DENIED
);
}
}
continue
;
...
...
@@ -160,6 +166,9 @@ final class PermissionManager {
if
(
permission
==
PermissionConstants
.
PERMISSION_GROUP_NOTIFICATION
)
{
return
checkNotificationPermissionStatus
(
context
);
}
if
(
permission
==
PermissionConstants
.
PERMISSION_GROUP_BLUETOOTH
){
return
checkBluetoothPermissionStatus
(
context
);
}
final
List
<
String
>
names
=
PermissionUtils
.
getManifestNames
(
context
,
permission
);
...
...
@@ -172,6 +181,15 @@ final class PermissionManager {
//if no permissions were found then there is an issue and permission is not set in Android manifest
if
(
names
.
size
()
==
0
)
{
Log
.
d
(
PermissionConstants
.
LOG_TAG
,
"No permissions found in manifest for: "
+
permission
);
// On Android below M, the android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS flag in AndroidManifest.xml
// may be ignored and not visible to the App as it's a new permission setting as a whole.
if
(
permission
==
PermissionConstants
.
PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
M
)
{
return
PermissionConstants
.
PERMISSION_STATUS_RESTRICTED
;
}
}
return
PermissionConstants
.
PERMISSION_STATUS_DENIED
;
}
...
...
@@ -244,6 +262,16 @@ final class PermissionManager {
return
PermissionConstants
.
PERMISSION_STATUS_DENIED
;
}
private
int
checkBluetoothPermissionStatus
(
Context
context
)
{
List
<
String
>
names
=
PermissionUtils
.
getManifestNames
(
context
,
PermissionConstants
.
PERMISSION_GROUP_BLUETOOTH
);
boolean
missingInManifest
=
names
==
null
||
names
.
isEmpty
();
if
(
missingInManifest
)
{
Log
.
d
(
PermissionConstants
.
LOG_TAG
,
"Bluetooth permission missing in manifest"
);
return
PermissionConstants
.
PERMISSION_STATUS_DENIED
;
}
return
PermissionConstants
.
PERMISSION_STATUS_GRANTED
;
}
@VisibleForTesting
static
final
class
ActivityResultListener
implements
PluginRegistry
.
ActivityResultListener
{
...
...
permission_handler/android/src/main/java/com/baseflow/permissionhandler/PermissionUtils.java
View file @
3227538b
...
...
@@ -193,6 +193,10 @@ public class PermissionUtils {
permissionNames
.
add
(
Manifest
.
permission
.
ACTIVITY_RECOGNITION
);
break
;
case
PermissionConstants
.
PERMISSION_GROUP_BLUETOOTH
:
if
(
hasPermissionInManifest
(
context
,
permissionNames
,
Manifest
.
permission
.
BLUETOOTH
))
permissionNames
.
add
(
Manifest
.
permission
.
BLUETOOTH
);
break
;
case
PermissionConstants
.
PERMISSION_GROUP_NOTIFICATION
:
case
PermissionConstants
.
PERMISSION_GROUP_MEDIA_LIBRARY
:
case
PermissionConstants
.
PERMISSION_GROUP_PHOTOS
:
...
...
permission_handler/android/src/main/java/com/baseflow/permissionhandler/ServiceManager.java
View file @
3227538b
package
com
.
baseflow
.
permissionhandler
;
import
android.bluetooth.BluetoothAdapter
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
...
...
@@ -43,6 +44,13 @@ final class ServiceManager {
successCallback
.
onSuccess
(
serviceStatus
);
return
;
}
if
(
permission
==
PermissionConstants
.
PERMISSION_GROUP_BLUETOOTH
){
final
int
serviceStatus
=
isBluetoothServiceEnabled
()
?
PermissionConstants
.
SERVICE_STATUS_ENABLED
:
PermissionConstants
.
SERVICE_STATUS_DISABLED
;
successCallback
.
onSuccess
(
serviceStatus
);
}
if
(
permission
==
PermissionConstants
.
PERMISSION_GROUP_PHONE
)
{
PackageManager
pm
=
context
.
getPackageManager
();
...
...
@@ -139,4 +147,9 @@ final class ServiceManager {
Settings
.
Secure
.
LOCATION_PROVIDERS_ALLOWED
);
return
!
TextUtils
.
isEmpty
(
locationProviders
);
}
private
boolean
isBluetoothServiceEnabled
()
{
final
BluetoothAdapter
bluetoothAdapter
=
BluetoothAdapter
.
getDefaultAdapter
();
return
bluetoothAdapter
.
isEnabled
();
}
}
permission_handler/example/android/app/src/main/AndroidManifest.xml
View file @
3227538b
...
...
@@ -60,6 +60,9 @@
<!-- Permissions options for the `ignoreBatteryOptimizations` group -->
<uses-permission
android:name=
"android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"
/>
<!-- Permissions options for the `bluetooth` group -->
<uses-permission
android:name=
"android.permission.BLUETOOTH"
/>
<application
android:name=
"io.flutter.app.FlutterApplication"
android:icon=
"@mipmap/ic_launcher"
...
...
permission_handler/ios/Classes/PermissionHandlerEnums.h
View file @
3227538b
...
...
@@ -88,6 +88,13 @@
#define PERMISSION_SENSORS 1
#endif
// ios: PermissionGroupBluetooth
// Info.plist: [NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription]
// dart: PermissionGroup.bluetooth
#ifndef PERMISSION_BLUETOOTH
#define PERMISSION_BLUETOOTH 1
#endif
typedef
NS_ENUM
(
int
,
PermissionGroup
)
{
PermissionGroupCalendar
=
0
,
PermissionGroupCamera
,
...
...
@@ -108,7 +115,9 @@ typedef NS_ENUM(int, PermissionGroup) {
PermissionGroupIgnoreBatteryOptimizations
,
PermissionGroupNotification
,
PermissionGroupAccessMediaLocation
,
PermissionGroupActivityRecognition
,
PermissionGroupUnknown
,
PermissionGroupBluetooth
,
};
typedef
NS_ENUM
(
int
,
PermissionStatus
)
{
...
...
permission_handler/ios/Classes/PermissionManager.h
View file @
3227538b
...
...
@@ -10,6 +10,7 @@
#import <UIKit/UIKit.h>
#import "AudioVideoPermissionStrategy.h"
#import "BluetoothPermissionStrategy.h"
#import "ContactPermissionStrategy.h"
#import "EventPermissionStrategy.h"
#import "LocationPermissionStrategy.h"
...
...
permission_handler/ios/Classes/PermissionManager.m
View file @
3227538b
...
...
@@ -123,6 +123,8 @@
return
[
NotificationPermissionStrategy
new
];
case
PermissionGroupStorage
:
return
[
StoragePermissionStrategy
new
];
case
PermissionGroupBluetooth
:
return
[
BluetoothPermissionStrategy
new
];
default
:
return
[
UnknownPermissionStrategy
new
];
}
...
...
permission_handler/ios/Classes/strategies/BluetoothPermissionStrategy.h
0 → 100644
View file @
3227538b
//
// BluetoothPermissionStrategy.h
// permission_handler
//
// Created by Rene Floor on 12/03/2021.
//
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"
#if PERMISSION_BLUETOOTH
#import <CoreBluetooth/CoreBluetooth.h>
@interface
BluetoothPermissionStrategy
:
NSObject
<
PermissionStrategy
>
@end
#else
#import "UnknownPermissionStrategy.h"
@interface
BluetoothPermissionStrategy
:
UnknownPermissionStrategy
@end
#endif
permission_handler/ios/Classes/strategies/BluetoothPermissionStrategy.m
0 → 100644
View file @
3227538b
//
// BluetoothPermissionStrategy.m
// permission_handler
//
// Created by Rene Floor on 12/03/2021.
//
#import "BluetoothPermissionStrategy.h"
#if PERMISSION_BLUETOOTH
@implementation
BluetoothPermissionStrategy
-
(
PermissionStatus
)
checkPermissionStatus
:(
PermissionGroup
)
permission
{
if
(
@available
(
iOS
13
.
1
,
*
))
{
CBManagerAuthorization
blePermission
=
[
CBCentralManager
authorization
];
return
[
BluetoothPermissionStrategy
parsePermission
:
blePermission
];
}
else
if
(
@available
(
iOS
13
.
0
,
*
)){
CBCentralManager
*
manager
=
[[
CBCentralManager
alloc
]
init
];
CBManagerAuthorization
blePermission
=
[
manager
authorization
];
return
[
BluetoothPermissionStrategy
parsePermission
:
blePermission
];
}
return
PermissionStatusGranted
;
}
-
(
ServiceStatus
)
checkServiceStatus
:(
PermissionGroup
)
permission
{
CBCentralManager
*
manager
=
[[
CBCentralManager
alloc
]
init
];
if
(
@available
(
iOS
10
,
*
))
{
return
[
manager
state
]
==
CBManagerStatePoweredOn
?
ServiceStatusEnabled
:
ServiceStatusDisabled
;
}
return
[
manager
state
]
==
CBCentralManagerStatePoweredOn
?
ServiceStatusEnabled
:
ServiceStatusDisabled
;
}
-
(
void
)
requestPermission
:(
PermissionGroup
)
permission
completionHandler
:(
PermissionStatusHandler
)
completionHandler
{
completionHandler
([
self
checkPermissionStatus
:
permission
]);
}
+
(
PermissionStatus
)
parsePermission
:(
CBManagerAuthorization
)
bluetoothPermission
API_AVAILABLE
(
ios
(
13
)){
switch
(
bluetoothPermission
){
case
CBManagerAuthorizationNotDetermined
:
return
PermissionStatusDenied
;
case
CBManagerAuthorizationRestricted
:
return
PermissionStatusRestricted
;
case
CBManagerAuthorizationDenied
:
return
PermissionStatusDenied
;
case
CBManagerAuthorizationAllowedAlways
:
return
PermissionStatusGranted
;
}
}
@end
#else
@implementation
BluetoothPermissionStrategy
@end
#endif
permission_handler/pubspec.yaml
View file @
3227538b
name
:
permission_handler
description
:
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
version
:
6.
0.1+1
version
:
6.
1.0
homepage
:
https://github.com/baseflowit/flutter-permission-handler
flutter
:
...
...
@@ -16,7 +16,7 @@ dependencies:
flutter
:
sdk
:
flutter
meta
:
^1.3.0
permission_handler_platform_interface
:
^3.
0.0+1
permission_handler_platform_interface
:
^3.
1.0
dev_dependencies
:
effective_dart
:
^1.3.0
...
...
permission_handler_platform_interface/CHANGELOG.md
View file @
3227538b
## 3.1.0
*
Added support for bluetooth permissions.
## 3.0.0+1
*
**BREAKING**
: Removed PermissionStatus.undetermined. This is now replaced by PermissionStatus.denied.
...
...
permission_handler_platform_interface/lib/src/permissions.dart
View file @
3227538b
...
...
@@ -103,6 +103,10 @@ class Permission {
/// The unknown only used for return type, never requested
static
const
unknown
=
Permission
.
_
(
20
);
/// iOS 13 and above: The authorization state of Core Bluetooth manager.
/// When running < iOS 13 or Android this is always allowed.
static
const
bluetooth
=
Permission
.
_
(
21
);
/// Returns a list of all possible [PermissionGroup] values.
static
const
List
<
Permission
>
values
=
<
Permission
>[
calendar
,
...
...
@@ -126,6 +130,7 @@ class Permission {
accessMediaLocation
,
activityRecognition
,
unknown
,
bluetooth
];
static
const
List
<
String
>
_names
=
<
String
>[
...
...
@@ -150,6 +155,7 @@ class Permission {
'access_media_location'
,
'activity_recognition'
,
'unknown'
,
'bluetooth'
,
];
@override
...
...
permission_handler_platform_interface/pubspec.yaml
View file @
3227538b
...
...
@@ -3,7 +3,7 @@ description: A common platform interface for the permission_handler plugin.
homepage
:
https://github.com/baseflow/flutter-permission-handler/tree/master/permission_handler_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version
:
3.
0.0+1
version
:
3.
1.0
dependencies
:
flutter
:
...
...
@@ -18,5 +18,5 @@ dev_dependencies:
effective_dart
:
^1.3.0
environment
:
sdk
:
"
>=2.12.0
-259.9.beta
<3.0.0"
sdk
:
"
>=2.12.0
<3.0.0"
flutter
:
"
>=1.22.0"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment