|
|
|
@ -10,13 +10,11 @@ import android.content.ServiceConnection;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.content.res.AssetManager;
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.IBinder;
|
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.support.v7.widget.SwitchCompat;
|
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
@ -29,6 +27,10 @@ import android.widget.Switch;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
|
import com.xypower.common.LogFormatter;
|
|
|
|
|
import com.xypower.common.LogcatHandler;
|
|
|
|
|
import com.xypower.common.RotatingHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
|
@ -36,6 +38,9 @@ import java.io.Closeable;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
@ -57,6 +62,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
Handler mHandler;
|
|
|
|
|
|
|
|
|
|
public Logger logger;
|
|
|
|
|
|
|
|
|
|
private String mServer = DEFAULT_SERVER;
|
|
|
|
|
private int mPort = DEFAULT_PORT;
|
|
|
|
|
private int mRemotePort = DEFAULT_REMOTE_PORT;
|
|
|
|
@ -84,8 +91,36 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
|
|
|
File file = new File(getDataDir(), "running.txt");
|
|
|
|
|
FilesUtils.writeTextFile(file.getAbsolutePath(), "");
|
|
|
|
|
|
|
|
|
|
mHandler = new Handler();
|
|
|
|
|
|
|
|
|
|
logger = Logger.getLogger("com.xypower.frp.logger");
|
|
|
|
|
logger.setLevel(Level.ALL);
|
|
|
|
|
// LogFormatter.installFormatter(logger);
|
|
|
|
|
LogFormatter logFormatter = new LogFormatter();
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
|
LogcatHandler logcatHandler = new LogcatHandler(TAG);
|
|
|
|
|
logcatHandler.setFormatter(logFormatter);
|
|
|
|
|
logger.addHandler(logcatHandler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RotatingHandler rotatingHandler = null;
|
|
|
|
|
try {
|
|
|
|
|
File logFile = new File(getDataDir(), "frplog.txt");
|
|
|
|
|
|
|
|
|
|
rotatingHandler = new RotatingHandler(logFile.getAbsolutePath(), logFormatter);
|
|
|
|
|
|
|
|
|
|
logger.addHandler(rotatingHandler);
|
|
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
System.out.println("Failed to create directory:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.info("FrpAndroid is launching");
|
|
|
|
|
|
|
|
|
|
String versionName = null;
|
|
|
|
|
try {
|
|
|
|
|
versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
|
|
|
|
@ -154,7 +189,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
if (mBound) {
|
|
|
|
|
Intent intent = new Intent((Context)this, ShellService.class);
|
|
|
|
|
this.bindService(intent, (ServiceConnection)this.connection, 1);
|
|
|
|
|
this.bindService(intent, (ServiceConnection)this.connection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setListener();
|
|
|
|
@ -172,6 +207,15 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
|
|
File file = new File(getDataDir(), "running.txt");
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final void setListener() {
|
|
|
|
|
Button configButton = (Button)this.findViewById(R.id.configButton);
|
|
|
|
|
configButton.setOnClickListener((View.OnClickListener)(new View.OnClickListener() {
|
|
|
|
@ -233,7 +277,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
closeFinally(inputStream);
|
|
|
|
|
FilesUtils.closeFriendly(inputStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -254,23 +298,22 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final void closeFinally(Closeable closable) {
|
|
|
|
|
if (closable != null) {
|
|
|
|
|
try {
|
|
|
|
|
closable.close();
|
|
|
|
|
} catch (Throwable var3) {
|
|
|
|
|
// ExceptionsKt.addSuppressed(cause, var3);
|
|
|
|
|
private final void startShell() {
|
|
|
|
|
logger.info("Start Shell");
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent(getApplicationContext(), ShellService.class);
|
|
|
|
|
intent.putExtra("filename", "libfrpc.so");
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
startForegroundService(intent);
|
|
|
|
|
} else {
|
|
|
|
|
startService(intent);
|
|
|
|
|
}
|
|
|
|
|
this.bindService(intent, (ServiceConnection) this.connection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
logger.warning(ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final void startShell() {
|
|
|
|
|
Intent intent = new Intent((Context)this, ShellService.class);
|
|
|
|
|
intent.putExtra("filename", "libfrpc.so");
|
|
|
|
|
this.startService(intent);
|
|
|
|
|
this.bindService(intent, (ServiceConnection)this.connection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final void stopShell() {
|
|
|
|
|
Intent intent = new Intent((Context)this, ShellService.class);
|
|
|
|
|
this.unbindService((ServiceConnection)this.connection);
|
|
|
|
@ -351,6 +394,11 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
File file = new File(MainActivity.this.getDataDir(), "running.txt");
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainActivity.this.finish();
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|