Changes needed for android merge. Sysactivity checks and loads implementation for current os.

cusax-fix
Damian Minkov 13 years ago
parent aad6f7cb26
commit a30e6955f6

@ -21,7 +21,8 @@
*/
@SuppressWarnings("rawtypes")
public class NetworkManagerListenerImpl
implements DBusSigHandler
implements DBusSigHandler,
SystemActivityManager
{
/**
* The logger.
@ -29,11 +30,6 @@ public class NetworkManagerListenerImpl
private Logger logger = Logger.getLogger(
NetworkManagerListenerImpl.class.getName());
/**
* The only instance of this impl.
*/
private static NetworkManagerListenerImpl networkManagerListenerImpl;
/**
* Dbus connection we use.
*/
@ -54,18 +50,6 @@ private NetworkManagerListenerImpl()
}
}
/**
* Gets the instance of <tt>NetworkManagerListenerImpl</tt>.
* @return the NetworkManagerListenerImpl.
*/
public static NetworkManagerListenerImpl getInstance()
{
if(networkManagerListenerImpl == null)
networkManagerListenerImpl = new NetworkManagerListenerImpl();
return networkManagerListenerImpl;
}
/**
* Starts
*/

@ -50,6 +50,8 @@ public class SysActivityActivator
public void start(BundleContext bundleContext)
throws Exception
{
SysActivityActivator.bundleContext = bundleContext;
if (logger.isDebugEnabled())
logger.debug("Started.");

@ -0,0 +1,32 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.sysactivity;
/**
* Common interface shared between different OS implementations.
*
* @author Damian Minkov
*/
public interface SystemActivityManager
{
/**
* Starts the manager.
*/
public void start();
/**
* Stops the manager.
*/
public void stop();
/**
* Whether the underlying implementation is currently connected and
* working.
* @return whether we are connected and working.
*/
public boolean isConnected();
}

@ -88,6 +88,23 @@ public class SystemActivityNotificationsServiceImpl
*/
private Boolean networkIsConnected = null;
/**
* The linux impl class name.
*/
private static final String SYSTEM_ACTIVITY_MANAGER_LINUX_CLASS
= "net.java.sip.communicator.impl.sysactivity.NetworkManagerListenerImpl";
/**
* The android impl class name.
*/
private static final String SYSTEM_ACTIVITY_MANAGER_ANDROID_CLASS
= "net.java.sip.communicator.impl.sysactivity.ConnectivityManagerListenerImpl";
/**
* The currently instantiated and working manager.
*/
private SystemActivityManager currentRunningManager = null;
/**
* Init and start notifications.
*/
@ -112,17 +129,19 @@ public void run()
notifystartThread.setDaemon(true);
notifystartThread.start();
// a thread periodically checks system idle state and if it pass the
// idle time for a particular listener, will inform it.
Thread idleNotifyThread
= new Thread(
this,
"SystemActivityNotificationsServiceImpl.IdleNotifyThread");
idleNotifyThread.setDaemon(true);
idleNotifyThread.start();
if(isSupported(SystemActivityEvent.EVENT_SYSTEM_IDLE))
{
// a thread periodically checks system idle state and if it pass the
// idle time for a particular listener, will inform it.
Thread idleNotifyThread = new Thread(
this,
"SystemActivityNotificationsServiceImpl.IdleNotifyThread");
idleNotifyThread.setDaemon(true);
idleNotifyThread.start();
}
if (OSUtils.IS_LINUX)
NetworkManagerListenerImpl.getInstance().start();
if (getCurrentRunningManager() != null)
getCurrentRunningManager().start();
}
/**
@ -132,8 +151,8 @@ public void stop()
{
SystemActivityNotifications.stop();
if (OSUtils.IS_LINUX)
NetworkManagerListenerImpl.getInstance().stop();
if (getCurrentRunningManager() != null)
getCurrentRunningManager().stop();
eventDispatcher.stop();
@ -566,8 +585,10 @@ else if(OSUtils.IS_LINUX)
case SystemActivityEvent.EVENT_SLEEP:
case SystemActivityEvent.EVENT_NETWORK_CHANGE:
{
return NetworkManagerListenerImpl.getInstance()
.isConnected();
return
getCurrentRunningManager() != null ?
getCurrentRunningManager().isConnected()
: false;
}
case SystemActivityEvent.EVENT_SYSTEM_IDLE:
case SystemActivityEvent.EVENT_SYSTEM_IDLE_END:
@ -591,4 +612,38 @@ else if(OSUtils.IS_ANDROID)
else
return false;
}
/**
* Returns or instantiate the manager.
* @return
*/
private SystemActivityManager getCurrentRunningManager()
{
if(currentRunningManager == null)
{
try
{
String className = null;
if(OSUtils.IS_LINUX)
{
className = SYSTEM_ACTIVITY_MANAGER_LINUX_CLASS;
}
else if(OSUtils.IS_ANDROID)
{
className = SYSTEM_ACTIVITY_MANAGER_ANDROID_CLASS;
}
if(className != null)
currentRunningManager = (SystemActivityManager)
Class.forName(SYSTEM_ACTIVITY_MANAGER_LINUX_CLASS)
.newInstance();
}
catch(Throwable t)
{
logger.error("Error creating manager", t);
}
}
return currentRunningManager;
}
}

@ -6,11 +6,8 @@
*/
package net.java.sip.communicator.service.protocol;
import java.util.*;
import java.util.regex.*;
import net.java.sip.communicator.impl.gui.*;
import org.jitsi.service.configuration.*;
/**

Loading…
Cancel
Save