Target Android SDK 35

This commit is contained in:
Nico
2025-10-27 11:36:19 +01:00
committed by akwizgran
parent 070a0181d9
commit 65f4f09d8f
34 changed files with 366 additions and 118 deletions

View File

@@ -1,6 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.briarproject.bramble">
xmlns:tools="http://schemas.android.com/tools">
<uses-feature
android:name="android.hardware.bluetooth"

View File

@@ -53,7 +53,7 @@ class AndroidBatteryManager implements BatteryManager, Service {
public boolean isCharging() {
// Get the sticky intent for ACTION_BATTERY_CHANGED
IntentFilter filter = new IntentFilter(ACTION_BATTERY_CHANGED);
Intent i = registerReceiver(appContext, null, filter);
Intent i = registerReceiver(appContext, null, filter, false);
if (i == null) return false;
int status = i.getIntExtra(EXTRA_PLUGGED, 0);
return status != 0;
@@ -72,7 +72,7 @@ class AndroidBatteryManager implements BatteryManager, Service {
filter.addAction(ACTION_LOW_POWER_STANDBY_ENABLED_CHANGED);
filter.addAction(ACTION_DEVICE_LIGHT_IDLE_MODE_CHANGED);
}
registerReceiver(appContext, batteryReceiver, filter);
registerReceiver(appContext, batteryReceiver, filter, false);
}
@Override

View File

@@ -104,7 +104,7 @@ class AndroidNetworkManager implements NetworkManager, Service {
filter.addAction(WIFI_AP_STATE_CHANGED_ACTION);
filter.addAction(WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
if (SDK_INT >= 23) filter.addAction(ACTION_DEVICE_IDLE_MODE_CHANGED);
registerReceiver(app, networkStateReceiver, filter);
registerReceiver(app, networkStateReceiver, filter, false);
}
@Override

View File

@@ -113,7 +113,7 @@ class AndroidBluetoothPlugin extends
filter.addAction(ACTION_STATE_CHANGED);
filter.addAction(ACTION_SCAN_MODE_CHANGED);
receiver = new BluetoothStateReceiver();
registerReceiver(app, receiver, filter);
registerReceiver(app, receiver, filter, true);
}
@Override
@@ -238,7 +238,7 @@ class AndroidBluetoothPlugin extends
filter.addAction(ACTION_DISCOVERY_STARTED);
filter.addAction(ACTION_DISCOVERY_FINISHED);
filter.addAction(ACTION_FOUND);
registerReceiver(app, receiver, filter);
registerReceiver(app, receiver, filter, true);
try {
if (adapter.startDiscovery()) {
long now = clock.currentTimeMillis();

View File

@@ -18,23 +18,30 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.content.Context.MODE_PRIVATE;
import static android.content.Context.RECEIVER_EXPORTED;
import static android.content.Context.RECEIVER_NOT_EXPORTED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Process.myPid;
import static android.os.Process.myUid;
import static java.util.Arrays.asList;
import static java.util.logging.Level.INFO;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.nullsafety.NullSafety.requireNonNull;
@NotNullByDefault
public class AndroidUtils {
private static final Logger LOG =
getLogger(AndroidUtils.class.getName());
// Fake Bluetooth address returned by BluetoothAdapter on API 23 and later
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
@@ -60,11 +67,20 @@ public class AndroidUtils {
// If we don't have permission to access the adapter's address, let
// the caller know we can't find it
if (!hasBtConnectPermission(ctx)) return new Pair<>("", "");
// Return the adapter's address if it's valid and not fake
@SuppressLint("HardwareIds")
String address = adapter.getAddress();
if (isValidBluetoothAddress(address)) {
return new Pair<>(address, "adapter");
String address;
// Return the adapter's address if it's valid and not fake
try {
address = adapter.getAddress();
if (isValidBluetoothAddress(address)) {
return new Pair<>(address, "adapter");
}
} catch (SecurityException e) {
if (LOG.isLoggable(INFO)) {
LOG.info("Security exception when getting BT address: " +
e.getMessage());
}
}
// Return the address from settings if it's valid and not fake
if (SDK_INT < 33) {
@@ -153,10 +169,11 @@ public class AndroidUtils {
@Nullable
@SuppressLint("UnspecifiedRegisterReceiverFlag") // we specify where needed
public static Intent registerReceiver(Context ctx,
@Nullable BroadcastReceiver receiver, IntentFilter filter) {
@Nullable BroadcastReceiver receiver, IntentFilter filter,
boolean export) {
if (SDK_INT >= 33) {
return ctx.registerReceiver(receiver, filter,
RECEIVER_NOT_EXPORTED);
export ? RECEIVER_EXPORTED : RECEIVER_NOT_EXPORTED);
} else {
return ctx.registerReceiver(receiver, filter);
}