allow password protecting the whole app

This commit is contained in:
tibbi 2019-03-01 14:23:36 +01:00
parent 209494bab4
commit 82f2a9fe0d
4 changed files with 84 additions and 21 deletions

View File

@ -31,10 +31,12 @@ import java.io.File
import java.util.* import java.util.*
class MainActivity : SimpleActivity() { class MainActivity : SimpleActivity() {
private var isSearchOpen = false
private val BACK_PRESS_TIMEOUT = 5000 private val BACK_PRESS_TIMEOUT = 5000
private val PICKED_PATH = "picked_path" private val PICKED_PATH = "picked_path"
private var isSearchOpen = false
private var wasBackJustPressed = false private var wasBackJustPressed = false
private var mIsPasswordProtectionPending = false
private var mWasProtectionHandled = false
private var searchMenuItem: MenuItem? = null private var searchMenuItem: MenuItem? = null
private lateinit var fragment: ItemsFragment private lateinit var fragment: ItemsFragment
@ -43,6 +45,7 @@ class MainActivity : SimpleActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
appLaunched(BuildConfig.APPLICATION_ID) appLaunched(BuildConfig.APPLICATION_ID)
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
fragment = (fragment_holder as ItemsFragment).apply { fragment = (fragment_holder as ItemsFragment).apply {
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
@ -51,10 +54,18 @@ class MainActivity : SimpleActivity() {
} }
if (savedInstanceState == null) { if (savedInstanceState == null) {
tryInitFileManager() handleAppPasswordProtection {
checkWhatsNewDialog() mWasProtectionHandled = it
checkIfRootAvailable() if (it) {
checkInvalidFavorites() mIsPasswordProtectionPending = false
tryInitFileManager()
checkWhatsNewDialog()
checkIfRootAvailable()
checkInvalidFavorites()
} else {
finish()
}
}
} }
} }
@ -108,11 +119,27 @@ class MainActivity : SimpleActivity() {
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
outState.putString(PICKED_PATH, (fragment_holder as ItemsFragment).currentPath) outState.putString(PICKED_PATH, (fragment_holder as ItemsFragment).currentPath)
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
} }
override fun onRestoreInstanceState(savedInstanceState: Bundle) { override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState) super.onRestoreInstanceState(savedInstanceState)
openPath(savedInstanceState.getString(PICKED_PATH), true) mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath
if (!mWasProtectionHandled) {
handleAppPasswordProtection {
mWasProtectionHandled = it
if (it) {
mIsPasswordProtectionPending = false
openPath(path, true)
} else {
finish()
}
}
} else {
openPath(path, true)
}
} }
private fun setupSearch(menu: Menu) { private fun setupSearch(menu: Menu) {
@ -179,6 +206,10 @@ class MainActivity : SimpleActivity() {
} }
private fun openPath(path: String, forceRefresh: Boolean = false) { private fun openPath(path: String, forceRefresh: Boolean = false) {
if (mIsPasswordProtectionPending && !mWasProtectionHandled) {
return
}
var newPath = path var newPath = path
val file = File(path) val file = File(path)
if (file.exists() && !file.isDirectory) { if (file.exists() && !file.isDirectory) {

View File

@ -30,6 +30,7 @@ class SettingsActivity : SimpleActivity() {
setupManageFavorites() setupManageFavorites()
setupShowHidden() setupShowHidden()
setupHiddenItemPasswordProtection() setupHiddenItemPasswordProtection()
setupAppPasswordProtection()
setupKeepLastModified() setupKeepLastModified()
setupShowInfoBubble() setupShowInfoBubble()
setupEnableRootAccess() setupEnableRootAccess()
@ -106,6 +107,28 @@ class SettingsActivity : SimpleActivity() {
} }
} }
private fun setupAppPasswordProtection() {
settings_app_password_protection.isChecked = config.isAppPasswordProtectionOn
settings_app_password_protection_holder.setOnClickListener {
val tabToShow = if (config.isAppPasswordProtectionOn) config.appProtectionType else SHOW_ALL_TABS
SecurityDialog(this, config.appPasswordHash, tabToShow) { hash, type, success ->
if (success) {
val hasPasswordProtection = config.isAppPasswordProtectionOn
settings_app_password_protection.isChecked = !hasPasswordProtection
config.isAppPasswordProtectionOn = !hasPasswordProtection
config.appPasswordHash = if (hasPasswordProtection) "" else hash
config.appProtectionType = type
if (config.isAppPasswordProtectionOn) {
val confirmationTextId = if (config.appProtectionType == PROTECTION_FINGERPRINT)
R.string.fingerprint_setup_successfully else R.string.protection_setup_successfully
ConfirmationDialog(this, "", confirmationTextId, R.string.ok, 0) { }
}
}
}
}
}
private fun setupKeepLastModified() { private fun setupKeepLastModified() {
settings_keep_last_modified.isChecked = config.keepLastModified settings_keep_last_modified.isChecked = config.keepLastModified
settings_keep_last_modified_holder.setOnClickListener { settings_keep_last_modified_holder.setOnClickListener {

View File

@ -173,12 +173,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
skipItemUpdating = false skipItemUpdating = false
Thread { Thread {
if (activity?.isDestroyed == false) { if (activity?.isDestroyed == false) {
/*if (path.startsWith(OTG_PATH)) { if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
val getProperFileSize = context!!.config.sorting and SORT_BY_SIZE != 0
context!!.getOTGItems(path, context!!.config.shouldShowHidden, getProperFileSize) {
callback(path, it)
}
} else */if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
getRegularItemsOf(path, callback) getRegularItemsOf(path, callback)
} else { } else {
RootHelpers(activity!!).getFiles(path, callback) RootHelpers(activity!!).getFiles(path, callback)

View File

@ -29,7 +29,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:paddingStart="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/customize_colors"/> android:text="@string/customize_colors"/>
</RelativeLayout> </RelativeLayout>
@ -74,7 +73,6 @@
android:background="@null" android:background="@null"
android:clickable="false" android:clickable="false"
android:paddingStart="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/use_english_language" android:text="@string/use_english_language"
app:switchPadding="@dimen/medium_margin"/> app:switchPadding="@dimen/medium_margin"/>
@ -116,7 +114,6 @@
android:background="@null" android:background="@null"
android:clickable="false" android:clickable="false"
android:paddingStart="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/show_hidden_items" android:text="@string/show_hidden_items"
app:switchPadding="@dimen/medium_margin"/> app:switchPadding="@dimen/medium_margin"/>
@ -134,7 +131,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/bigger_margin" android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin" android:layout_marginTop="@dimen/activity_margin"
android:text="@string/file_operations" android:text="@string/file_operations"
android:textAllCaps="true" android:textAllCaps="true"
@ -158,7 +154,6 @@
android:background="@null" android:background="@null"
android:clickable="false" android:clickable="false"
android:paddingStart="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/keep_last_modified" android:text="@string/keep_last_modified"
app:switchPadding="@dimen/medium_margin"/> app:switchPadding="@dimen/medium_margin"/>
@ -176,7 +171,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/bigger_margin" android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin" android:layout_marginTop="@dimen/activity_margin"
android:text="@string/scrolling" android:text="@string/scrolling"
android:textAllCaps="true" android:textAllCaps="true"
@ -200,7 +194,6 @@
android:background="@null" android:background="@null"
android:clickable="false" android:clickable="false"
android:paddingStart="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/show_info_bubble" android:text="@string/show_info_bubble"
app:switchPadding="@dimen/medium_margin"/> app:switchPadding="@dimen/medium_margin"/>
@ -218,7 +211,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/bigger_margin" android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin" android:layout_marginTop="@dimen/activity_margin"
android:text="@string/security" android:text="@string/security"
android:textAllCaps="true" android:textAllCaps="true"
@ -242,12 +234,34 @@
android:background="@null" android:background="@null"
android:clickable="false" android:clickable="false"
android:paddingStart="@dimen/medium_margin" android:paddingStart="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/password_protect_hidden_items" android:text="@string/password_protect_hidden_items"
app:switchPadding="@dimen/medium_margin"/> app:switchPadding="@dimen/medium_margin"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_app_password_protection_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingBottom="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_app_password_protection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingStart="@dimen/medium_margin"
android:text="@string/password_protect_whole_app"
app:switchPadding="@dimen/medium_margin"/>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/settings_enable_root_access_holder" android:id="@+id/settings_enable_root_access_holder"
android:layout_width="match_parent" android:layout_width="match_parent"