On Jul 29, 2:59 pm, Ne0 <[email protected]> wrote:
> I am using ACCESS_COARSE_LOCATION in my manifest.
>
> On 29 July, 14:49, Ne0 <[email protected]> wrote:
>
> > Hi,
>
> > Been having some issues with my PhoneStateListener, what i would like
> > it to do is to always listen to CellLocationUpdates even when the
> > phone "sleeps". I am currently trying to do this with the following
> > code.
>
> > public class MyService extends Service {
>
> > ...
>
> >   public void onCreate() {
>
> >     // Start listening to the phone
> >     mMyPhoneListener = new MyPhoneStateListener(this);
> >     mTelephonyManager = (TelephonyManager)getSystemService
> > (TELEPHONY_SERVICE);
> >     mTelephonyManager.listen(mMGPhoneListener,
> > PhoneStateListener.LISTEN_CELL_LOCATION)
>
> >    mPm = (PowerManager) getSystemService(Context.POWER_SERVICE);
> >    mWl = mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MYS");
> >    mWl.acquire();
>
> >   Log.d("MGS", "ServiceOnCreate");
>
> >   }
>
> >    public void onDestroy() {
>
> >    // Stop listen to the location updates
> >    mTelephonyManager.listen(mMGPhoneListener,
> > PhoneStateListener.LISTEN_NONE);
>
> >    // Release wake lock
> >    mWl.release();
>
> >    Log.d("MGS", "ServiceOnDestroy");
> >   }
>
> > }
>
> > public class MyPhoneStateListener extends PhoneStateListener {
>
> >     public voidonCellLocationChanged(CellLocation location) {
>
> >     // DOING SOME LOGGING
>
> >     }
>
> > }
>
> > Even though i am using a PARTIAL_WAKE_LOCK the CellLocationUpdates
> > stop when the phone "sleeps", i am almost certain that my service is
> > not getting destroyed as i have debug in place onDestroy to show this
> > happening on logcat.
>
> > I have also noticed this on logcat,
>
> > D/MGS     ( 6153): ServiceOnCreate (my debug of the service starting)
>
> > and
>
> > D/SurfaceFlinger(   59): About to give-up screen, flinger = 0x1841e8
> > D/dalvikvm(  143): GC freed 54 objects / 2328 bytes in 146ms
> > D/dalvikvm( 6153): GC freed 2115 objects / 126456 bytes in 140ms
>
> > Is this android freeing up the memory from my service? looks like the
> > same PID?
>
> > Can anyone shed some light on why i am not receiving any updates after
> > the screen/phone "sleeps"?
>
> > Thanks Liam.
>
>

Hi Liam,
    I've tried the following:

- create a Service which creates a PhoneStateListener based class
- setup a Handler in the Service to run every minute and reset the
TelephonyManager.listen call with LISTEN_CELL_LOCATION and
LISTEN_SIGNAL_STRENGTH
- make the Handler in the Service run PowerManager.WakeLock.acquire
every minute with SCREEN_DIM_WAKE_LOCK
- create a class that is called by RECEIVE_BOOT_COMPLETED to run the
service on phone boot with the idea that maybe services started on
boot are treated differently

    I've found that the PhoneStateListener class begins returning -1
for cell and signal when it is forcefully sent a listen request every
minute which I think illustrates why the cell listener goes quiet -
ie. the Android framework is no longer receiving the cell/signal data
from the modem. I think that a possible solution is to call
PowerManager.WakeLock.acquire with SCREEN_DIM_WAKE_LOCK after the
phone is sent to idle state though I need to leave it running for a
while to see how it behaves.

    Obviously this has a significant battery impact so it would be
much better if the framework is modified. Perhaps the framework is
meant to stop receiving cell/signal updates from the modem when the
phone is idle to save power though a forceful wakeup must clearly be
sent when a call/message comes in at which point I guess the cell/
signal data is made available again to correctly set the signal
indicator on the UI. I have seen an enableLocationUpdates method in
the TelephonyManager.java code in the source download and maybe it is
this which is being called by the framework when the phone is sent to
idle to disable the cell/signal updates. I will try and see if calling
this after the phone is sent to idle makes a difference (if I can
compile against the internal version and the symbol is available on
device).

chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to