Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] speculative fixes for performance on Android 14+ #723

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions wiglewifiwardriving/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ ext {
dependencies {
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "androidx.legacy:legacy-support-core-utils:1.0.0"
implementation "androidx.core:core:1.6.0"
implementation "androidx.appcompat:appcompat:1.4.2"
implementation "com.google.android.material:material:1.6.0"
implementation "com.google.android.gms:play-services-maps:18.1.0"
implementation "androidx.core:core:1.13.1"
implementation "androidx.appcompat:appcompat:1.7.0"
implementation "com.google.android.material:material:1.12.0"
implementation "com.google.android.gms:play-services-maps:18.2.0"
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'org.slf4j:slf4j-android:1.7.19'
Expand Down
3 changes: 2 additions & 1 deletion wiglewifiwardriving/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<!-- permission for start-on-boot -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Expand Down Expand Up @@ -302,7 +303,7 @@
<service
android:name=".WigleService"
android:enabled="true"
android:foregroundServiceType="location"
android:foregroundServiceType="location|dataSync"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding data sync to properties of background service thread, since database writes are a file operation

android:icon="@mipmap/ic_launcher" />
<uses-library
android:name="com.google.android.maps"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ServiceInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -286,8 +287,14 @@ public void setupNotification() {
notificationManager.notify(NOTIFICATION_ID, notification);
}
else {
Logging.info("service startForeground");
startForeground(NOTIFICATION_ID, notification);
if (SDK_INT >= Build.VERSION_CODES.R) {
Logging.info("service startForeground version R+");
startForeground(NOTIFICATION_ID, notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION | ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

special case to fix priority for startForeground for Android R+

Logging.info("service startForeground");
startForeground(NOTIFICATION_ID, notification);
}
}
} catch (Exception ex) {
Logging.error("notification service error: ", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteStatement;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Process;

import androidx.annotation.WorkerThread;

import com.google.android.gms.maps.model.LatLng;

/**
Expand All @@ -72,7 +75,9 @@ public final class DatabaseHelper extends Thread {
private static final int LEVEL_CHANGE = 5;
private static final String DATABASE_NAME = "wiglewifi"+SQL_EXT;
private static final String EXTERNAL_DATABASE_PATH = FileUtility.getSDPath();
private static final int DB_PRIORITY = Process.THREAD_PRIORITY_BACKGROUND;
private static final int DB_PRIORITY = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ?
/*Process.THREAD_PRIORITY_BACKGROUND |*/ Process.THREAD_PRIORITY_DEFAULT :
Process.THREAD_PRIORITY_BACKGROUND;
private static final Object TRANS_LOCK = new Object();

private static final long QUEUE_CULL_TIMEOUT = 10000L;
Expand Down Expand Up @@ -162,8 +167,8 @@ public final class DatabaseHelper extends Thread {

private SQLiteDatabase db;

private static final int MAX_QUEUE = 512;
private static final int MAX_DRAIN = 512; // seems to work fine slurping the whole darn thing
private static final int MAX_QUEUE = Build.VERSION_CODES.R >= Build.VERSION.SDK_INT ? 768 : 512;
private static final int MAX_DRAIN = MAX_QUEUE;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving more queue depth in R+

private static final String ERROR = "error";
private static final String EXCEPTION = "exception";
private final Context context;
Expand Down Expand Up @@ -713,6 +718,7 @@ public boolean addObservation( final Network network, final Location location, f
return false;
}

@WorkerThread
private boolean addObservation( final Network network, final int level, final Location location,
final boolean newForRun, final boolean frequencyChanged, final boolean typeMorphed ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ else if ( newOK && NETWORK_PROVIDER.equals( newLocation.getProvider() ) ) {
} else if (prevLocation == null || prevLocation.getTime() < currentLocation.getTime()) {
// initialize previous location
prevLocation = currentLocation;
} else if (prevLocation != null){
} else if (prevLocation != null) {
if (currentLocation.getTime() != prevLocation.getTime()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log message improvement

Logging.warn("Location timestamp (" + currentLocation.getTime() + ") < previous location timestamp (" + prevLocation.getTime() + ")");
//ALIBI: we're ignoring this rather than trying to slot it in only because we'd need an in-memory or DB route otherwise.
Expand Down
Loading