Improve device transfer reliability.

This commit is contained in:
Cody Henthorne
2026-03-27 16:51:27 -04:00
committed by Alex Hart
parent 0c4c280a50
commit 3e9146a6f5
3 changed files with 25 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
@@ -47,6 +48,7 @@ public class DeviceToDeviceTransferService extends Service implements ShutdownCa
private DeviceTransferServer server;
private DeviceTransferClient client;
private PowerManager.WakeLock wakeLock;
private WifiManager.WifiLock wifiLock;
public static void startServer(@NonNull Context context,
@NonNull ServerTask serverTask,
@@ -121,6 +123,10 @@ public class DeviceToDeviceTransferService extends Service implements ShutdownCa
wakeLock.release();
}
if (wifiLock != null && wifiLock.isHeld()) {
wifiLock.release();
}
super.onDestroy();
}
@@ -207,6 +213,17 @@ public class DeviceToDeviceTransferService extends Service implements ShutdownCa
if (!wakeLock.isHeld()) {
wakeLock.acquire(TimeUnit.HOURS.toMillis(2));
}
if (wifiLock == null) {
WifiManager wifiManager = ContextCompat.getSystemService(this, WifiManager.class);
if (wifiManager != null) {
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "signal:d2dwifi");
}
}
if (wifiLock != null && !wifiLock.isHeld()) {
wifiLock.acquire();
}
}
private void updateNotification(@NonNull TransferStatus transferStatus) {