Better protection of device locked with secure keyguard
This commit is contained in:
@@ -50,11 +50,13 @@ class BaresipService: Service() {
|
|||||||
private lateinit var wm: WifiManager
|
private lateinit var wm: WifiManager
|
||||||
private lateinit var tm: TelecomManager
|
private lateinit var tm: TelecomManager
|
||||||
private lateinit var btm: BluetoothManager
|
private lateinit var btm: BluetoothManager
|
||||||
|
private lateinit var kgm: KeyguardManager
|
||||||
private lateinit var partialWakeLock: PowerManager.WakeLock
|
private lateinit var partialWakeLock: PowerManager.WakeLock
|
||||||
private lateinit var proximityWakeLock: PowerManager.WakeLock
|
private lateinit var proximityWakeLock: PowerManager.WakeLock
|
||||||
private lateinit var wifiLock: WifiManager.WifiLock
|
private lateinit var wifiLock: WifiManager.WifiLock
|
||||||
private lateinit var bluetoothReceiver: BroadcastReceiver
|
private lateinit var bluetoothReceiver: BroadcastReceiver
|
||||||
private lateinit var hotSpotReceiver: BroadcastReceiver
|
private lateinit var hotSpotReceiver: BroadcastReceiver
|
||||||
|
private lateinit var screenReceiver: BroadcastReceiver
|
||||||
|
|
||||||
private var rtTimer: Timer? = null
|
private var rtTimer: Timer? = null
|
||||||
private var audioFocusRequest: AudioFocusRequest? = null
|
private var audioFocusRequest: AudioFocusRequest? = null
|
||||||
@@ -206,6 +208,30 @@ class BaresipService: Service() {
|
|||||||
this.registerReceiver(hotSpotReceiver,
|
this.registerReceiver(hotSpotReceiver,
|
||||||
IntentFilter("android.net.wifi.WIFI_AP_STATE_CHANGED"))
|
IntentFilter("android.net.wifi.WIFI_AP_STATE_CHANGED"))
|
||||||
|
|
||||||
|
kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
|
||||||
|
screenReceiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(contxt: Context, intent: Intent) {
|
||||||
|
when (intent.action) {
|
||||||
|
Intent.ACTION_SCREEN_ON ->
|
||||||
|
if (kgm.isKeyguardLocked) {
|
||||||
|
Log.d(TAG, "Screen on LOCKED")
|
||||||
|
if (Utils.isVisible()) {
|
||||||
|
val i = Intent("screen event")
|
||||||
|
i.putExtra("event", Intent.ACTION_SCREEN_ON)
|
||||||
|
LocalBroadcastManager.getInstance(this@BaresipService)
|
||||||
|
.sendBroadcast(i)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Screen on UNLOCKED")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.registerReceiver(screenReceiver, IntentFilter(Intent.ACTION_SCREEN_ON))
|
||||||
|
|
||||||
tm = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
tm = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
||||||
|
|
||||||
btm = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
btm = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
||||||
@@ -482,6 +508,7 @@ class BaresipService: Service() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
this.unregisterReceiver(bluetoothReceiver)
|
this.unregisterReceiver(bluetoothReceiver)
|
||||||
this.unregisterReceiver(hotSpotReceiver)
|
this.unregisterReceiver(hotSpotReceiver)
|
||||||
|
this.unregisterReceiver(screenReceiver)
|
||||||
if (am.isBluetoothScoOn) am.stopBluetoothSco()
|
if (am.isBluetoothScoOn) am.stopBluetoothSco()
|
||||||
cleanService()
|
cleanService()
|
||||||
if (isServiceRunning) {
|
if (isServiceRunning) {
|
||||||
|
|||||||
@@ -103,5 +103,12 @@ class Call(val callp: String, val ua: UserAgent, val peerUri: String, val dir: S
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isIncoming(): Boolean {
|
||||||
|
for (call in BaresipService.calls)
|
||||||
|
if (call.status == "incoming")
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import java.net.URLDecoder
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
import android.content.IntentFilter
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private lateinit var am: AudioManager
|
private lateinit var am: AudioManager
|
||||||
private lateinit var kgm: KeyguardManager
|
private lateinit var kgm: KeyguardManager
|
||||||
private lateinit var serviceEventReceiver: BroadcastReceiver
|
private lateinit var serviceEventReceiver: BroadcastReceiver
|
||||||
|
private lateinit var screenEventReceiver: BroadcastReceiver
|
||||||
private lateinit var quitTimer: CountDownTimer
|
private lateinit var quitTimer: CountDownTimer
|
||||||
private lateinit var stopState: String
|
private lateinit var stopState: String
|
||||||
private var micIcon: MenuItem? = null
|
private var micIcon: MenuItem? = null
|
||||||
@@ -120,11 +122,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
BaresipService.callActionUri = URLDecoder.decode(intent.data.toString(), "UTF-8")
|
BaresipService.callActionUri = URLDecoder.decode(intent.data.toString(), "UTF-8")
|
||||||
|
|
||||||
kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
|
||||||
dismissKeyguard()
|
dismissKeyguard()
|
||||||
|
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES)
|
window.addFlags(WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES)
|
||||||
|
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
setSupportActionBar(binding.toolbar)
|
setSupportActionBar(binding.toolbar)
|
||||||
|
|
||||||
layout = binding.mainActivityLayout
|
layout = binding.mainActivityLayout
|
||||||
@@ -162,6 +166,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
LocalBroadcastManager.getInstance(this).registerReceiver(serviceEventReceiver,
|
LocalBroadcastManager.getInstance(this).registerReceiver(serviceEventReceiver,
|
||||||
IntentFilter("service event"))
|
IntentFilter("service event"))
|
||||||
|
|
||||||
|
screenEventReceiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
val event = intent.getStringExtra("event")!!
|
||||||
|
if (event == Intent.ACTION_SCREEN_ON && !Call.isIncoming())
|
||||||
|
dismissKeyguard()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(screenEventReceiver,
|
||||||
|
IntentFilter("screen event"))
|
||||||
|
|
||||||
stopState = "initial"
|
stopState = "initial"
|
||||||
quitTimer = object : CountDownTimer(5000, 1000) {
|
quitTimer = object : CountDownTimer(5000, 1000) {
|
||||||
override fun onTick(millisUntilFinished: Long) {
|
override fun onTick(millisUntilFinished: Long) {
|
||||||
@@ -259,16 +273,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
callUri.threshold = 2
|
callUri.threshold = 2
|
||||||
callUri.setOnFocusChangeListener { view, b ->
|
callUri.setOnFocusChangeListener { view, b ->
|
||||||
if (b) {
|
if (b) {
|
||||||
if (Build.VERSION.SDK_INT >= 27) {
|
|
||||||
kgm.requestDismissKeyguard(this, null)
|
|
||||||
}
|
|
||||||
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callUri.setOnClickListener { view ->
|
callUri.setOnClickListener { view ->
|
||||||
if (Build.VERSION.SDK_INT >= 27) {
|
|
||||||
kgm.requestDismissKeyguard(this, null)
|
|
||||||
}
|
|
||||||
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1081,6 +1089,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Toast.LENGTH_LONG).show()
|
Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
restoreActivities()
|
restoreActivities()
|
||||||
|
if (Build.VERSION.SDK_INT >= 22 && kgm.isDeviceLocked && kgm.isKeyguardSecure) {
|
||||||
|
dismissKeyguard()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"message", "message show", "message reply" -> {
|
"message", "message show", "message reply" -> {
|
||||||
val peer = params[1]
|
val peer = params[1]
|
||||||
@@ -1910,6 +1921,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
private fun dismissKeyguard() {
|
private fun dismissKeyguard() {
|
||||||
|
Log.d(TAG, "Dismissing keyguard")
|
||||||
if (Build.VERSION.SDK_INT >= 27) {
|
if (Build.VERSION.SDK_INT >= 27) {
|
||||||
setShowWhenLocked(true)
|
setShowWhenLocked(true)
|
||||||
setTurnScreenOn(true)
|
setTurnScreenOn(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user