Commit 19e78913 authored by Administrator's avatar Administrator

重播前服务器mark

parent 7bb8aaea
......@@ -7,9 +7,10 @@ android {
defaultConfig {
applicationId "com.virjar.majora.adr"
minSdkVersion 19
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 23
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.2"
archivesBaseName = "Majora_${versionName}".replace(' ', '_')
}
......
......@@ -31,6 +31,7 @@ import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
public class KeepAliveService extends Service {
private static boolean start = false;
private static MajoraClient majoraClient;
// 重播任务定时器
private Timer timer = new Timer("reDial");
......@@ -108,6 +109,14 @@ public class KeepAliveService extends Service {
}
public static void reDial() {
if (majoraClient == null) {
reDialInternal();
} else {
majoraClient.prepareReDial(KeepAliveService::reDialInternal);
}
}
private static void reDialInternal() {
try {
Shell.doCmds("settings put global airplane_mode_on 1 && am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true");
......@@ -123,7 +132,7 @@ public class KeepAliveService extends Service {
SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(this);
String serverHost = spf.getString("server_host", "majora.virjar.com");
int serverPort = NumberUtils.toInt(spf.getString("server_port", "5879"), 5879);
new MajoraClient(serverHost, serverPort, ClientIdentifier.id()).startUp();
majoraClient = new MajoraClient(serverHost, serverPort, ClientIdentifier.id());
}
// 5. Drawable----> Bitmap
......
package com.virjar.majora.adr;
import android.util.Log;
import com.virjar.majora.client.sdk.log.MajoraLogger;
import java.io.BufferedReader;
......@@ -15,49 +13,49 @@ import java.io.OutputStream;
public class Shell {
public static void doCmds(String cmd) throws Exception {
MajoraLogger.getLogger().info("doCmds:" + cmd);
Process process = null;
String result = "";
DataOutputStream os = null;
DataInputStream is = null;
MajoraLogger.getLogger().info("doCmds:" + cmd);
Process process = null;
String result = "";
DataOutputStream os = null;
DataInputStream is = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
is = new DataInputStream(process.getInputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
String line;
while ((line = is.readLine()) != null) {
result += line;
}
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (os != null) {
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
is = new DataInputStream(process.getInputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
String line = null;
while ((line = is.readLine()) != null) {
result += line;
}
process.waitFor();
os.close();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (process != null) {
process.destroy();
}
}
MajoraLogger.getLogger().info("doCmds result:" + result);
}
if (process != null) {
process.destroy();
}
}
MajoraLogger.getLogger().info("doCmds result:" + result);
}
public static void executeCmd(String cmd) {
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment