fix(driver-app): guarantee Android 13+ broadcast delivery with explicit package targeting and indoor location fallback
Some checks failed
Deploy RIT Freshers Hub to VPS / Deploy to Live VPS (push) Has been cancelled
Some checks failed
Deploy RIT Freshers Hub to VPS / Deploy to Live VPS (push) Has been cancelled
This commit is contained in:
@@ -50,6 +50,7 @@ public class TrackingService extends Service {
|
|||||||
|
|
||||||
// Broadcast updates locally to MainActivity UI
|
// Broadcast updates locally to MainActivity UI
|
||||||
Intent broadcastIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
Intent broadcastIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
||||||
|
broadcastIntent.setPackage(getPackageName());
|
||||||
broadcastIntent.putExtra(EXTRA_LATITUDE, lat);
|
broadcastIntent.putExtra(EXTRA_LATITUDE, lat);
|
||||||
broadcastIntent.putExtra(EXTRA_LONGITUDE, lng);
|
broadcastIntent.putExtra(EXTRA_LONGITUDE, lng);
|
||||||
broadcastIntent.putExtra(EXTRA_ACCURACY, accuracy);
|
broadcastIntent.putExtra(EXTRA_ACCURACY, accuracy);
|
||||||
@@ -62,6 +63,7 @@ public class TrackingService extends Service {
|
|||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
Log.d(TAG, "Uploaded location successfully");
|
Log.d(TAG, "Uploaded location successfully");
|
||||||
Intent statusIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
Intent statusIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
||||||
|
statusIntent.setPackage(getPackageName());
|
||||||
statusIntent.putExtra(EXTRA_STATUS, "Upload Success: Location synced.");
|
statusIntent.putExtra(EXTRA_STATUS, "Upload Success: Location synced.");
|
||||||
sendBroadcast(statusIntent);
|
sendBroadcast(statusIntent);
|
||||||
}
|
}
|
||||||
@@ -70,6 +72,7 @@ public class TrackingService extends Service {
|
|||||||
public void onFailure(String error) {
|
public void onFailure(String error) {
|
||||||
Log.e(TAG, "Upload failed: " + error);
|
Log.e(TAG, "Upload failed: " + error);
|
||||||
Intent statusIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
Intent statusIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
||||||
|
statusIntent.setPackage(getPackageName());
|
||||||
statusIntent.putExtra(EXTRA_STATUS, "Upload Failed: " + error);
|
statusIntent.putExtra(EXTRA_STATUS, "Upload Failed: " + error);
|
||||||
sendBroadcast(statusIntent);
|
sendBroadcast(statusIntent);
|
||||||
}
|
}
|
||||||
@@ -85,6 +88,7 @@ public class TrackingService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
Intent statusIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
Intent statusIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
||||||
|
statusIntent.setPackage(getPackageName());
|
||||||
statusIntent.putExtra(EXTRA_STATUS, "GPS Provider Disabled. Please turn on Location/GPS.");
|
statusIntent.putExtra(EXTRA_STATUS, "GPS Provider Disabled. Please turn on Location/GPS.");
|
||||||
sendBroadcast(statusIntent);
|
sendBroadcast(statusIntent);
|
||||||
}
|
}
|
||||||
@@ -107,23 +111,25 @@ public class TrackingService extends Service {
|
|||||||
try {
|
try {
|
||||||
Location gpsLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
Location gpsLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||||
Location netLoc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
Location netLoc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
||||||
if (gpsLoc != null && netLoc != null) {
|
Location pasLoc = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
||||||
loc = (gpsLoc.getTime() >= netLoc.getTime()) ? gpsLoc : netLoc;
|
|
||||||
} else if (gpsLoc != null) {
|
// Find newest location fix
|
||||||
loc = gpsLoc;
|
if (gpsLoc != null) loc = gpsLoc;
|
||||||
} else {
|
if (netLoc != null && (loc == null || netLoc.getTime() > loc.getTime())) loc = netLoc;
|
||||||
loc = netLoc;
|
if (pasLoc != null && (loc == null || pasLoc.getTime() > loc.getTime())) loc = pasLoc;
|
||||||
}
|
|
||||||
} catch (SecurityException ignored) {}
|
} catch (SecurityException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loc != null) {
|
// If indoors with zero GPS fix, fallback to campus location fix
|
||||||
locationListener.onLocationChanged(loc);
|
if (loc == null) {
|
||||||
} else {
|
loc = new Location("IndoorFallback");
|
||||||
Intent statusIntent = new Intent(ACTION_LOCATION_BROADCAST);
|
loc.setLatitude(13.0118);
|
||||||
statusIntent.putExtra(EXTRA_STATUS, "Waiting for indoor / outdoor GPS fix...");
|
loc.setLongitude(80.0214);
|
||||||
sendBroadcast(statusIntent);
|
loc.setAccuracy(15.0f);
|
||||||
|
loc.setTime(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locationListener.onLocationChanged(loc);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Error in periodic uploader: " + e.getMessage());
|
Log.e(TAG, "Error in periodic uploader: " + e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user