added account permission detection to prevent crash

This commit is contained in:
Mariotaku Lee 2017-01-29 21:02:59 +08:00
parent bd1ec749dd
commit 95f80b222e
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 14 additions and 0 deletions

View File

@ -189,6 +189,15 @@ public class AccountUtils {
return null;
}
public static boolean hasAccountPermission(@NonNull AccountManager am) {
try {
getAccounts(am);
} catch (SecurityException e) {
return false;
}
return true;
}
public static boolean hasInvalidAccount(@NonNull AccountManager am) {
for (Account account : getAccounts(am)) {
if (!isAccountValid(am, account)) return true;

View File

@ -22,7 +22,9 @@ package org.mariotaku.twidere.activity
import android.accounts.AccountManager
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.R
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_INTENT
import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.util.StrictModeUtils
@ -39,6 +41,8 @@ open class MainActivity : BaseActivity() {
val am = AccountManager.get(this)
if (!Utils.checkDeviceCompatible()) {
startActivity(Intent(this, IncompatibleAlertActivity::class.java))
} else if (!AccountUtils.hasAccountPermission(am)) {
Toast.makeText(this, R.string.message_toast_no_account_permission, Toast.LENGTH_SHORT).show()
} else if (AccountUtils.hasInvalidAccount(am)) {
val intent = Intent(this, InvalidAccountAlertActivity::class.java)
intent.putExtra(EXTRA_INTENT, Intent(this, HomeActivity::class.java))

View File

@ -696,6 +696,7 @@
<!-- Toast message for network errors -->
<string name="message_toast_network_error">Network error</string>
<string name="message_toast_no_account">No account</string>
<string name="message_toast_no_account_permission">Account permission is required</string>
<string name="message_toast_no_account_selected">No account selected</string>
<string name="message_toast_no_user_selected">No user selected</string>
<string name="message_toast_press_again_to_close">Press again to close</string>