Commit 7bb8aaea authored by Administrator's avatar Administrator

Merge branch 'develop-alex' into 'master'

Develop alex

See merge request iinti/majora-adr!1
parents b1fdd507 7a867662
......@@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.virjar.majora.adr"
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 23
versionCode 1
versionName "1.0"
archivesBaseName = "Majora_${versionName}".replace(' ', '_')
......
......@@ -107,11 +107,13 @@ public class KeepAliveService extends Service {
start = true;
}
private void reDial() {
public static void reDial() {
try {
Shell.executeCmd("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");
Thread.sleep(5000);
Shell.executeCmd("am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false");
Shell.doCmds("settings put global airplane_mode_on 0 && am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false");
} catch (Exception e) {
MajoraLogger.getLogger().info("reDial error", e);
}
......
......@@ -28,6 +28,7 @@ public class MainActivity extends Activity {
Button btn = findViewById(R.id.goSetting);
Button changeIpBt = findViewById(R.id.changeIpBt);
btn.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -35,7 +36,12 @@ public class MainActivity extends Activity {
SettingsActivity.go(MainActivity.this);
}
});
changeIpBt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
KeepAliveService.reDial();
}
});
showRatelFloatWindow();
}
......
package com.virjar.majora.adr;
import android.util.Log;
import com.virjar.majora.client.sdk.log.MajoraLogger;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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;
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();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException 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);
}
public static void executeCmd(String cmd) {
try {
......
......@@ -2,6 +2,7 @@
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
......@@ -40,4 +41,12 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<Button
android:id="@+id/changeIpBt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="切换ip"
tools:layout_editor_absoluteX="151dp"
tools:layout_editor_absoluteY="425dp" />
</android.support.constraint.ConstraintLayout>
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