Permalink
Browse files

calls do not get declined when screen is off

  • Loading branch information...
dakhnod committed Jul 16, 2018
1 parent 0e240c3 commit 5b38258240a3389b16b5e20851fb2a4953079749
Showing with 12 additions and 3 deletions.
  1. +12 −3 app/src/main/java/d/d/meshenger/CallActivity.java
@@ -36,12 +36,11 @@
private RTCCall currentCall;
boolean callAccepted = false;
private boolean calledWhileScreenOff = false;
private SensorManager sensorManager;
private PowerManager powerManager;
private PowerManager.WakeLock wakeLock;
private PowerManager.WakeLock wakeLock, passiveWakeLock = null;
private final long buttonAnimationDuration = 400;
private final int CAMERA_PERMISSION_REQUEST_CODE = 2;
@@ -84,6 +83,9 @@ public void onServiceDisconnected(ComponentName componentName) {
findViewById(R.id.callDecline).setOnClickListener(this);
startSensor();
} else if ("ACTION_ACCEPT_CALL".equals(action)) {
calledWhileScreenOff = !((PowerManager) getSystemService(POWER_SERVICE)).isScreenOn();
passiveWakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "wakeup");
passiveWakeLock.acquire(10000);
connection = this;
bindService(new Intent(this, MainService.class), this, 0);
nameTextView.setText(intent.getStringExtra("EXTRA_USERNAME"));
@@ -93,13 +95,15 @@ public void onServiceDisconnected(ComponentName componentName) {
if (view.getId() == R.id.callDecline) {
Log.d(RTCCall.class.getSimpleName(), "declining call...");
currentCall.decline();
if(passiveWakeLock != null && passiveWakeLock.isHeld()) passiveWakeLock.release();
finish();
return;
}
try {
currentCall.setRemoteRenderer(findViewById(R.id.remoteRenderer));
//currentCall.setLocalRenderer(findViewById(R.id.localRenderer));
currentCall.accept(passiveCallback);
if(passiveWakeLock != null && passiveWakeLock.isHeld()) passiveWakeLock.release();
Log.d(CallActivity.class.getSimpleName(), "call accepted");
findViewById(R.id.callDecline).setOnClickListener(this);
startSensor();
@@ -202,6 +206,10 @@ private void startSensor() {
@Override
protected void onPause() {
super.onPause();
if(calledWhileScreenOff) {
calledWhileScreenOff = false;
return;
}
if(permissionRequested) return;
permissionRequested = false;
finish();
@@ -210,6 +218,7 @@ protected void onPause() {
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("RTCCall", "destroyed");
currentCall.decline();
if (binder != null) {

0 comments on commit 5b38258

Please sign in to comment.