On Aug 10, 9:00 am, Ne0 <[email protected]> wrote:
> Thanks for you input Chris.
>
> I have managed to get around the issue by using SCREEN_DIM_WAKE_LOCK,
> the PhoneStateListener still receives updates when held in that state.
> As my app is for engineering purposes and will not be for the general
> Market, i have decided to make it a platform application so i am no
> longer bound by the SDK API's. I would have preferred to stick to the
> SDK, but it is in need of some work. According to issue 700 (i think)
> google is planning on making that API better.
>
> Liam
>
> On Aug 7, 12:32 pm, chrisnew <[email protected]> wrote:
>
> > 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

Having observed the behaviour I think the wake lock is unreliable. I
still get lots of -1s in sleep state though sometimes it is populated.
Maybe this is to do with other background services. Note
PowerManager.goToSleep indicates that all wake locks are overriden and
I guess the cancel button does this.

I've built a custom version of the SDK with @hide removed from
enableLocationUpdates() in frameworks/base/telephony/java/android/
telephony/TelephonyManager.java so I can compile against it. However
the permission CONTROL_LOCATION_UPDATES is only allowed for apps
included in the fiirmware so it doesn't work at runtime but this may
work for your engineering build. I also tried to call
enabledLocationUpdates() using the frameworks/base/telephony/java/com/
android/internal/telephony/ITelephony.aidl interface from a non
firmware app but this is also security protected. Maybe the updates
are for GPS location rather than LAC / CID I'm not sure.

I found this in frameworks/base/telephony/java/com/android/internal/
telephony/Phone.java which I think is called by
CellLocation.requestLocationUpdate():

    /**
     * Udpate LAC and CID in service state for currnet GSM netowrk
registration
     *
     * If get different LAC and/or CID, notifyServiceState will be
sent
     *
     * @param
     * <strong>On failure</strong>,
     * (((AsyncResult)response.obj).result) == null and
     * (((AsyncResult)response.obj).exception) being an instance of
     * com.android.internal.telephony.gsm.CommandException
     */
    void updateServiceLocation(Message response);

...followed by:

    /**
     * Enable location update notifications.
     */
    void enableLocationUpdates();

    /**
     * Disable location update notifications.
     */
    void disableLocationUpdates();

...and I found this in frameworks/base/telephony/java/com/android/
internal/telephony/gsm/CommandsInterface.java:

  /**
     * Request to enable/disable network state change notifications
when
     * location informateion (lac and/or cid) has changed.
     *
     * @param enable true to enable, false to disable
     * @param response callback message
     */
    void setLocationUpdates(boolean enable, Message response);

Next try is to call this from the firmware.

--~--~---------~--~----~------------~-------~--~----~
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