Skip to content

Commit

Permalink
Use ContextCompat.registerReceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
TuxPaper committed Sep 12, 2023
1 parent 4b0d6a4 commit d545ded
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;

import com.biglybt.android.client.*;
import com.biglybt.android.client.CorePrefs.CorePrefsChangedListener;
Expand Down Expand Up @@ -392,6 +393,9 @@ class ScreenReceiver
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (CorePrefs.DEBUG_CORE) {
logd("Screen " + action);
}
if (action == null) {
return;
}
Expand Down Expand Up @@ -1153,7 +1157,11 @@ public void onCreate() {
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
screenReceiver = new ScreenReceiver();
registerReceiver(screenReceiver, filter);
Intent intent = ContextCompat.registerReceiver(this, screenReceiver, filter,
ContextCompat.RECEIVER_EXPORTED);
if (CorePrefs.DEBUG_CORE) {
logd("registered Screen intent " + intent);
}
initChannels(this);
}

Expand Down Expand Up @@ -1712,18 +1720,14 @@ private void enableBatteryMonitoring(@NonNull Context context,
if (batteryReceiver != null) {
return;
}
IntentFilter intentFilterConnected = new IntentFilter(
Intent.ACTION_POWER_CONNECTED);
IntentFilter intentFilterDisconnected = new IntentFilter(
Intent.ACTION_POWER_DISCONNECTED);
IntentFilter filter = new IntentFilter(Intent.ACTION_POWER_CONNECTED);
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);

batteryReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (CorePrefs.DEBUG_CORE && intent.getAction() != null) {
boolean isConnected = intent.getAction().equals(
Intent.ACTION_POWER_CONNECTED);
logd("Battery connected? " + isConnected);
if (CorePrefs.DEBUG_CORE) {
logd("Battery received " + intent.getAction());
}
Core core = BiglyBTService.this.core;
if (core == null) {
Expand All @@ -1738,8 +1742,8 @@ public void onReceive(Context context, Intent intent) {
}
}
};
context.registerReceiver(batteryReceiver, intentFilterConnected);
context.registerReceiver(batteryReceiver, intentFilterDisconnected);
ContextCompat.registerReceiver(context, batteryReceiver, filter,
ContextCompat.RECEIVER_EXPORTED);
if (CorePrefs.DEBUG_CORE) {
logd("enableBatteryMonitoring: ");
}
Expand Down

0 comments on commit d545ded

Please sign in to comment.