Sanitizes sysactivitynotifications.dll in order to make it easier to determine why it crashes.

cusax-fix
Lyubomir Marinov 13 years ago
parent 1b2f91a6db
commit c2f63cbef1

@ -597,18 +597,20 @@
<cc outtype="shared" name="gcc" outfile="${native_install_dir}/sysactivitynotifications"
objdir="${obj}">
<!-- common compiler flags -->
<!-- Common compiler flags -->
<compilerarg value="-D_JNI_IMPLEMENTATION_" />
<compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
<compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
<compilerarg value="-O2" />
<compilerarg value="-Wall" />
<compilerarg value="-Wextra" />
<compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
<compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
<!-- Common linker flags -->
<linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
<linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
<!-- Mac OS X specific flags -->
<!-- Mac OS X-specific flags -->
<compilerarg value="-mmacosx-version-min=10.5" if="is.running.macos"/>
<compilerarg value="-O2" if="is.running.macos"/>
<compilerarg value="-arch" if="is.running.macos"/>
<compilerarg value="x86_64" if="is.running.macos"/>
<compilerarg value="-arch" if="is.running.macos"/>
@ -636,12 +638,9 @@
<linkerarg value="-framework" if="is.running.macos" />
<linkerarg value="IOKit" if="is.running.macos" />
<fileset dir="${src}/native/sysactivity"
includes="*.m" if="is.running.macos"/>
<!-- Linux specific flags -->
<fileset dir="${src}/native/sysactivity" includes="*.c" if="is.running.linux" />
<fileset dir="${src}/native/sysactivity" includes="*.m" if="is.running.macos"/>
<!-- Linux-specific flags -->
<compilerarg value="-I/usr/include/gtk-2.0" if="is.running.linux" />
<compilerarg value="-I/usr/include/glib-2.0/" if="is.running.linux" />
<compilerarg value="-I/usr/include/cairo/" if="is.running.linux" />
@ -654,16 +653,26 @@
<compilerarg value="-I/usr/lib/i386-linux-gnu/glib-2.0/include" if="is.running.linux" />
<compilerarg value="-I/usr/lib/i386-linux-gnu/gtk-2.0/include" if="is.running.linux" />
<compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
<compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
<compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
<compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />
<linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
<linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
<linkerarg value="-lgdk-x11-2.0" if="is.running.linux" />
<linkerarg value="-lXss" if="is.running.linux" />
<linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
<fileset dir="${src}/native/sysactivity" includes="*.c" if="is.running.linux" />
<!-- Windows-specific flags -->
<compilerarg value="-D_WIN32_WINNT=0x0502" if="is.running.windows" />
<compilerarg value="-DWINVER=0x0502" if="is.running.windows" />
<compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.windows" />
<compilerarg value="-I${system.JAVA_HOME}/include/win32" if="is.running.windows" />
<linkerarg value="-osysactivitynotifications.dll" if="is.running.windows" />
<linkerarg value="-liphlpapi" location="end" if="is.running.windows" />
<linkerarg value="-Wl,--kill-at" if="is.running.windows" />
<fileset dir="${src}/native/sysactivity" includes="*.cpp" if="is.running.windows" />
</cc>
</target>
<!-- compile sysactivity library for Windows

