Skip to content

Commit 8fd7de5

Browse files
committed
rework offline/online switch and bootstrapping, and use the log friend
1 parent d9e177a commit 8fd7de5

File tree

6 files changed

+130
-203
lines changed

6 files changed

+130
-203
lines changed

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/ConnectionManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import android.net.NetworkInfo;
88
import android.util.Log;
99

10+
import static com.zoffcc.applications.trifa.HelperGeneric.append_logger_msg;
1011
import static com.zoffcc.applications.trifa.TRIFAGlobals.HAVE_INTERNET_CONNECTIVITY;
12+
import static com.zoffcc.applications.trifa.TrifaToxService.bootstrap_me;
1113

1214
public class ConnectionManager extends BroadcastReceiver
1315
{
@@ -21,7 +23,15 @@ public void onReceive(Context context, Intent intent)
2123
Log.i(TAG, "onReceive:intent=" + intent);
2224

2325
boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
26+
final boolean connectivity_old = HAVE_INTERNET_CONNECTIVITY;
2427
HAVE_INTERNET_CONNECTIVITY = !noConnectivity;
28+
append_logger_msg(TAG + "::" + "HAVE_INTERNET_CONNECTIVITY=" + HAVE_INTERNET_CONNECTIVITY + " connectivity_old=" + connectivity_old);
29+
30+
if ((connectivity_old != HAVE_INTERNET_CONNECTIVITY) && (HAVE_INTERNET_CONNECTIVITY == true))
31+
{
32+
append_logger_msg(TAG + "::" + "bootstrap_me()");
33+
bootstrap_me(false);
34+
}
2535

2636
NetworkInfo info1 = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
2737
NetworkInfo info2 = intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
@@ -31,6 +41,9 @@ public void onReceive(Context context, Intent intent)
3141
Log.i(TAG, "onReceive:failOver=" + failOver);
3242
Log.i(TAG, "onReceive:noConnectivity=" + noConnectivity);
3343
Log.i(TAG, "onReceive: mNetworkInfo=" + info1 + " mOtherNetworkInfo = " + (info2 == null ? "[none]" : info2 + " noConn=" + noConnectivity));
44+
append_logger_msg(TAG + "::" + "reason=" + reason + " failOver=" + failOver);
45+
append_logger_msg(TAG + "::" + "mNetworkInfo=" + info1);
46+
append_logger_msg(TAG + "::" + "mOtherNetworkInfo=" + (info2 == null ? "[none]" : info2));
3447
}
3548
catch (Exception e)
3649
{
@@ -39,6 +52,7 @@ public void onReceive(Context context, Intent intent)
3952

4053
// HINT: if in doubt, say that we have connectivity
4154
HAVE_INTERNET_CONNECTIVITY = true;
55+
append_logger_msg(TAG + "::" + "HAVE_INTERNET_CONNECTIVITY[hardcoded]=" + HAVE_INTERNET_CONNECTIVITY);
4256
}
4357
}
4458
}

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/MainActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
import static com.zoffcc.applications.trifa.HelperFriend.tox_friend_get_public_key__wrapper;
175175
import static com.zoffcc.applications.trifa.HelperFriend.update_friend_in_db_capabilities;
176176
import static com.zoffcc.applications.trifa.HelperFriend.update_friend_in_db_ip_addr_str;
177+
import static com.zoffcc.applications.trifa.HelperGeneric.append_logger_msg;
177178
import static com.zoffcc.applications.trifa.HelperGeneric.bytes_to_hex;
178179
import static com.zoffcc.applications.trifa.HelperGeneric.del_g_opts;
179180
import static com.zoffcc.applications.trifa.HelperGeneric.display_toast;
@@ -5759,10 +5760,22 @@ else if (remain_bytes == 0)
57595760

