Android Open Source - AGOGCyberStat Net R






From Project

Back to project page AGOGCyberStat.

License

The source code is released under:

MIT License

If you think the Android project AGOGCyberStat 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 com.agog.cyberstat;
/*from www .jav a2  s.  com*/
import java.util.Date;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.v4.content.WakefulBroadcastReceiver;
import me.allenz.androidapplog.Logger;
import me.allenz.androidapplog.LoggerFactory;

/**
 * @author greg@agog.com
 *
 * Process network broadcasts and relay on cleaned wifi events to BrR receiver
 */
public class NetR extends WakefulBroadcastReceiver {
  private static final Logger logger = LoggerFactory.getLogger();

  private Context mContext;

  @Override
  public void onReceive(Context context, Intent intent) {
    this.mContext = context;
    MyPrefs.init(context);
    
    String action = intent.getAction();

    logger.debug("onReceive " + action);     

    // We never want to send a notification unless we have a connection that is ready to transmit data.
    // A wifi disconnect should not be sent until a new network connection is ready.
    if(action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
      logger.debug( "CONNECTIVITY_ACTION: onReceive() is called with " + intent);
            NetworkInfo ni =  ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo ();
            WifiManager wim = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
           logger.debug( "NetworkInfo " + ni);
           if(!wim.isWifiEnabled ()) {
             logger.debug( "Wifi disabled");    
           }
           // If wifi is disabled then enter and exit events are not valid
            if(ni.isConnected() && wim.isWifiEnabled ()) {
              String newssid = null;
                if(ni.getType() == ConnectivityManager.TYPE_WIFI) {
                  WifiInfo  wifi = wim.getConnectionInfo();
                  if(wifi != null) {
                    logger.debug( "have wifi");
                    newssid = cleanup(wifi.getSSID());
                  }
                }
                String currentSSID = MyPrefs.getString("currentssid","");
                logger.debug("current \"" + currentSSID + "\" new \"" + newssid + "\"");
                if(!currentSSID.equals("") && (newssid == null || !currentSSID.equals(newssid))) {
                  sendwifi("Disconnected from " + currentSSID + " at " + new Date());
                }
                if(newssid != null && (currentSSID.equals("")  || !currentSSID.equals(newssid))) {
                  sendwifi("Connected to " +  newssid + " at " + new Date());
                }
                currentSSID = newssid == null ? "" : newssid;
                MyPrefs.putString("currentssid", currentSSID);
                // Commit the edits!
                MyPrefs.commit();
            }
    }
    /**** Unused code
    else if(action.equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {

      Object messages[] = (Object[]) bundle.get("pdus");
      SmsMessage smsMessage[] = new SmsMessage[messages.length];
      String mAddress;
      String mBody;
      Date mDate;

      for (int n = 0; n < messages.length; n++) {
        smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
        mAddress=smsMessage[n].getDisplayOriginatingAddress().toString();

        mBody=smsMessage[n].getDisplayMessageBody().toString();
        mDate = new Date(smsMessage[n].getTimestampMillis());

        logger.debug("Incoming SMS " + mAddress + " " + mBody + " " + mDate.toString());    
        String begintext = MyPrefs.getString("begin","");
        if(!begintext.equals("") && mBody.startsWith(begintext)) {
          sendsms(mBody.replaceAll(begintext,""));
        }
      }
    }
    *******/

  }

  protected void sendwifi(String msg)
  {
    Intent i = new Intent("com.agog.trigger.wifi");
    i.putExtra("msg",msg);
    logger.debug("send " + msg);
    mContext.sendBroadcast(i);
  }

  protected void sendsms(String msg)
  {
    Intent i = new Intent("com.agog.trigger.sms");
    i.putExtra("msg",msg);
    logger.debug("send " + msg);
    mContext.sendBroadcast(i);
  }

  

  // Remove double quotes and replace spaces to make a tag not a correct ssid
  protected String cleanup(String ssid)
  {
    return(ssid.substring(1,ssid.length()-1).replaceAll(" ","_"));
  }

}




Java Source Code List

com.agog.cyberstat.BrR.java
com.agog.cyberstat.JSONSettings.java
com.agog.cyberstat.MainActivity.java
com.agog.cyberstat.MotisonNetTask.java
com.agog.cyberstat.MotisonXML.java
com.agog.cyberstat.MyPrefs.java
com.agog.cyberstat.NetR.java
com.agog.cyberstat.Trigger.java
me.allenz.androidapplog.AbstractAppender.java
me.allenz.androidapplog.AbstractLogger.java
me.allenz.androidapplog.AppenderSupportLogger.java
me.allenz.androidapplog.Appender.java
me.allenz.androidapplog.AsyncAppender.java
me.allenz.androidapplog.Configure.java
me.allenz.androidapplog.InternalLogger.java
me.allenz.androidapplog.LogCatAppender.java
me.allenz.androidapplog.LogEvent.java
me.allenz.androidapplog.LogLevel.java
me.allenz.androidapplog.LogTextView.java
me.allenz.androidapplog.LoggerConfig.java
me.allenz.androidapplog.LoggerFactory.java
me.allenz.androidapplog.Logger.java
me.allenz.androidapplog.PropertiesParser.java
me.allenz.androidapplog.ReflectUtils.java
me.allenz.androidapplog.Repository.java
me.allenz.androidapplog.RollingFileAppender.java
me.allenz.androidapplog.TextViewAppender.java