-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added a full screen activity for unlocking app - Added app lock manager for managing global lock state - Added new FossifyApp base application class that apps must subclass. This will help remedy issues like FossifyOrg/Gallery#126
- Loading branch information
1 parent
c144de7
commit 1e5b935
Showing
33 changed files
with
544 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.fossify.commons | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.ProcessLifecycleOwner | ||
import org.fossify.commons.extensions.appLockManager | ||
import org.fossify.commons.extensions.checkUseEnglish | ||
|
||
open class FossifyApp : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
checkUseEnglish() | ||
setupAppLockManager() | ||
} | ||
|
||
private fun setupAppLockManager() { | ||
ProcessLifecycleOwner.get().lifecycle.addObserver(appLockManager) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
commons/src/main/kotlin/org/fossify/commons/activities/AppLockActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.fossify.commons.activities | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.addCallback | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.biometric.auth.AuthPromptHost | ||
import org.fossify.commons.R | ||
import org.fossify.commons.adapters.AppLockAdapter | ||
import org.fossify.commons.databinding.ActivityAppLockBinding | ||
import org.fossify.commons.extensions.* | ||
import org.fossify.commons.helpers.PROTECTION_FINGERPRINT | ||
import org.fossify.commons.helpers.isRPlus | ||
import org.fossify.commons.interfaces.HashListener | ||
|
||
class AppLockActivity : AppCompatActivity(), HashListener { | ||
|
||
private val binding by viewBinding(ActivityAppLockBinding::inflate) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
overrideActivityTransition() | ||
setupTheme() | ||
|
||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
onBackPressedDispatcher.addCallback(owner = this) { | ||
appLockManager.lock() | ||
finishAffinity() | ||
} | ||
|
||
setupViewPager() | ||
} | ||
|
||
private fun setupViewPager() { | ||
val adapter = AppLockAdapter( | ||
context = binding.root.context, | ||
requiredHash = baseConfig.appPasswordHash, | ||
hashListener = this, | ||
viewPager = binding.viewPager, | ||
biometricPromptHost = AuthPromptHost(this), | ||
showBiometricIdTab = isBiometricAuthSupported(), | ||
showBiometricAuthentication = baseConfig.appProtectionType == PROTECTION_FINGERPRINT && isRPlus() | ||
) | ||
|
||
binding.viewPager.apply { | ||
this.adapter = adapter | ||
currentItem = baseConfig.appProtectionType | ||
isUserInputEnabled = false | ||
onGlobalLayout { | ||
for (i in 0..2) { | ||
adapter.isTabVisible(i, binding.viewPager.currentItem == i) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
if (appLockManager.isLocked()) { | ||
setupTheme() | ||
} else { | ||
finish() | ||
} | ||
} | ||
|
||
override fun onNewIntent(intent: Intent?) { | ||
super.onNewIntent(intent) | ||
overrideActivityTransition() | ||
} | ||
|
||
override fun finish() { | ||
super.finish() | ||
overrideActivityTransition(exiting = true) | ||
} | ||
|
||
private fun setupTheme() { | ||
setTheme(getThemeId(showTransparentTop = true)) | ||
with(getProperBackgroundColor()) { | ||
window.updateStatusBarColors(this) | ||
window.updateNavigationBarColors(this) | ||
window.decorView.setBackgroundColor(this) | ||
} | ||
} | ||
|
||
private fun overrideActivityTransition(exiting: Boolean = false) { | ||
overrideActivityTransition(R.anim.fadein, R.anim.fadeout, exiting) | ||
} | ||
|
||
override fun receivedHash(hash: String, type: Int) { | ||
appLockManager.unlock() | ||
setResult(RESULT_OK) | ||
finish() | ||
} | ||
} | ||
|
||
fun Activity.maybeLaunchAppUnlockActivity(requestCode: Int) { | ||
if (appLockManager.isLocked()) { | ||
Intent(this, AppLockActivity::class.java).apply { | ||
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) | ||
startActivityForResult(this, requestCode) | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
commons/src/main/kotlin/org/fossify/commons/activities/BaseComposeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.fossify.commons.activities | ||
|
||
import androidx.activity.ComponentActivity | ||
import org.fossify.commons.helpers.REQUEST_APP_UNLOCK | ||
|
||
abstract class BaseComposeActivity : ComponentActivity() { | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
maybeLaunchAppUnlockActivity(REQUEST_APP_UNLOCK) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
commons/src/main/kotlin/org/fossify/commons/adapters/AppLockAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.fossify.commons.adapters | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.biometric.auth.AuthPromptHost | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import org.fossify.commons.R | ||
import org.fossify.commons.helpers.PROTECTION_FINGERPRINT | ||
import org.fossify.commons.helpers.PROTECTION_PATTERN | ||
import org.fossify.commons.helpers.PROTECTION_PIN | ||
import org.fossify.commons.helpers.isRPlus | ||
import org.fossify.commons.interfaces.HashListener | ||
import org.fossify.commons.interfaces.SecurityTab | ||
|
||
class AppLockAdapter( | ||
private val context: Context, | ||
private val requiredHash: String, | ||
private val hashListener: HashListener, | ||
private val viewPager: ViewPager2, | ||
private val biometricPromptHost: AuthPromptHost, | ||
private val showBiometricIdTab: Boolean, | ||
private val showBiometricAuthentication: Boolean | ||
) : RecyclerView.Adapter<AppLockAdapter.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = LayoutInflater.from(context).inflate(layoutSelection(viewType), parent, false) | ||
view.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind() | ||
|
||
override fun getItemCount(): Int = if (showBiometricIdTab) 3 else 2 | ||
|
||
override fun getItemViewType(position: Int) = position | ||
|
||
private fun layoutSelection(position: Int): Int = when (position) { | ||
PROTECTION_PATTERN -> R.layout.tab_pattern | ||
PROTECTION_PIN -> R.layout.tab_pin | ||
PROTECTION_FINGERPRINT -> if (isRPlus()) R.layout.tab_biometric_id else R.layout.tab_fingerprint | ||
else -> throw RuntimeException("Only 3 tabs allowed") | ||
} | ||
|
||
fun isTabVisible(position: Int, isVisible: Boolean) { | ||
val viewHolder = (viewPager.getChildAt(0) as? RecyclerView)?.findViewHolderForAdapterPosition(position) as? ViewHolder | ||
viewHolder?.itemView?.let { | ||
(it as SecurityTab).visibilityChanged(isVisible) | ||
} | ||
} | ||
|
||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
fun bind() { | ||
(itemView as SecurityTab).initTab( | ||
requiredHash = requiredHash, | ||
listener = hashListener, | ||
scrollView = null, | ||
biometricPromptHost = biometricPromptHost, | ||
showBiometricAuthentication = showBiometricAuthentication | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.