57605761
static void android_tox_callback_self_connection_status_cb_method(int a_TOX_CONNECTION)
57615762
{
5763+
final int connection_status_prev = global_self_connection_status;
57625764
Log.i(TAG, "self_connection_status:" + a_TOX_CONNECTION);
57635765
global_self_connection_status = a_TOX_CONNECTION;
57645766
TrifaToxService.write_debug_file("CB_SELF_CONN_STATUS__cstatus:" + a_TOX_CONNECTION + "_b:" + bootstrapping);
57655767

5768+
if ((connection_status_prev == TOX_CONNECTION_NONE.value) && (a_TOX_CONNECTION != TOX_CONNECTION_NONE.value))
5769+
{
5770+
// we just went online
5771+
append_logger_msg(TAG + "::" + "went online:self connection status=" + a_TOX_CONNECTION);
5772+
}
5773+
else if ((connection_status_prev != TOX_CONNECTION_NONE.value) && (a_TOX_CONNECTION == TOX_CONNECTION_NONE.value))
5774+
{
5775+
// we just went OFFLINE
5776+
append_logger_msg(TAG + "::" + "went OFFLINE:self connection status=" + a_TOX_CONNECTION);
5777+
}
5778+
57665779
if (bootstrapping)
57675780
{
57685781
Log.i(TAG, "self_connection_status:bootstrapping=true");

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/MyExternReceiver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import androidx.core.app.NotificationCompat;
3535

36+
import static com.zoffcc.applications.trifa.HelperGeneric.append_logger_msg;
37+
import static com.zoffcc.applications.trifa.TRIFAGlobals.global_last_activity_for_battery_savings_ts;
3638
import static com.zoffcc.applications.trifa.TrifaToxService.trifa_service_thread;
3739

3840
public class MyExternReceiver extends BroadcastReceiver
@@ -160,7 +162,9 @@ public void run()
160162

161163
if (trifa_service_thread != null)
162164
{
165+
append_logger_msg(TAG + "::" + "need_wakeup_now trigger 002");
163166
TrifaToxService.need_wakeup_now = true;
167+
global_last_activity_for_battery_savings_ts = System.currentTimeMillis();
164168
trifa_service_thread.interrupt();
165169
}
166170
}

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class TRIFAGlobals
4343
static long global_self_last_entered_battery_saving_timestamp = -1;
4444
static boolean global_showing_messageview = false;
4545
static boolean global_showing_anygroupview = false;
46+
final static int TOX_MIN_NORMAL_ITERATE_DELTA_MS = 100;
4647
static int global_tox_self_status = ToxVars.TOX_USER_STATUS.TOX_USER_STATUS_NONE.value;
4748

4849
static String global_notification_token = null;
@@ -61,6 +62,7 @@ public class TRIFAGlobals
6162
final static String TRIFA_GITHUB_NEW_ISSUE_URL = TRIFA_GITHUB_REPO_URL + "/issues/new";
6263

6364
static boolean HAVE_INTERNET_CONNECTIVITY = true;
65+
final static int TOX_BOOTSTRAP_MIN_INTERVAL_SECS = 60; // 60 seconds
6466
final static int TOX_BOOTSTRAP_AGAIN_AFTER_OFFLINE_MILLIS =
6567
1000 * 60 * 2; // bootstrap again after 2 minutes offline
6668
final static int SECONDS_TO_STAY_ONLINE_IN_BATTERY_SAVINGS_MODE = 60 * 3; // 3 minutes
@@ -256,8 +258,8 @@ public class TRIFAGlobals
256258
static final int LEN_TRIFA_AUTOGEN_PASSWORD = 32;
257259
static final int LEN_TRIFA_MANUAL_PASSWORD_MIN_LEN = 7;
258260

259-
static final int USE_MAX_NUMBER_OF_BOOTSTRAP_NODES = 8;
260-
static final int USE_MAX_NUMBER_OF_BOOTSTRAP_TCP_RELAYS = 8;
261+
static final int USE_MAX_NUMBER_OF_BOOTSTRAP_NODES = 20;
262+
static final int USE_MAX_NUMBER_OF_BOOTSTRAP_TCP_RELAYS = 20;
261263

262264
static final int INTERVAL_ADD_ALL_FRIENDS_CLEAR_MS = 1000;
263265
static final int INTERVAL_UPDATE_NGC_GROUP_ALL_USERS_MS = 1000;
@@ -285,6 +287,7 @@ public class TRIFAGlobals
285287

286288
static long global_last_activity_outgoung_ft_ts = -1;
287289
static long global_last_activity_incoming_ft_ts = -1;
290+
static long global_last_bootstrap_ts = -1;
288291

289292
static long ONE_HOUR_IN_MS = 3600 * 1000;
290293
static int MESSAGES_TIMEDELTA_NO_TIMESTAMP_MS = 30 * 1000;

0 commit comments

Comments
 (0)