def stop_service(self): if self.service: self.service.stop() self.service = None if self.terminal_stop: self.terminal_stop.set() # self.error_log = LOGO_STRING self.log_info( "Plugin stopped. Detailed analytic results are saved in " + self.log_name) self.stop_collection() # close ongoing collections # Haotian: save orphan log dated_files = [] self.__logdir = main_utils.get_mobileinsight_log_path() self.__phone_info = main_utils.get_phone_info() mi2log_folder = os.path.join(main_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() if len(dated_files) > 0: self.__original_filename = dated_files[0][1] # print "The last orphan log file: " + # str(self.__original_filename) chmodcmd = "chmod 644 " + self.__original_filename p = subprocess.Popen("su ", executable=main_utils.ANDROID_SHELL, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) p.communicate(chmodcmd + '\n') p.wait() self._save_log()
def create_folder(): cmd = "" mobileinsight_path = main_utils.get_mobileinsight_path() if not mobileinsight_path: return False try: legacy_mobileinsight_path = main_utils.get_legacy_mobileinsight_path() cmd = cmd + "mv " + legacy_mobileinsight_path + " " + mobileinsight_path + "; " cmd = cmd + "mv " + legacy_mobileinsight_path + "/apps/ " + mobileinsight_path + "/plugins/; " except: pass if not os.path.exists(mobileinsight_path): cmd = cmd + "mkdir " + mobileinsight_path + "; " cmd = cmd + "chmod -R 755 " + mobileinsight_path + "; " log_path = main_utils.get_mobileinsight_log_path() if not os.path.exists(log_path): cmd = cmd + "mkdir " + log_path + "; " cmd = cmd + "chmod -R 755 " + log_path + "; " analysis_path = main_utils.get_mobileinsight_analysis_path() if not os.path.exists(analysis_path): cmd = cmd + "mkdir " + analysis_path + "; " cmd = cmd + "chmod -R 755 " + analysis_path + "; " cfg_path = main_utils.get_mobileinsight_cfg_path() if not os.path.exists(analysis_path): cmd = cmd + "mkdir " + cfg_path + "; " cmd = cmd + "chmod -R 755 " + cfg_path + "; " db_path = main_utils.get_mobileinsight_db_path() if not os.path.exists(db_path): cmd = cmd + "mkdir " + db_path + "; " cmd = cmd + "chmod -R 755 " + db_path + "; " plugin_path = main_utils.get_mobileinsight_plugin_path() if not os.path.exists(plugin_path): cmd = cmd + "mkdir " + plugin_path + "; " cmd = cmd + "chmod -R 755 " + plugin_path + "; " log_decoded_path = main_utils.get_mobileinsight_log_decoded_path() if not os.path.exists(log_decoded_path): cmd = cmd + "mkdir " + log_decoded_path + "; " cmd = cmd + "chmod -R 755 " + log_decoded_path + "; " log_uploaded_path = main_utils.get_mobileinsight_log_uploaded_path() if not os.path.exists(log_uploaded_path): cmd = cmd + "mkdir " + log_uploaded_path + "; " cmd = cmd + "chmod -R 755 " + log_uploaded_path + "; " crash_log_path = main_utils.get_mobileinsight_crash_log_path() if not os.path.exists(crash_log_path): cmd = cmd + "mkdir " + crash_log_path + "; " cmd = cmd + "chmod -R 755 " + crash_log_path + "; " # cmd = cmd + "chmod -R 755 "+mobileinsight_path+"; " main_utils.run_shell_cmd(cmd) return True