Merge pull request #13533 from nextcloud/fix-secure-flag

Flag FLAG_SECURE should only be active when in passcode screen
This commit is contained in:
Alper Öztürk 2024-09-12 10:51:55 +02:00 коммит произвёл GitHub
Родитель 5116cdcca9 3c6db3819e
Коммит 3929a34425
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 34 добавлений и 11 удалений

Просмотреть файл

@ -37,6 +37,18 @@ class PassCodeManager(private val preferences: AppPreferences, private val clock
* the pass code being requested on screen rotations. * the pass code being requested on screen rotations.
*/ */
private const val PASS_CODE_TIMEOUT = 5000 private const val PASS_CODE_TIMEOUT = 5000
fun setSecureFlag(activity: Activity, isSet: Boolean) {
activity.window?.let { window ->
if (isSet) {
println("flag added")
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else {
println("flag cleared")
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
}
} }
var canAskPin = true var canAskPin = true
@ -49,7 +61,6 @@ class PassCodeManager(private val preferences: AppPreferences, private val clock
fun onActivityResumed(activity: Activity): Boolean { fun onActivityResumed(activity: Activity): Boolean {
var askedForPin = false var askedForPin = false
val timestamp = preferences.lockTimestamp val timestamp = preferences.lockTimestamp
setSecureFlag(activity)
if (!isExemptActivity(activity)) { if (!isExemptActivity(activity)) {
val passcodeRequested = passCodeShouldBeRequested(timestamp) val passcodeRequested = passCodeShouldBeRequested(timestamp)
@ -76,16 +87,6 @@ class PassCodeManager(private val preferences: AppPreferences, private val clock
return askedForPin return askedForPin
} }
private fun setSecureFlag(activity: Activity) {
activity.window?.let { window ->
if (isPassCodeEnabled() || deviceCredentialsAreEnabled(activity)) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
}
private fun requestPasscode(activity: Activity) { private fun requestPasscode(activity: Activity) {
val i = Intent(MainApp.getAppContext(), PassCodeActivity::class.java).apply { val i = Intent(MainApp.getAppContext(), PassCodeActivity::class.java).apply {
action = PassCodeActivity.ACTION_CHECK action = PassCodeActivity.ACTION_CHECK

Просмотреть файл

@ -79,6 +79,7 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
binding = PasscodelockBinding.inflate(layoutInflater) binding = PasscodelockBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
PassCodeManager.setSecureFlag(this, true)
applyTint() applyTint()
setupPasscodeEditTexts() setupPasscodeEditTexts()
setSoftInputMode() setSoftInputMode()
@ -374,6 +375,11 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
} }
} }
override fun onDestroy() {
PassCodeManager.setSecureFlag(this, false)
super.onDestroy()
}
private inner class PassCodeDigitTextWatcher(index: Int, lastOne: Boolean) : TextWatcher { private inner class PassCodeDigitTextWatcher(index: Int, lastOne: Boolean) : TextWatcher {
private var mIndex = -1 private var mIndex = -1
private val mLastOne: Boolean private val mLastOne: Boolean

Просмотреть файл

@ -14,15 +14,19 @@ import android.app.Activity;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.widget.Toast; import android.widget.Toast;
import com.nextcloud.client.preferences.AppPreferencesImpl; import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.authentication.PassCodeManager;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.DeviceCredentialUtils; import com.owncloud.android.utils.DeviceCredentialUtils;
import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.DisplayUtils;
import androidx.annotation.Nullable;
/** /**
* Dummy activity that is used to handle the device's default authentication workflow. * Dummy activity that is used to handle the device's default authentication workflow.
*/ */
@ -36,6 +40,12 @@ public class RequestCredentialsActivity extends Activity {
public final static int KEY_CHECK_RESULT_CANCEL = -1; public final static int KEY_CHECK_RESULT_CANCEL = -1;
private static final int REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1; private static final int REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PassCodeManager.Companion.setSecureFlag(this,true);
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) { if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) {
@ -82,4 +92,10 @@ public class RequestCredentialsActivity extends Activity {
setResult(Activity.RESULT_OK, resultIntent); setResult(Activity.RESULT_OK, resultIntent);
finish(); finish();
} }
@Override
protected void onDestroy() {
PassCodeManager.Companion.setSecureFlag(this,false);
super.onDestroy();
}
} }