1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Thomas Martitz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 import java
.util
.Timer
;
25 import java
.util
.TimerTask
;
27 import android
.content
.Context
;
28 import android
.telephony
.TelephonyManager
;
29 import android
.util
.Log
;
31 public class RockboxTimer
extends Timer
33 RockboxTimerTask task
;
36 private class RockboxTimerTask
extends TimerTask
{
37 private RockboxTimer t
;
38 private TelephonyManager tm
;
39 private int last_state
;
40 public RockboxTimerTask(RockboxService s
, RockboxTimer parent
) {
43 tm
= (TelephonyManager
)s
.getSystemService(Context
.TELEPHONY_SERVICE
);
44 last_state
= tm
.getCallState();
50 int state
= tm
.getCallState();
51 if (state
!= last_state
)
54 case TelephonyManager
.CALL_STATE_IDLE
:
57 case TelephonyManager
.CALL_STATE_RINGING
:
70 public RockboxTimer(RockboxService instance
, long period_inverval_in_ms
)
72 super("tick timer", false);
73 task
= new RockboxTimerTask(instance
, this);
74 schedule(task
, 0, period_inverval_in_ms
);
75 interval
= period_inverval_in_ms
;
78 private void LOG(CharSequence text
)
80 Log
.d("Rockbox", (String
) text
);
84 /* methods called from native, keep them simple */
85 public void java_wait_for_interrupt()
90 } catch (InterruptedException e
) {
91 /* wakeup and return */
92 } catch (Exception e
) {
97 public native void timerTask();
98 private native void postCallIncoming();
99 private native void postCallHungUp();