@ -9,470 +9,289 @@
/**
* \def WIN32_LEAN_AND_MEAN
* \brief Exclude not commonly used headers from win32 API.
* \brief Excludes not commonly used headers from Win32 API.
*
* It excludes some unused stuff from windows headers and
* by the way code compiles faster.
* Excludes some unused stuff from Windows headers which allows the code to
* compile faster.
*/
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <ws2def.h>
#include <ws2ipdef.h>
#include <windows.h>
#include <iphlpapi.h>
#include <process.h>
#include <tchar.h>
// cache for the JavaVM* pointer
JavaVM *jvm;
// cache for the a generic pointer
jobject delegateObject;
// thread id
UINT uThreadId;
// cache for the instance handle
HINSTANCE hInstance;
void RegisterWindowClassW();
LRESULT CALLBACK WndProcW(HWND, UINT, WPARAM, LPARAM);
HRESULT callback(UINT Msg, WPARAM wParam, LPARAM lParam);
void notify(int notificationType);
void notifyNetwork(int family,
long luidIndex,
char* name,
long type,
bool connected);
typedef void (WINAPI *NIpIfaceChange)(ADDRESS_FAMILY,
PIPINTERFACE_CHANGE_CALLBACK,
PVOID,
BOOLEAN,
HANDLE);
typedef NETIO_STATUS (*FnConvertInterfaceLuidToNameA)(
const NET_LUID *,
PSTR,
SIZE_T);
typedef NETIO_STATUS (*FnGetIpInterfaceEntry)(
PMIB_IPINTERFACE_ROW);
OVERLAPPED overlap;
/*static HHOOK hhookSysMsg;
static LRESULT CALLBACK msghook(int nCode, WPARAM wParam, LPARAM lParam)
#include <iphlpapi.h> /* CancelIPChangeNotify, NotifyAddrChange */
#include <process.h> /* _beginthreadex */
#include <stdint.h> /* uintptr_t */
static void SystemActivityNotifications_notify(jint type);
unsigned WINAPI SystemActivityNotifications_runMessageLoop(LPVOID);
LRESULT CALLBACK SystemActivityNotifications_wndProc(HWND, UINT, WPARAM, LPARAM);
/**
* The Java object which has been set on the SystemActivityNotifications class
* with a call to the setDelegate method.
*/
static jobject SystemActivityNotifications_delegate = NULL;
static OVERLAPPED SystemActivityNotifications_overlapped;
static JavaVM *SystemActivityNotifications_vm;
JNIEXPORT jlong JNICALL
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_allocAndInit
(JNIEnv* env, jclass clazz)
{
if(nCode < 0)
{
CallNextHookEx(hhookSysMsg, nCode, wParam, lParam);
return 0;
}
(void) env;
(void) clazz;
LPMSG msg = (LPMSG)lParam;
HINSTANCE hInstance = GetModuleHandle(NULL);
if(msg->message == WM_SYSCOMMAND)
if (hInstance)
{
if(wParam == SC_SCREENSAVE)
LPCWSTR lpszClassName = L"Jitsi SystemActivityNotifications Window";
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEXW);
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wcex.hIcon = 0;
wcex.hIconSm = 0;
wcex.hCursor = 0;
wcex.hInstance = hInstance;
wcex.lpfnWndProc = SystemActivityNotifications_wndProc;
wcex.lpszClassName = lpszClassName;
wcex.lpszMenuName = 0;
wcex.style = CS_HREDRAW | CS_VREDRAW;
if (RegisterClassExW(&wcex))
{
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START);
}
else if(wParam == SC_MONITORPOWER)
{
if(lParam == -1)
{
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE);
}
else if(lParam == 2)
HWND hWnd
= CreateWindowW(
lpszClassName,
/* lpWindowName*/ NULL,
WS_OVERLAPPEDWINDOW,
/* x */ CW_USEDEFAULT,
/* y */ CW_USEDEFAULT,
/* nWidth */ CW_USEDEFAULT,
/* nHeight */ CW_USEDEFAULT,
/* hWndParent */ NULL,
/* hMenu */ NULL,
hInstance,
/* LPVOID */ NULL);
if (hWnd)
{
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP);
ZeroMemory(
&SystemActivityNotifications_overlapped,
sizeof(SystemActivityNotifications_overlapped));
uintptr_t thrdh
= _beginthreadex(
/* security */ NULL,
/* stack_size */ 0,
SystemActivityNotifications_runMessageLoop,
(LPVOID) hWnd,
/* initflag */ 0,
/* thrdaddr */ NULL);
return (jlong) thrdh;
}
}
}
return CallNextHookEx(hhookSysMsg, nCode, wParam, lParam);
return 0;
}
*/
unsigned WINAPI CreateWndThreadW(LPVOID pThreadParam)
JNIEXPORT jlong JNICALL
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
(JNIEnv* env, jclass clazz)
{
hInstance = GetModuleHandle (NULL);
RegisterWindowClassW();
/*
hhookSysMsg = SetWindowsHookEx(
WH_MSGFILTER,
(HOOKPROC)msghook,
hInstance,
GetCurrentThreadId());
if(hhookSysMsg == NULL)
{
fprintf(stderr, "Failed to create hoook %i\n", GetLastError() );
fflush(stderr);
}
*/
HWND hWnd = CreateWindowW( L"Jitsi Window Hook", NULL, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if( hWnd == NULL)
{
fprintf(stderr, "Failed to create window\n" );
fflush(stderr);
(void) env;
(void) clazz;
return( 0 );
}else
{
MSG Msg;
while(GetMessageW(&Msg, hWnd, 0, 0)) {
TranslateMessage(&Msg);
LASTINPUTINFO lii;
DispatchMessageW(&Msg);
}
lii.cbSize = sizeof(LASTINPUTINFO);
lii.dwTime = 0;
return GetLastInputInfo(&lii) ? (GetTickCount() - lii.dwTime) : -1;
}
return Msg.wParam;
}
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_release
(JNIEnv* env, jclass clazz, jlong ptr)
{
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate(
env,
clazz,
ptr,
NULL);
}
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: setDelegate
* Signature: (Lnet/java/sip/communicator/impl/sysactivity/SystemActivityNotifications/NotificationsDelegate;)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate
(JNIEnv* jniEnv, jclass clazz, jlong ptr, jobject m_delegate)
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate
(JNIEnv* env, jclass clazz, jlong ptr, jobject delegate)
{
if (delegateObject)
(void) clazz;
(void) ptr;
if (SystemActivityNotifications_delegate)
{
if (!jniEnv)
jvm->AttachCurrentThread((void **)&jniEnv, NULL);
jniEnv->DeleteGlobalRef(delegateObject);
delegateObject = NULL;
jvm = NULL;
env->DeleteGlobalRef(SystemActivityNotifications_delegate);
SystemActivityNotifications_delegate = NULL;
}
if (m_delegate)
if (delegate)
{
m_delegate = jniEnv->NewGlobalRef(m_delegate);
if (m_delegate)
{
jniEnv->GetJavaVM(&(jvm));
delegateObject = m_delegate;
}
delegate = env->NewGlobalRef(delegate);
if (delegate)
SystemActivityNotifications_delegate = delegate;
}
}
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: allocAndInit
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_allocAndInit
(JNIEnv* jniEnv, jclass clazz)
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
(JNIEnv* env, jclass clazz, jlong ptr)
{
HANDLE hThread;
(void) env;
(void) clazz;
(void) ptr;
hThread = (HANDLE)_beginthreadex(NULL, 0, &CreateWndThreadW, NULL, 0, &uThreadId);
if(!hThread)
do
{
//throwException( env, "_beginthreadex", "initialisation failed" );
}
HANDLE handle = NULL;
if (ERROR_IO_PENDING
!= NotifyAddrChange(
&handle,
&SystemActivityNotifications_overlapped))
break; // Break in case of an error.
return (jlong)hThread;
DWORD numberOfBytesTransferred;
if (!GetOverlappedResult(
handle,
&SystemActivityNotifications_overlapped,
&numberOfBytesTransferred,
/* bWait */ TRUE))
break; // Break in case of an error.
SystemActivityNotifications_notify(
net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE);
}
while (TRUE);
}
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_release
(JNIEnv* jniEnv, jclass clazz, jlong ptr)
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_stop
(JNIEnv* env, jclass clazz, jlong ptr)
{
if (!jniEnv)
jvm->AttachCurrentThread((void **)&jniEnv, NULL);
jniEnv->DeleteGlobalRef(delegateObject);
delegateObject = NULL;
jvm = NULL;
(void) env;
(void) clazz;
(void) ptr;
CancelIPChangeNotify(&SystemActivityNotifications_overlapped);
}
static void InterfaceChangeCallback(
PVOID CallerContext,
PMIB_IPINTERFACE_ROW Row,
MIB_NOTIFICATION_TYPE NotificationType)
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved)
{
if(Row)
{
FnGetIpInterfaceEntry getIpIfaceEntry;
getIpIfaceEntry = (FnGetIpInterfaceEntry)GetProcAddress(
GetModuleHandle(TEXT("Iphlpapi.dll")),
"GetIpInterfaceEntry");
if(getIpIfaceEntry && getIpIfaceEntry(Row) == NO_ERROR)
{
FnConvertInterfaceLuidToNameA convertName;
convertName = (FnConvertInterfaceLuidToNameA)GetProcAddress(
GetModuleHandle(TEXT("Iphlpapi.dll")),
"ConvertInterfaceLuidToNameA");
char interfaceName[MAX_PATH];
if (convertName &&
convertName(&(Row->InterfaceLuid),
interfaceName,
sizeof(interfaceName))
== NO_ERROR)
{
//fprintf( stderr, "Interface LUID Name : %s\n", interfaceName);
}
(void) reserved;
notifyNetwork(
Row->Family,
Row->InterfaceLuid.Info.NetLuidIndex,
interfaceName,
Row->InterfaceLuid.Info.IfType,
Row->Connected);
}
}
SystemActivityNotifications_vm = vm;
return JNI_VERSION_1_4;
}
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: getLastInput
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
(JNIEnv* jniEnv, jclass clazz)
JNIEXPORT void JNICALL
JNI_OnUnload(JavaVM *vm, void *reserved)
{
DWORD result = 0;
LASTINPUTINFO lii;
memset(&lii, 0, sizeof(lii));
lii.cbSize = sizeof(LASTINPUTINFO);
if (GetLastInputInfo(&lii))
{
return GetTickCount() - lii.dwTime;
}
(void) vm;
(void) reserved;
return -1;
SystemActivityNotifications_vm = NULL;
}
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: start
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
(JNIEnv* jniEnv, jclass clazz, jlong ptr)
static void
SystemActivityNotifications_notify(jint type)
{
/*
OSVERSIONINFOEX osVersionInfoEx;
memset( &osVersionInfoEx, 0, sizeof(OSVERSIONINFOEX) );
osVersionInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx((OSVERSIONINFO*) &osVersionInfoEx );
jobject delegate = SystemActivityNotifications_delegate;
if( osVersionInfoEx.dwMajorVersion == 5)
if (delegate)
{
*/
// XP
while(true)
{
HANDLE hand = NULL;
DWORD ret, bytes;
JavaVM *vm = SystemActivityNotifications_vm;
hand = NULL;
ZeroMemory(&overlap, sizeof(overlap));
overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
ret = NotifyAddrChange(&hand, &overlap);
if (vm)
{
JNIEnv *env;
if(ret != ERROR_IO_PENDING )
if (0 == vm->AttachCurrentThreadAsDaemon((void **) &env, NULL))
{
//fprintf(stderr, "NotifyAddrChange returned %d,
// expected ERROR_IO_PENDING \n", ret);fflush(stderr);
// break in case of error.
break;
}
jclass clazz = env->GetObjectClass(delegate);
BOOL success = GetOverlappedResult(hand, &overlap, &bytes, TRUE);
if (clazz)
{
jmethodID methodID
= env->GetMethodID(clazz,"notify", "(I)V");
if(!success)
break;
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE);
}
/*
}
else if( osVersionInfoEx.dwMajorVersion > 5)
{
// Vista, 7, ....
NIpIfaceChange nIpIfaceChange;
nIpIfaceChange = (NIpIfaceChange)GetProcAddress(
GetModuleHandle(TEXT("Iphlpapi.dll")),
"NotifyIpInterfaceChange");
if(nIpIfaceChange)
{
ADDRESS_FAMILY family = AF_UNSPEC;
HANDLE hNotification;
nIpIfaceChange(
family,
(PIPINTERFACE_CHANGE_CALLBACK)InterfaceChangeCallback,
NULL,
FALSE,
&hNotification);
if (methodID)
env->CallVoidMethod(delegate, methodID, type);
}
env->ExceptionClear();
}
}
}
*/
}
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: stop
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_stop
(JNIEnv* jniEnv, jclass clazz, jlong ptr)
unsigned WINAPI
SystemActivityNotifications_runMessageLoop(LPVOID pv)
{
CancelIPChangeNotify(&overlap);
}
MSG msg;
HWND hWnd = (HWND) pv;
void RegisterWindowClassW()
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEXW);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProcW;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = 0;
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = L"Jitsi Window Hook";
wcex.hIconSm = 0;
RegisterClassExW(&wcex);
}
LRESULT CALLBACK WndProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
long res = callback( Msg, wParam, lParam );
if ( res != -1 )
while (GetMessageW(&msg, hWnd, 0, 0))
{
return( res );
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return DefWindowProcW(hWnd, Msg, wParam, lParam);
return msg.wParam;
}
HRESULT callback(UINT Msg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK
SystemActivityNotifications_wndProc
(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
JNIEnv *env;
if ( jvm->AttachCurrentThread((void **)&env, NULL ))
{
fprintf( stderr, "failed to attach current thread to JVM\n" );fflush(stderr);
return( -1 );
}
jlong result = -1;
if (Msg == WM_POWERBROADCAST)
switch (uMsg)
{
case WM_POWERBROADCAST:
if (wParam == PBT_APMSUSPEND)
{
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP);
SystemActivityNotifications_notify(
net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP);
return TRUE;
}
else if (wParam == PBT_APMRESUMESUSPEND)
{
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE);
SystemActivityNotifications_notify(
net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE);
return TRUE;
}
}
else if (Msg == WM_QUERYENDSESSION)
{
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION);
return TRUE;
}
else if (Msg == WM_ENDSESSION && wParam == TRUE)
{
// we fire the message only if we are really ending the session
// is wParam is False means someone has canceled the shutdown/logoff
notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION);
return TRUE;
}
jvm->DetachCurrentThread();
return((HRESULT)result );
}
void notify(int notificationType)
{
JNIEnv *jniEnv;
jclass delegateClass = NULL;
if (!delegateObject)
return;
break; // WM_POWERBROADCAST
if (0 != jvm->AttachCurrentThreadAsDaemon( (void **)&jniEnv, NULL))
return;
delegateClass = jniEnv->GetObjectClass(delegateObject);
if(delegateClass)
{
jmethodID methodid = NULL;
case WM_QUERYENDSESSION:
SystemActivityNotifications_notify(
net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION);
return TRUE;
methodid = jniEnv->GetMethodID(delegateClass,"notify", "(I)V");
if(methodid)
case WM_ENDSESSION:
// We fire the message only if we are really ending the session. If
// wParam is FALSE, then someone has canceled the shutdown/logoff.
if (wParam == TRUE)
{
jniEnv->CallVoidMethod(delegateObject, methodid, notificationType);
SystemActivityNotifications_notify(
net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION);
return TRUE;
}
}
jniEnv->ExceptionClear();
}
void notifyNetwork(int family,
long luidIndex,
char* name,
long type,
bool connected)
{
JNIEnv *jniEnv;
jclass delegateClass = NULL;
if (!delegateObject)
return;
if (0 != jvm->AttachCurrentThreadAsDaemon( (void **)&jniEnv, NULL))
return;
else
break; // WM_ENDSESSION
delegateClass = jniEnv->GetObjectClass(delegateObject);
if(delegateClass)
{
jmethodID methodid = NULL;
methodid = jniEnv->GetMethodID(delegateClass,
"notifyNetworkChange",
"(IJLjava/lang/String;JZ)V");
if(methodid)
{
jniEnv->CallVoidMethod(delegateObject, methodid,
family,
luidIndex,
name ? jniEnv->NewStringUTF(name) : NULL,
type,
connected);
}
default:
break;
}
jniEnv->ExceptionClear();
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}

