Back to project page adkintun-mobile-browser.
The source code is released under:
Apache License
If you think the Android project adkintun-mobile-browser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Copyright 2013 NIC Chile Research Labs * //from ww w . jav a 2s .c om * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package cl.niclabs.adkintunmobile.browser; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.telephony.PhoneStateListener; import android.telephony.SignalStrength; import android.telephony.TelephonyManager; import android.telephony.gsm.GsmCellLocation; import android.util.Log; /** * Clase encargada de recibir los datos del browser, obtener las mediciones y * datos necesarios (Intensidad de la seal, ID de la antena, etc) y * registrarlos en el archivo de datos. * * @author Sebastin Pereira * */ public class Register { private TelephonyManager mTelephonyManager; private ConnectivityManager cm; private NetworkInfo networkInfo; private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { @Override public void onSignalStrengthsChanged(SignalStrength ss) { // Log.d("AdkinBrowser", "Signal Strengths Changed"); super.onSignalStrengthsChanged(ss); setSignalStrength(ss.getGsmSignalStrength()); saveToFile(); } }; /* Data */ private long time; private int signalStrength; private String cellInfo; private String networkSubtype; private String carrier; private boolean interrupted; private String TLD; private long timeToLoad, bytesSent, bytesReceived; /** * @param context * Contexto desde el que se registran los datos. */ public Register(Context context) { cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); mTelephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); } /** * Setea los datos recibidos del browser * * @param interrupted * Indica si el usuario interrumpi la carga de la URL * @param tld * TLD de la URL * @param timeToLoad * Tiempo que tom cargar la URL * @param bytesSent * Cantidad de bytes enviados * @param bytesReceived * Cantidad de bytes recibidos */ public void saveFromBrowser(boolean interrupted, String TLD, long timeToLoad, long bytesSent, long bytesReceived) { Log.d("AdkinBrowser", "registerLoad()" + interrupted); networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.getType() != ConnectivityManager.TYPE_MOBILE) return; setInterrupted(interrupted); setTLD(TLD); setTimeToLoad(timeToLoad); setBytesSent(bytesSent); setBytesReceived(bytesReceived); saveData(); } /** * Actualiza y guarda los datos del dispositivo (Intensidad de la seal, ID * de la antena, etc) y los guarda junto con los datos del browser. * * Debido a que la intensidad de la seal solo se puede obtener de forma * asncrona, una vez que se obtiene este dato se escribe sobre el archivo. */ public void saveData() { /* Time */ setTime(System.currentTimeMillis()); /* CellLocation */ try { setCellInfo(((GsmCellLocation)mTelephonyManager.getCellLocation()).toString()); } catch (NullPointerException e) { setCellInfo("No Antenna Data"); } /*Network subtype*/ try{ NetworkInfo ni = cm.getActiveNetworkInfo(); setNetworkSubtype(ni.getSubtypeName()); } catch(Exception e) { setNetworkSubtype("No conection"); } setCarrier(mTelephonyManager.getNetworkOperatorName()); /* SignalStrength */ mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); } /** * Escribe los datos locales del objeto en el archivo. */ private void saveToFile() { Log.d("AdkinBrowser", "saveToFile()" + getInterrupted()); FileHandler.addEntry(mTelephonyManager.getDeviceId(), getTime(), getSignalStrength(), getCellInfo(), getNetworkSubtype(), getCarrier(), getInterrupted(), getTLD(), getTimeToLoad(), getBytesSent(), getBytesReceived()); } public long getTime() { return time; } public void setTime(long time) { this.time = time; } public int getSignalStrength() { return signalStrength; } public void setSignalStrength(int signalStrength) { this.signalStrength = signalStrength; } public String getCellInfo() { return cellInfo; } public void setCellInfo(String cellInfo) { this.cellInfo = cellInfo; } public boolean getInterrupted() { return interrupted; } public void setInterrupted(boolean interrupted) { this.interrupted = interrupted; } public String getTLD() { return TLD; } public void setTLD(String tLD) { TLD = tLD; } public long getTimeToLoad() { return timeToLoad; } public void setTimeToLoad(long timeToLoad) { this.timeToLoad = timeToLoad; } public long getBytesSent() { return bytesSent; } public void setBytesSent(long bytesSent) { this.bytesSent = bytesSent; } public long getBytesReceived() { return bytesReceived; } public void setBytesReceived(long bytesReceived) { this.bytesReceived = bytesReceived; } public String getCarrier() { return carrier; } public void setCarrier(String carrier) { this.carrier = carrier; } public String getNetworkSubtype() { return this.networkSubtype; } private void setNetworkSubtype(String subtypeName) { this.networkSubtype = subtypeName; } }