Commit 1a2365b4 by Sebastian Roth

Add a few more conditions for ServiceStatus (phone) on Android

parent 43f4ffc5
......@@ -7,9 +7,12 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
......@@ -283,7 +286,30 @@ public class PermissionHandlerPlugin implements MethodCallHandler {
if (permission == PERMISSION_GROUP_PHONE) {
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) ? SERVICE_STATUS_ENABLED : SERVICE_STATUS_NOT_APPLICABLE;
if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
return SERVICE_STATUS_NOT_APPLICABLE;
}
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
return SERVICE_STATUS_NOT_APPLICABLE;
}
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123123"));
List<ResolveInfo> callAppsList = pm.queryIntentActivities(callIntent, 0);
if (callAppsList.isEmpty()) {
return SERVICE_STATUS_NOT_APPLICABLE;
}
if (telephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
return SERVICE_STATUS_DISABLED;
}
return SERVICE_STATUS_ENABLED;
}
return SERVICE_STATUS_NOT_APPLICABLE;
......
......@@ -40,6 +40,18 @@ class PermissionHandler {
/// Check current service status.
///
/// Returns a [Future] containing the current service status for the supplied [PermissionGroup].
///
/// Notes about specific PermissionGroups:
/// - **PermissionGroup.phone** on Android:
/// - The method will return [ServiceStatus.notApplicable] when:
/// 1. the device lacks the TELEPHONY feature
/// 1. TelephonyManager.getPhoneType() returns PHONE_TYPE_NONE
/// 1. when no Intents can be resolved to handle the `tel:` scheme
/// - The method will return [ServiceStatus.disabled] when:
/// 1. the SIM card is missing
/// - **PLEASE NOTE that this is still not a perfect indication** of the
/// devices' capability to place & connect phone calls
/// as it also depends on the network condition.
Future<ServiceStatus> checkServiceStatus(PermissionGroup permission) async {
final int status = await _methodChannel.invokeMethod(
'checkServiceStatus', permission.value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment