Commit 19e78913 authored by Administrator's avatar Administrator

重播前服务器mark

parent 7bb8aaea
...@@ -7,9 +7,10 @@ android { ...@@ -7,9 +7,10 @@ android {
defaultConfig { defaultConfig {
applicationId "com.virjar.majora.adr" applicationId "com.virjar.majora.adr"
minSdkVersion 19 minSdkVersion 19
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 23 targetSdkVersion 23
versionCode 1 versionCode 2
versionName "1.0" versionName "1.2"
archivesBaseName = "Majora_${versionName}".replace(' ', '_') archivesBaseName = "Majora_${versionName}".replace(' ', '_')
} }
......
...@@ -31,6 +31,7 @@ import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; ...@@ -31,6 +31,7 @@ import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
public class KeepAliveService extends Service { public class KeepAliveService extends Service {
private static boolean start = false; private static boolean start = false;
private static MajoraClient majoraClient;
// 重播任务定时器 // 重播任务定时器
private Timer timer = new Timer("reDial"); private Timer timer = new Timer("reDial");
...@@ -108,6 +109,14 @@ public class KeepAliveService extends Service { ...@@ -108,6 +109,14 @@ public class KeepAliveService extends Service {
} }
public static void reDial() { public static void reDial() {
if (majoraClient == null) {
reDialInternal();
} else {
majoraClient.prepareReDial(KeepAliveService::reDialInternal);
}
}
private static void reDialInternal() {
try { try {
Shell.doCmds("settings put global airplane_mode_on 1 && am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true"); 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 { ...@@ -123,7 +132,7 @@ public class KeepAliveService extends Service {
SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(this);
String serverHost = spf.getString("server_host", "majora.virjar.com"); String serverHost = spf.getString("server_host", "majora.virjar.com");
int serverPort = NumberUtils.toInt(spf.getString("server_port", "5879"), 5879); 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 // 5. Drawable----> Bitmap
......
package com.virjar.majora.adr; package com.virjar.majora.adr;
import android.util.Log;
import com.virjar.majora.client.sdk.log.MajoraLogger; import com.virjar.majora.client.sdk.log.MajoraLogger;
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -15,49 +13,49 @@ import java.io.OutputStream; ...@@ -15,49 +13,49 @@ import java.io.OutputStream;
public class Shell { public class Shell {
public static void doCmds(String cmd) throws Exception { public static void doCmds(String cmd) throws Exception {
MajoraLogger.getLogger().info("doCmds:" + cmd); MajoraLogger.getLogger().info("doCmds:" + cmd);
Process process = null; Process process = null;
String result = ""; String result = "";
DataOutputStream os = null; DataOutputStream os = null;
DataInputStream is = 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 { try {
process = Runtime.getRuntime().exec("su"); os.close();
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();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (InterruptedException e) { }
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace(); 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) { public static void executeCmd(String cmd) {
try { 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