Skip to content

Commit d7a71a1

Browse files
committed
Replace the community share switch with none/anonymous/key, share only own SDR input, warn when sharing anonymously, update AIS-catcher and bump version to 1.18 (118)
1 parent 34db5fd commit d7a71a1

8 files changed

Lines changed: 72 additions & 24 deletions

File tree

‎app/build.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.jvdegithub.aiscatcher"
1111
minSdk 23
1212
targetSdk 34
13-
versionCode 117
14-
versionName '1.17'
13+
versionCode 118
14+
versionName '1.18'
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
externalNativeBuild {

‎app/src/main/java/com/jvdegithub/aiscatcher/AisCatcherJava.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public interface AisCallback {
5858
static native int createTCPlistener(String p);
5959
static native int createWebViewer(String p);
6060

61-
static native int createSharing(boolean b, String key);
61+
static native int createSharing(boolean b, String key, boolean anonymous);
6262

6363
static native int setOwnMMSI(int mmsi, int mode, int interval);
6464

‎app/src/main/java/com/jvdegithub/aiscatcher/DeviceManager.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ public static DeviceType getDeviceType() {
156156
return deviceType;
157157
}
158158

159+
// Sources we receive ourselves. RTLTCP relays someone else's stream, so it is
160+
// excluded from the community feed.
161+
public static boolean isSharableSource() {
162+
return deviceType == DeviceType.RTLSDR || deviceType == DeviceType.AIRSPY ||
163+
deviceType == DeviceType.AIRSPYHF || deviceType == DeviceType.HACKRF ||
164+
deviceType == DeviceType.SPYSERVER;
165+
}
166+
159167
public static String getDeviceTypeDescription() {
160168

161169
switch (deviceType) {

‎app/src/main/java/com/jvdegithub/aiscatcher/Settings.java‎

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void setDefault(Context context) {
5858
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
5959

6060
preferences.edit().putString("sSHARINGKEY", "").commit();
61-
preferences.edit().putBoolean("sSHARING", false).commit();
61+
preferences.edit().putString("sSHARINGMODE", "ANONYMOUS").commit();
6262
preferences.edit().putBoolean("sAUTOSTART", false).commit();
6363
preferences.edit().putBoolean("sKEEPSCREENON", false).commit();
6464

@@ -125,6 +125,7 @@ static boolean setDefaultOnFirst(Context context) {
125125
boolean pref_set = preferences.getBoolean("pref_set", false);
126126
if (!pref_set) setDefault(context);
127127
preferences.edit().putBoolean("pref_set", true).commit();
128+
migrateSharing(context);
128129
return !pref_set;
129130
}
130131

@@ -169,7 +170,12 @@ static public int getModelType(Context context)
169170

170171
private void setSummaries() {
171172
setSummaryText(new String[]{"w1PORT","tPORT","tHOST","sPORT","sHOST","u1HOST","u1PORT","u2HOST","u2PORT", "u3HOST","u3PORT", "u4HOST","u4PORT", "s1PORT", "rFREQOFFSET", "sSHARINGKEY", "httpURL","httpUSER","httpID","httpINTERVAL"});
172-
setSummaryList(new String[]{"rTUNER","rRATE","sRATE","tRATE","tPROTOCOL","tTUNER","mRATE","hRATE","oMODEL_TYPE","oCGF_WIDE","httpPROTOCOL","oOWNMODE"});
173+
setSummaryList(new String[]{"rTUNER","rRATE","sRATE","tRATE","tPROTOCOL","tTUNER","mRATE","hRATE","oMODEL_TYPE","oCGF_WIDE","httpPROTOCOL","oOWNMODE","sSHARINGMODE"});
174+
175+
// a sharing key is only used in KEY mode, ListPreference cannot drive
176+
// android:dependency so the field is gated here
177+
findPreference("sSHARINGKEY").setEnabled(
178+
"KEY".equals(((ListPreference) findPreference("sSHARINGMODE")).getValue()));
173179

174180
EditTextPreference own = findPreference("oOWNMMSI");
175181
String mmsi = own.getText();
@@ -487,21 +493,44 @@ static private boolean SetWebViewerOutput(Context context) {
487493
return true;
488494
}
489495

490-
static private boolean SetSharing(Context context) {
491-
String defaultKey = "a6392e08-c57e-4e7a-a4fb-d73bfc7619ae";
496+
static final String ANONYMOUS_KEY = "a6392e08-c57e-4e7a-a4fb-d73bfc7619ae";
492497

498+
// Carry the old on/off switch over to the three-way mode. Sharing was off by
499+
// default, so anyone who never touched it keeps it off rather than being opted
500+
// in by the new Anonymous default.
501+
static public void migrateSharing(Context context) {
493502
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
494503

495-
boolean b = preferences.getBoolean("sSHARING", false);
496-
if (b) {
497-
String key = preferences.getString("sSHARINGKEY", defaultKey);
498-
if (key.equals("")) key = defaultKey;
499-
return AisCatcherJava.createSharing(b, key) == 0;
504+
if (preferences.contains("sSHARINGMODE") || !preferences.contains("sSHARING")) return;
505+
506+
String mode = "NONE";
507+
if (preferences.getBoolean("sSHARING", false))
508+
mode = preferences.getString("sSHARINGKEY", "").isEmpty() ? "ANONYMOUS" : "KEY";
509+
510+
preferences.edit().putString("sSHARINGMODE", mode).remove("sSHARING").commit();
511+
}
512+
513+
static private boolean SetSharing(Context context) {
514+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
515+
516+
String mode = preferences.getString("sSHARINGMODE", "ANONYMOUS");
500517

518+
// relayed input is not ours to contribute, only what we receive ourselves
519+
if (mode.equals("NONE") || !DeviceManager.isSharableSource()) {
520+
AisCatcherJava.createSharing(false, ANONYMOUS_KEY, false);
521+
return true;
501522
}
502-
else
503-
AisCatcherJava.createSharing(b, defaultKey);
504-
return true;
523+
524+
String key = ANONYMOUS_KEY;
525+
boolean anonymous = true;
526+
527+
if (mode.equals("KEY")) {
528+
key = preferences.getString("sSHARINGKEY", "");
529+
anonymous = key.isEmpty();
530+
if (anonymous) key = ANONYMOUS_KEY;
531+
}
532+
533+
return AisCatcherJava.createSharing(true, key, anonymous) == 0;
505534
}
506535

507536
}

‎app/src/main/jni/JNI/AIScatcherNDK.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,18 @@ Java_com_jvdegithub_aiscatcher_AisCatcherJava_createWebViewer(JNIEnv *env, jclas
677677
extern "C"
678678
JNIEXPORT jint JNICALL
679679
Java_com_jvdegithub_aiscatcher_AisCatcherJava_createSharing(JNIEnv *env, jclass clazz, jboolean b,
680-
jstring k) {
680+
jstring k, jboolean anonymous) {
681681
if(b) {
682682
jboolean isCopy;
683683
std::string key = toString(env,k);
684684

685685
sharing = communityFeed = true;
686686
sharingKey = key;
687-
Info() << "Community Sharing: " << key;
687+
688+
if(anonymous)
689+
Warning() << "Sharing anonymously with the aiscatcher.org community. Choose Settings > Community Share to add your own sharing key or to stop sharing.";
690+
else
691+
Info() << "Community Sharing: " << key;
688692
}
689693
else {
690694
sharing = communityFeed = false;

‎app/src/main/res/values/arrays.xml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<item>Auto</item><item>1</item><item>2</item><item>3</item><item>4</item><item>5</item><item>6</item><item>7</item><item>8</item><item>9</item><item>10</item><item>11</item><item>12</item><item>13</item><item>14</item><item>15</item><item>16</item><item>17</item><item>18</item><item>19</item><item>20</item><item>21</item><item>22</item><item>23</item><item>24</item><item>25</item><item>26</item><item>27</item><item>28</item><item>29</item><item>30</item><item>31</item><item>32</item><item>33</item><item>34</item><item>35</item><item>36</item><item>37</item><item>38</item><item>39</item><item>40</item><item>41</item><item>42</item><item>43</item><item>44</item><item>45</item><item>46</item><item>47</item><item>48</item><item>49</item><item>50</item>
55
</string-array>
66

7+
<string-array name="sharing_mode_entries">
8+
<item>None</item><item>Anonymous</item><item>Sharing key</item>
9+
</string-array>
10+
11+
<string-array name="sharing_mode_values">
12+
<item>NONE</item><item>ANONYMOUS</item><item>KEY</item>
13+
</string-array>
14+
715
<string-array name="rtltcp_rate_array">
816
<item>240K</item><item>288K</item><item>1536K</item><item>2304K</item>
917
</string-array>

‎app/src/main/res/xml/preferences.xml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
android:key="system_category"
77
android:title="System">
88

9-
<SwitchPreferenceCompat
10-
android:key="sSHARING"
11-
android:summary="Share AIS with aiscatcher.org"
12-
android:defaultValue="False"
9+
<ListPreference
10+
android:key="sSHARINGMODE"
11+
android:entries="@array/sharing_mode_entries"
12+
android:entryValues="@array/sharing_mode_values"
13+
android:defaultValue="ANONYMOUS"
1314
android:title="Community Share"/>
1415

1516
<EditTextPreference
@@ -300,7 +301,6 @@
300301

301302
<SwitchPreferenceCompat
302303
android:key="u3SWITCH"
303-
android:dependency="sSHARING"
304304
android:defaultValue="False"
305305
android:title="UDP Server 3"/>
306306

@@ -324,7 +324,6 @@
324324

325325
<SwitchPreferenceCompat
326326
android:key="u4SWITCH"
327-
android:dependency="sSHARING"
328327
android:defaultValue="False"
329328
android:title="UDP Server 4"/>
330329

0 commit comments

Comments
 (0)