Skip to content

Commit 82f2a9f

Browse files
committed
allow password protecting the whole app
1 parent 209494b commit 82f2a9f

File tree

4 files changed

+84
-21
lines changed

4 files changed

+84
-21
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ import java.io.File
3131
import java.util.*
3232

3333
class MainActivity : SimpleActivity() {
34-
private var isSearchOpen = false
3534
private val BACK_PRESS_TIMEOUT = 5000
3635
private val PICKED_PATH = "picked_path"
36+
private var isSearchOpen = false
3737
private var wasBackJustPressed = false
38+
private var mIsPasswordProtectionPending = false
39+
private var mWasProtectionHandled = false
3840
private var searchMenuItem: MenuItem? = null
3941

4042
private lateinit var fragment: ItemsFragment
@@ -43,6 +45,7 @@ class MainActivity : SimpleActivity() {
4345
super.onCreate(savedInstanceState)
4446
setContentView(R.layout.activity_main)
4547
appLaunched(BuildConfig.APPLICATION_ID)
48+
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
4649

4750
fragment = (fragment_holder as ItemsFragment).apply {
4851
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
@@ -51,10 +54,18 @@ class MainActivity : SimpleActivity() {
5154
}
5255

5356
if (savedInstanceState == null) {
54-
tryInitFileManager()
55-
checkWhatsNewDialog()
56-
checkIfRootAvailable()
57-
checkInvalidFavorites()
57+
handleAppPasswordProtection {
58+
mWasProtectionHandled = it
59+
if (it) {
60+
mIsPasswordProtectionPending = false
61+
tryInitFileManager()
62+
checkWhatsNewDialog()
63+
checkIfRootAvailable()
64+
checkInvalidFavorites()
65+
} else {
66+
finish()
67+
}
68+
}
5869
}
5970
}
6071

@@ -108,11 +119,27 @@ class MainActivity : SimpleActivity() {
108119
override fun onSaveInstanceState(outState: Bundle) {
109120
super.onSaveInstanceState(outState)
110121
outState.putString(PICKED_PATH, (fragment_holder as ItemsFragment).currentPath)
122+
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
111123
}
112124

113125
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
114126
super.onRestoreInstanceState(savedInstanceState)
115-
openPath(savedInstanceState.getString(PICKED_PATH), true)
127+
mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
128+
val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath
129+
130+
if (!mWasProtectionHandled) {
131+
handleAppPasswordProtection {
132+
mWasProtectionHandled = it
133+
if (it) {
134+
mIsPasswordProtectionPending = false
135+
openPath(path, true)
136+
} else {
137+
finish()
138+
}
139+
}
140+
} else {
141+
openPath(path, true)
142+
}
116143
}
117144

118145
private fun setupSearch(menu: Menu) {
@@ -179,6 +206,10 @@ class MainActivity : SimpleActivity() {
179206
}
180207

181208
private fun openPath(path: String, forceRefresh: Boolean = false) {
209+
if (mIsPasswordProtectionPending && !mWasProtectionHandled) {
210+
return
211+
}
212+
182213
var newPath = path
183214
val file = File(path)
184215
if (file.exists() && !file.isDirectory) {

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SettingsActivity.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class SettingsActivity : SimpleActivity() {
3030
setupManageFavorites()
3131
setupShowHidden()
3232
setupHiddenItemPasswordProtection()
33+
setupAppPasswordProtection()
3334
setupKeepLastModified()
3435
setupShowInfoBubble()
3536
setupEnableRootAccess()
@@ -106,6 +107,28 @@ class SettingsActivity : SimpleActivity() {
106107
}
107108
}
108109

110+
private fun setupAppPasswordProtection() {
111+
settings_app_password_protection.isChecked = config.isAppPasswordProtectionOn
112+
settings_app_password_protection_holder.setOnClickListener {
113+
val tabToShow = if (config.isAppPasswordProtectionOn) config.appProtectionType else SHOW_ALL_TABS
114+
SecurityDialog(this, config.appPasswordHash, tabToShow) { hash, type, success ->
115+
if (success) {
116+
val hasPasswordProtection = config.isAppPasswordProtectionOn
117+
settings_app_password_protection.isChecked = !hasPasswordProtection
118+
config.isAppPasswordProtectionOn = !hasPasswordProtection
119+
config.appPasswordHash = if (hasPasswordProtection) "" else hash
120+
config.appProtectionType = type
121+
122+
if (config.isAppPasswordProtectionOn) {
123+
val confirmationTextId = if (config.appProtectionType == PROTECTION_FINGERPRINT)
124+
R.string.fingerprint_setup_successfully else R.string.protection_setup_successfully
125+
ConfirmationDialog(this, "", confirmationTextId, R.string.ok, 0) { }
126+
}
127+
}
128+
}
129+
}
130+
}
131+
109132
private fun setupKeepLastModified() {
110133
settings_keep_last_modified.isChecked = config.keepLastModified
111134
settings_keep_last_modified_holder.setOnClickListener {

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
173173
skipItemUpdating = false
174174
Thread {
175175
if (activity?.isDestroyed == false) {
176-
/*if (path.startsWith(OTG_PATH)) {
177-
val getProperFileSize = context!!.config.sorting and SORT_BY_SIZE != 0
178-
context!!.getOTGItems(path, context!!.config.shouldShowHidden, getProperFileSize) {
179-
callback(path, it)
180-
}
181-
} else */if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
176+
if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
182177
getRegularItemsOf(path, callback)
183178
} else {
184179
RootHelpers(activity!!).getFiles(path, callback)

app/src/main/res/layout/activity_settings.xml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
android:layout_height="wrap_content"
3030
android:layout_centerVertical="true"
3131
android:paddingStart="@dimen/medium_margin"
32-
android:paddingLeft="@dimen/medium_margin"
3332
android:text="@string/customize_colors"/>
3433

3534
</RelativeLayout>
@@ -74,7 +73,6 @@
7473
android:background="@null"
7574
android:clickable="false"
7675
android:paddingStart="@dimen/medium_margin"
77-
android:paddingLeft="@dimen/medium_margin"
7876
android:text="@string/use_english_language"
7977
app:switchPadding="@dimen/medium_margin"/>
8078

@@ -116,7 +114,6 @@
116114
android:background="@null"
117115
android:clickable="false"
118116
android:paddingStart="@dimen/medium_margin"
119-
android:paddingLeft="@dimen/medium_margin"
120117
android:text="@string/show_hidden_items"
121118
app:switchPadding="@dimen/medium_margin"/>
122119

@@ -134,7 +131,6 @@
134131
android:layout_width="wrap_content"
135132
android:layout_height="wrap_content"
136133
android:layout_marginStart="@dimen/bigger_margin"
137-
android:layout_marginLeft="@dimen/bigger_margin"
138134
android:layout_marginTop="@dimen/activity_margin"
139135
android:text="@string/file_operations"
140136
android:textAllCaps="true"
@@ -158,7 +154,6 @@
158154
android:background="@null"
159155
android:clickable="false"
160156
android:paddingStart="@dimen/medium_margin"
161-
android:paddingLeft="@dimen/medium_margin"
162157
android:text="@string/keep_last_modified"
163158
app:switchPadding="@dimen/medium_margin"/>
164159

@@ -176,7 +171,6 @@
176171
android:layout_width="wrap_content"
177172
android:layout_height="wrap_content"
178173
android:layout_marginStart="@dimen/bigger_margin"
179-
android:layout_marginLeft="@dimen/bigger_margin"
180174
android:layout_marginTop="@dimen/activity_margin"
181175
android:text="@string/scrolling"
182176
android:textAllCaps="true"
@@ -200,7 +194,6 @@
200194
android:background="@null"
201195
android:clickable="false"
202196
android:paddingStart="@dimen/medium_margin"
203-
android:paddingLeft="@dimen/medium_margin"
204197
android:text="@string/show_info_bubble"
205198
app:switchPadding="@dimen/medium_margin"/>
206199

@@ -218,7 +211,6 @@
218211
android:layout_width="wrap_content"
219212
android:layout_height="wrap_content"
220213
android:layout_marginStart="@dimen/bigger_margin"
221-
android:layout_marginLeft="@dimen/bigger_margin"
222214
android:layout_marginTop="@dimen/activity_margin"
223215
android:text="@string/security"
224216
android:textAllCaps="true"
@@ -242,12 +234,34 @@
242234
android:background="@null"
243235
android:clickable="false"
244236
android:paddingStart="@dimen/medium_margin"
245-
android:paddingLeft="@dimen/medium_margin"
246237
android:text="@string/password_protect_hidden_items"
247238
app:switchPadding="@dimen/medium_margin"/>
248239

249240
</RelativeLayout>
250241

242+
<RelativeLayout
243+
android:id="@+id/settings_app_password_protection_holder"
244+
android:layout_width="match_parent"
245+
android:layout_height="wrap_content"
246+
android:layout_marginTop="@dimen/medium_margin"
247+
android:background="?attr/selectableItemBackground"
248+
android:paddingLeft="@dimen/normal_margin"
249+
android:paddingTop="@dimen/activity_margin"
250+
android:paddingRight="@dimen/normal_margin"
251+
android:paddingBottom="@dimen/activity_margin">
252+
253+
<com.simplemobiletools.commons.views.MySwitchCompat
254+
android:id="@+id/settings_app_password_protection"
255+
android:layout_width="match_parent"
256+
android:layout_height="wrap_content"
257+
android:background="@null"
258+
android:clickable="false"
259+
android:paddingStart="@dimen/medium_margin"
260+
android:text="@string/password_protect_whole_app"
261+
app:switchPadding="@dimen/medium_margin"/>
262+
263+
</RelativeLayout>
264+
251265
<RelativeLayout
252266
android:id="@+id/settings_enable_root_access_holder"
253267
android:layout_width="match_parent"

0 commit comments

Comments
 (0)