Android Open Source - Aether-s-Notebook-Android-Client Service State Logger






From Project

Back to project page Aether-s-Notebook-Android-Client.

License

The source code is released under:

GNU General Public License

If you think the Android project Aether-s-Notebook-Android-Client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package aethers.notebook.logger.managed.servicestate;
//from ww w.j av a2  s  .c  o  m
import org.json.JSONStringer;

import aethers.notebook.core.LoggerServiceIdentifier;
import aethers.notebook.logger.managed.PushLogger;
import aethers.notebook.util.Logger;

import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;

public class ServiceStateLogger
extends PushLogger<PhoneStateListener>
{            
    private static final LoggerServiceIdentifier IDENTIFIER = new LoggerServiceIdentifier(
            "aethers.notebook.logger.managed.servicestate.ServiceStateLogger");
    {
        IDENTIFIER.setConfigurable(false);
        IDENTIFIER.setDescription("Logs when the service state changes.");
        IDENTIFIER.setName("Service State Logger");
        IDENTIFIER.setServiceClass(ServiceStateLogger.class.getName());
        IDENTIFIER.setVersion(1);
    }

    private static final String ENCODING = "UTF-8";
    
    private static Logger logger = Logger.getLogger(ServiceStateLogger.class);
    
    @Override
    protected PhoneStateListener preLogging() 
    {
        PhoneStateListener psl = new PhoneStateListener()
        {
            @Override
            public void onServiceStateChanged(ServiceState serviceState)
            {
                try
                {
                    JSONStringer data = new JSONStringer();
                    data.object()
                            .key("isManualSelection").value(serviceState.getIsManualSelection())
                            .key("operatorAlphaLong").value(serviceState.getOperatorAlphaLong())
                            .key("operatorAlphaShort").value(serviceState.getOperatorAlphaShort())
                            .key("operatorNumeric").value(serviceState.getOperatorNumeric())
                            .key("roaming").value(serviceState.getRoaming())
                            .key("state");
                    switch(serviceState.getState())
                    {
                    case ServiceState.STATE_EMERGENCY_ONLY :
                        data.value("STATE_EMERGENCY_ONLY");
                        break;
                    case ServiceState.STATE_IN_SERVICE :
                        data.value("STATE_IN_SERVICE");
                        break;
                    case ServiceState.STATE_OUT_OF_SERVICE :
                        data.value("STATE_OUT_OF_SERVICE");
                        break;
                    case ServiceState.STATE_POWER_OFF :
                        data.value("STATE_POWER_OFF");
                        break;
                    default :
                        data.value("STATE_UNKNOWN");
                    }        
                    data.endObject();
                    aethersNotebook.log(IDENTIFIER, data.toString().getBytes(ENCODING));
                }
                catch(Exception e)
                {
                    logger.error("Unable to log service state change", e);
                }
            }
        };
        telephonyManager.listen(psl, PhoneStateListener.LISTEN_SERVICE_STATE);
        return psl;
    }
    
    @Override
    protected void postLogging(PhoneStateListener psl) 
    {
        telephonyManager.listen(psl, PhoneStateListener.LISTEN_NONE);
    }
}




Java Source Code List

aethers.notebook.appender.managed.file.ConfigurationActivity.java
aethers.notebook.appender.managed.file.Configuration.java
aethers.notebook.appender.managed.file.FileAppender.java
aethers.notebook.appender.managed.uploader.ConfigurationActivity.java
aethers.notebook.appender.managed.uploader.Configuration.java
aethers.notebook.appender.managed.uploader.UploaderAppender.java
aethers.notebook.core.Action.java
aethers.notebook.core.AppenderServiceIdentifier.java
aethers.notebook.core.BootReceiver.java
aethers.notebook.core.ConfigurationTemplate.java
aethers.notebook.core.Configuration.java
aethers.notebook.core.CoreService.java
aethers.notebook.core.LoggerServiceIdentifier.java
aethers.notebook.core.TimeStamp.java
aethers.notebook.core.ui.ConfigurationActivity.java
aethers.notebook.core.ui.EditIntegerPreference.java
aethers.notebook.core.ui.IntegerPreferenceChangeListener.java
aethers.notebook.core.ui.NonPersistingButtonPreference.java
aethers.notebook.core.ui.PersistingButtonPreference.java
aethers.notebook.core.ui.filechooser.DirectoryChooser.java
aethers.notebook.core.ui.filechooser.FileChooser.java
aethers.notebook.core.ui.filechooser.FileListAdapter.java
aethers.notebook.logger.managed.PushLogger.java
aethers.notebook.logger.managed.celllocation.CellLocationLogger.java
aethers.notebook.logger.managed.dataconnectionstate.DataConnectionStateLogger.java
aethers.notebook.logger.managed.position.ConfigurationActivity.java
aethers.notebook.logger.managed.position.Configuration.java
aethers.notebook.logger.managed.position.PositionLogger.java
aethers.notebook.logger.managed.servicestate.ServiceStateLogger.java
aethers.notebook.logger.managed.signalstrength.SignalStrengthLogger.java
aethers.notebook.logger.managed.wifi.ConfigurationActivity.java
aethers.notebook.logger.managed.wifi.Configuration.java
aethers.notebook.logger.managed.wifi.WifiLogger.java
aethers.notebook.util.Logger.java