@ -1,45 +1,53 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications */
#ifndef _Included_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
/* Header for class net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications */
#ifndef _Included_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
#define _Included_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C" {
#endif
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP 0L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE 1L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP 2L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE 3L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START 4L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP 5L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP 6L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED 7L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED 8L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE 9L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE 10L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION 11L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION 12L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE 9L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION 11L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED 7L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED 8L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START 4L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP 6L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP 5L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP 0L
#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE 1L
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: allocAndInit
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_allocAndInit
(JNIEnv *, jclass);
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: getLastInput
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@ -47,7 +55,7 @@ JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAc
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_release
(JNIEnv *, jclass, jlong);
(JNIEnv *, jclass, jlong);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@ -55,7 +63,7 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAct
* Signature: (JLnet/java/sip/communicator/impl/sysactivity/SystemActivityNotifications/NotificationsDelegate;)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate
(JNIEnv *, jclass, jlong, jobject);
(JNIEnv *, jclass, jlong, jobject);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@ -63,7 +71,7 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAct
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
(JNIEnv *, jclass, jlong);
(JNIEnv *, jclass, jlong);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@ -71,18 +79,9 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAct
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_stop
(JNIEnv *, jclass, jlong);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: getLastInput
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
(JNIEnv *, jclass);
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#ifdef __cplusplus
}
#endif
#endif

