Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
belle-sip
Commits
f6337be8
Commit
f6337be8
authored
Aug 25, 2014
by
François Grisez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integration of Android's wake locks
parent
0837e201
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
1 deletion
+99
-1
include/belle-sip/belle-sip.h
include/belle-sip/belle-sip.h
+4
-0
include/belle-sip/wakelock.h
include/belle-sip/wakelock.h
+8
-0
src/channel.c
src/channel.c
+15
-1
src/wakelock.c
src/wakelock.c
+68
-0
src/wakelock_internal.h
src/wakelock_internal.h
+4
-0
No files found.
include/belle-sip/belle-sip.h
View file @
f6337be8
...
...
@@ -43,6 +43,10 @@
#include "belle-sip/belle-sdp.h"
#include "belle-sip/bodyhandler.h"
#ifdef ANDROID
#include "belle-sip/wakelock.h"
#endif
#define BELLE_SIP_POINTER_TO_INT(p) ((int)(long)(p))
#define BELLE_SIP_INT_TO_POINTER(i) ((void*)(long)(i))
...
...
include/belle-sip/wakelock.h
0 → 100644
View file @
f6337be8
#ifndef WAKE_LOCK_H
#define WAKE_LOCK_H
#include <jni.h>
extern
void
bellesip_wake_lock_init_jni
(
JNIEnv
*
env
,
jobject
powerManager
);
#endif // WALE_LOCK_H
src/channel.c
View file @
f6337be8
...
...
@@ -21,6 +21,10 @@
#include <limits.h>
#include <ctype.h>
#ifdef ANDROID
#include "wakelock_internal.h"
#endif
static
void
channel_prepare_continue
(
belle_sip_channel_t
*
obj
);
static
void
channel_process_queue
(
belle_sip_channel_t
*
obj
);
static
void
channel_begin_send_background_task
(
belle_sip_channel_t
*
obj
);
...
...
@@ -1299,7 +1303,17 @@ belle_sip_channel_t *belle_sip_channel_find_from_list(belle_sip_list_t *l, int a
return
chan
;
}
#if !TARGET_OS_IPHONE
#ifdef ANDROID
unsigned
int
belle_sip_begin_background_task
(
const
char
*
name
,
belle_sip_background_task_end_callback_t
cb
,
void
*
data
){
return
wake_lock_acquire
();
}
void
belle_sip_end_background_task
(
unsigned
int
id
){
wake_lock_release
(
id
);
}
#elif !TARGET_OS_IPHONE
/*defines stubs*/
unsigned
int
belle_sip_begin_background_task
(
const
char
*
name
,
belle_sip_background_task_end_callback_t
cb
,
void
*
data
){
...
...
src/wakelock.c
0 → 100644
View file @
f6337be8
#include "wakelock_internal.h"
#include "belle-sip/utils.h"
static
JavaVM
*
_jvm
=
NULL
;
static
jobject
_powerManager
=
NULL
;
void
bellesip_wake_lock_init
(
JavaVM
*
jvm
,
jobject
powerManager
)
{
if
(
_jvm
==
NULL
)
{
_jvm
=
jvm
;
_powerManager
=
powerManager
;
}
else
{
ms_error
(
"bellesip_wake_lock_init(): the wakelock system has already been initialized"
);
}
}
unsigned
long
wake_lock_acquire
(
const
char
*
tag
)
{
if
(
_jvm
!=
NULL
&&
_powerManager
!=
NULL
)
{
JNIEnv
*
env
;
if
(
AttachCurrentThread
(
_jvm
,
&
env
,
NULL
)
==
JNI_OK
)
{
jclass
PowerManager
=
FindClass
(
env
,
"android/os/PowerManager"
);
jclass
WakeLock
=
FindClass
(
env
,
"android/os/PowerManager/WakeLock"
);
jint
PARTIAL_WAKE_LOCK
=
getStaticIntField
(
env
,
powerManager
,
GetFieldId
(
env
,
PowerManager
,
"PARTIAL_WAKE_LOCK"
,
"I"
)
);
jobject
lock
=
CallObjectMethod
(
env
,
_powerManager
,
GetMethodID
(
env
,
PowerManager
,
"newWakeLock"
,
"(ILjava/lang/String;)Landroid/os/PowerManager/WakeLock;"
),
PARTIAL_WAKE_LOCK
,
tag
);
CallVoidMethod
(
env
,
lock
,
GetMethodID
(
env
,
WakeLock
,
"acquire"
,
""
));
DetachCurrentThread
(
_jvm
);
return
(
unsigned
long
)
NewGlobalRef
(
env
,
lock
);
}
else
{
ms_error
(
"bellesip_wake_lock_acquire(): cannot attach current thread to the JVM"
);
}
}
else
{
ms_error
(
"bellesip_wake_lock_acquire(): cannot acquire wake lock. No jvm found"
);
}
return
0
;
}
void
wake_lock_release
(
unsigned
long
id
)
{
if
(
_jvm
!=
NULL
&&
_powerManager
!=
NULL
)
{
if
(
id
!=
0
)
{
jobject
lock
=
(
jobject
)
id
;
JNIEnv
*
env
;
if
(
AttachCurrentThread
(
_jvm
,
&
env
,
NULL
)
==
JNI_OK
)
{
jclass
WakeLock
=
FindClass
(
env
,
"android/os/PowerManager/WakeLock"
);
CallVoidMethod
(
env
,
lock
,
GetMethodID
(
env
,
WakeLock
,
"release"
,
"()V"
));
DeleteGlobalRef
(
env
,
lock
);
DetachCurrentThread
(
_jvm
);
}
else
{
ms_error
(
"bellesip_wake_lock_release(): cannot attach current thread to the JVM"
);
}
}
}
else
{
ms_error
(
"wake_lock_release(): cannot release wake lock. No jvm found"
);
}
}
src/wakelock_internal.h
0 → 100644
View file @
f6337be8
#include "belle-sip/wakelock.h"
extern
unsigned
long
wake_lock_acquire
(
const
char
*
tag
);
extern
void
wake_lock_release
(
unsigned
long
id
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment