Skip to content

Commit bc3e34a

Browse files
committed
Version 3.1.0
2 parents 9acc371 + 6a19290 commit bc3e34a

19 files changed

+157
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.0
2+
3+
* Support service status inquiry for phone permission on iOS & Android.
4+
15
## 3.0.2
26

37
* Fixed bug when rapidly requesting permissions (#23);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To use this plugin, add `permission_handler` as a [dependency in your pubspec.ya
2222

2323
```yaml
2424
dependencies:
25-
permission_handler: '^3.0.0'
25+
permission_handler: '^3.1.0'
2626
```
2727
2828
> **NOTE:** There's a known issue with integrating plugins that use Swift into a Flutter project created with the Objective-C template. See issue [Flutter#16049](https://github.com/flutter/flutter/issues/16049) for help on integration.

android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.4.0'
12+
classpath 'com.android.tools.build:gradle:3.4.1'
1313
}
1414
}
1515

@@ -35,8 +35,8 @@ android {
3535
}
3636

3737
dependencies {
38-
implementation 'androidx.annotation:annotation:1.0.1'
39-
implementation 'androidx.core:core:1.0.1'
38+
implementation 'androidx.annotation:annotation:1.0.2'
39+
implementation 'androidx.core:core:1.0.2'
4040
}
4141

