1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 20:31:16 +00:00

Attempt to fix NPE when calling SyncthingService.getApi().isConfigLoaded()

This commit is contained in:
Felix Ableitner 2017-09-27 12:50:35 +09:00
parent 8e1dfe875e
commit 94d72d768f
2 changed files with 10 additions and 5 deletions

View file

@ -175,10 +175,14 @@ public class SettingsActivity extends SyncthingActivity {
mSyncthingService = ((SyncthingActivity) getActivity()).getService();
mSyncthingService.registerOnApiChangeListener(this);
if (mSyncthingService.getApi().isConfigLoaded()) {
mGui = mSyncthingService.getApi().getGui();
mOptions = mSyncthingService.getApi().getOptions();
}
// Use callback to make sure getApi() doesn't return null.
mSyncthingService.registerOnWebGuiAvailableListener(() -> {
if (mSyncthingService.getApi().isConfigLoaded()) {
mGui = mSyncthingService.getApi().getGui();
mOptions = mSyncthingService.getApi().getOptions();
}
});
}
@Override

View file

@ -15,6 +15,7 @@ import android.os.Environment;
import android.os.IBinder;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.util.Pair;
@ -457,7 +458,7 @@ public class SyncthingService extends Service implements
return !new File(getFilesDir(), PUBLIC_KEY_FILE).exists();
}
public RestApi getApi() {
public @Nullable RestApi getApi() {
return mApi;
}