Offline hotspot: don't crash if group is null

This commit is contained in:
Sebastian Kürten
2021-11-22 16:53:21 +01:00
parent 8fca06e040
commit 2295db4361

View File

@@ -312,12 +312,19 @@ class HotspotManager {
} }
GroupInfoListener groupListener = group -> { GroupInfoListener groupListener = group -> {
boolean valid = isGroupValid(group); boolean valid = isGroupValid(group);
// If the group is valid, set the hotspot to started. If we don't if (valid) {
// have any attempts left, we try what we got // the group is valid, set the hotspot to started.
if (valid || attempt >= MAX_GROUP_INFO_ATTEMPTS) { onHotspotStarted(group);
} else if (attempt < MAX_GROUP_INFO_ATTEMPTS) {
// we have attempts left, try again
retryRequestingGroupInfo(attempt);
} else if (group != null) {
// no attempts left, but group is not null, try what we got
onHotspotStarted(group); onHotspotStarted(group);
} else { } else {
retryRequestingGroupInfo(attempt); // no attempts left and group is null, fail
releaseHotspotWithError(ctx.getString(
R.string.hotspot_error_start_callback_no_group_info));
} }
}; };
try { try {
@@ -366,13 +373,8 @@ class HotspotManager {
private void retryRequestingGroupInfo(int attempt) { private void retryRequestingGroupInfo(int attempt) {
LOG.info("retrying to request group info"); LOG.info("retrying to request group info");
// On some devices we need to wait for the group info to become available // On some devices we need to wait for the group info to become available
if (attempt < MAX_GROUP_INFO_ATTEMPTS) { handler.postDelayed(() -> requestGroupInfo(attempt + 1),
handler.postDelayed(() -> requestGroupInfo(attempt + 1), RETRY_DELAY_MILLIS);
RETRY_DELAY_MILLIS);
} else {
releaseHotspotWithError(ctx.getString(
R.string.hotspot_error_start_callback_no_group_info));
}
} }
@UiThread @UiThread