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
8e770716
Commit
8e770716
authored
Jul 24, 2018
by
Maurits van Beusekom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated build script
parent
e0ec8026
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
185 additions
and
71 deletions
+185
-71
.travis.yml
+69
-19
example/ios/Runner.xcodeproj/project.pbxproj
+1
-1
example/lib/main.dart
+12
-8
ios/Classes/PermissionHandlerPlugin.h
+1
-1
lib/permission_enums.dart
+32
-16
lib/permission_handler.dart
+16
-18
lib/utils/codec.dart
+11
-8
scripts/build.sh
+13
-0
scripts/format_code.sh
+30
-0
scripts/utils/google-java-format-1.3-all-deps.jar
+0
-0
No files found.
.travis.yml
View file @
8e770716
os
:
matrix
:
-
linux
include
:
sudo
:
false
# Job 1) Run analyzer
addons
:
-
os
:
linux
apt
:
sudo
:
false
sources
:
addons
:
-
ubuntu-toolchain-r-test
apt
:
packages
:
# Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
-
libstdc++6
sources
:
-
fonts-droid
-
ubuntu-toolchain-r-test
# if we don't specify this, the libstdc++6 we get is the wrong version
before_script
:
packages
:
-
git clone https://github.com/flutter/flutter.git -b master --depth 1
-
libstdc++6
-
./flutter/bin/flutter doctor
-
fonts-droid
script
:
before_script
:
-
./flutter/bin/flutter test --coverage --coverage-path=lcov.info
-
git clone https://github.com/flutter/flutter.git
after_success
:
-
export PATH=`pwd`/flutter/bin:`pwd`/flutter/bin/cache/dart-sdk/bin:$PATH
# Still have to setup account at codecov.io
-
flutter doctor
#- bash <(curl -s https://codecov.io/bash)
script
:
-
flutter analyze
# Job 2) Check format and run tests
-
os
:
linux
jdk
:
oraclejdk8
sudo
:
false
addons
:
apt
:
# Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
sources
:
-
ubuntu-toolchain-r-test
# if we don't specify this, the libstdc++6 we get is the wrong version
-
llvm-toolchain-precise
# for clang-format-5.0
packages
:
-
libstdc++6
-
fonts-droid
-
clang-format-5.0
before_script
:
-
git clone https://github.com/flutter/flutter.git
-
export PATH=`pwd`/flutter/bin:`pwd`/flutter/bin/cache/dart-sdk/bin:$PATH
-
flutter doctor
script
:
-
./scripts/format_code.sh
# Job 3) Build example APKs and run Java tests
-
os
:
linux
jdk
:
oraclejdk8
sudo
:
false
addons
:
apt
:
# Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
sources
:
-
ubuntu-toolchain-r-test
# if we don't specify this, the libstdc++6 we get is the wrong version
packages
:
-
lib32stdc++6
# https://github.com/flutter/flutter/issues/6207
-
libstdc++6
-
fonts-droid
before_script
:
-
./script/before_build_apks.sh
-
export ANDROID_HOME=`pwd`/android-sdk
-
export PATH=`pwd`/flutter/bin:`pwd`/flutter/bin/cache/dart-sdk/bin:$PATH
script
:
-
./scripts/build.sh apk
# Job 4) Build example IPAs
-
os
:
osx
language
:
generic
osx_image
:
xcode9.3
before_script
:
-
./script/before_build_ipas.sh
-
export PATH=`pwd`/flutter/bin:`pwd`/flutter/bin/cache/dart-sdk/bin:$PATH
script
:
-
./scripts/build.sh ipa
cache
:
cache
:
directories
:
directories
:
-
$HOME/.pub-cache
-
$HOME/.pub-cache
\ No newline at end of file
example/ios/Runner.xcodeproj/project.pbxproj
View file @
8e770716
...
@@ -226,7 +226,7 @@
...
@@ -226,7 +226,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/Flutter.framework"
,
"${PODS_ROOT}/../.symlinks/flutter/ios
-release
/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"
;
...
...
example/lib/main.dart
View file @
8e770716
...
@@ -27,14 +27,17 @@ class _MyAppState extends State<MyApp> {
...
@@ -27,14 +27,17 @@ class _MyAppState extends State<MyApp> {
// Platform messages may fail, so we use a try/catch PlatformException.
// Platform messages may fail, so we use a try/catch PlatformException.
try
{
try
{
permissionStatus
=
await
PermissionHandler
.
checkPermissionStatus
(
PermissionGroup
.
calendar
);
permissionStatus
=
await
PermissionHandler
.
checkPermissionStatus
(
PermissionGroup
.
calendar
);
if
(
permissionStatus
!=
PermissionStatus
.
granted
){
if
(
permissionStatus
!=
PermissionStatus
.
granted
)
{
final
shouldShowRationale
=
await
PermissionHandler
.
shouldShowRequestPermissionRationale
(
PermissionGroup
.
calendar
);
final
shouldShowRationale
=
await
PermissionHandler
.
shouldShowRequestPermissionRationale
(
PermissionGroup
.
calendar
);
if
(
shouldShowRationale
)
{
var
permissions
=
await
PermissionHandler
.
requestPermissions
([
PermissionGroup
.
calendar
]);
if
(
shouldShowRationale
)
{
if
(
permissions
.
containsKey
(
PermissionGroup
.
calendar
))
{
var
permissions
=
await
PermissionHandler
.
requestPermissions
([
PermissionGroup
.
calendar
]);
if
(
permissions
.
containsKey
(
PermissionGroup
.
calendar
))
{
permissionStatus
=
permissions
[
PermissionGroup
.
calendar
];
permissionStatus
=
permissions
[
PermissionGroup
.
calendar
];
}
}
}
}
...
@@ -66,7 +69,8 @@ class _MyAppState extends State<MyApp> {
...
@@ -66,7 +69,8 @@ class _MyAppState extends State<MyApp> {
new
Text
(
'Running on:
$_permissionStatus
\n
'
),
new
Text
(
'Running on:
$_permissionStatus
\n
'
),
new
RaisedButton
(
new
RaisedButton
(
child:
new
Text
(
"Open settings"
),
child:
new
Text
(
"Open settings"
),
onPressed:
()
async
=>
await
PermissionHandler
.
openAppSettings
(),
onPressed:
()
async
=>
await
PermissionHandler
.
openAppSettings
(),
),
),
],
],
),
),
...
...
ios/Classes/PermissionHandlerPlugin.h
View file @
8e770716
#import <Flutter/Flutter.h>
#import <Flutter/Flutter.h>
@interface
PermissionHandlerPlugin
:
NSObject
<
FlutterPlugin
>
@interface
PermissionHandlerPlugin
:
NSObject
<
FlutterPlugin
>
@end
@end
lib/permission_enums.dart
View file @
8e770716
/// Defines the state of a permission group
/// Defines the state of a permission group
enum
PermissionStatus
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.
/// The feature is disabled (or not available) on the device.
disabled
,
disabled
,
/// Permission to access the requested feature is granted by the user.
granted
,
/// Permission to access the requested feature is granted by the user.
/// The user granted restricted access to the requested feature (only on iOS).
granted
,
restricted
,
/// Permission is in an unknown state
/// The user granted restricted access to the requested feature (only on iOS).
unknown
restricted
,
/// Permission is in an unknown state
unknown
}
}
/// Defines the permission groups for which permissions can be checked or requested.
/// Defines the permission groups for which permissions can be checked or requested.
enum
PermissionGroup
enum
PermissionGroup
{
{
/// The unknown permission only used for return type, never requested
/// The unknown permission only used for return type, never requested
unknown
,
unknown
,
/// Android: Calendar
/// Android: Calendar
/// iOS: Calendar (Events)
/// iOS: Calendar (Events)
calendar
,
calendar
,
/// Android: Camera
/// Android: Camera
/// iOS: Photos (Camera Roll and Camera)
/// iOS: Photos (Camera Roll and Camera)
camera
,
camera
,
/// Android: Contacts
/// Android: Contacts
/// iOS: AddressBook
/// iOS: AddressBook
contacts
,
contacts
,
/// Android: Fine and Coarse Location
/// Android: Fine and Coarse Location
/// iOS: CoreLocation (Always and WhenInUse)
/// iOS: CoreLocation (Always and WhenInUse)
location
,
location
,
/// Android: Microphone
/// Android: Microphone
/// iOS: Microphone
/// iOS: Microphone
microphone
,
microphone
,
/// Android: Phone
/// Android: Phone
/// iOS: Nothing
/// iOS: Nothing
phone
,
phone
,
/// Android: Nothing
/// Android: Nothing
/// iOS: Photos
/// iOS: Photos
photos
,
photos
,
/// Android: Nothing
/// Android: Nothing
/// iOS: Reminders
/// iOS: Reminders
reminders
,
reminders
,
/// Android: Body Sensors
/// Android: Body Sensors
/// iOS: CoreMotion
/// iOS: CoreMotion
sensors
,
sensors
,
/// Android: Sms
/// Android: Sms
/// iOS: Nothing
/// iOS: Nothing
sms
,
sms
,
/// Android: External Storage
/// Android: External Storage
/// iOS: Nothing
/// iOS: Nothing
storage
,
storage
,
/// Android: Microphone
/// Android: Microphone
/// iOS: Speech
/// iOS: Speech
speech
,
speech
,
/// Android: Fine and Coarse Location
/// Android: Fine and Coarse Location
/// iOS: CoreLocation - Always
/// iOS: CoreLocation - Always
locationAlways
,
locationAlways
,
/// Android: Fine and Coarse Location
/// Android: Fine and Coarse Location
/// iOS: CoreLocation - WhenInUse
/// iOS: CoreLocation - WhenInUse
locationWhenInUse
,
locationWhenInUse
,
/// Android: None
/// Android: None
/// iOS: MPMediaLibrary
/// iOS: MPMediaLibrary
mediaLibrary
mediaLibrary
}
}
\ No newline at end of file
lib/permission_handler.dart
View file @
8e770716
...
@@ -10,39 +10,37 @@ class PermissionHandler {
...
@@ -10,39 +10,37 @@ class PermissionHandler {
const
MethodChannel
(
'flutter.baseflow.com/permissions/methods'
);
const
MethodChannel
(
'flutter.baseflow.com/permissions/methods'
);
/// Returns a [Future] containing the current permission status for the supplied [PermissionGroup].
/// Returns a [Future] containing the current permission status for the supplied [PermissionGroup].
static
Future
<
PermissionStatus
>
checkPermissionStatus
(
PermissionGroup
permission
)
async
{
static
Future
<
PermissionStatus
>
checkPermissionStatus
(
PermissionGroup
permission
)
async
{
final
status
=
await
_channel
.
invokeMethod
(
final
status
=
await
_channel
.
invokeMethod
(
'checkPermissionStatus'
,
'checkPermissionStatus'
,
Codec
.
encodePermissionGroup
(
permission
));
Codec
.
encodePermissionGroup
(
permission
));
return
Codec
.
decodePermissionStatus
(
status
);
return
Codec
.
decodePermissionStatus
(
status
);
}
}
/// Open the App settings page.
/// Open the App settings page.
///
///
/// Returns [true] if the app settings page could be opened, otherwise [false] is returned.
/// Returns [true] if the app settings page could be opened, otherwise [false] is returned.
static
Future
<
bool
>
openAppSettings
()
async
=>
static
Future
<
bool
>
openAppSettings
()
async
=>
await
_channel
.
invokeMethod
(
"openAppSettings"
);
await
_channel
.
invokeMethod
(
"openAppSettings"
);
/// Request the user for access to the supplied list of permissiongroups.
/// Request the user for access to the supplied list of permissiongroups.
///
///
/// Returns a [Map] containing the status per requested permissiongroup.
/// Returns a [Map] containing the status per requested permissiongroup.
static
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
List
<
PermissionGroup
>
permissions
)
async
{
static
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
List
<
PermissionGroup
>
permissions
)
async
{
final
jsonData
=
Codec
.
encodePermissionGroups
(
permissions
);
final
jsonData
=
Codec
.
encodePermissionGroups
(
permissions
);
final
status
=
await
_channel
.
invokeMethod
(
final
status
=
await
_channel
.
invokeMethod
(
'requestPermissions'
,
jsonData
);
'requestPermissions'
,
jsonData
);
return
Codec
.
decodePermissionRequestResult
(
status
);
return
Codec
.
decodePermissionRequestResult
(
status
);
}
}
/// Request to see if you should show a rationale for requesting permission.
/// Request to see if you should show a rationale for requesting permission.
///
///
/// This method is only implemented on Android, calling this on iOS always
/// This method is only implemented on Android, calling this on iOS always
/// returns [false].
/// returns [false].
static
Future
<
bool
>
shouldShowRequestPermissionRationale
(
PermissionGroup
permission
)
async
=>
static
Future
<
bool
>
shouldShowRequestPermissionRationale
(
await
_channel
.
invokeMethod
(
PermissionGroup
permission
)
async
=>
'shouldShowRequestPermissionRationale'
,
await
_channel
.
invokeMethod
(
'shouldShowRequestPermissionRationale'
,
Codec
.
encodePermissionGroup
(
permission
));
Codec
.
encodePermissionGroup
(
permission
));
}
}
lib/utils/codec.dart
View file @
8e770716
...
@@ -6,30 +6,34 @@ class Codec {
...
@@ -6,30 +6,34 @@ class Codec {
static
PermissionStatus
decodePermissionStatus
(
dynamic
value
)
{
static
PermissionStatus
decodePermissionStatus
(
dynamic
value
)
{
final
permission
=
json
.
decode
(
value
);
final
permission
=
json
.
decode
(
value
);
return
PermissionStatus
.
values
.
firstWhere
((
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
permission
);
return
PermissionStatus
.
values
.
firstWhere
((
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
permission
);
}
}
static
Map
<
PermissionGroup
,
PermissionStatus
>
decodePermissionRequestResult
(
dynamic
value
)
{
static
Map
<
PermissionGroup
,
PermissionStatus
>
decodePermissionRequestResult
(
dynamic
value
)
{
final
jsonObject
=
json
.
decode
(
value
);
final
jsonObject
=
json
.
decode
(
value
);
final
permissionResults
=
Map
<
PermissionGroup
,
PermissionStatus
>();
final
permissionResults
=
Map
<
PermissionGroup
,
PermissionStatus
>();
jsonObject
.
forEach
((
key
,
value
)
{
jsonObject
.
forEach
((
key
,
value
)
{
final
permissionGroup
=
PermissionGroup
.
values
.
firstWhere
((
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
key
.
toString
());
final
permissionGroup
=
PermissionGroup
.
values
final
permissionStatus
=
PermissionStatus
.
values
.
firstWhere
((
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
value
.
toString
());
.
firstWhere
((
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
key
.
toString
());
final
permissionStatus
=
PermissionStatus
.
values
.
firstWhere
((
e
)
=>
e
.
toString
().
split
(
'.'
).
last
==
value
.
toString
());
permissionResults
[
permissionGroup
]
=
permissionStatus
;
permissionResults
[
permissionGroup
]
=
permissionStatus
;
});
});
return
permissionResults
;
return
permissionResults
;
}
}
static
String
encodePermissionGroup
(
PermissionGroup
permissionGroup
)
=>
static
String
encodePermissionGroup
(
PermissionGroup
permissionGroup
)
=>
json
.
encode
(
_encodeEnum
(
permissionGroup
));
json
.
encode
(
_encodeEnum
(
permissionGroup
));
static
String
encodePermissionGroups
(
List
<
PermissionGroup
>
permissions
)
=>
static
String
encodePermissionGroups
(
List
<
PermissionGroup
>
permissions
)
=>
json
.
encode
(
permissions
.
map
((
p
)
=>
_encodeEnum
(
p
)).
toList
());
json
.
encode
(
permissions
.
map
((
p
)
=>
_encodeEnum
(
p
)).
toList
());
static
String
_encodeEnum
(
dynamic
value
)
{
static
String
_encodeEnum
(
dynamic
value
)
{
return
value
.
toString
().
split
(
'.'
).
last
;
return
value
.
toString
().
split
(
'.'
).
last
;
}
}
}
}
\ No newline at end of file
scripts/build.sh
0 → 100755
View file @
8e770716
#!/bin/bash
set
-e
cd
../example
if
[[
$1
==
'apk'
]]
;
then
flutter build apk
elif
[[
$1
==
'ios'
]]
;
then
flutter build ios
--no-codesign
else
echo
"Neither 'apk' or 'ios' were specified, so not building"
fi
scripts/format_code.sh
0 → 100755
View file @
8e770716
#!/bin/bash
set
-e
cd
..
# Format Dart code
printf
'Formatting Dart code\n'
flutter format
.
printf
'\n'
# Format Objective-C code
printf
'Formatting Objective-C code\n'
find
.
\(
-name
'*.h'
-o
-name
'*.m'
\)
-exec
clang-format
-i
-style
=
Google
'{}'
\;
printf
'\n'
# Format Java code
printf
'Formatting JAVA code\n'
find
.
\(
-name
'*.java'
\)
-exec
java
-jar
./scripts/utils/google-java-format-1.3-all-deps.jar
--replace
'{}'
\;
printf
'\n'
modified_files
=
$(
git ls-files
--modified
)
if
[[
$modified_files
]]
;
then
printf
'These files are not formatted correctly:\n'
printf
'\n'
echo
$modified_files
| tr
' '
'\n'
exit
1
else
printf
"All files are formatted correctly"
exit
0
fi
scripts/utils/google-java-format-1.3-all-deps.jar
0 → 100644
View file @
8e770716
File added
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