Fix a bunch of warnings

This commit is contained in:
CactiChameleon9 2024-08-31 12:08:44 +01:00
parent 937909a985
commit fa3f9b8ca5
2 changed files with 15 additions and 12 deletions

View File

@ -18,7 +18,6 @@ public class PowerReceiver extends BroadcastReceiver {
/** /**
* Receiver method for the phone boot that starts the traffic monitoring service * Receiver method for the phone boot that starts the traffic monitoring service
*/ */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override @Override
public void onReceive(Context appContext, Intent bootIntent) { public void onReceive(Context appContext, Intent bootIntent) {
Log.v("BatteryReceiver", "Received a power intent"); Log.v("BatteryReceiver", "Received a power intent");

View File

@ -23,6 +23,7 @@ import android.os.Binder;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.PowerManager; import android.os.PowerManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -31,6 +32,10 @@ import android.telephony.TelephonyManager;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.Log; import android.util.Log;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/** /**
* Main service class that monitors the network speed and updates the notification every second * Main service class that monitors the network speed and updates the notification every second
*/ */
@ -100,8 +105,8 @@ public class TrafficService extends Service {
Intent ittSettings = new Intent(); Intent ittSettings = new Intent();
ittSettings.setComponent(new ComponentName("com.android.settings", CMP)); ittSettings.setComponent(new ComponentName("com.android.settings", CMP));
PendingIntent pitSettings = PendingIntent.getActivity(this, 0, ittSettings, PendingIntent.FLAG_IMMUTABLE); PendingIntent pitSettings = PendingIntent.getActivity(getApplicationContext(), 0, ittSettings, PendingIntent.FLAG_IMMUTABLE);
notBuilder = new NotificationCompat.Builder(this); notBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
notBuilder.setSmallIcon(R.drawable.wkb000); notBuilder.setSmallIcon(R.drawable.wkb000);
notBuilder.setContentIntent(pitSettings); notBuilder.setContentIntent(pitSettings);
notBuilder.setOngoing(true); notBuilder.setOngoing(true);
@ -110,7 +115,6 @@ 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);
notBuilder.setChannelId(CHANNEL_ID);
setColor(settings.getInt("color", Color.TRANSPARENT)); setColor(settings.getInt("color", Color.TRANSPARENT));
visibilityPublic(settings.getBoolean("lockscreen", true)); visibilityPublic(settings.getBoolean("lockscreen", true));
@ -134,7 +138,7 @@ public class TrafficService extends Service {
@Override @Override
public void onReceive(Context ctcContext, Intent ittIntent) { public void onReceive(Context ctcContext, Intent ittIntent) {
if (ittIntent.getAction().equalsIgnoreCase(Intent.ACTION_SCREEN_OFF)) { if (Objects.requireNonNull(ittIntent.getAction()).equalsIgnoreCase(Intent.ACTION_SCREEN_OFF)) {
Log.d("TrafficService", "Screen off; hiding the notification"); Log.d("TrafficService", "Screen off; hiding the notification");
hndNotifier.removeMessages(1); hndNotifier.removeMessages(1);
@ -170,11 +174,9 @@ public class TrafficService extends Service {
ittScreen.addAction(ConnectivityManager.CONNECTIVITY_ACTION); ittScreen.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(recScreen, ittScreen); registerReceiver(recScreen, ittScreen);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { IntentFilter ittSaver = new IntentFilter();
IntentFilter ittSaver = new IntentFilter(); ittScreen.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
ittScreen.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); registerReceiver(recSaver, ittSaver);
registerReceiver(recSaver, ittSaver);
}
} }
/** /**
@ -318,9 +320,11 @@ public class TrafficService extends Service {
*/ */
@SuppressLint("CommitPrefEdits") @SuppressLint("CommitPrefEdits")
public NotificationHandler(Context ctxContext) { public NotificationHandler(Context ctxContext) {
super(Looper.getMainLooper());
this.ctxContext = ctxContext; this.ctxContext = ctxContext;
} }
/** /**
* Handler method that updates the notification icon with the current speed. It is a very * Handler method that updates the notification icon with the current speed. It is a very
* hackish method. We have icons for 1 KB/s to 999 KB/s and 1.0 MB/s to 99.9 MB/s. Every time * hackish method. We have icons for 1 KB/s to 999 KB/s and 1.0 MB/s to 99.9 MB/s. Every time
@ -332,7 +336,7 @@ public class TrafficService extends Service {
* integer references of the drawables in the sequential order. * integer references of the drawables in the sequential order.
*/ */
@Override @Override
public void handleMessage(Message msgMessage) { public void handleMessage(@NotNull Message msgMessage) {
TrafficService.hndNotifier.sendEmptyMessageDelayed(1, 1000L); TrafficService.hndNotifier.sendEmptyMessageDelayed(1, 1000L);
@ -368,7 +372,7 @@ public class TrafficService extends Service {
updateIcon(1180 + R.drawable.wkb000); updateIcon(1180 + R.drawable.wkb000);
} }
Long lngTotal = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes(); long lngTotal = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes();
String strTotal = Formatter.formatFileSize(this.ctxContext, lngTotal); String strTotal = Formatter.formatFileSize(this.ctxContext, lngTotal);
TrafficService.notBuilder.setContentInfo(strTotal); TrafficService.notBuilder.setContentInfo(strTotal);
TrafficService.mgrNotifications.notify(ID, TrafficService.notBuilder.build()); TrafficService.mgrNotifications.notify(ID, TrafficService.notBuilder.build());