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
2fef231c
Commit
2fef231c
authored
Jan 28, 2019
by
Abid Hasan
Browse files
Options
Browse Files
Download
Plain Diff
merge conflict resolved
parents
59109a4d
89e62f9c
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
52 additions
and
28 deletions
+52
-28
README.md
+1
-1
analysis_options.yaml
+13
-1
android/.settings/org.eclipse.buildship.core.prefs
+1
-1
android/src/main/kotlin/com/baseflow/permissionhandler/PermissionHandlerPlugin.kt
+11
-3
example/ios/Runner.xcodeproj/project.pbxproj
+1
-1
ios/Classes/strategies/LocationPermissionStrategy.swift
+7
-6
ios/Classes/strategies/SensorPermissionStrategy.swift
+11
-8
lib/permission_handler.dart
+2
-2
lib/utils/codec.dart
+4
-4
pubspec.yaml
+1
-1
No files found.
README.md
View file @
2fef231c
...
@@ -143,7 +143,7 @@ enum PermissionStatus {
...
@@ -143,7 +143,7 @@ enum PermissionStatus {
/// Permission to access the requested feature is denied by the user.
/// Permission to access the requested feature is denied by the user.
denied
,
denied
,
///
The feature is disabled (or not available) on the device
.
///
Permissions to access the feature is granted by the user but the feature is disabled
.
disabled
,
disabled
,
/// Permission to access the requested feature is granted by the user.
/// Permission to access the requested feature is granted by the user.
...
...
analysis_options.yaml
View file @
2fef231c
...
@@ -28,6 +28,10 @@ analyzer:
...
@@ -28,6 +28,10 @@ analyzer:
missing_return
:
warning
missing_return
:
warning
# allow having TODOs in the code
# allow having TODOs in the code
todo
:
ignore
todo
:
ignore
# Ignore analyzer hints for updating pubspecs when using Future or
# Stream and not importing dart:async
# Please see https://github.com/flutter/flutter/pull/24528 for details.
#sdk_version_async_exported_from_core: ignore
exclude
:
exclude
:
-
'
bin/cache/**'
-
'
bin/cache/**'
# the following two are relative to the stocks example and the flutter package respectively
# the following two are relative to the stocks example and the flutter package respectively
...
@@ -56,6 +60,7 @@ linter:
...
@@ -56,6 +60,7 @@ linter:
-
avoid_empty_else
-
avoid_empty_else
-
avoid_field_initializers_in_const_classes
-
avoid_field_initializers_in_const_classes
-
avoid_function_literals_in_foreach_calls
-
avoid_function_literals_in_foreach_calls
# - avoid_implementing_value_types # not yet tested
-
avoid_init_to_null
-
avoid_init_to_null
# - avoid_js_rounded_ints # only useful when targeting JS runtime
# - avoid_js_rounded_ints # only useful when targeting JS runtime
-
avoid_null_checks_in_equality_operators
-
avoid_null_checks_in_equality_operators
...
@@ -65,8 +70,11 @@ linter:
...
@@ -65,8 +70,11 @@ linter:
-
avoid_renaming_method_parameters
-
avoid_renaming_method_parameters
-
avoid_return_types_on_setters
-
avoid_return_types_on_setters
# - avoid_returning_null # there are plenty of valid reasons to return null
# - avoid_returning_null # there are plenty of valid reasons to return null
# - avoid_returning_null_for_future # not yet tested
-
avoid_returning_null_for_void
# - avoid_returning_this # there are plenty of valid reasons to return this
# - avoid_returning_this # there are plenty of valid reasons to return this
# - avoid_setters_without_getters # not yet tested
# - avoid_setters_without_getters # not yet tested
# - avoid_shadowing_type_parameters # not yet tested
# - avoid_single_cascade_in_expression_statements # not yet tested
# - avoid_single_cascade_in_expression_statements # not yet tested
-
avoid_slow_async_io
-
avoid_slow_async_io
-
avoid_types_as_parameter_names
-
avoid_types_as_parameter_names
...
@@ -87,6 +95,7 @@ linter:
...
@@ -87,6 +95,7 @@ linter:
-
empty_constructor_bodies
-
empty_constructor_bodies
-
empty_statements
-
empty_statements
# - file_names # not yet tested
# - file_names # not yet tested
-
flutter_style_todos
-
hash_and_equals
-
hash_and_equals
-
implementation_imports
-
implementation_imports
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
...
@@ -111,7 +120,6 @@ linter:
...
@@ -111,7 +120,6 @@ linter:
# - parameter_assignments # we do this commonly
# - parameter_assignments # we do this commonly
-
prefer_adjacent_string_concatenation
-
prefer_adjacent_string_concatenation
-
prefer_asserts_in_initializer_lists
-
prefer_asserts_in_initializer_lists
-
prefer_bool_in_asserts
-
prefer_collection_literals
-
prefer_collection_literals
-
prefer_conditional_assignment
-
prefer_conditional_assignment
-
prefer_const_constructors
-
prefer_const_constructors
...
@@ -128,6 +136,7 @@ linter:
...
@@ -128,6 +136,7 @@ linter:
# - prefer_function_declarations_over_variables # not yet tested
# - prefer_function_declarations_over_variables # not yet tested
-
prefer_generic_function_type_aliases
-
prefer_generic_function_type_aliases
-
prefer_initializing_formals
-
prefer_initializing_formals
# - prefer_int_literals # not yet tested
# - prefer_interpolation_to_compose_strings # not yet tested
# - prefer_interpolation_to_compose_strings # not yet tested
-
prefer_is_empty
-
prefer_is_empty
-
prefer_is_not_empty
-
prefer_is_not_empty
...
@@ -140,6 +149,7 @@ linter:
...
@@ -140,6 +149,7 @@ linter:
-
recursive_getters
-
recursive_getters
-
slash_for_doc_comments
-
slash_for_doc_comments
-
sort_constructors_first
-
sort_constructors_first
-
sort_pub_dependencies
-
sort_unnamed_constructors_first
-
sort_unnamed_constructors_first
-
super_goes_last
-
super_goes_last
-
test_types_in_equals
-
test_types_in_equals
...
@@ -147,6 +157,7 @@ linter:
...
@@ -147,6 +157,7 @@ linter:
# - type_annotate_public_apis # subset of always_specify_types
# - type_annotate_public_apis # subset of always_specify_types
-
type_init_formals
-
type_init_formals
# - unawaited_futures # too many false positives
# - unawaited_futures # too many false positives
# - unnecessary_await_in_return # not yet tested
-
unnecessary_brace_in_string_interps
-
unnecessary_brace_in_string_interps
-
unnecessary_const
-
unnecessary_const
-
unnecessary_getters_setters
-
unnecessary_getters_setters
...
@@ -159,6 +170,7 @@ linter:
...
@@ -159,6 +170,7 @@ linter:
-
unnecessary_statements
-
unnecessary_statements
-
unnecessary_this
-
unnecessary_this
-
unrelated_type_equality_checks
-
unrelated_type_equality_checks
# - use_function_type_syntax_for_parameters # not yet tested
-
use_rethrow_when_possible
-
use_rethrow_when_possible
# - use_setters_to_change_properties # not yet tested
# - use_setters_to_change_properties # not yet tested
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
...
...
android/.settings/org.eclipse.buildship.core.prefs
View file @
2fef231c
connection.project.dir=
connection.project.dir=
../example/android
eclipse.preferences.version=1
eclipse.preferences.version=1
android/src/main/kotlin/com/baseflow/permissionhandler/PermissionHandlerPlugin.kt
View file @
2fef231c
...
@@ -149,8 +149,13 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
...
@@ -149,8 +149,13 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
val
targetsMOrHigher
=
context
.
applicationInfo
.
targetSdkVersion
>=
android
.
os
.
Build
.
VERSION_CODES
.
M
val
targetsMOrHigher
=
context
.
applicationInfo
.
targetSdkVersion
>=
android
.
os
.
Build
.
VERSION_CODES
.
M
for
(
name
in
names
)
{
for
(
name
in
names
)
{
if
(
targetsMOrHigher
&&
ContextCompat
.
checkSelfPermission
(
context
,
name
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
targetsMOrHigher
)
{
return
PermissionStatus
.
DENIED
val
permissionStatus
=
ContextCompat
.
checkSelfPermission
(
context
,
name
)
if
(
permissionStatus
==
PackageManager
.
PERMISSION_DENIED
)
{
return
PermissionStatus
.
DENIED
}
else
if
(
permissionStatus
!=
PackageManager
.
PERMISSION_GRANTED
)
{
return
PermissionStatus
.
UNKNOWN
}
}
}
}
}
...
@@ -258,7 +263,10 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
...
@@ -258,7 +263,10 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
}
else
if
(
permission
==
PermissionGroup
.
LOCATION
)
{
}
else
if
(
permission
==
PermissionGroup
.
LOCATION
)
{
val
context
:
Context
?
=
registrar
.
activity
()
?:
registrar
.
activeContext
()
val
context
:
Context
?
=
registrar
.
activity
()
?:
registrar
.
activeContext
()
val
isLocationServiceEnabled
=
if
(
context
==
null
)
false
else
isLocationServiceEnabled
(
context
)
val
isLocationServiceEnabled
=
if
(
context
==
null
)
false
else
isLocationServiceEnabled
(
context
)
val
permissionStatus
=
if
(
isLocationServiceEnabled
)
grantResults
[
i
].
toPermissionStatus
()
else
PermissionStatus
.
DISABLED
var
permissionStatus
=
grantResults
[
i
].
toPermissionStatus
()
if
(
permissionStatus
==
PermissionStatus
.
GRANTED
&&
!
isLocationServiceEnabled
)
{
permissionStatus
=
PermissionStatus
.
DISABLED
}
if
(!
mRequestResults
.
containsKey
(
PermissionGroup
.
LOCATION_ALWAYS
))
{
if
(!
mRequestResults
.
containsKey
(
PermissionGroup
.
LOCATION_ALWAYS
))
{
mRequestResults
[
PermissionGroup
.
LOCATION_ALWAYS
]
=
permissionStatus
mRequestResults
[
PermissionGroup
.
LOCATION_ALWAYS
]
=
permissionStatus
...
...
example/ios/Runner.xcodeproj/project.pbxproj
View file @
2fef231c
...
@@ -222,7 +222,7 @@
...
@@ -222,7 +222,7 @@
);
);
inputPaths
=
(
inputPaths
=
(
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh"
,
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh"
,
"${PODS_ROOT}/../.symlinks/flutter/ios
-release
/Flutter.framework"
,
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework"
,
"${BUILT_PRODUCTS_DIR}/permission_handler/permission_handler.framework"
,
"${BUILT_PRODUCTS_DIR}/permission_handler/permission_handler.framework"
,
);
);
name
=
"[CP] Embed Pods Frameworks"
;
name
=
"[CP] Embed Pods Frameworks"
;
...
...
ios/Classes/strategies/LocationPermissionStrategy.swift
View file @
2fef231c
...
@@ -18,15 +18,16 @@ class LocationPermissionStrategy : NSObject, PermissionStrategy, CLLocationManag
...
@@ -18,15 +18,16 @@ class LocationPermissionStrategy : NSObject, PermissionStrategy, CLLocationManag
}
}
private
static
func
getPermissionStatus
(
permission
:
PermissionGroup
)
->
PermissionStatus
{
private
static
func
getPermissionStatus
(
permission
:
PermissionGroup
)
->
PermissionStatus
{
if
!
CLLocationManager
.
locationServicesEnabled
()
{
let
authorizationStatus
:
CLAuthorizationStatus
=
CLLocationManager
.
authorizationStatus
()
let
permissionStatus
:
PermissionStatus
=
LocationPermissionStrategy
.
determinePermissionStatus
(
permission
:
permission
,
authorizationStatus
:
authorizationStatus
)
if
permissionStatus
==
PermissionStatus
.
granted
&&
!
CLLocationManager
.
locationServicesEnabled
()
{
return
PermissionStatus
.
disabled
return
PermissionStatus
.
disabled
}
}
let
status
:
CLAuthorizationStatus
=
CLLocationManager
.
authorizationStatus
()
return
permissionStatus
return
LocationPermissionStrategy
.
determinePermissionStatus
(
permission
:
permission
,
authorizationStatus
:
status
)
}
}
func
requestPermission
(
permission
:
PermissionGroup
,
completionHandler
:
@escaping
PermissionStatusHandler
)
{
func
requestPermission
(
permission
:
PermissionGroup
,
completionHandler
:
@escaping
PermissionStatusHandler
)
{
...
...
ios/Classes/strategies/SensorPermissionStrategy.swift
View file @
2fef231c
...
@@ -15,22 +15,25 @@ class SensorPermissionStrategy : NSObject, PermissionStrategy {
...
@@ -15,22 +15,25 @@ class SensorPermissionStrategy : NSObject, PermissionStrategy {
}
}
private
static
func
getPermissionStatus
()
->
PermissionStatus
{
private
static
func
getPermissionStatus
()
->
PermissionStatus
{
if
!
CMMotionActivityManager
.
isActivityAvailable
()
{
return
PermissionStatus
.
disabled
}
if
#available(iOS 11.0, *)
{
if
#available(iOS 11.0, *)
{
let
status
:
CMAuthorizationStatus
=
CMMotionActivityManager
.
authorizationStatus
()
let
status
:
CMAuthorizationStatus
=
CMMotionActivityManager
.
authorizationStatus
()
var
permissionStatus
:
PermissionStatus
switch
status
{
switch
status
{
case
CMAuthorizationStatus
.
authorized
:
case
CMAuthorizationStatus
.
authorized
:
return
PermissionStatus
.
granted
permissionStatus
=
PermissionStatus
.
granted
case
CMAuthorizationStatus
.
denied
:
case
CMAuthorizationStatus
.
denied
:
return
PermissionStatus
.
denied
permissionStatus
=
PermissionStatus
.
denied
case
CMAuthorizationStatus
.
restricted
:
case
CMAuthorizationStatus
.
restricted
:
return
PermissionStatus
.
restricted
permissionStatus
=
PermissionStatus
.
restricted
default
:
default
:
return
PermissionStatus
.
unknown
permissionStatus
=
PermissionStatus
.
unknown
}
if
permissionStatus
==
PermissionStatus
.
granted
&&
!
CMMotionActivityManager
.
isActivityAvailable
()
{
return
PermissionStatus
.
disabled
}
else
{
return
permissionStatus
}
}
}
}
...
...
lib/permission_handler.dart
View file @
2fef231c
...
@@ -32,7 +32,7 @@ class PermissionHandler {
...
@@ -32,7 +32,7 @@ class PermissionHandler {
/// Returns a [Future] containing the current permission status for the supplied [PermissionGroup].
/// Returns a [Future] containing the current permission status for the supplied [PermissionGroup].
Future
<
PermissionStatus
>
checkPermissionStatus
(
Future
<
PermissionStatus
>
checkPermissionStatus
(
PermissionGroup
permission
)
async
{
PermissionGroup
permission
)
async
{
final
dynamic
status
=
await
_methodChannel
.
invokeMethod
(
final
String
status
=
await
_methodChannel
.
invokeMethod
(
'checkPermissionStatus'
,
Codec
.
encodePermissionGroup
(
permission
));
'checkPermissionStatus'
,
Codec
.
encodePermissionGroup
(
permission
));
return
Codec
.
decodePermissionStatus
(
status
);
return
Codec
.
decodePermissionStatus
(
status
);
...
@@ -52,7 +52,7 @@ class PermissionHandler {
...
@@ -52,7 +52,7 @@ class PermissionHandler {
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
List
<
PermissionGroup
>
permissions
)
async
{
List
<
PermissionGroup
>
permissions
)
async
{
final
String
jsonData
=
Codec
.
encodePermissionGroups
(
permissions
);
final
String
jsonData
=
Codec
.
encodePermissionGroups
(
permissions
);
final
dynamic
status
=
final
String
status
=
await
_methodChannel
.
invokeMethod
(
'requestPermissions'
,
jsonData
);
await
_methodChannel
.
invokeMethod
(
'requestPermissions'
,
jsonData
);
return
Codec
.
decodePermissionRequestResult
(
status
);
return
Codec
.
decodePermissionRequestResult
(
status
);
...
...
lib/utils/codec.dart
View file @
2fef231c
part of
permission_handler
;
part of
permission_handler
;
class
Codec
{
class
Codec
{
static
PermissionStatus
decodePermissionStatus
(
dynamic
value
)
{
static
PermissionStatus
decodePermissionStatus
(
String
value
)
{
final
dynamic
permission
=
json
.
decode
(
value
.
toString
()
);
final
dynamic
permission
=
json
.
decode
(
value
);
return
PermissionStatus
.
values
.
firstWhere
(
return
PermissionStatus
.
values
.
firstWhere
(
(
PermissionStatus
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
permission
);
(
PermissionStatus
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
permission
);
}
}
static
Map
<
PermissionGroup
,
PermissionStatus
>
decodePermissionRequestResult
(
static
Map
<
PermissionGroup
,
PermissionStatus
>
decodePermissionRequestResult
(
dynamic
value
)
{
String
value
)
{
final
Map
<
String
,
dynamic
>
jsonObject
=
json
.
decode
(
value
.
toString
()
);
final
Map
<
String
,
dynamic
>
jsonObject
=
json
.
decode
(
value
);
final
Map
<
PermissionGroup
,
PermissionStatus
>
permissionResults
=
final
Map
<
PermissionGroup
,
PermissionStatus
>
permissionResults
=
<
PermissionGroup
,
PermissionStatus
>{};
<
PermissionGroup
,
PermissionStatus
>{};
...
...
pubspec.yaml
View file @
2fef231c
...
@@ -20,7 +20,7 @@ flutter:
...
@@ -20,7 +20,7 @@ flutter:
pluginClass
:
PermissionHandlerPlugin
pluginClass
:
PermissionHandlerPlugin
environment
:
environment
:
sdk
:
"
>=2.
0.0-dev.68
.0
<3.0.0"
sdk
:
"
>=2.
1.0-dev.5
.0
<3.0.0"
# To add assets to your plugin package, add an assets section, like this:
# To add assets to your plugin package, add an assets section, like this:
# assets:
# assets:
...
...
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