mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Prevent loading messages before app is unlocked
This commit is contained in:
@@ -50,6 +50,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
private var lastSearchedText = ""
|
private var lastSearchedText = ""
|
||||||
private var bus: EventBus? = null
|
private var bus: EventBus? = null
|
||||||
private val smsExporter by lazy { MessagesExporter(this) }
|
private val smsExporter by lazy { MessagesExporter(this) }
|
||||||
|
private var wasProtectionHandled = false
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -64,7 +65,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
handleAppPasswordProtection {
|
handleAppPasswordProtection {
|
||||||
if (!it) {
|
wasProtectionHandled = it
|
||||||
|
if (it) {
|
||||||
|
loadMessages()
|
||||||
|
} else {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,29 +78,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isQPlus()) {
|
|
||||||
val roleManager = getSystemService(RoleManager::class.java)
|
|
||||||
if (roleManager!!.isRoleAvailable(RoleManager.ROLE_SMS)) {
|
|
||||||
if (roleManager.isRoleHeld(RoleManager.ROLE_SMS)) {
|
|
||||||
askPermissions()
|
|
||||||
} else {
|
|
||||||
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
|
|
||||||
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast(R.string.unknown_error_occurred)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Telephony.Sms.getDefaultSmsPackage(this) == packageName) {
|
|
||||||
askPermissions()
|
|
||||||
} else {
|
|
||||||
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
|
|
||||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)
|
|
||||||
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clearAllMessagesIfNeeded()
|
clearAllMessagesIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +129,27 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
|
super.onSaveInstanceState(outState)
|
||||||
|
outState.putBoolean(WAS_PROTECTION_HANDLED, wasProtectionHandled)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
|
super.onRestoreInstanceState(savedInstanceState)
|
||||||
|
wasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
|
||||||
|
|
||||||
|
if (!wasProtectionHandled) {
|
||||||
|
handleAppPasswordProtection {
|
||||||
|
wasProtectionHandled = it
|
||||||
|
if (it) {
|
||||||
|
loadMessages()
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupOptionsMenu() {
|
private fun setupOptionsMenu() {
|
||||||
main_menu.getToolbar().inflateMenu(R.menu.menu_main)
|
main_menu.getToolbar().inflateMenu(R.menu.menu_main)
|
||||||
main_menu.toggleHideOnScroll(true)
|
main_menu.toggleHideOnScroll(true)
|
||||||
@@ -213,6 +215,31 @@ class MainActivity : SimpleActivity() {
|
|||||||
main_menu.updateColors()
|
main_menu.updateColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadMessages() {
|
||||||
|
if (isQPlus()) {
|
||||||
|
val roleManager = getSystemService(RoleManager::class.java)
|
||||||
|
if (roleManager!!.isRoleAvailable(RoleManager.ROLE_SMS)) {
|
||||||
|
if (roleManager.isRoleHeld(RoleManager.ROLE_SMS)) {
|
||||||
|
askPermissions()
|
||||||
|
} else {
|
||||||
|
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
|
||||||
|
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toast(R.string.unknown_error_occurred)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (Telephony.Sms.getDefaultSmsPackage(this) == packageName) {
|
||||||
|
askPermissions()
|
||||||
|
} else {
|
||||||
|
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
|
||||||
|
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)
|
||||||
|
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// while SEND_SMS and READ_SMS permissions are mandatory, READ_CONTACTS is optional. If we don't have it, we just won't be able to show the contact name in some cases
|
// while SEND_SMS and READ_SMS permissions are mandatory, READ_CONTACTS is optional. If we don't have it, we just won't be able to show the contact name in some cases
|
||||||
private fun askPermissions() {
|
private fun askPermissions() {
|
||||||
handlePermission(PERMISSION_READ_SMS) {
|
handlePermission(PERMISSION_READ_SMS) {
|
||||||
|
Reference in New Issue
Block a user