@@ -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}
0 commit comments