Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
implement battery optimization setting request
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironrabbit committed May 30, 2018
1 parent 52de466 commit 6b0a6f5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/org/awesomeapp/messenger/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.PowerManager;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
Expand Down Expand Up @@ -255,6 +257,11 @@ public void onClick(View view) {

applyStyle();

if (Preferences.doCheckBatteryOptimizations())
{
requestChangeBatteryOptimizations();
Preferences.checkedBatteryOptimizations();
}
}

private void installRingtones ()
Expand Down Expand Up @@ -1290,4 +1297,36 @@ private void checkCustomFont ()

}

private void requestChangeBatteryOptimizations ()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle(R.string.battery_opt_title)
.setMessage(R.string.battery_opt_message)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {


Intent myIntent = new Intent();
myIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
startActivity(myIntent);

}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {

/* User clicked cancel so do some stuff */
dialog.dismiss();
}
})
.create();
dialog.show();
}

}

}
5 changes: 5 additions & 0 deletions app/src/main/java/org/awesomeapp/messenger/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,9 @@ public static int getProxyServerPort ()

public static boolean doGroupEncryption () { return preferences.getBoolean("prefGroupEncryption", false);}

public static boolean doCheckBatteryOptimizations () { return preferences.getBoolean("prefCheckBattery",true); };

public static void checkedBatteryOptimizations () {
preferences.edit().putBoolean("prefCheckBattery", false).apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,10 @@ public int sendMessageAsync(Message message, boolean sendOmemo) {
mCanOmemo = mManager.resourceSupportsOmemo(mJid);
}

if (mCanOmemo) {
if (mCanOmemo && otrStatus != SessionStatus.ENCRYPTED) {
mManager.sendMessageAsync(this, message);
} else {


//do OTR!

if (otrStatus == SessionStatus.ENCRYPTED) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@
<string name="action_resend">Resend</string>
<string name="title_activity_nearby">NearbyActivity</string>
<string name="nearby_not_supported">Nearby sharing not supported on this device</string>
<string name="battery_opt_title">Battery Optimization</string>
<string name="battery_opt_message">Ensure Zom receives messages in the background, by disabling battery optimizations</string>


</resources>

0 comments on commit 6b0a6f5

Please sign in to comment.