Fix a few more warnings

This commit is contained in:
CactiChameleon9 2024-08-31 12:34:35 +01:00
parent fa3f9b8ca5
commit c0a486383c
4 changed files with 11 additions and 4 deletions

View File

@ -6,6 +6,8 @@ import android.content.Intent;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import java.util.Objects;
/** /**
* Broadcast receiver class to help start or stop the traffic monitoring service when the phone's * Broadcast receiver class to help start or stop the traffic monitoring service when the phone's
* battery level is low or okay. * battery level is low or okay.
@ -20,7 +22,7 @@ public class BatteryReceiver extends BroadcastReceiver {
Log.v("BatteryReceiver", "Received a battery intent"); Log.v("BatteryReceiver", "Received a battery intent");
if (PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean("enabled", true) && if (PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean("enabled", true) &&
PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean("lowpower", false)) { 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"); Log.i("BatteryReceiver", "Battery low. Stopping service");
appContext.stopService(new Intent(appContext, TrafficService.class)); appContext.stopService(new Intent(appContext, TrafficService.class));
} else { } else {

View File

@ -5,6 +5,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.util.Objects;
/** /**
* Broadcast receiver class to help start the traffic monitoring service when the phone boots up only * Broadcast receiver class to help start the traffic monitoring service when the phone boots up only
* if the service is enabled. * if the service is enabled.
@ -16,6 +18,11 @@ public class BootReceiver extends BroadcastReceiver {
*/ */
@Override @Override
public void onReceive(Context appContext, Intent bootIntent) { 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)) { if (PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean("enabled", true)) {
appContext.startService(new Intent(appContext, TrafficService.class)); appContext.startService(new Intent(appContext, TrafficService.class));
} }

View File

@ -1,10 +1,8 @@
package com.mridang.speedo; package com.mridang.speedo;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import android.util.Log; import android.util.Log;

View File

@ -115,7 +115,7 @@ public class TrafficService extends Service {
notBuilder.setPriority(Integer.MAX_VALUE); notBuilder.setPriority(Integer.MAX_VALUE);
notBuilder.setCategory(NotificationCompat.CATEGORY_SERVICE); notBuilder.setCategory(NotificationCompat.CATEGORY_SERVICE);
notBuilder.setLocalOnly(true); notBuilder.setLocalOnly(true);
setColor(settings.getInt("color", Color.TRANSPARENT)); setColor(Color.TRANSPARENT);
visibilityPublic(settings.getBoolean("lockscreen", true)); visibilityPublic(settings.getBoolean("lockscreen", true));
Log.d("HardwareService", "Setting up the service manager and the broadcast receiver"); Log.d("HardwareService", "Setting up the service manager and the broadcast receiver");