Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 27 additions & 3 deletions app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import android.text.format.DateUtils
import android.util.Log
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -97,11 +98,22 @@ open class BaseActivity : AppCompatActivity() {

fun lockScreenIfConditionsApply() {
val keyguardManager = getSystemService(KEYGUARD_SERVICE) as KeyguardManager
if (!keyguardManager.isKeyguardSecure || !appPreferences.isScreenLocked) return
val isKeyguardSecure = keyguardManager.isKeyguardSecure
val isScreenLocked = appPreferences.isScreenLocked
Log.d(TAG, "lockScreenIfConditionsApply: isKeyguardSecure=$isKeyguardSecure isScreenLocked=$isScreenLocked")
if (!isKeyguardSecure || !isScreenLocked) return
try {
val timeoutSeconds = SecurityUtils.getIntegerFromStringTimeout(appPreferences.screenLockTimeout)
val elapsedSeconds = (System.currentTimeMillis() - appPreferences.lockTimestamp) / 1000
if (elapsedSeconds >= timeoutSeconds) {
val lockTimestamp = appPreferences.lockTimestamp
val elapsedSeconds = (System.currentTimeMillis() - lockTimestamp) / DateUtils.SECOND_IN_MILLIS
Log.d(
TAG,
"lockScreenIfConditionsApply: " +
"timeoutSeconds=$timeoutSeconds " +
"lockTimestamp=$lockTimestamp " +
"elapsedSeconds=$elapsedSeconds"
)
if (timeoutSeconds == 0 || elapsedSeconds >= timeoutSeconds) {
startActivity(Intent(this, LockedActivity::class.java))
}
} catch (e: Exception) {
Expand All @@ -122,8 +134,20 @@ open class BaseActivity : AppCompatActivity() {
eventBus.register(this)
}

protected open val skipLockCheckOnResume: Boolean = false

public override fun onResume() {
super.onResume()
Log.d(
TAG,
"onResume: " +
"pendingLockCheck=${NextcloudTalkApplication.pendingLockCheck} " +
"activity=${this.javaClass.simpleName}"
)
if (!skipLockCheckOnResume && NextcloudTalkApplication.pendingLockCheck) {
NextcloudTalkApplication.pendingLockCheck = false
lockScreenIfConditionsApply()
}

if (appPreferences.isKeyboardIncognito) {
val viewGroup = (findViewById<View>(android.R.id.content) as ViewGroup).getChildAt(0) as ViewGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class MainActivity :
@Inject
lateinit var userManager: UserManager

// MainActivity only routes to ConversationsListActivity or ChatActivity and is never
// visible to the user. The lock check must run in the actual destination activity.
override val skipLockCheckOnResume: Boolean = true

private val disposables = CompositeDisposable()

private val onBackPressedCallback = object : OnBackPressedCallback(true) {
Expand Down Expand Up @@ -108,7 +112,6 @@ class MainActivity :
override fun onStart() {
Log.d(TAG, "onStart: Activity: " + System.identityHashCode(this).toString())
super.onStart()
lockScreenIfConditionsApply()
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ class NextcloudTalkApplication :

ProcessLifecycleOwner.get().lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onStop(owner: LifecycleOwner) {
appPreferences.setLockTimestamp(System.currentTimeMillis())
val ts = System.currentTimeMillis()
Log.d(TAG, "ProcessLifecycle onStop: saving lockTimestamp=$ts")
appPreferences.setLockTimestamp(ts)
pendingLockCheck = true
}
})

Expand Down Expand Up @@ -270,6 +273,9 @@ class NextcloudTalkApplication :

var sharedApplication: NextcloudTalkApplication? = null
protected set

@Volatile
var pendingLockCheck = true
//endregion

//region Setters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,6 @@ class ConversationsListActivity : BaseActivity() {
}
}

override fun onStart() {
super.onStart()
lockScreenIfConditionsApply()
}

override fun onResume() {
super.onResume()
scrollPositionRestored = false
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-v28/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</array>

<array name="screen_lock_timeout_entry_int_values">
<item>1</item>
<item>0</item>
<item>30</item>
<item>60</item>
<item>300</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</array>

<array name="screen_lock_timeout_entry_int_values">
<item>1</item>
<item>0</item>
<item>30</item>
<item>60</item>
<item>300</item>
Expand Down
Loading