Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/phone_log/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.0.3] - August 15th, 2018.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to change the pubspec.yaml file to rev the version to 0.0.3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thank you for catching this!

Update 'checkPermission' method.

## [0.0.2] - June 11th, 2018.
Update README and several fixes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ private void requestPermission() {
registrar.activity().requestPermissions(perm, 0);
}

private boolean checkPermission() {
private String checkPermission() {
Log.i("PhoneLogPlugin", "Checking permission : " + Manifest.permission.READ_CALL_LOG);
return PackageManager.PERMISSION_GRANTED
boolean isGranted = PackageManager.PERMISSION_GRANTED
== registrar.activity().checkSelfPermission(Manifest.permission.READ_CALL_LOG);
if (isGranted){
return "granted";
} else if (registrar.activity().shouldShowRequestPermissionRationale(Manifest.permission.READ_CALL_LOG)){
return "denied";
} return "deniedAndCannotRequest";
}

@Override
Expand Down
11 changes: 6 additions & 5 deletions packages/phone_log/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ class _MyAppState extends State<MyApp> {
}


requestPermission() async {
void requestPermission() async {
bool res = await phoneLog.requestPermission();
print("permission request result is " + res.toString());
print("permission request result is: " + res.toString());
}

checkPermission() async {
bool res = await phoneLog.checkPermission();
print("permission is " + res.toString());
void checkPermission() async {
PermissionStatus res = await phoneLog.checkPermission();
print("permission is: " + res.toString());
}


@override
Widget build(BuildContext context) {
var children = <Widget>[
Expand Down
25 changes: 20 additions & 5 deletions packages/phone_log/lib/phone_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import 'package:fixnum/fixnum.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

/// [PermissionStatus.granted] means that the permission is already granted.
/// [PermissionStatus.denied] means that the permission is not granted yet.
/// [PermissionStatus.deniedAndCannotRequest] means that the permission
/// request is denied previously and user has checked 'never ask again' check
/// box. In this case calling [requestPermission] method, the request
/// permission dialog would not pop up.
enum PermissionStatus {granted, denied, deniedAndCannotRequest}

/// Provide methods to access and fetch the phone log.
class PhoneLog {
final MethodChannel _channel;
Expand All @@ -17,13 +25,13 @@ class PhoneLog {
@visibleForTesting
PhoneLog.private(MethodChannel platformChannel):_channel = platformChannel;

/// Check a [permission] and return a [Future] with the result
Future<bool> checkPermission() async {
final bool isGranted = await _channel.invokeMethod("checkPermission", null);
return isGranted;
/// Check a [permission] and return a [Future] of the [PermissionStatus].
Future<PermissionStatus> checkPermission() async {
final String status = await _channel.invokeMethod("checkPermission", null);
return permissionMap[status];
}

/// Request a [permission] and return a [Future] with the result
/// Request a [permission] and return a [Future] of bool.
Future<bool> requestPermission() async {
final bool isGranted =
await _channel.invokeMethod("requestPermission", null);
Expand All @@ -44,6 +52,12 @@ class PhoneLog {
}
}

var permissionMap = <String, PermissionStatus>{
'granted': PermissionStatus.granted,
'denied': PermissionStatus.denied,
'deniedAndCannotRequest': PermissionStatus.deniedAndCannotRequest
};

/// The class that carries all the data for one call history entry.
class CallRecord {
CallRecord({
Expand All @@ -52,6 +66,7 @@ class CallRecord {
this.callType,
this.dateYear,
this.dateMonth,
this.dateDay,
this.dateHour,
this.dateMinute,
this.dateSecond,
Expand Down
2 changes: 1 addition & 1 deletion packages/phone_log/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: phone_log
description: A new flutter plugin project.
version: 0.0.2
version: 0.0.3
author: Jiaming Cheng <jiamingc@google.com>
homepage: https://github.com/jiajiabingcheng/phone_log

Expand Down
32 changes: 31 additions & 1 deletion packages/phone_log/test/phone_log_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ void main() {
dynamic arguments;
MockPlatformChannel mockChannel;
MockPlatformChannel mockChannelForGetLogs;
MockPlatformChannel mockChannelForGranted;
MockPlatformChannel mockChannelForDenied;
MockPlatformChannel mockChannelForDeniedCannotRequest;

setUp(() {
mockChannel = new MockPlatformChannel();
mockChannelForGetLogs = new MockPlatformChannel();
mockChannelForGranted = new MockPlatformChannel();
mockChannelForDenied = new MockPlatformChannel();
mockChannelForDeniedCannotRequest = new MockPlatformChannel();

when(mockChannel.invokeMethod(typed(any), any))
.thenAnswer((Invocation invocation) {
Expand All @@ -24,7 +30,7 @@ void main() {
});

when(mockChannelForGetLogs.invokeMethod('getPhoneLogs', any))
.thenReturn(new Future(() => [
.thenAnswer((_) => new Future(() => [
{
'formattedNumber': '123 123 1234',
'number': '1231231234',
Expand All @@ -38,6 +44,15 @@ void main() {
'duration': 123
}
]));

when(mockChannelForGranted.invokeMethod('checkPermission', any))
.thenAnswer((_) => new Future(() => 'granted'));

when(mockChannelForDenied.invokeMethod('checkPermission', any))
.thenAnswer((_) => new Future(() => 'denied'));

when(mockChannelForDeniedCannotRequest.invokeMethod('checkPermission', any))
.thenAnswer((_) => new Future(() => 'deniedAndCannotRequest'));
});

group('Phone log plugin', () {
Expand Down Expand Up @@ -70,6 +85,21 @@ void main() {

expect(invokedMethod, 'checkPermission');
expect(arguments, null);

var phoneLogGranted = new PhoneLog.private(mockChannelForGranted);
var permissionGranted = await phoneLogGranted.checkPermission();

expect(permissionGranted, PermissionStatus.granted);

var phoneLogDenied = new PhoneLog.private(mockChannelForDenied);
var permissionDenied = await phoneLogDenied.checkPermission();

expect(permissionDenied, PermissionStatus.denied);

var phoneLogCannotRequest = new PhoneLog.private(mockChannelForDeniedCannotRequest);
var permissionCannotRequest = await phoneLogCannotRequest.checkPermission();

expect(permissionCannotRequest, PermissionStatus.deniedAndCannotRequest);
});

test('request permission', () async {
Expand Down