|
|
@ -38,9 +38,10 @@ import java.util.Iterator;
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "FRP";
|
|
|
|
private static final String TAG = "FRP";
|
|
|
|
private static final String DEFAULT_SERVER = "61.169.135.146";
|
|
|
|
public static final String DEFAULT_SERVER = "61.169.135.146";
|
|
|
|
private static final int DEFAULT_PORT = 7000;
|
|
|
|
// private static final String DEFAULT_PROXY_NAME = "p2p_adb_" + Long.toString(System.currentTimeMillis() / 1000);
|
|
|
|
private static final int DEFAULT_REMOTE_PORT = 50001;
|
|
|
|
public static final int DEFAULT_PORT = 7000;
|
|
|
|
|
|
|
|
public static final int DEFAULT_REMOTE_PORT = 50001;
|
|
|
|
|
|
|
|
|
|
|
|
private Switch state_switch;
|
|
|
|
private Switch state_switch;
|
|
|
|
private Switch auto_start_switch;
|
|
|
|
private Switch auto_start_switch;
|
|
|
@ -50,12 +51,14 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
private static final String MICRO_KEY_SERVER = "%%SERVER%%";
|
|
|
|
private static final String MICRO_KEY_SERVER = "%%SERVER%%";
|
|
|
|
private static final String MICRO_KEY_PORT = "%%PORT%%";
|
|
|
|
private static final String MICRO_KEY_PORT = "%%PORT%%";
|
|
|
|
private static final String MICRO_KEY_REMOTE_PORT = "%%REMOTE_PORT%%";
|
|
|
|
private static final String MICRO_KEY_REMOTE_PORT = "%%REMOTE_PORT%%";
|
|
|
|
|
|
|
|
private static final String MICRO_KEY_PROXY_NAME = "%%PROXY_NAME%%";
|
|
|
|
|
|
|
|
|
|
|
|
Handler mHandler;
|
|
|
|
Handler mHandler;
|
|
|
|
|
|
|
|
|
|
|
|
private String mServer = DEFAULT_SERVER;
|
|
|
|
private String mServer = DEFAULT_SERVER;
|
|
|
|
private int mPort = DEFAULT_PORT;
|
|
|
|
private int mPort = DEFAULT_PORT;
|
|
|
|
private int mRemotePort = DEFAULT_REMOTE_PORT;
|
|
|
|
private int mRemotePort = DEFAULT_REMOTE_PORT;
|
|
|
|
|
|
|
|
private String mProxyName = "p2p_adb_" + Long.toString(System.currentTimeMillis() / 1000);
|
|
|
|
|
|
|
|
|
|
|
|
private final ServiceConnection connection = new ServiceConnection() {
|
|
|
|
private final ServiceConnection connection = new ServiceConnection() {
|
|
|
|
public void onServiceConnected(@NotNull ComponentName className, @NotNull IBinder service) {
|
|
|
|
public void onServiceConnected(@NotNull ComponentName className, @NotNull IBinder service) {
|
|
|
@ -95,13 +98,17 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
int autoClose = 0;
|
|
|
|
int autoClose = 0;
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Intent intent = getIntent();
|
|
|
|
Intent intent = getIntent();
|
|
|
|
String server = intent.getStringExtra("server");
|
|
|
|
String stringVal = intent.getStringExtra("server");
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(stringVal)) {
|
|
|
|
|
|
|
|
mServer = stringVal;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stringVal = intent.getStringExtra("proxyName");
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(stringVal)) {
|
|
|
|
|
|
|
|
mProxyName = stringVal;
|
|
|
|
|
|
|
|
}
|
|
|
|
mPort = intent.getIntExtra("port", DEFAULT_PORT);
|
|
|
|
mPort = intent.getIntExtra("port", DEFAULT_PORT);
|
|
|
|
mRemotePort = intent.getIntExtra("remotePort", DEFAULT_REMOTE_PORT);
|
|
|
|
mRemotePort = intent.getIntExtra("remotePort", DEFAULT_REMOTE_PORT);
|
|
|
|
startFrp = intent.getIntExtra("startFrp", 0);
|
|
|
|
startFrp = intent.getIntExtra("startFrp", 0);
|
|
|
|
if (!TextUtils.isEmpty(server)) {
|
|
|
|
|
|
|
|
mServer = server;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (startFrp != 0) {
|
|
|
|
if (startFrp != 0) {
|
|
|
|
Log.i(TAG, "Will start server");
|
|
|
|
Log.i(TAG, "Will start server");
|
|
|
@ -111,7 +118,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkConfig(mServer, mPort, mRemotePort);
|
|
|
|
checkConfig(getApplicationContext(), mServer, mPort, mRemotePort, mProxyName);
|
|
|
|
checkNotificationPermission();
|
|
|
|
checkNotificationPermission();
|
|
|
|
createBGNotificationChannel();
|
|
|
|
createBGNotificationChannel();
|
|
|
|
|
|
|
|
|
|
|
@ -168,6 +175,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
configButton.setOnClickListener((View.OnClickListener)(new View.OnClickListener() {
|
|
|
|
configButton.setOnClickListener((View.OnClickListener)(new View.OnClickListener() {
|
|
|
|
public final void onClick(View it) {
|
|
|
|
public final void onClick(View it) {
|
|
|
|
Intent intent = new Intent((Context)MainActivity.this, ConfigActivity.class);
|
|
|
|
Intent intent = new Intent((Context)MainActivity.this, ConfigActivity.class);
|
|
|
|
|
|
|
|
intent.putExtras(getIntent());
|
|
|
|
MainActivity.this.startActivity(intent);
|
|
|
|
MainActivity.this.startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
@ -199,15 +207,15 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public final void checkConfig(String server, int port, int remotePort) {
|
|
|
|
public static File checkConfig(Context context, String server, int port, int remotePort, String proxyName) {
|
|
|
|
// Intrinsics.checkNotNullExpressionValue(var12, "resources");
|
|
|
|
// Intrinsics.checkNotNullExpressionValue(var12, "resources");
|
|
|
|
AssetManager assetmanager = getResources().getAssets();
|
|
|
|
AssetManager assetmanager = context.getResources().getAssets();
|
|
|
|
|
|
|
|
|
|
|
|
File confFile = new File(getDataDir(), "conf");
|
|
|
|
File confFile = new File(context.getDataDir(), "conf");
|
|
|
|
if (!confFile.exists()) {
|
|
|
|
if (!confFile.exists()) {
|
|
|
|
confFile.mkdirs();
|
|
|
|
confFile.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
File file = new File(new File(getDataDir(), "conf"), "config.toml");
|
|
|
|
File file = new File(new File(context.getDataDir(), "conf"), "config.toml");
|
|
|
|
|
|
|
|
|
|
|
|
StringBuffer configContent = new StringBuffer();
|
|
|
|
StringBuffer configContent = new StringBuffer();
|
|
|
|
InputStream inputStream = null;
|
|
|
|
InputStream inputStream = null;
|
|
|
@ -217,6 +225,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
content = content.replaceAll(MICRO_KEY_SERVER, server);
|
|
|
|
content = content.replaceAll(MICRO_KEY_SERVER, server);
|
|
|
|
content = content.replaceAll(MICRO_KEY_PORT, Integer.toString(port));
|
|
|
|
content = content.replaceAll(MICRO_KEY_PORT, Integer.toString(port));
|
|
|
|
content = content.replaceAll(MICRO_KEY_REMOTE_PORT, Integer.toString(remotePort));
|
|
|
|
content = content.replaceAll(MICRO_KEY_REMOTE_PORT, Integer.toString(remotePort));
|
|
|
|
|
|
|
|
content = content.replaceAll(MICRO_KEY_PROXY_NAME, proxyName);
|
|
|
|
|
|
|
|
|
|
|
|
FilesUtils.writeTextFile(file.getAbsolutePath(), content);
|
|
|
|
FilesUtils.writeTextFile(file.getAbsolutePath(), content);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
} catch (Throwable ex) {
|
|
|
@ -239,6 +248,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final void closeFinally(Closeable closable) {
|
|
|
|
private static final void closeFinally(Closeable closable) {
|
|
|
|