Skip to content

Commit d46f174

Browse files
authored
Merge pull request #63 from grit96/no-sim-phone-account
Prevent default phone account check when no SIM present
2 parents 28791bc + 60d78e8 commit d46f174

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import android.graphics.drawable.BitmapDrawable;
3131
import android.graphics.drawable.Icon;
3232
import android.net.Uri;
33-
import android.util.Log;
3433
import android.os.Build;
3534
import android.os.Bundle;
3635
import android.support.annotation.NonNull;
@@ -44,6 +43,8 @@
4443
import android.telecom.PhoneAccount;
4544
import android.telecom.PhoneAccountHandle;
4645
import android.telecom.TelecomManager;
46+
import android.telephony.TelephonyManager;
47+
import android.util.Log;
4748

4849
import com.facebook.react.bridge.Arguments;
4950
import com.facebook.react.bridge.Dynamic;
@@ -92,6 +93,7 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule {
9293

9394
private static final String TAG = "RNCallKeepModule";
9495
private static TelecomManager telecomManager;
96+
private static TelephonyManager telephonyManager;
9597
private static Promise hasPhoneAccountPromise;
9698
private ReactApplicationContext reactContext;
9799
public static PhoneAccountHandle handle;
@@ -251,7 +253,10 @@ public void checkDefaultPhoneAccount(Promise promise) {
251253
return;
252254
}
253255

254-
promise.resolve(telecomManager.getDefaultOutgoingPhoneAccount("tel") != null);
256+
boolean hasSim = telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT;
257+
boolean hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;
258+
259+
promise.resolve(!hasSim || hasDefaultAccount);
255260
}
256261

257262
@ReactMethod
@@ -435,7 +440,9 @@ private void registerPhoneAccount(Context appContext) {
435440

436441
PhoneAccount account = builder.build();
437442

438-
telecomManager = (TelecomManager) this.getAppContext().getSystemService(this.getAppContext().TELECOM_SERVICE);
443+
telephonyManager = (TelephonyManager) this.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
444+
telecomManager = (TelecomManager) this.getAppContext().getSystemService(Context.TELECOM_SERVICE);
445+
439446
telecomManager.registerPhoneAccount(account);
440447
}
441448

0 commit comments

Comments
 (0)