Skip to content

Commit

Permalink
Merge pull request #102 from aashishksahu/autolock
Browse files Browse the repository at this point in the history
Auto lock and minor ui fixes
  • Loading branch information
aashishksahu authored Dec 25, 2024
2 parents 0af6133 + 2a23a18 commit 5834f44
Show file tree
Hide file tree
Showing 22 changed files with 435 additions and 174 deletions.
107 changes: 67 additions & 40 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Download the APK from [here](https://github.com/aashishksahu/SafeSpace/releases)

[<img alt="alt_text" width="200px" src="https://user-content.gitlab-static.net/0cdd89e5cc347206465251782615ab91f99a542d/68747470733a2f2f6664726f69642e6769746c61622e696f2f617274776f726b2f62616467652f6765742d69742d6f6e2e706e67" />](https://f-droid.org/en/packages/org.privacymatters.safespace/)
[<img alt="alt_text" width="200px" src="https://github.com/aashishksahu/SafeSpace/blob/be3c70a58220e21d643151e44699e9931d845d77/assets/google-play-badge.png" />](https://play.google.com/store/apps/details?id=org.privacymatters.safespace&pcampaignid=web_share)

## Disclaimer

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {

minSdk 29
targetSdk 34
versionCode 38
versionName "2.0.7"
versionCode 40
versionName "2.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
</intent-filter>
</activity>
<activity
android:name=".document.TextDocumentView"
android:name=".document.TextDocumentActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="false" />
<activity
android:name=".document.PDFView"
android:name=".document.PDFActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="false" />

Expand Down
24 changes: 21 additions & 3 deletions app/src/main/java/org/privacymatters/safespace/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.view.WindowManager
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -13,17 +14,22 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.privacymatters.safespace.utils.LockTimer
import org.privacymatters.safespace.utils.Reload

class AboutActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
setContentView(R.layout.activity_about)

val app_title = findViewById<TextView>(R.id.app_title)
val appTitle = findViewById<TextView>(R.id.app_title)

ViewCompat.setOnApplyWindowInsetsListener(app_title) { v, windowInsets ->
ViewCompat.setOnApplyWindowInsetsListener(appTitle) { v, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())

v.updateLayoutParams<MarginLayoutParams> {
Expand Down Expand Up @@ -98,4 +104,16 @@ class AboutActivity : AppCompatActivity() {
holder.link.text = libItem.link
}
}
}

override fun onResume() {
LockTimer.stop()
LockTimer.checkLock(this)
super.onResume()
}

override fun onPause() {
LockTimer.stop()
LockTimer.start()
super.onPause()
}
}
40 changes: 34 additions & 6 deletions app/src/main/java/org/privacymatters/safespace/AuthActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import android.content.SharedPreferences
import android.os.Bundle
import android.os.CountDownTimer
import android.view.KeyEvent
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import android.widget.ImageButton
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.biometric.BiometricManager
Expand All @@ -20,6 +22,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.privacymatters.safespace.main.MainnActivity
import org.privacymatters.safespace.utils.Constants
import org.privacymatters.safespace.utils.EncPref
import org.privacymatters.safespace.utils.LockTimer
import org.privacymatters.safespace.utils.RootCheck
import org.privacymatters.safespace.utils.SetTheme
import java.util.concurrent.Executor
Expand Down Expand Up @@ -75,11 +78,16 @@ class AuthActivity : AppCompatActivity() {
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
// enableEdgeToEdged


// check if app pin is set
isHardPinSet = EncPref.getBoolean(Constants.HARD_PIN_SET, applicationContext)

enableEdgeToEdge()
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
setContentView(R.layout.activity_auth)

authTouch = findViewById(R.id.fingerprint)
Expand Down Expand Up @@ -142,6 +150,15 @@ class AuthActivity : AppCompatActivity() {
}
}

// back button - system navigation
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (LockTimer.firstActivity) { // back button works if there are no previous activities in stack
finish()
}
}
})

}

override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
Expand Down Expand Up @@ -172,9 +189,13 @@ class AuthActivity : AppCompatActivity() {

blockBiometric(false, 0)

val intent = Intent(applicationContext, MainnActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
LockTimer.removeLock()

if (LockTimer.firstActivity) {
val intent = Intent(applicationContext, MainnActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
finish()
} else {
pinField.error = getString(R.string.pin_error5)
Expand Down Expand Up @@ -345,6 +366,8 @@ class AuthActivity : AppCompatActivity() {
EncPref.setBoolean(Constants.HARD_PIN_SET, true, applicationContext)

finish()
val intent = Intent(applicationContext, AuthActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)

}
Expand Down Expand Up @@ -372,9 +395,14 @@ class AuthActivity : AppCompatActivity() {
result: BiometricPrompt.AuthenticationResult
) {
super.onAuthenticationSucceeded(result)
val intent = Intent(applicationContext, MainnActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)

LockTimer.removeLock()

if (LockTimer.firstActivity) {
val intent = Intent(applicationContext, MainnActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
finish()
}

Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/org/privacymatters/safespace/LogActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.privacymatters.safespace

import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
Expand All @@ -23,6 +24,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import org.privacymatters.safespace.main.ui.SafeSpaceTheme
import org.privacymatters.safespace.utils.LockTimer
import org.privacymatters.safespace.utils.Utils
import java.io.BufferedReader
import java.io.File
Expand All @@ -37,6 +39,10 @@ class LogActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)

val logsFolder = File(application.filesDir.canonicalPath + File.separator + "logs")
val logFile = File(logsFolder.canonicalPath + File.separator + "safe_space_log.txt")
Expand Down Expand Up @@ -98,4 +104,16 @@ class LogActivity : ComponentActivity() {
}
}
}

override fun onResume() {
LockTimer.stop()
LockTimer.checkLock(this)
super.onResume()
}

override fun onPause() {
LockTimer.stop()
LockTimer.start()
super.onPause()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.media.AudioManager
import android.media.MediaActionSound
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.ImageButton
import android.widget.TextView
Expand All @@ -30,9 +31,10 @@ import androidx.camera.view.PreviewView
import androidx.core.content.ContextCompat
import androidx.core.util.Consumer
import org.privacymatters.safespace.R
import org.privacymatters.safespace.utils.Reload
import org.privacymatters.safespace.main.DataManager
import org.privacymatters.safespace.utils.Constants
import org.privacymatters.safespace.utils.LockTimer
import org.privacymatters.safespace.utils.Reload
import org.privacymatters.safespace.utils.Utils
import java.io.File
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -110,6 +112,10 @@ class CameraActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
setContentView(R.layout.activity_camera)

window.statusBarColor = ContextCompat.getColor(applicationContext, R.color.black)
Expand Down Expand Up @@ -537,5 +543,17 @@ class CameraActivity : AppCompatActivity() {
super.onDestroy()
cameraExecutor.shutdown()
}

override fun onResume() {
LockTimer.stop()
LockTimer.checkLock(this)
super.onResume()
}

override fun onPause() {
LockTimer.stop()
LockTimer.start()
super.onPause()
}
}

Loading

0 comments on commit 5834f44

Please sign in to comment.