List of usage examples for android.telephony TelephonyManager getNetworkType
@Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public @NetworkType int getNetworkType()
From source file:com.andybotting.tubechaser.activity.Home.java
/** * Upload statistics to remote server//from w w w . ja v a2s.com */ private void uploadStats() { if (LOGV) Log.v(TAG, "Sending statistics"); // gather all of the device info String app_version = ""; try { try { PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0); app_version = pi.versionName; } catch (NameNotFoundException e) { app_version = "N/A"; } TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String device_uuid = tm.getDeviceId(); String device_id = "00000000000000000000000000000000"; if (device_uuid != null) { device_id = GenericUtil.MD5(device_uuid); } String mobile_country_code = tm.getNetworkCountryIso(); String mobile_network_number = tm.getNetworkOperator(); int network_type = tm.getNetworkType(); // get the network type string String mobile_network_type = "N/A"; switch (network_type) { case 0: mobile_network_type = "TYPE_UNKNOWN"; break; case 1: mobile_network_type = "GPRS"; break; case 2: mobile_network_type = "EDGE"; break; case 3: mobile_network_type = "UMTS"; break; case 4: mobile_network_type = "CDMA"; break; case 5: mobile_network_type = "EVDO_0"; break; case 6: mobile_network_type = "EVDO_A"; break; case 7: mobile_network_type = "1xRTT"; break; case 8: mobile_network_type = "HSDPA"; break; case 9: mobile_network_type = "HSUPA"; break; case 10: mobile_network_type = "HSPA"; break; } String device_version = android.os.Build.VERSION.RELEASE; if (device_version == null) { device_version = "N/A"; } String device_model = android.os.Build.MODEL; if (device_model == null) { device_model = "N/A"; } String device_language = getResources().getConfiguration().locale.getLanguage(); String home_function = mPreferenceHelper.defaultLaunchActivity(); // post the data HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://tubechaser.andybotting.com/stats/app/send"); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("device_id", device_id)); pairs.add(new BasicNameValuePair("app_version", app_version)); pairs.add(new BasicNameValuePair("home_function", home_function)); pairs.add(new BasicNameValuePair("device_model", device_model)); pairs.add(new BasicNameValuePair("device_version", device_version)); pairs.add(new BasicNameValuePair("device_language", device_language)); pairs.add(new BasicNameValuePair("mobile_country_code", mobile_country_code)); pairs.add(new BasicNameValuePair("mobile_network_number", mobile_network_number)); pairs.add(new BasicNameValuePair("mobile_network_type", mobile_network_type)); try { post.setEntity(new UrlEncodedFormEntity(pairs)); } catch (UnsupportedEncodingException e) { // Do nothing } try { HttpResponse response = client.execute(post); response.getStatusLine().getStatusCode(); } catch (Exception e) { if (LOGV) Log.v(TAG, "Error uploading stats: " + e.getMessage()); } } catch (Exception e) { // Do nothing } }
From source file:pandroid.agent.PandroidAgentListener.java
/** * Retrieve the type of data network currently connected to, i.e. edge, gprs, etc... *//*from w ww . jav a 2 s .c o m*/ private void getNetworkType() { String networkType = Core.defaultNetworkType; TelephonyManager tM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); int nT = tM.getNetworkType(); switch (nT) { case 0: networkType = "Unknown"; break; case 1: networkType = "GPRS"; break; case 2: networkType = "EDGE"; break; case 3: networkType = "UMTS"; break; case 4: networkType = "CDMA"; break; case 5: networkType = "EVDO rev. 0"; break; case 6: networkType = "EVDO rev. A"; break; case 7: networkType = "1xRTT"; break; case 8: networkType = "HSDPA"; break; case 9: networkType = "HSUPA"; break; case 10: networkType = "HSPA"; break; case 11: networkType = "iDen"; break; case 12: networkType = "EVDO rev. B"; break; case 13: networkType = "LTE"; break; case 14: networkType = "eHRPD"; break; case 15: networkType = "HSPA+"; break; } if (networkType != null) putSharedData("PANDROID_DATA", "networkType", networkType, "string"); }
From source file:com.landenlabs.all_devtool.NetFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();/*from w w w .j ava 2 s . c o m*/ // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Connection Services ------------- try { ConnectivityManager connMgr = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); if (netInfo != null) { Map<String, String> netListStr = new LinkedHashMap<String, String>(); putIf(netListStr, "Available", "Yes", netInfo.isAvailable()); putIf(netListStr, "Connected", "Yes", netInfo.isConnected()); putIf(netListStr, "Connecting", "Yes", !netInfo.isConnected() && netInfo.isConnectedOrConnecting()); putIf(netListStr, "Roaming", "Yes", netInfo.isRoaming()); putIf(netListStr, "Extra", netInfo.getExtraInfo(), !TextUtils.isEmpty(netInfo.getExtraInfo())); putIf(netListStr, "WhyFailed", netInfo.getReason(), !TextUtils.isEmpty(netInfo.getReason())); if (Build.VERSION.SDK_INT >= 16) { putIf(netListStr, "Metered", "Avoid heavy use", connMgr.isActiveNetworkMetered()); } netListStr.put("NetworkType", netInfo.getTypeName()); if (connMgr.getAllNetworkInfo().length > 1) { netListStr.put("Available Networks:", " "); for (NetworkInfo netI : connMgr.getAllNetworkInfo()) { if (netI.isAvailable()) { netListStr.put(" " + netI.getTypeName(), netI.isAvailable() ? "Yes" : "No"); } } } if (netInfo.isConnected()) { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr .hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (inetAddress.getHostAddress() != null) { String ipType = (inetAddress instanceof Inet4Address) ? "IPv4" : "IPv6"; netListStr.put(intf.getName() + " " + ipType, inetAddress.getHostAddress()); } // if (!TextUtils.isEmpty(inetAddress.getHostName())) // listStr.put( "HostName", inetAddress.getHostName()); } } } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } } addBuild("Network...", netListStr); } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } // --------------- Telephony Services ------------- TelephonyManager telephonyManager = (TelephonyManager) getActivity() .getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { Map<String, String> cellListStr = new LinkedHashMap<String, String>(); try { cellListStr.put("Version", telephonyManager.getDeviceSoftwareVersion()); cellListStr.put("Number", telephonyManager.getLine1Number()); cellListStr.put("Service", telephonyManager.getNetworkOperatorName()); cellListStr.put("Roaming", telephonyManager.isNetworkRoaming() ? "Yes" : "No"); cellListStr.put("Type", getNetworkTypeName(telephonyManager.getNetworkType())); if (Build.VERSION.SDK_INT >= 17) { if (telephonyManager.getAllCellInfo() != null) { for (CellInfo cellInfo : telephonyManager.getAllCellInfo()) { String cellName = cellInfo.getClass().getSimpleName(); int level = 0; if (cellInfo instanceof CellInfoCdma) { level = ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoGsm) { level = ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoLte) { level = ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoWcdma) { if (Build.VERSION.SDK_INT >= 18) { level = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel(); } } cellListStr.put(cellName, "Level% " + String.valueOf(100 * level / 4)); } } } for (NeighboringCellInfo cellInfo : telephonyManager.getNeighboringCellInfo()) { int level = cellInfo.getRssi(); cellListStr.put("Cell level%", String.valueOf(100 * level / 31)); } } catch (Exception ex) { m_log.e("Cell %s", ex.getMessage()); } if (!cellListStr.isEmpty()) { addBuild("Cell...", cellListStr); } } // --------------- Bluetooth Services (API18) ------------- if (Build.VERSION.SDK_INT >= 18) { try { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { Map<String, String> btListStr = new LinkedHashMap<String, String>(); btListStr.put("Enabled", bluetoothAdapter.isEnabled() ? "yes" : "no"); btListStr.put("Name", bluetoothAdapter.getName()); btListStr.put("ScanMode", String.valueOf(bluetoothAdapter.getScanMode())); btListStr.put("State", String.valueOf(bluetoothAdapter.getState())); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a ListView btListStr.put("Paired:" + device.getName(), device.getAddress()); } } BluetoothManager btMgr = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); if (btMgr != null) { // btMgr.getAdapter(). } addBuild("Bluetooth", btListStr); } } catch (Exception ex) { } } // --------------- Wifi Services ------------- final WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { if (mSystemBroadcastReceiver == null) { mSystemBroadcastReceiver = new SystemBroadcastReceiver(wifiMgr); getActivity().registerReceiver(mSystemBroadcastReceiver, INTENT_FILTER_SCAN_AVAILABLE); } if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { if (wifiMgr.getScanResults() == null || wifiMgr.getScanResults().size() != mLastScanSize) { mLastScanSize = wifiMgr.getScanResults().size(); wifiMgr.startScan(); } } Map<String, String> wifiListStr = new LinkedHashMap<String, String>(); try { DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); wifiListStr.put("DNS1", Formatter.formatIpAddress(dhcpInfo.dns1)); wifiListStr.put("DNS2", Formatter.formatIpAddress(dhcpInfo.dns2)); wifiListStr.put("Default Gateway", Formatter.formatIpAddress(dhcpInfo.gateway)); wifiListStr.put("IP Address", Formatter.formatIpAddress(dhcpInfo.ipAddress)); wifiListStr.put("Subnet Mask", Formatter.formatIpAddress(dhcpInfo.netmask)); wifiListStr.put("Server IP", Formatter.formatIpAddress(dhcpInfo.serverAddress)); wifiListStr.put("Lease Time(sec)", String.valueOf(dhcpInfo.leaseDuration)); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); if (wifiInfo != null) { wifiListStr.put("LinkSpeed Mbps", String.valueOf(wifiInfo.getLinkSpeed())); int numberOfLevels = 10; int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1); wifiListStr.put("Signal%", String.valueOf(100 * level / numberOfLevels)); if (Build.VERSION.SDK_INT >= 23) { wifiListStr.put("MAC", getMacAddr()); } else { wifiListStr.put("MAC", wifiInfo.getMacAddress()); } } } catch (Exception ex) { m_log.e("Wifi %s", ex.getMessage()); } if (!wifiListStr.isEmpty()) { addBuild("WiFi...", wifiListStr); } try { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { List<ScanResult> listWifi = wifiMgr.getScanResults(); if (listWifi != null && !listWifi.isEmpty()) { int idx = 0; for (ScanResult scanResult : listWifi) { Map<String, String> wifiScanListStr = new LinkedHashMap<String, String>(); wifiScanListStr.put("SSID", scanResult.SSID); if (Build.VERSION.SDK_INT >= 23) { wifiScanListStr.put(" Name", scanResult.operatorFriendlyName.toString()); wifiScanListStr.put(" Venue", scanResult.venueName.toString()); } // wifiScanListStr.put(" BSSID ",scanResult.BSSID); wifiScanListStr.put(" Capabilities", scanResult.capabilities); // wifiScanListStr.put(" Center Freq", String.valueOf(scanResult.centerFreq0)); // wifiScanListStr.put(" Freq width", String.valueOf(scanResult.channelWidth)); wifiScanListStr.put(" Level, Freq", String.format("%d, %d", scanResult.level, scanResult.frequency)); if (Build.VERSION.SDK_INT >= 17) { Date wifiTime = new Date(scanResult.timestamp); wifiScanListStr.put(" Time", wifiTime.toLocaleString()); } addBuild(String.format("WiFiScan #%d", ++idx), wifiScanListStr); } } } } catch (Exception ex) { m_log.e("WifiList %s", ex.getMessage()); } try { List<WifiConfiguration> listWifiCfg = wifiMgr.getConfiguredNetworks(); for (WifiConfiguration wifiCfg : listWifiCfg) { Map<String, String> wifiCfgListStr = new LinkedHashMap<String, String>(); if (Build.VERSION.SDK_INT >= 23) { wifiCfgListStr.put("Name", wifiCfg.providerFriendlyName); } wifiCfgListStr.put("SSID", wifiCfg.SSID); String netStatus = ""; switch (wifiCfg.status) { case WifiConfiguration.Status.CURRENT: netStatus = "Connected"; break; case WifiConfiguration.Status.DISABLED: netStatus = "Disabled"; break; case WifiConfiguration.Status.ENABLED: netStatus = "Enabled"; break; } wifiCfgListStr.put(" Status", netStatus); wifiCfgListStr.put(" Priority", String.valueOf(wifiCfg.priority)); if (null != wifiCfg.wepKeys) { // wifiCfgListStr.put(" wepKeys", TextUtils.join(",", wifiCfg.wepKeys)); } String protocols = ""; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) protocols = "RSN "; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.WPA)) protocols = protocols + "WPA "; wifiCfgListStr.put(" Protocols", protocols); String keyProt = ""; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) keyProt = "none"; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP)) keyProt = "WPA+EAP "; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) keyProt = "WPA+PSK "; wifiCfgListStr.put(" Keys", keyProt); if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) { // Remove network connections with no Password. // wifiMgr.removeNetwork(wifiCfg.networkId); } addBuild("WiFiCfg #" + wifiCfg.networkId, wifiCfgListStr); } } catch (Exception ex) { m_log.e("Wifi Cfg List %s", ex.getMessage()); } } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:org.restcomm.app.qoslib.Utils.QosInfo.java
/** * Called Internally to initialize all of the current measurements for every type of connected newtork * This is like a snapshot of everything at this moment in time * The information comes from various sources and it mainly fetched from the database for this call, or from APIs such as WiFi *///ww w. j a v a 2 s . c o m private void updateFromDB() { Cursor sig_cursor = null; Cursor cell_cursor = null; try { Uri signalUri = UriMatch.SIGNAL_STRENGTHS.getContentUri(); Uri limitSignalUri = signalUri.buildUpon().appendQueryParameter("limit", "1").build(); // sig_cursor = managedQuery( Provider dbProvider = ReportManager.getInstance(context.getApplicationContext()).getDBProvider(); if (dbProvider == null) { return; } sig_cursor = dbProvider.query(UriMatch.SIGNAL_STRENGTHS.getContentUri(), null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC"); sig_cursor.moveToFirst(); Uri baseStationTable = (UriMatch.BASE_STATIONS .getContentUri()/*telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA ? UriMatchOld.BASE_STATIONS_CDMA.getContentUri() : UriMatchOld.BASE_STATIONS_GSM.getContentUri()*/ ); Uri limitBSUri = baseStationTable.buildUpon().appendQueryParameter("limit", "1").build(); // Cursor cell_cursor = managedQuery( cell_cursor = dbProvider.query(limitBSUri, null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC"); cell_cursor.moveToFirst(); int LowIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_LOW); int MidIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_MID); int HighIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_HIGH); int CodeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CODE); int BandIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_BAND); int ChanIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CHAN); int netTypeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.NET_TYPE); String netType = cell_cursor.getString(netTypeIndex); int bsLow = cell_cursor.getInt(LowIndex); int bsMid = cell_cursor.getInt(MidIndex); int bsHigh = cell_cursor.getInt(HighIndex); int bsCode = cell_cursor.getInt(CodeIndex); int bsBand = cell_cursor.getInt(BandIndex); int bsChan = cell_cursor.getInt(ChanIndex); if (netType.equals("cdma")) { if (LowIndex != -1) BID = bsLow; if (MidIndex != -1) NID = bsMid; if (HighIndex != -1) SID = bsHigh; } else if (netType.equals("gsm")) { if (LowIndex != -1) { RNC = bsMid; CellID = cell_cursor.getInt(LowIndex); } // the network Id is kept 0 for gsm phones if (HighIndex != -1) LAC = bsHigh; if (bsCode > 0 && bsCode < 1000) PSC = bsCode; else PSC = 0; if (bsBand > 0) Band = bsBand; else Band = 0; if (bsChan > 0) Channel = bsChan; else Channel = 0; } if (sig_cursor.getCount() != 0) { int signalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL); int signal2GIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL2G); int rsrpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRP); int rsrqIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRQ); int lteSnrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SNR); int lteSignalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SIGNAL); int lteCqiIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_CQI); int ecioIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECI0); int ecnoIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECN0); int snrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SNR); int berIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.BER); int rscpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.RSCP); int tierIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.COVERAGE); Integer tier = sig_cursor.isNull(tierIndex) ? null : sig_cursor.getInt(tierIndex); Integer rssi = sig_cursor.isNull(signalIndex) ? null : sig_cursor.getInt(signalIndex); Integer rssi2G = sig_cursor.isNull(signal2GIndex) ? null : sig_cursor.getInt(signal2GIndex); Integer rsrp = sig_cursor.isNull(rsrpIndex) ? null : sig_cursor.getInt(rsrpIndex); Float lteSnr = (sig_cursor.isNull(lteSnrIndex) ? null : (float) sig_cursor.getInt(lteSnrIndex)); Integer lteSignal = sig_cursor.isNull(lteSignalIndex) ? null : sig_cursor.getInt(lteSignalIndex); Integer lteCqi = sig_cursor.isNull(lteCqiIndex) ? null : sig_cursor.getInt(lteCqiIndex); Integer rsrq = sig_cursor.isNull(rsrqIndex) ? null : sig_cursor.getInt(rsrqIndex); Integer eci0 = sig_cursor.isNull(ecioIndex) ? null : sig_cursor.getInt(ecioIndex); Integer ecn0 = sig_cursor.isNull(ecnoIndex) ? null : sig_cursor.getInt(ecnoIndex); Integer snr = sig_cursor.isNull(snrIndex) ? null : sig_cursor.getInt(snrIndex); Integer ber = sig_cursor.isNull(berIndex) ? null : sig_cursor.getInt(berIndex); Integer rscp = sig_cursor.isNull(rscpIndex) ? null : sig_cursor.getInt(rscpIndex); if (eci0 != null && (netType.equals("cdma") || netType.equals("lte")) && eci0 <= -30) eci0 = (eci0 / 10); else if (ecn0 != null && ecn0 > 1 && ecn0 < 60 && netType.equals("gsm")) ecn0 = -(ecn0 / 2); else if (eci0 != null && eci0 > 1 && eci0 < 60 && netType.equals("gsm")) eci0 = -(eci0 / 2); // if (lteSnr != null && lteSnr > 1 && lteSnr < 500) // lteSnr = (lteSnr+5)/10; if (lteSignal != null && lteSignal > -120 && lteSignal < -20) // rssi == lteSignal) { LTE_RSSI = simpleValidate(lteSignal); RSSI = 0; } else if (rssi == null || rssi == -255) RSSI = 0; else if (rssi == -256) RSSI = -256; else { String name = "RSCP: "; int spacing = 15; if (netType.equals("gsm") && (tier == 3 || tier == 4)) { RSCP = rssi; RSSI = 0; } else { RSSI = rssi; RSCP = 0; } LTE_RSSI = 0; } if (netType.equals("cdma") && rssi2G != null && rssi2G < -30 && rssi2G >= -120) CDMA_RSSI = rssi2G; if (tier == 5) { if (lteSnr != null && lteSnr > -101) lteSnr = lteSnr / 10; if (rsrq != null && rsrq > 0) rsrq = -rsrq; LTE_RSRP = simpleValidate(rsrp); LTE_RSRQ = simpleValidate(rsrq); LTE_SNR = simpleValidate(lteSnr); LTE_CQI = simpleValidate(lteCqi); ECIO = simpleValidate(eci0); ECNO = simpleValidate(ecn0); } //nerdview.setValue(0, "RSCP", simpleValidate(rscp, "RSCP", "dBm")); //BER = simpleValidate(ber); SNR = simpleValidate(snr); if (rsrp != null && rsrp <= -10 && rsrp >= -140 && tier == 5) { LTEIdentity = ReportManager.getInstance(context.getApplicationContext()).getNeighbors(); } else { LTEIdentity = null; Neighbors = ReportManager.getInstance(context.getApplicationContext()).getNeighbors(); } } location = ReportManager.getInstance(context.getApplicationContext()).getLastKnownLocation(); try { JSONObject serviceMode = PhoneState.getServiceMode(); if (serviceMode != null && serviceMode.getLong("time") + 5000 > System.currentTimeMillis()) { if (serviceMode.has("rrc") && serviceMode.getString("rrc").length() > 1) { RRC = serviceMode.getString("rrc"); } else RRC = null; if (serviceMode.has("band") && serviceMode.getString("band").length() > 0) { Band = Integer.parseInt(serviceMode.getString("band")); } //else if (serviceMode.has("freq") && serviceMode.getString("freq").length() > 0) { Band = Integer.parseInt(serviceMode.getString("freq")); } else Band = 0; if (serviceMode.has("channel") && serviceMode.getString("channel").length() > 0) { Channel = Integer.parseInt(serviceMode.getString("channel")); } else Channel = 0; } else { RRC = null; Band = 0; Channel = 0; } TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Service.TELEPHONY_SERVICE); String carrier = telephonyManager.getNetworkOperatorName(); String mcc = "0", mnc = "0"; if (telephonyManager.getNetworkOperator() != null && telephonyManager.getNetworkOperator().length() >= 4) { mcc = telephonyManager.getNetworkOperator().substring(0, 3); mnc = telephonyManager.getNetworkOperator().substring(3); } int networkType = telephonyManager.getNetworkType(); int networkTier = PhoneState.getNetworkGeneration(networkType); String nettype = PhoneState.getNetworkName(telephonyManager.getNetworkType()); String data = PhoneState.getNetworkName(telephonyManager.getNetworkType()) + " "; int dataState = telephonyManager.getDataState(); if (dataState == TelephonyManager.DATA_CONNECTED) { String activity = getActivityName(telephonyManager.getDataActivity()); data += activity; } else if (telephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) { String state = getStateName(telephonyManager.getDataState()); data += state; } Data = data; Carrier = carrier; Date date = new Date(System.currentTimeMillis()); final String dateStr = DateFormat.getDateFormat(context).format(date); final String timeStr = dateStr + " " + DateFormat.getTimeFormat(context).format(date); Time = timeStr; MCC = Integer.parseInt(mcc); MNC = Integer.parseInt(mnc); // Tell the service we're watching the signal, so keep it updated Intent intent = new Intent(CommonIntentActionsOld.VIEWING_SIGNAL); context.sendBroadcast(intent); WifiInfo wifiinfo = getWifiInfo(); WifiConfiguration wifiConfig = getWifiConfig(); setWifi(wifiinfo, wifiConfig); // Instantiate only the relevant Network type if (netType.equals("cdma")) connectedNetwork = CDMAInfo = new CDMAInfo(this); else if (netType.equals("gsm") && networkTier < 3) connectedNetwork = GSMInfo = new GSMInfo(this); else if (netType.equals("gsm") && networkTier < 5) connectedNetwork = WCDMAInfo = new WCDMAInfo(this); if (networkTier == 5) // LTE connectedNetwork = LTEInfo = new LTEInfo(this); if (wifiConfig != null) connectedNetwork = WiFiInfo = new WIFIInfo(this); // The most relevant network ends up in NetworkInfo } catch (Exception e) { } } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "updateNerdViewFromDB", "exception querying signal data: " + e.getMessage()); } finally { if (cell_cursor != null) cell_cursor.close(); if (sig_cursor != null) sig_cursor.close(); } }
From source file:org.restcomm.app.qoslib.Services.Events.EventManager.java
/** * At the start of the event, stores like-timestamped entries in the tables for signals, cells and locations * This is so that querying the timespan of the event recording will easily return records for the beginning of the event * among other things/* www .j av a2 s .c om*/ * @param event */ public void signalSnapshot(EventObj event) { // In case the signal hasn't changed recently (last 30 sec or so), // the signal won't be retrieved by the cursor unless we timestamp the last known signal now try { TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); // Update the database and intents with a snapshot of the last known signal, cell, location SignalEx signal = context.getPhoneState().getLastMMCSignal(); long timestamp = System.currentTimeMillis(); if (event != null) timestamp = event.getEventTimestamp(); if (signal != null) { signal.setTimestamp(timestamp); context.getPhoneState().clearLastMMCSignal(); // to force a duplicate signal to be added context.getPhoneStateListener().processNewMMCSignal(signal); } CellLocationEx cell = context.getPhoneStateListener().getLastCellLocation(); if (cell != null) { cell.setCellIdTimestamp(timestamp); context.getPhoneStateListener().clearLastCellLocation(); context.getPhoneStateListener().processNewCellLocation(cell); } if (event == null) return; ongoingEvents.add(event); Location location = context.getLastLocation(); int satellites = context.getLastNumSatellites(); if (location != null) { location.setTime(timestamp); context.setLastLocation(null); // to force a duplicate location to be added context.processNewFilteredLocation(location, satellites); } // set an initial location on the event if it is recent, but update it if a better location becomes available location = context.getLastLocation(); event.setSignal(context.getPhoneState().getLastMMCSignal()); event.setCell(context.getPhoneStateListener().getLastCellLocation()); event.setServiceState(context.getPhoneState().getLastServiceStateObj()); if (location != null && location.getTime() - 10000 > System.currentTimeMillis()) event.setLocation(location, context.getLastNumSatellites()); // Also, set the coverage flags at the time of the event int tier = context.getPhoneState().getNetworkGeneration(); int servicestate = context.getPhoneState().getLastServiceState(); int datastate = telephonyManager.getDataState(); int activeConnection = PhoneState.ActiveConnection(context); if (activeConnection == 10) event.setFlag(EventObj.SERVICE_WIFI, true); else if (activeConnection == 11) event.setFlag(EventObj.SERVICE_WIMAX, true); ReportManager reportManager = ReportManager.getInstance(context); if (reportManager.manualPlottingEvent != null || event.getEventType() == EventType.MAN_PLOTTING) event.setFlag(EventObj.MANUAL_SAMPLES, true); if (datastate == TelephonyManager.DATA_CONNECTED || activeConnection > 1) event.setFlag(EventObj.SERVICE_DATA, true); else if (datastate == TelephonyManager.DATA_SUSPENDED && servicestate == ServiceState.STATE_IN_SERVICE) // not counted as data outage if data turned off event.setFlag(EventObj.SERVICE_DATA, true); else event.setFlag(EventObj.SERVICE_DATA, false); if (servicestate == ServiceState.STATE_OUT_OF_SERVICE || servicestate == ServiceState.STATE_EMERGENCY_ONLY) event.setFlag(EventObj.SERVICE_VOICE, false); else event.setFlag(EventObj.SERVICE_VOICE, true); if (tier > 2) event.setFlag(EventObj.SERVICE_3G, true); if (tier > 4) event.setFlag(EventObj.SERVICE_4G, true); if (context.getPhoneState().isCallConnected() || context.getPhoneState().isCallDialing() || event.getEventType().getIntValue() <= 6) event.setFlag(EventObj.PHONE_INUSE, true); // dropped call detection support using logcat or precise call state? if (event.getEventType().getIntValue() <= 7) { String pname = context.getPackageName(); int permissionForReadLogs = context.getPackageManager() .checkPermission(android.Manifest.permission.READ_LOGS, pname); //0 means allowed int permissionForPrecise = context.getPackageManager() .checkPermission("android.permission.READ_PRECISE_PHONE_STATE", pname); // 0 means allowed if (permissionForPrecise == 0) event.setFlag(EventObj.CALL_PRECISE, true); else if (permissionForReadLogs == 0) event.setFlag(EventObj.CALL_LOGCAT, true); } event.setBattery(DeviceInfoOld.battery); if (event.getEventType() == EventType.COV_VOD_NO || event.getEventType() == EventType.COV_VOD_YES || event.getEventType() == EventType.COV_UPDATE || event.getEventType() == EventType.TRAVEL_CHECK) { long duration = 0; if (mLastServiceStateChangeTimeStamp != 0) { duration = System.currentTimeMillis() - mLastServiceStateChangeTimeStamp; mLastServiceStateChangeTimeStamp = System.currentTimeMillis(); event.setDuration(duration); } else duration = mLastScreenOffDuration; } if (event.getEventType() == EventType.COV_3G_NO || event.getEventType() == EventType.COV_3G_YES || event.getEventType() == EventType.COV_UPDATE || event.getEventType() == EventType.TRAVEL_CHECK) { long duration = 0; if (mLast3GStateChangeTimeStamp != 0) { duration = System.currentTimeMillis() - mLast3GStateChangeTimeStamp; if (event.getEventType() == EventType.COV_UPDATE || event.getEventType() == EventType.TRAVEL_CHECK) event.setEventIndex(duration); else event.setDuration(duration); mLast3GStateChangeTimeStamp = System.currentTimeMillis(); } } //context.getCellHistory ().snapshotHistory(); String conn = context.getConnectionHistory().updateConnectionHistory(telephonyManager.getNetworkType(), telephonyManager.getDataState(), telephonyManager.getDataActivity(), context.getPhoneState().getLastServiceStateObj(), context.getConnectivityManager().getActiveNetworkInfo()); context.getIntentDispatcher().updateConnection(conn, true); WifiInfo wifiinfo = getWifiInfo(); WifiConfiguration wifiConfig = getWifiConfig(); event.setWifi(wifiinfo, wifiConfig); localReportEvent(event); } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "signalSnapshot", "error", e); } }