From e6a9829dd2b275f80231b19930fbb75b209f4c2e Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 6 Mar 2016 15:53:49 +0100 Subject: don't show opt-out of battery optimization dialog when push is enabled --- .../eu/siacs/conversations/ui/ConversationActivity.java | 14 +++++++++++++- .../eu/siacs/conversations/ui/EditAccountActivity.java | 5 +++-- src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src/main/java/eu/siacs/conversations') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index eac531242..aee923f63 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1353,7 +1353,9 @@ public class ConversationActivity extends XmppActivity } private void openBatteryOptimizationDialogIfNeeded() { - if (showBatteryOptimizationWarning() && getPreferences().getBoolean("show_battery_optimization", true)) { + if (hasAccountWithoutPush() + && isOptimizingBattery() + && getPreferences().getBoolean("show_battery_optimization", true)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.battery_optimizations_enabled); builder.setMessage(R.string.battery_optimizations_enabled_dialog); @@ -1378,6 +1380,16 @@ public class ConversationActivity extends XmppActivity } } + private boolean hasAccountWithoutPush() { + for(Account account : xmppConnectionService.getAccounts()) { + if (account.getStatus() != Account.State.DISABLED + && !xmppConnectionService.getPushManagementService().available(account)) { + return true; + } + } + return false; + } + private void attachLocationToConversation(Conversation conversation, Uri uri) { if (conversation == null) { return; diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index b6f1b430c..ed80a509f 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -641,11 +641,12 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mRegisterNew.setChecked(false); } if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) { + Features features = this.mAccount.getXmppConnection().getFeatures(); this.mStats.setVisibility(View.VISIBLE); - this.mBatteryOptimizations.setVisibility(showBatteryOptimizationWarning() ? View.VISIBLE : View.GONE); + boolean showOptimizingWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery(); + this.mBatteryOptimizations.setVisibility(showOptimizingWarning ? View.VISIBLE : View.GONE); this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection() .getLastSessionEstablished())); - Features features = this.mAccount.getXmppConnection().getFeatures(); if (features.rosterVersioning()) { this.mServerInfoRosterVersion.setText(R.string.server_info_available); } else { diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 5682f7853..baf40b223 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -391,7 +391,7 @@ public abstract class XmppActivity extends Activity { return super.onCreateOptionsMenu(menu); } - protected boolean showBatteryOptimizationWarning() { + protected boolean isOptimizingBattery() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); return !pm.isIgnoringBatteryOptimizations(getPackageName()); -- cgit v1.2.3