Skip to content

Prevent default phone account check when no SIM present #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2019
Merged
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
13 changes: 10 additions & 3 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
Expand All @@ -39,6 +38,8 @@
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule {

private static final String TAG = "RNCallKeepModule";
private static TelecomManager telecomManager;
private static TelephonyManager telephonyManager;
private static Promise hasPhoneAccountPromise;
private ReactApplicationContext reactContext;
private static PhoneAccountHandle handle;
Expand Down Expand Up @@ -197,7 +199,10 @@ public void checkDefaultPhoneAccount(Promise promise) {
return;
}

promise.resolve(telecomManager.getDefaultOutgoingPhoneAccount("tel") != null);
boolean hasSim = telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT;
boolean hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;

promise.resolve(!hasSim || hasDefaultAccount);
}

@ReactMethod
Expand Down Expand Up @@ -287,7 +292,9 @@ private void registerPhoneAccount(Context appContext) {
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
.build();

telecomManager = (TelecomManager) this.getAppContext().getSystemService(this.getAppContext().TELECOM_SERVICE);
telephonyManager = (TelephonyManager) this.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
telecomManager = (TelecomManager) this.getAppContext().getSystemService(Context.TELECOM_SERVICE);

telecomManager.registerPhoneAccount(account);
}

Expand Down