From 232de4436c05f40f7f3a7c8afceaedb9cf2d7674 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 12 Jun 2016 21:13:09 +0200 Subject: add permission exception for android < Marshmallow --- .../eu/siacs/conversations/ui/ConversationActivity.java | 17 ++++++++++++----- src/main/java/eu/siacs/conversations/ui/startUI.java | 13 ++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 6c93a3acc..16d49ccf7 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -126,6 +126,8 @@ public class ConversationActivity extends XmppActivity private AtomicBoolean mRedirected = new AtomicBoolean(false); private Pair mPostponedActivityResult; + long FirstStartTime = 0; + @SuppressLint("NewApi") private static List extractUriFromIntent(final Intent intent) { List uris = new ArrayList<>(); @@ -1313,11 +1315,16 @@ public class ConversationActivity extends XmppActivity this.xmppConnectionService.getNotificationService().setIsInForeground(true); updateConversationList(); - long FirstStartTime = 0; - Bundle extras = getIntent().getExtras(); - if(extras != null) { - FirstStartTime = extras.getLong("FirstStart"); - } + Bundle extras = getIntent().getExtras(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (extras != null) { + FirstStartTime = extras.getLong("FirstStart"); + Log.d(Config.LOGTAG, "Get first start time from StartUI: " + FirstStartTime); + } + } else { + FirstStartTime = System.currentTimeMillis(); + Log.d(Config.LOGTAG, "Device is running Android < SDK 23, no restart required: " + FirstStartTime); + } if (mPendingConferenceInvite != null) { mPendingConferenceInvite.execute(this); diff --git a/src/main/java/eu/siacs/conversations/ui/startUI.java b/src/main/java/eu/siacs/conversations/ui/startUI.java index e69db94aa..5b919dbad 100644 --- a/src/main/java/eu/siacs/conversations/ui/startUI.java +++ b/src/main/java/eu/siacs/conversations/ui/startUI.java @@ -41,22 +41,21 @@ public class startUI extends AppCompatActivity @AfterPermissionGranted(NeededPermissions) private void requestNeededPermissions() { + String PREFS_NAME = "FirstStart"; + SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + long FirstStartTime = FirstStart.getLong("FirstStart", 0); if (EasyPermissions.hasPermissions(this, perms)) { // Already have permission, start ConversationsActivity - String PREFS_NAME = "FirstStart"; - SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - long FirstStartTime = FirstStart.getLong("FirstStart", 0); + Log.d(Config.LOGTAG, "All permissions granted, starting "+getString(R.string.app_name) + "(" +FirstStartTime + ")"); Intent intent = new Intent (this, ConversationActivity.class); intent.putExtra("FirstStart", FirstStartTime); startActivity(intent); finish(); } else { // set first start to 0 if there are permissions to request - String PREFS_NAME = "FirstStart"; - long FirstStartTime = 0; - SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + Log.d(Config.LOGTAG, "Requesting required permissions"); SharedPreferences.Editor editor = FirstStart.edit(); - editor.putLong("FirstStart", FirstStartTime); + editor.putLong("FirstStart", 0); editor.commit(); // Do not have permissions, request them now EasyPermissions.requestPermissions(this, getString(R.string.request_permissions_message), -- cgit v1.2.3