4242
repositories {

android/src/main/java/com/baseflow/permissionhandler/PermissionHandlerPlugin.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import android.content.Intent;
88
import android.content.pm.PackageInfo;
99
import android.content.pm.PackageManager;
10+
import android.content.pm.ResolveInfo;
1011
import android.location.LocationManager;
12+
import android.net.Uri;
1113
import android.os.Build;
1214
import android.provider.Settings;
15+
import android.telephony.TelephonyManager;
1316
import android.text.TextUtils;
1417
import android.util.Log;
1518

@@ -281,6 +284,34 @@ private int checkServiceStatus(int permission) {
281284
return isLocationServiceEnabled(context) ? SERVICE_STATUS_ENABLED : SERVICE_STATUS_DISABLED;
282285
}
283286

287+
if (permission == PERMISSION_GROUP_PHONE) {
288+
PackageManager pm = context.getPackageManager();
289+
if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
290+
return SERVICE_STATUS_NOT_APPLICABLE;
291+
}
292+
293+
TelephonyManager telephonyManager = (TelephonyManager) context
294+
.getSystemService(Context.TELEPHONY_SERVICE);
295+
296+
if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
297+
return SERVICE_STATUS_NOT_APPLICABLE;
298+
}
299+
300+
Intent callIntent = new Intent(Intent.ACTION_CALL);
301+
callIntent.setData(Uri.parse("tel:123123"));
302+
List<ResolveInfo> callAppsList = pm.queryIntentActivities(callIntent, 0);
303+
304+
if (callAppsList.isEmpty()) {
305+
return SERVICE_STATUS_NOT_APPLICABLE;
306+
}
307+
308+
if (telephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
309+
return SERVICE_STATUS_DISABLED;
310+
}
311+
312+
return SERVICE_STATUS_ENABLED;
313+
}
314+
284315
return SERVICE_STATUS_NOT_APPLICABLE;
285316
}
286317

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.4.0'
8+
classpath 'com.android.tools.build:gradle:3.4.1'
99
}
1010
}
1111

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
platform :ios, '8.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1414
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
1515
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
16-
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
1716
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
1817
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
1918
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
@@ -179,7 +178,7 @@
179178
97C146E61CF9000F007C117D /* Project object */ = {
180179
isa = PBXProject;
181180
attributes = {
182-
LastUpgradeCheck = 0910;
181+
LastUpgradeCheck = 1020;
183182
ORGANIZATIONNAME = "The Chromium Authors";
184183
TargetAttributes = {
185184
97C146ED1CF9000F007C117D = {
@@ -213,7 +212,6 @@
213212
files = (
214213
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
215214
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
216-
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
217215
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
218216
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
219217
);
@@ -242,7 +240,7 @@
242240
files = (
243241
);
244242
inputPaths = (
245-
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
243+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
246244
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
247245
);
248246
name = "[CP] Embed Pods Frameworks";
@@ -251,7 +249,7 @@
251249
);
252250
runOnlyForDeploymentPostprocessing = 0;
253251
shellPath = /bin/sh;
254-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
252+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
255253
showEnvVarsInLog = 0;
256254
};
257255
9740EEB61CF901F6004384FC /* Run Script */ = {
@@ -330,6 +328,7 @@
330328
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
331329
buildSettings = {
332330
ALWAYS_SEARCH_USER_PATHS = NO;
331+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
333332
CLANG_ANALYZER_NONNULL = YES;
334333
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
335334
CLANG_CXX_LIBRARY = "libc++";
@@ -339,12 +338,14 @@
339338
CLANG_WARN_BOOL_CONVERSION = YES;
340339
CLANG_WARN_COMMA = YES;
341340
CLANG_WARN_CONSTANT_CONVERSION = YES;
341+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
342342
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
343343
CLANG_WARN_EMPTY_BODY = YES;
344344
CLANG_WARN_ENUM_CONVERSION = YES;
345345
CLANG_WARN_INFINITE_RECURSION = YES;
346346
CLANG_WARN_INT_CONVERSION = YES;
347347
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
348+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
348349
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
349350
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
350351
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -402,6 +403,7 @@
402403
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
403404
buildSettings = {
404405
ALWAYS_SEARCH_USER_PATHS = NO;
406+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
405407
CLANG_ANALYZER_NONNULL = YES;
406408
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
407409
CLANG_CXX_LIBRARY = "libc++";
@@ -411,12 +413,14 @@
411413
CLANG_WARN_BOOL_CONVERSION = YES;
412414
CLANG_WARN_COMMA = YES;
413415
CLANG_WARN_CONSTANT_CONVERSION = YES;
416+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
414417
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
415418
CLANG_WARN_EMPTY_BODY = YES;
416419
CLANG_WARN_ENUM_CONVERSION = YES;
417420
CLANG_WARN_INFINITE_RECURSION = YES;
418421
CLANG_WARN_INT_CONVERSION = YES;
419422
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
423+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
420424
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
421425
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
422426
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -456,6 +460,7 @@
456460
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
457461
buildSettings = {
458462
ALWAYS_SEARCH_USER_PATHS = NO;
463+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
459464
CLANG_ANALYZER_NONNULL = YES;
460465
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
461466
CLANG_CXX_LIBRARY = "libc++";
@@ -465,12 +470,14 @@
465470
CLANG_WARN_BOOL_CONVERSION = YES;
466471
CLANG_WARN_COMMA = YES;
467472
CLANG_WARN_CONSTANT_CONVERSION = YES;
473+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
468474
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
469475
CLANG_WARN_EMPTY_BODY = YES;
470476
CLANG_WARN_ENUM_CONVERSION = YES;
471477
CLANG_WARN_INFINITE_RECURSION = YES;
472478
CLANG_WARN_INT_CONVERSION = YES;
473479
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
480+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
474481
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
475482
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
476483
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0910"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
</Testables>
@@ -46,7 +45,6 @@
4645
buildConfiguration = "Debug"
4746
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4847
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49-
language = ""
5048
launchStyle = "0"
5149
useCustomWorkingDirectory = "NO"
5250
ignoresPersistentStateOnLaunch = "NO"

example/lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class MyApp extends StatelessWidget {
2828
.where((PermissionGroup permission) {
2929
if (Platform.isIOS) {
3030
return permission != PermissionGroup.unknown &&
31-
permission != PermissionGroup.phone &&
3231
permission != PermissionGroup.sms &&
3332
permission != PermissionGroup.storage;
3433
} else {

ios/Classes/PermissionManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "LocationPermissionStrategy.h"
1616
#import "MediaLibraryPermissionStrategy.h"
1717
#import "PermissionStrategy.h"
18+
#import "PhonePermissionStrategy.h"
1819
#import "PhotoPermissionStrategy.h"
1920
#import "SensorPermissionStrategy.h"
2021
#import "SpeechPermissionStrategy.h"

ios/Classes/PermissionManager.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ + (id)createPermissionStrategy:(PermissionGroup)permission {
8989
return [MediaLibraryPermissionStrategy new];
9090
case PermissionGroupMicrophone:
9191
return [AudioVideoPermissionStrategy new];
92+
case PermissionGroupPhone:
93+
return [PhonePermissionStrategy new];
9294
case PermissionGroupPhotos:
9395
return [PhotoPermissionStrategy new];
9496
case PermissionGroupReminders:

ios/Classes/strategies/LocationPermissionStrategy.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ + (PermissionStatus)determinePermissionStatus:(PermissionGroup)permission author
133133
}
134134
}
135135

136+
#pragma clang diagnostic push
137+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
138+
136139
switch (authorizationStatus) {
137140
case kCLAuthorizationStatusNotDetermined:
138141
return PermissionStatusUnknown;
@@ -145,6 +148,9 @@ + (PermissionStatus)determinePermissionStatus:(PermissionGroup)permission author
145148
default:
146149
return PermissionStatusUnknown;
147150
}
151+
152+
#pragma clang diagnostic pop
153+
148154
}
149155

150156
@end

ios/Classes/strategies/MediaLibraryPermissionStrategy.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ + (PermissionStatus)permissionStatus {
4343
return PermissionStatusUnknown;
4444
}
4545

46-
+ (PermissionStatus)determinePermissionStatus:(MPMediaLibraryAuthorizationStatus)authorizationStatus {
46+
+ (PermissionStatus)determinePermissionStatus:(MPMediaLibraryAuthorizationStatus)authorizationStatus API_AVAILABLE(ios(9.3)){
4747
switch (authorizationStatus) {
4848
case MPMediaLibraryAuthorizationStatusNotDetermined:
4949
return PermissionStatusUnknown;
@@ -58,4 +58,4 @@ + (PermissionStatus)determinePermissionStatus:(MPMediaLibraryAuthorizationStatus
5858
return PermissionStatusUnknown;
5959
}
6060

61-
@end
61+
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// PhonePermissionStrategy.h
3+
// permission_handler
4+
//
5+
// Created by Sebastian Roth on 5/20/19.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
#import "PermissionStrategy.h"
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface PhonePermissionStrategy : NSObject<PermissionStrategy>
14+
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// PhonePermissionStrategy.m
3+
// permission_handler
4+
//
5+
// Created by Sebastian Roth on 5/20/19.
6+
//
7+
8+
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
9+
#import <CoreTelephony/CTCarrier.h>
10+
11+
#import "PhonePermissionStrategy.h"
12+
13+
@implementation PhonePermissionStrategy
14+
15+
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
16+
return PermissionStatusUnknown;
17+
}
18+
19+
- (ServiceStatus)checkServiceStatus:(PermissionGroup)permission {
20+
// https://stackoverflow.com/a/5095058
21+
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]]) {
22+
return ServiceStatusNotApplicable;
23+
}
24+
25+
return [self canDevicePlaceAPhoneCall] ? ServiceStatusEnabled : ServiceStatusDisabled;
26+
}
27+
28+
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
29+
completionHandler(PermissionStatusUnknown);
30+
}
31+
32+
33+
// https://stackoverflow.com/a/11595365
34+
-(bool) canDevicePlaceAPhoneCall {
35+
/*
36+
* Returns YES if the device can place a phone call
37+
*/
38+
39+
// Device supports phone calls, lets confirm it can place one right now
40+
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
41+
CTCarrier *carrier = [netInfo subscriberCellularProvider];
42+
NSString *mnc = [carrier mobileNetworkCode];
43+
if (([mnc length] == 0) || ([mnc isEqualToString:@"65535"])) {
44+
// Device cannot place a call at this time. SIM might be removed.
45+
return NO;
46+
} else {
47+
// Device can place a phone call
48+
return YES;
49+
}
50+
}
51+
52+
@end

ios/Classes/strategies/SpeechPermissionStrategy.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ + (PermissionStatus)permissionStatus {
4242
return PermissionStatusUnknown;
4343
}
4444

45-
+ (PermissionStatus)determinePermissionStatus:(SFSpeechRecognizerAuthorizationStatus)authorizationStatus {
45+
+ (PermissionStatus)determinePermissionStatus:(SFSpeechRecognizerAuthorizationStatus)authorizationStatus API_AVAILABLE(ios(10.0)){
4646
switch (authorizationStatus) {
4747
case SFSpeechRecognizerAuthorizationStatusNotDetermined:
4848
return PermissionStatusUnknown;

ios/permission_handler.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'permission_handler'
6-
s.version = '3.0.2'
6+
s.version = '3.1.0'
77
s.summary = 'Permission plugin for Flutter.'
88
s.description = <<-DESC
99
A new Flutter project.

0 commit comments

Comments
 (0)