diff --git a/app/src/main/java/com/mridang/speedo/BatteryReceiver.java b/app/src/main/java/com/mridang/speedo/BatteryReceiver.java index f62c6db..023a6a1 100644 --- a/app/src/main/java/com/mridang/speedo/BatteryReceiver.java +++ b/app/src/main/java/com/mridang/speedo/BatteryReceiver.java @@ -6,6 +6,8 @@ import android.content.Intent; import androidx.preference.PreferenceManager; import android.util.Log; +import java.util.Objects; + /** * Broadcast receiver class to help start or stop the traffic monitoring service when the phone's * battery level is low or okay. @@ -20,7 +22,7 @@ public class BatteryReceiver extends BroadcastReceiver { Log.v("BatteryReceiver", "Received a battery intent"); if (PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean("enabled", true) && PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean("lowpower", false)) { - if (ittIntent.getAction().equals(Intent.ACTION_BATTERY_LOW)) { + if (Objects.equals(ittIntent.getAction(), Intent.ACTION_BATTERY_LOW)) { Log.i("BatteryReceiver", "Battery low. Stopping service"); appContext.stopService(new Intent(appContext, TrafficService.class)); } else { diff --git a/app/src/main/java/com/mridang/speedo/BootReceiver.java b/app/src/main/java/com/mridang/speedo/BootReceiver.java index 9bfc129..04f0c9b 100644 --- a/app/src/main/java/com/mridang/speedo/BootReceiver.java +++ b/app/src/main/java/com/mridang/speedo/BootReceiver.java @@ -5,6 +5,8 @@ import android.content.Context; import android.content.Intent; import androidx.preference.PreferenceManager; +import java.util.Objects; + /** * Broadcast receiver class to help start the traffic monitoring service when the phone boots up only * if the service is enabled. @@ -16,6 +18,11 @@ public class BootReceiver extends BroadcastReceiver { */ @Override public void onReceive(Context appContext, Intent bootIntent) { + if (!(Objects.equals(bootIntent.getAction(), Intent.ACTION_BOOT_COMPLETED)) + || Objects.equals(bootIntent.getAction(), Intent.ACTION_MY_PACKAGE_REPLACED)) { + return; + } + if (PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean("enabled", true)) { appContext.startService(new Intent(appContext, TrafficService.class)); } diff --git a/app/src/main/java/com/mridang/speedo/PowerReceiver.java b/app/src/main/java/com/mridang/speedo/PowerReceiver.java index 2f144fc..9a3cef1 100644 --- a/app/src/main/java/com/mridang/speedo/PowerReceiver.java +++ b/app/src/main/java/com/mridang/speedo/PowerReceiver.java @@ -1,10 +1,8 @@ package com.mridang.speedo; -import android.annotation.TargetApi; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.Build; import android.os.PowerManager; import androidx.preference.PreferenceManager; import android.util.Log; diff --git a/app/src/main/java/com/mridang/speedo/TrafficService.java b/app/src/main/java/com/mridang/speedo/TrafficService.java index a2c606f..3fc8433 100644 --- a/app/src/main/java/com/mridang/speedo/TrafficService.java +++ b/app/src/main/java/com/mridang/speedo/TrafficService.java @@ -115,7 +115,7 @@ public class TrafficService extends Service { notBuilder.setPriority(Integer.MAX_VALUE); notBuilder.setCategory(NotificationCompat.CATEGORY_SERVICE); notBuilder.setLocalOnly(true); - setColor(settings.getInt("color", Color.TRANSPARENT)); + setColor(Color.TRANSPARENT); visibilityPublic(settings.getBoolean("lockscreen", true)); Log.d("HardwareService", "Setting up the service manager and the broadcast receiver");