microg / IchnaeaNlpBackend

Backend for UnifiedNlp that uses Mozilla Location Service for geolocation.
116 stars 29 forks source link

"No instance found active" in first several runs #51

Open Iey4iej3 opened 4 years ago

Iey4iej3 commented 4 years ago

I refer to this post for a background, especially a filtered logcat.

MozillaNlpBackend version 1.4.0 with microG version 0.2.8.17785-4 (06c8b76)

When Mozilla Nlp backend is (firstly) enabled in UnifiedNlp, there are messages in logcat: IchnaeaBackendService: No instance found active. The backend gives the location only after a long period and maybe the repeated re-enablings are also necessary.

After searching in codes, I found that the only place to print this message is in the member function reloadInstanceSettings() when instance == null. Note that

  1. instance is a private static variable which is written only by protected member functions onOpen() and onClose(), as far as I understand.
  2. reloadInstanceSettings() is a public member function. However, among member functions, only onCreate() calls it.

This seems to be illogical. The instance could only be set to a non-null value by onOpen(). That is to say, every call to onCreate() would have failed with No instance found active. before the first call of onOpen() - this is a plausible reason why Ichnaea does not work once enabled in UnifiedNlp. Other backends do not share a similar issue under the same circumstance. Especially if we compare the code onCreate() here and that in Apple WiFi Nlp Backend, we see that onCreate() there does not check any analog of instance.