Gps receiver / receiver wakes up the CPU

From what I see in the AOSP code, wakelock captured by wakelock or when Android launches the intention to call a registered location receiver. Thus, you do not need to accept wakelock for processing, or at least you should use wakelock for the async operation performed on onLocationChanged , or if you are launching the service intent from the recipient, and so on. Now my question is: does the processor wake up gps? I mean: when the GPS trigger is accepted by the OS, wakelock gives you the ability to process information, but earlier? Will gps generate an interrupt to wake up the processor? Even if you use the receiver version, it does not let you know that gps is waking up the processor, or is it a listener / pendignIntent, like an alarm alarmManager , and can we trust it? Do I need to capture wakelock so that the system does not receive information?

+5
source share
2 answers

I think maybe you thought about it a bit. Typically, an application or user launches GPS, not GPS, which starts tracking locks.

Basically, if you request updates, you should receive them (depending on several things).

Criteria
Whether the application supports GPS wakefulness or not, depends heavily on Criteria

According to the documentation of LocationManager.requestLocationUpdates(long minTime, float minDistance, Criteria c, PendingIntent i) :

The location update interval can be controlled using the minTime parameter. The elapsed time between location updates will never be less than minTime, although this may be longer depending on the location of the vendor’s implementation and the update interval requested by other Applications.

Active providers

GPS and the network provider are considered "active providers". Both take time to start and get a new patch and battery consumption.

The system will try to start / use an active provider to meet your criteria, and if you use BroadcastReceiver , then the onRecieve method will be completed.

If you request GPS every hour, the system should wake up the device and start GPS and check it against your Criteria every hour, assuming that the provider is turned on.

If the provider is disabled by the user, the updates will be stopped and the supplier availability update will be sent. Once the provider is back on, location updates will be resumed immediately and the provider will update availability.

Additional issues and triggers

That's why they recommend considering additional triggers for listening, for example, when the provider is on or off. They can be combined with what @ danny177 mentioned, for example, charge level and battery level. Even the current state of the network can make a difference here.

Suppliers can also send status updates, at any time, with additional provider-specific. If the callback was after this status and availability update onProviderDisabled (String), onProviderEnabled (String) or onStatusChanged (String, int, Bundle). Alternatively, if the expected intention was provided, then status and availability updates will be transmitted with the optional keys KEY_PROVIDER_ENABLED or KEY_STATUS_CHANGED.

Finally, you can also use a passive provider. This will only give you an update if other applications awaken one of the active providers for you.

If your application wants to passively monitor location updates caused by other applications, but do not consume any additional power, otherwise use PASSIVE_PROVIDER. This provider is not actively enabling or changing providers of the active location.

Placement strategies

Generally, you want to go from least accurate to more, less power to maximum, etc. For example, you can use PASSIVE_PROVIDER to see if the user is moving more than 100 meters. Then, if they are, request updates to the active location from the network provider to find out if they are close to a specific location, then if that's true, use GPS for something more specific.

See: Placement Strategies

Determining what to use and trust is a matter of compromising accuracy, speed, and battery performance.

Google Play Services

Finally, you also use Google Play Services as your location provider and copy its location updates. It also gives you β€œfree” geospatial and geocoding.

+4
source

You do not need wakelock to handle the locations obtained in onLocationChanged() .

However, the background GPS log for a long period of time may require the use of wakelock

Before turning on the speaker, consider the battery level if the device is charging when wakelock is released.

Universal backgrounds for wakelock backdrop.

  • The device then charges wakelock.
  • The device does not charge beyond N%, and then wakelock else release wakelock.
  • processing completed wakelock release.

EDIT

Please use BroadcastReciver with your tracking lock.

 final IntentFilter theFilter = new IntentFilter(); theFilter.addAction(Intent.ACTION_BATTERY_LOW); registerReceiver(yourReceiver, theFilter); private static BroadcastReceiver yourReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent != null) { String s = intent.getAction(); if (s != null) { if (s.equals(LocationManager.PROVIDERS_BATTERY_LOW)) { cancelMyWakeLock(); } } } } }; 

Remember to register with onStop (); unregistered code is not shown.

+1
source

Source: https://habr.com/ru/post/1202027/


All Articles