From 8b3c08970c56c6b33e33d7fc2ec7cd530a25172e Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 28 Nov 2018 15:19:51 +0100 Subject: [PATCH] show an incoming call screen over the lockscreen, if the screen is off --- app/src/main/AndroidManifest.xml | 3 +- .../contacts/pro/activities/DialerActivity.kt | 6 ++++ .../pro/services/MyIncomingCallService.kt | 32 +++++++++++++------ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b1953893..c6b76294 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -225,7 +225,8 @@ + android:launchMode="singleTask" + android:showOnLockScreen="true"> diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index ffe521f3..718781ba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -18,6 +18,7 @@ import android.os.PowerManager import android.telecom.Call import android.telecom.PhoneAccount import android.telecom.TelecomManager +import android.view.WindowManager import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.contacts.pro.R @@ -48,6 +49,11 @@ class DialerActivity : SimpleActivity(), SensorEventListener { setContentView(R.layout.activity_dialer) initProximityWakeLock() LocalBroadcastManager.getInstance(applicationContext).registerReceiver(messageReceiver, IntentFilter(DIALER_INTENT_FILTER)) + window.apply { + addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) + addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) + addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } val action = intent.action val extras = intent.extras diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyIncomingCallService.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyIncomingCallService.kt index efc70b50..15652cb4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyIncomingCallService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyIncomingCallService.kt @@ -1,15 +1,17 @@ package com.simplemobiletools.contacts.pro.services import android.annotation.TargetApi +import android.app.KeyguardManager +import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Build +import android.os.Bundle import android.telecom.Call import android.telecom.InCallService import androidx.localbroadcastmanager.content.LocalBroadcastManager -import com.simplemobiletools.contacts.pro.helpers.CALL_NUMBER -import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS -import com.simplemobiletools.contacts.pro.helpers.DIALER_INTENT_FILTER -import com.simplemobiletools.contacts.pro.helpers.IS_INCOMING_CALL +import com.simplemobiletools.contacts.pro.activities.DialerActivity +import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.objects.CallManager @TargetApi(Build.VERSION_CODES.M) @@ -25,11 +27,23 @@ class MyIncomingCallService : InCallService() { handle } - Intent(this, DialerCallService::class.java).apply { - putExtra(CALL_STATUS, call.state) - putExtra(CALL_NUMBER, callerNumber) - putExtra(IS_INCOMING_CALL, true) - startService(this) + val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager + if (keyguardManager.isKeyguardLocked) { + Intent(this, DialerActivity::class.java).apply { + action = RESUME_DIALER + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(CALL_NUMBER, callerNumber) + putExtra(CALL_STATUS, call.state) + putExtra(IS_INCOMING_CALL, true) + startActivity(this) + } + } else { + Intent(this, DialerCallService::class.java).apply { + putExtra(CALL_STATUS, call.state) + putExtra(CALL_NUMBER, callerNumber) + putExtra(IS_INCOMING_CALL, true) + startService(this) + } } CallManager.updateCall(call)