Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
improve GNSS PSDS setting
Browse files Browse the repository at this point in the history
- do not hardcode URL paths
- use java.net.URL API instead of manual string concatenation
- improve logging
- disable PSDS when PSDS type is not specified instead of keeping it enabled in a broken state
  • Loading branch information
muhomorr authored and thestinger committed May 15, 2024
1 parent f03d5b6 commit 1d1afe3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
3 changes: 0 additions & 3 deletions core/java/android/ext/settings/GnssConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ public interface GnssConstants {
int SUPL_SERVER_GRAPHENEOS_PROXY = 2;

String PSDS_TYPE_QUALCOMM_XTRA = "qualcomm_xtra";
String PSDS_TYPE_BROADCOM = "broadcom";

String PSDS_SERVER_GRAPHENEOS_BROADCOM = "https://broadcom.psds.grapheneos.org";

// keep in sync with bionic/libc/bionic/gnss_psds_setting.c
int PSDS_SERVER_GRAPHENEOS = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -517,23 +519,46 @@ private static void applyConfigOverrides(Context ctx, Properties props) {
}

private static void applyPsdsConfigOverrides(Context ctx, Properties props) {
final int psdsMode = ExtSettings.GNSS_PSDS_STANDARD.get(ctx);

final String psdsType = ctx.getString(com.android.internal.R.string.config_gnssPsdsType);
Slog.d(TAG, "PSDS type: " + psdsType);

final int psdsMode;
if (psdsType.isEmpty()) {
Slog.e(TAG, "PSDS type is not specified, disabling PSDS");
psdsMode = GnssConstants.PSDS_DISABLED;
} else {
psdsMode = ExtSettings.GNSS_PSDS_STANDARD.get(ctx);
}

switch (psdsMode) {
case GnssConstants.PSDS_SERVER_GRAPHENEOS:
Slog.d(TAG, "PSDS: using the GrapheneOS server");
clearPsdsServerProps(props);
final String hostname = psdsType + ".psds.grapheneos.org";
Slog.d(TAG, "PSDS: using GrapheneOS server " + hostname);

for (String propName : getPsdsPropNames()) {
String origValue = props.getProperty(propName);
if (TextUtils.isEmpty(origValue)) {
continue;
}

final URL origUrl;
try {
origUrl = new URL(origValue);
} catch (MalformedURLException e) {
props.remove(propName);
Slog.e(TAG, "malformed value of " + propName + ": " + origValue, e);
continue;
}

switch (psdsType) {
case GnssConstants.PSDS_TYPE_BROADCOM:
final String host = GnssConstants.PSDS_SERVER_GRAPHENEOS_BROADCOM;
props.setProperty(CONFIG_LONGTERM_PSDS_SERVER_1, host + "/lto2.dat");
props.setProperty(CONFIG_NORMAL_PSDS_SERVER, host + "/rto.dat");
props.setProperty(CONFIG_REALTIME_PSDS_SERVER, host + "/rtistatus.dat");
break;
final URL url;
try {
url = new URL("https", hostname, origUrl.getFile());
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
final String urlString = url.toString();
props.setProperty(propName, urlString);
Slog.d(TAG, "overridden " + propName + " from " + origValue + " to " + urlString);
}
break;
case GnssConstants.PSDS_SERVER_STANDARD:
Expand All @@ -550,10 +575,18 @@ private static void applyPsdsConfigOverrides(Context ctx, Properties props) {
}

private static void clearPsdsServerProps(Properties props) {
props.remove(CONFIG_LONGTERM_PSDS_SERVER_1);
props.remove(CONFIG_LONGTERM_PSDS_SERVER_2);
props.remove(CONFIG_LONGTERM_PSDS_SERVER_3);
props.remove(CONFIG_NORMAL_PSDS_SERVER);
props.remove(CONFIG_REALTIME_PSDS_SERVER);
for (String n : getPsdsPropNames()) {
props.remove(n);
}
}

private static String[] getPsdsPropNames() {
return new String[] {
CONFIG_LONGTERM_PSDS_SERVER_1,
CONFIG_LONGTERM_PSDS_SERVER_2,
CONFIG_LONGTERM_PSDS_SERVER_3,
CONFIG_NORMAL_PSDS_SERVER,
CONFIG_REALTIME_PSDS_SERVER,
};
}
}

0 comments on commit 1d1afe3

Please sign in to comment.