NetLoggerMMDiag/ 0000775 0001750 0001750 00000000000 13210425305 014430 5 ustar moonsky219 moonsky219 NetLoggerMMDiag/main.mi2app 0000664 0001750 0001750 00000007702 13210422310 016465 0 ustar moonsky219 moonsky219 #!/usr/bin/python
# Filename: main.mi2app
"""
Realtime monitor and parser
Author: Haotian
"""
import os
import shutil
import sys
import traceback
from jnius import autoclass
from logging_analyzer import LoggingAnalyzer
from mobile_insight.monitor import OnlineMonitor
from service import mi2app_utils
list_logEnabled = [
"LTE_RRC_OTA_Packet",
"LTE_RRC_Serv_Cell_Info",
# "LTE_RRC_MIB_Packet",
# "LTE_RRC_MIB_Message_Log_Packet",
# "LTE_NAS_ESM_State",
# "LTE_NAS_ESM_OTA_Incoming_Packet",
# "LTE_NAS_ESM_OTA_Outgoing_Packet",
# "LTE_NAS_EMM_State",
# "LTE_NAS_EMM_OTA_Incoming_Packet",
# "LTE_NAS_EMM_OTA_Outgoing_Packet",
# "LTE_PDCP_DL_Config",
# "LTE_PDCP_UL_Config",
# "LTE_PDCP_UL_Data_PDU",
# "LTE_PDCP_DL_Ctrl_PDU",
# "LTE_PDCP_UL_Ctrl_PDU",
# "LTE_PDCP_DL_Stats",
# "LTE_PDCP_UL_Stats",
# "LTE_PDCP_DL_SRB_Integrity_Data_PDU",
# "LTE_PDCP_UL_SRB_Integrity_Data_PDU",
# "LTE_RLC_UL_Config_Log_Packet",
# "LTE_RLC_DL_Config_Log_Packet",
# "LTE_RLC_UL_AM_All_PDU",
# "LTE_RLC_DL_AM_All_PDU",
# "LTE_RLC_UL_Stats",
# "LTE_RLC_DL_Stats",
# "LTE_MAC_Configuration",
# "LTE_MAC_UL_Transport_Block",
# "LTE_MAC_DL_Transport_Block",
# "LTE_MAC_UL_Buffer_Status_Internal",
# "LTE_MAC_UL_Tx_Statistics",
# "LTE_MAC_Rach_Trigger",
# "LTE_MAC_Rach_Attempt",
# "LTE_PHY_PDSCH_Packet",
# "LTE_PHY_Serv_Cell_Measurement",
# "LTE_PHY_Connected_Mode_Intra_Freq_Meas",
# "LTE_PHY_Inter_RAT_Measurement",
# "LTE_PHY_Inter_RAT_CDMA_Measurement",
# "LTE_PHY_Idle_Neighbor_Cell_Meas",
# "LTE_PHY_PUCCH_Power_Control",
# "LTE_PHY_PUSCH_Power_Control",
# "LTE_PHY_PDCCH_PHICH_Indication_Report",
# "LTE_PHY_PDSCH_Stat_Indication",
# "LTE_PHY_System_Scan_Results",
# "LTE_PHY_BPLMN_Cell_Request",
# "LTE_PHY_BPLMN_Cell_Confirm",
# "LTE_PHY_Serving_Cell_COM_Loop",
# "LTE_PHY_PDCCH_Decoding_Result",
# "LTE_PHY_PDSCH_Decoding_Result",
# "LTE_PHY_PUSCH_Tx_Report",
# "LTE_PHY_PUCCH_Tx_Report",
# "LTE_PHY_RLM_Report",
# "LTE_PHY_PUSCH_CSF",
# "LTE_PHY_PUCCH_CSF",
# "LTE_RRC_CDRX_Events_Info",
"WCDMA_RRC_States",
"1xEV_Rx_Partial_MultiRLP_Packet",
"1xEV_Connected_State_Search_Info",
# "1xEV_Signaling_Control_Channel_Broadcast",
"1xEV_Connection_Attempt",
"1xEV_Connection_Release",
"WCDMA_RRC_OTA_Packet",
"WCDMA_RRC_Serv_Cell_Info",
"WCDMA_Search_Cell_Reselection_Rank",
"UMTS_NAS_OTA_Packet",
"UMTS_NAS_GMM_State",
"UMTS_NAS_MM_State",
"UMTS_NAS_MM_REG_State",
"GSM_RR_Cell_Information",
"GSM_Surround_Cell_BA_List",
"GSM_RR_Cell_Reselection_Meas",
"Srch_TNG_1x_Searcher_Dump",
"_1xEVDO_Multi_Carrier_Pilot_Sets",
]
try:
cache_directory = mi2app_utils.get_cache_dir()
files_directory = mi2app_utils.get_files_dir()
log_directory = os.path.join(cache_directory, "mi2log")
app_directory = "/sdcard/mobileinsight/plugins/NetLoggerMMDiag"
fifo_path = os.path.join(cache_directory, "diag_revealer_fifo")
src = OnlineMonitor()
src.set_skip_decoding(True)
src.set_log_directory(log_directory)
src.set_log_cut_size(float(25.0)) # 25 MB
# src.set_log_cut_size(float(plugin_config['mi_log_size']) / 1000.0)
configSrc = os.path.join(app_directory, "Diag.cfg")
configDst = os.path.join(cache_directory, "Diag.cfg")
if os.path.isfile(configSrc):
shutil.copyfile(configSrc, configDst)
else:
src.enable_log(list_logEnabled)
loggingAnalyzer = LoggingAnalyzer(plugin_config)
loggingAnalyzer.set_source(src)
src.run()
except:
print str(traceback.format_exc())
NetLoggerMMDiag/settings.json 0000664 0001750 0001750 00000001242 13210422175 017164 0 ustar moonsky219 moonsky219 [
{
"type" : "title",
"title" : ""
},
{
"type" : "numeric",
"title" : "Log Size (KB)",
"desc" : "The max size of each log",
"key" : "mi_log_size",
"default": "25000"
},
{
"type" : "bool",
"title" : "Log upload",
"desc" : "Collected logs will only be uploaded when Wi-Fi is connected",
"key" : "is_use_wifi",
"default": "1"
},
{
"type": "string",
"title": "Task name",
"desc": "This value will be set to related task if it is launched from MILab",
"key": "task",
"default": "Unknown"
}
]
NetLoggerMMDiag/logging_analyzer.py 0000664 0001750 0001750 00000020400 13210067553 020340 0 ustar moonsky219 moonsky219 #!/usr/bin/python
# Filename: logging_analyzer.py
"""
logging_analyzer for NetLoggerMMDiag. Developed for MILab.
Author: Haotian Deng
"""
import datetime
import math
import os
import re
import shutil
import subprocess
import sys
import threading
import urllib
import urlparse
from android.broadcast import BroadcastReceiver
from jnius import autoclass
from mobile_insight.analyzer.analyzer import *
from service import mi2app_utils
__all__=["LoggingAnalyzer"]
class LoggingAnalyzer(Analyzer):
def __init__(self, config):
Analyzer.__init__(self)
self.__MILabPluginName = 'NetLoggerMMDiag'
self.add_source_callback(self.__msg_callback)
self.__own_log_uploaded_dir = os.path.join(
mi2app_utils.get_mobileinsight_plugin_path(),
self.__MILabPluginName,
"log", "uploaded")
if not os.path.exists(self.__own_log_uploaded_dir):
os.makedirs(self.__own_log_uploaded_dir)
self.__is_use_wifi = False
self.__task = "Unknown"
if 'task' in config:
self.__task = config['task']
if 'is_use_wifi' in config and config['is_use_wifi'] == '1':
self.__is_use_wifi = True
self.__own_log_task_dir = os.path.join(
mi2app_utils.get_mobileinsight_plugin_path(),
self.__MILabPluginName,
"log", self.__task)
if not os.path.exists(self.__own_log_task_dir):
os.makedirs(self.__own_log_task_dir)
self.br = BroadcastReceiver(self.on_broadcast,
actions=['MobileInsight.Main.StopService'])
self.br.start()
self.brStop = BroadcastReceiver(self.on_broadcastStop,
actions=['MobileInsight.MILab.Stop'])
self.brStop.start()
self.brStart = BroadcastReceiver(self.on_broadcastStart,
actions=['MobileInsight.MILab.Start'])
self.brStart.start()
def on_broadcastStop(self, context, intent):
self.log_info("MobileInsight.MILab.Stop is received")
self.source._pause_collection()
self._check_orphan_log()
def on_broadcastStart(self, context, intent):
self.log_info("MobileInsight.MILab.Start is received")
self.source._resume_collection()
def on_broadcast(self, context, intent):
'''
This plugin is going to be stopped, finish closure work
'''
print "LoggingAnalyzer are going to be stopped"
self.log_info("MobileInsight.Main.StopService is received")
self._check_orphan_log()
IntentClass = autoclass("android.content.Intent")
intent = IntentClass()
action = 'MobileInsight.Plugin.StopServiceAck'
intent.setAction(action)
try:
mi2app_utils.pyService.sendBroadcast(intent)
except Exception as e:
import traceback
self.log_error(str(traceback.format_exc()))
def set_source(self,source):
"""
Set the trace source. Enable the cellular signaling messages
:param source: the trace source (collector).
"""
Analyzer.set_source(self,source)
def _check_orphan_log(self):
'''
Check if there is any orphan log left in cache folder
'''
dated_files = []
mi2log_folder = os.path.join(mi2app_utils.get_cache_dir(), "mi2log")
for subdir, dirs, files in os.walk(mi2log_folder):
for f in files:
fn = os.path.join(subdir, f)
dated_files.append((os.path.getmtime(fn), fn))
dated_files.sort()
dated_files.reverse()
for dated_file in dated_files:
self.__orig_file = dated_file[1]
self.log_info("LoggingAnalyzer: find orphan log: %s" % self.__orig_file)
mi2app_utils.run_shell_cmd("chmod 644 %s" % self.__orig_file)
self._save_log()
self.log_info("mi2log file saved")
# def _upload_log(self, logfile):
# if not mi2app_utils.get_wifi_status():
# return
# import ehp
# basicUrl = "http://164.107.116.49/"
# s = requests.Session()
# url = basicUrl + 'milab/cellularlogs/create/'
# r = s.get(url)
# csrf_token = r.cookies['csrftoken']
# dictModel = {}
# dictOperator = {}
# dictPlugin = {}
# dictTask = {}
# html = ehp.Html()
# dom = html.feed(r.content)
# for root, item in dom.find_with_root('select'):
# if "id_model" in str(root[0]):
# for root, option in item.find_with_root('option'):
# txt = str(option)
# matchObj = re.match(r'^$', txt, re.M)
# if matchObj:
# dictModel[matchObj.group(2)] = matchObj.group(1)
# elif "id_operator" in str(root[0]):
# for root, option in item.find_with_root('option'):
# txt = str(option)
# matchObj = re.match(r'^$', txt, re.M)
# if matchObj:
# dictOperator[matchObj.group(2)] = matchObj.group(1)
# elif "id_plugin" in str(root[0]):
# for root, option in item.find_with_root('option'):
# txt = str(option)
# matchObj = re.match(r'^$', txt, re.M)
# if matchObj:
# dictPlugin[matchObj.group(2)] = matchObj.group(1)
# elif "id_task" in str(root[0]):
# for root, option in item.find_with_root('option'):
# txt = str(option)
# matchObj = re.match(r'^$', txt, re.M)
# if matchObj:
# dictTask[matchObj.group(2)] = matchObj.group(1)
# print dictModel
# print dictOperator
# print dictPlugin
# print dictTask
# phone_info = mi2app_utils.get_phone_info().split('_')[1]
# operator_info = mi2app_utils.get_operator_info()
# if self.__MILabPluginName not in dictPlugin \
# or phone_info not in dictModel\
# or operator_info not in dictOperator:
# self.log_error("mi2log (%s, %s, %s) upload aborted" % (
# self.__MILabPluginName,
# phone_info,
# operator_info))
# return
# multipart_form_data = {
# 'logfile': open(logfile, 'rb'),
# }
# inputData={'csrfmiddlewaretoken': csrf_token,
# 'plugin': dictPlugin[self.__MILabPluginName],
# 'model': dictModel[phone_info],
# 'operator': dictOperator[operator_info],
# }
# if self.__task in dictTask:
# inputData['task'] = dictTask[self.__task]
# r2 = s.post(url,
# data=inputData,
# headers=dict(Referer=url), files=multipart_form_data)
# self.log_info("mi2log file uploaded")
# shutil.copyfile(logfile, os.path.join(self.__own_log_uploaded_dir, os.path.basename(logfile)))
# os.remove(logfile)
def _save_log(self):
self.__log_timestamp = \
datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
milog_base_name = "diag_log_%s_%s_%s.mi2log" % (\
self.__log_timestamp, \
mi2app_utils.get_phone_info(), \
mi2app_utils.get_operator_info())
milog_abs_name = os.path.join(self.__own_log_task_dir, milog_base_name)
if os.path.isfile(self.__orig_file):
shutil.copyfile(self.__orig_file, milog_abs_name)
os.remove(self.__orig_file)
if self.__task == "Unknown":
pass
# self._upload_log(milog_abs_name)
def __msg_callback(self,msg):
if msg.type_id.find("new_diag_log") != -1:
log_item = msg.data.decode()
self.__orig_file = log_item.get("filename")
self.log_info("A new msg come in: " + self.__orig_file)
# FIXME (Zengwen): the change access command is a walkaround solution
mi2app_utils.run_shell_cmd("chmod 644 %s" % self.__orig_file)
self._save_log()
self.log_info("mi2log file saved")
NetLoggerMMDiag/Diag_full.cfg 0000664 0001750 0001750 00000003574 13210067354 017016 0 ustar moonsky219 moonsky219 ;~ x~|I~*~:~c~K `~K b~K ~K f~K I~K ~}] tA~s ځ~s ` ; ~s ! "