@ -14,14 +14,11 @@
public class SystemActivityNotifications
{
/**
* Notify that computers is going to sleep.
*/
public static final int NOTIFY_SLEEP = 0;
/**
* Notify that computer is wakeing up after stand by.
* The <tt>Logger</tt> used by the <tt>SystemActivityNotifications</tt>
* class to log debugging information.
*/
public static final int NOTIFY_WAKE = 1;
private static final Logger logger
= Logger.getLogger(SystemActivityNotifications.class);
/**
* Computer display has stand by.
@ -34,19 +31,26 @@ public class SystemActivityNotifications
public static final int NOTIFY_DISPLAY_WAKE = 3;
/**
* Screensaver has been started.
* A change in dns configuration has occurred.
*/
public static final int NOTIFY_SCREENSAVER_START = 4;
public static final int NOTIFY_DNS_CHANGE = 10;
/**
* Screensaver will stop.
* All processes have been informed about ending session, now notify for
* the actual end session.
*/
public static final int NOTIFY_SCREENSAVER_WILL_STOP = 5;
public static final int NOTIFY_ENDSESSION = 12;
/**
* Screensaver has been stopped.
* A change in network configuration has occurred.
*/
public static final int NOTIFY_SCREENSAVER_STOP = 6;
public static final int NOTIFY_NETWORK_CHANGE = 9;
/**
* Notifies for start of process of ending desktop session,
* logoff or shutdown.
*/
public static final int NOTIFY_QUERY_ENDSESSION = 11;
/**
* Screen has been locked.
@ -59,39 +63,34 @@ public class SystemActivityNotifications
public static final int NOTIFY_SCREEN_UNLOCKED = 8;
/**
* A change in network configuration has occurred.
* Screensaver has been started.
*/
public static final int NOTIFY_NETWORK_CHANGE = 9;
public static final int NOTIFY_SCREENSAVER_START = 4;
/**
* A change in dns configuration has occurred.
* Screensaver has been stopped.
*/
public static final int NOTIFY_DNS_CHANGE = 10;
public static final int NOTIFY_SCREENSAVER_STOP = 6;
/**
* Notifies for start of process of ending desktop session,
* logoff or shutdown.
* Screensaver will stop.
*/
public static final int NOTIFY_QUERY_ENDSESSION = 11;
public static final int NOTIFY_SCREENSAVER_WILL_STOP = 5;
/**
* All processes have been informed about ending session, now notify for
* the actual end session.
* Notify that computers is going to sleep.
*/
public static final int NOTIFY_ENDSESSION = 12;
public static final int NOTIFY_SLEEP = 0;
/**
* The logger.
* Notify that computer is wakeing up after stand by.
*/
private static Logger logger = Logger.getLogger(
SystemActivityNotifications.class.getName());
public static final int NOTIFY_WAKE = 1;
/**
* The native instance.
*/
private static long notifierInstance = -1;
private static boolean loaded = false;
private static long ptr;
/**
* Init native library.
@ -102,99 +101,119 @@ public class SystemActivityNotifications
{
System.loadLibrary("sysactivitynotifications");
notifierInstance = allocAndInit();
loaded = true;
ptr = allocAndInit();
if (ptr == -1)
ptr = 0;
}
catch(Throwable t)
catch (Throwable t)
{
logger.warn("Error init native functions, " + t.getMessage());
if (t instanceof ThreadDeath)
throw (ThreadDeath) t;
else
logger.warn("Failed to initialize native counterpart", t);
}
}
/**
* Allocate native resources and gets a pointer.
*
* @return
*/
private static native long allocAndInit();
/**
* Release native resources.
* @param ptr
* Returns the when was last input in milliseconds. The time when there was
* any activity on the computer.
*
* @return the last input in milliseconds
*/
private static native void release(long ptr);
public static native long getLastInput();
/**
* Sets delegate.
* @param delegate
* Whether native library is loaded.
*
* @return whether native library is loaded.
*/
public static void setDelegate(NotificationsDelegate delegate)
public static boolean isLoaded()
{
if(notifierInstance != -1)
{
setDelegate(notifierInstance, delegate);
}
return (ptr != 0);
}
/**
* Sets notifier delegate.
* Release native resources.
*
* @param ptr
* @param delegate
*/
public static native void setDelegate(long ptr, NotificationsDelegate delegate);
private static native void release(long ptr);
/**
* Start processing.
* Sets notifier delegate.
*
* @param ptr
* @param delegate
*/
private static native void start(long ptr);
public static native void setDelegate(
long ptr,
NotificationsDelegate delegate);
/**
* Stop processing.
* @param ptr
* Sets delegate.
*
* @param delegate
*/
private static native void stop(long ptr);
public static void setDelegate(NotificationsDelegate delegate)
{
if (ptr != 0)
setDelegate(ptr, delegate);
}
/**
* Start.
*/
public static void start()
{
if(notifierInstance != -1)
start(notifierInstance);
if (ptr != 0)
start(ptr);
}
/**
* Start processing.
*
* @param ptr
*/
private static native void start(long ptr);
/**
* Stop.
*/
public static void stop()
{
if(notifierInstance != -1)
if (ptr != 0)
{
stop(notifierInstance);
release(notifierInstance);
notifierInstance = -1;
stop(ptr);
release(ptr);
ptr = 0;
}
}
/**
* Returns the when was last input in milliseconds. The time when
* there was any activity on the computer.
* @return the last input in milliseconds
* Stop processing.
*
* @param ptr
*/
public static native long getLastInput();
private static native void stop(long ptr);
/**
* Delegate class to be notified for changes.
* Delegate class to be notified about changes.
*/
public static abstract class NotificationsDelegate
public interface NotificationsDelegate
{
/**
* Callback method when receiving notifications.
*
* @param type
*/
public abstract void notify(int type);
public void notify(int type);
/**
* Callback method when receiving special network notifications.
@ -205,20 +224,11 @@ public static abstract class NotificationsDelegate
* @param type of the interface
* @param connected whether interface is connected or not.
*/
public abstract void notifyNetworkChange(
public void notifyNetworkChange(
int family,
long luidIndex,
String name,
long type,
boolean connected);
}
/**
* Whether native library is loaded.
* @return whether native library is loaded.
*/
public static boolean isLoaded()
{
return loaded;
}
}

@ -21,8 +21,8 @@
* @author Damian Minkov
*/
public class SystemActivityNotificationsServiceImpl
extends SystemActivityNotifications.NotificationsDelegate
implements SystemActivityNotificationsService,
implements SystemActivityNotifications.NotificationsDelegate,
SystemActivityNotificationsService,
Runnable
{
/**
@ -243,7 +243,6 @@ public long getTimeSinceLastInput()
*
* @param type type of the notification.
*/
@Override
public void notify(int type)
{
SystemActivityEvent evt = null;
@ -350,7 +349,6 @@ public void notify(int type)
* serial bus network interface.)
* @param connected whether interface is connected or not.
*/
@Override
public void notifyNetworkChange(
int family,
long luidIndex,
@ -471,18 +469,20 @@ else if(idleTime != 0)
*/
protected void fireSystemActivityEvent(SystemActivityEvent evt)
{
// add network activity info, to track wake up problems
if(logger.isInfoEnabled() &&
(evt.getEventID() == SystemActivityEvent.EVENT_NETWORK_CHANGE
|| evt.getEventID() == SystemActivityEvent.EVENT_DNS_CHANGE))
int eventID = evt.getEventID();
// Add network activity info to track wake up problems.
if (logger.isInfoEnabled()
&& ((eventID == SystemActivityEvent.EVENT_NETWORK_CHANGE)
|| (eventID == SystemActivityEvent.EVENT_DNS_CHANGE)))
{
logger.info("Received system activity event: " + evt);
}
// give time to java to dispatch same
// event and populate its network interfaces
if(evt.getEventID() == SystemActivityEvent.EVENT_NETWORK_CHANGE)
if (eventID == SystemActivityEvent.EVENT_NETWORK_CHANGE)
{
// Give time to Java to dispatch same event and populate its network
// interfaces.
eventDispatcher.fireSystemActivityEvent(evt, 500);
}
else
@ -559,19 +559,16 @@ public boolean isSupported(int eventID)
{
if(OSUtils.IS_WINDOWS)
{
if(!SystemActivityNotifications.isLoaded())
return false;
switch(eventID)
{
case SystemActivityEvent.EVENT_SLEEP:
case SystemActivityEvent.EVENT_WAKE:
case SystemActivityEvent.EVENT_NETWORK_CHANGE:
case SystemActivityEvent.EVENT_SYSTEM_IDLE:
case SystemActivityEvent.EVENT_SYSTEM_IDLE_END:
return true;
default:
return false;
case SystemActivityEvent.EVENT_SLEEP:
case SystemActivityEvent.EVENT_WAKE:
case SystemActivityEvent.EVENT_NETWORK_CHANGE:
case SystemActivityEvent.EVENT_SYSTEM_IDLE:
case SystemActivityEvent.EVENT_SYSTEM_IDLE_END:
return SystemActivityNotifications.isLoaded();
default:
return false;
}
}
else if(OSUtils.IS_MAC)
@ -582,35 +579,32 @@ else if(OSUtils.IS_LINUX)
{
switch(eventID)
{
case SystemActivityEvent.EVENT_SLEEP:
case SystemActivityEvent.EVENT_NETWORK_CHANGE:
case SystemActivityEvent.EVENT_SLEEP:
case SystemActivityEvent.EVENT_NETWORK_CHANGE:
{
SystemActivityManager currentRunningManager
= getCurrentRunningManager();
return
getCurrentRunningManager() != null ?
getCurrentRunningManager().isConnected()
: false;
}
case SystemActivityEvent.EVENT_SYSTEM_IDLE:
case SystemActivityEvent.EVENT_SYSTEM_IDLE_END:
{
return SystemActivityNotifications.isLoaded();
(currentRunningManager == null)
? false
: currentRunningManager.isConnected();
}
default:
return false;
case SystemActivityEvent.EVENT_SYSTEM_IDLE:
case SystemActivityEvent.EVENT_SYSTEM_IDLE_END:
return SystemActivityNotifications.isLoaded();
default:
return false;
}
}
else if(OSUtils.IS_ANDROID)
{
switch(eventID)
{
case SystemActivityEvent.EVENT_NETWORK_CHANGE:
return true;
default:
return false;
}
return (eventID == SystemActivityEvent.EVENT_NETWORK_CHANGE);
}
else
{
return false;
}
}
/**

Loading…
Cancel
Save