data.js 1.7 KB
const path = require('path')
const fs = require('fs')
var io = require('socket.io').listen(3000);
var exec = require('child_process').exec, child;
//var mysql = require('mysql');


//3. adb backup 명령어를 통해 데이터베이스 추출
function extractDB () {
	cmd_backup = exec('adb backup com.example.dataextraction -f backup.dataextraction.ad', function(error, stdout, stderr){
		console.log("backup app");
		setTimeout(function(){
			cmd_unpack = exec('java -jar abe.jar unpack backup.dataextraction.ad dataextraction.tar',function(error, stdout, stderr){
				console.log("unpack backup");
				cmd_unzip = exec('tar xvf dataextraction.tar', function(error, stdout, stderr){
					console.log("unzip tar");
					cmd_moveIdb = fs.rename('apps/com.example.dataextraction/db/InnerDatabase.db', 'InnerDatabase.db', function(){
						console.log("move innerDB");
						cmd_moveNdb = fs.rename('apps/com.example.dataextraction/db/networkDatabase.db', 'networkDatabase.db',function(){
							console.log("move network db");
							python_execute = exec('python data_sender.py',
							    function (error, stdout, stderr) {
							    	console.log("python code execute")
							        console.log('stdout: ' + stdout);
							        console.log('stderr: ' + stderr);
							        if (error !== null) {
							             console.log('exec error: ' + error);
							        }
							    });
						})
					})
				})
			})
		},7000);
	});
}

//2. 애플리케이션에서 데이터베이스 생성이 끝나면 알림
io.on('connection', function(socket){
	var instanceId = socket.id;

	socket.on('alert', function(data){
		console.log("alert");
	})
	socket.on('end', function(data){
		console.log("extract db end");
		extractDB();
  	})
})