调整服务器相关参数和功能

main
Matthew 12 months ago
parent 23b6087344
commit a933f35788

@ -9,8 +9,8 @@ android {
applicationId "com.xypower.frpandroid" applicationId "com.xypower.frpandroid"
minSdk 25 minSdk 25
targetSdk 32 targetSdk 32
versionCode 1 versionCode 2
versionName "1.0" versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@ -54,9 +54,11 @@ android {
dependencies { dependencies {
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4' implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'org.jetbrains:annotations:15.0' implementation 'org.jetbrains:annotations:15.0'
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

@ -31,7 +31,8 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true"> android:exported="true"
android:screenOrientation="landscape" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

@ -6,8 +6,6 @@ auth.token = "mint"
transport.tls.enable = false transport.tls.enable = false
transport.tls.disableCustomTLSFirstByte = false transport.tls.disableCustomTLSFirstByte = false
[log] [log]
level = "debug" level = "debug"
disablePrintColor = true disablePrintColor = true

@ -15,6 +15,7 @@ import android.os.IBinder;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -22,9 +23,13 @@ import android.widget.CompoundButton;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import com.moandjiezana.toml.Toml;
import com.moandjiezana.toml.TomlWriter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.Closeable; import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
@ -38,6 +43,9 @@ public class MainActivity extends AppCompatActivity {
private ShellService mService; private ShellService mService;
private boolean mBound; private boolean mBound;
private String mServer = "61.169.135.146";
private int mPort = 7000;
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) {
// Intrinsics.checkNotNullParameter(className, "className"); // Intrinsics.checkNotNullParameter(className, "className");
@ -69,15 +77,15 @@ public class MainActivity extends AppCompatActivity {
TextView titleText = (TextView)this.findViewById(R.id.titleText); TextView titleText = (TextView)this.findViewById(R.id.titleText);
// Intrinsics.checkNotNullExpressionValue(titleText, "titleText"); // Intrinsics.checkNotNullExpressionValue(titleText, "titleText");
titleText.setText((CharSequence)("frp for Android - " + versionName + "/0.58.0")); titleText.setText((CharSequence)("frp for Android - " + versionName + "/0.58.0"));
this.checkConfig();
this.checkNotificationPermission(); checkConfig();
this.createBGNotificationChannel(); checkNotificationPermission();
this.mBound = this.isServiceRunning(ShellService.class); createBGNotificationChannel();
mBound = isServiceRunning(ShellService.class);
state_switch = (Switch)this.findViewById(R.id.state_switch); state_switch = (Switch)this.findViewById(R.id.state_switch);
// Intrinsics.checkNotNullExpressionValue(var10001, "findViewById<SwitchCompat>(R.id.state_switch)"); // Intrinsics.checkNotNullExpressionValue(var10001, "findViewById<SwitchCompat>(R.id.state_switch)");
state_switch.setChecked(this.mBound);
state_switch.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener)(new CompoundButton.OnCheckedChangeListener() { state_switch.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener)(new CompoundButton.OnCheckedChangeListener() {
public final void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public final void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) { if (isChecked) {
@ -89,7 +97,6 @@ public class MainActivity extends AppCompatActivity {
} }
})); }));
final SharedPreferences editor = this.getSharedPreferences("data", 0); final SharedPreferences editor = this.getSharedPreferences("data", 0);
auto_start_switch = (Switch) this.findViewById(R.id.auto_start_switch); auto_start_switch = (Switch) this.findViewById(R.id.auto_start_switch);
// Intrinsics.checkNotNullExpressionValue(var10001, "findViewById<SwitchCompat>(R.id.auto_start_switch)"); // Intrinsics.checkNotNullExpressionValue(var10001, "findViewById<SwitchCompat>(R.id.auto_start_switch)");
@ -103,12 +110,26 @@ public class MainActivity extends AppCompatActivity {
editorx.apply(); editorx.apply();
} }
})); }));
if (this.mBound) {
if (mBound) {
Intent intent = new Intent((Context)this, ShellService.class); Intent intent = new Intent((Context)this, ShellService.class);
this.bindService(intent, (ServiceConnection)this.connection, 1); this.bindService(intent, (ServiceConnection)this.connection, 1);
} }
this.setListener(); this.setListener();
int startFrp = 0;
{
Intent intent = getIntent();
String server = intent.getStringExtra("server");
mPort = intent.getIntExtra("port", 7000);
startFrp = intent.getIntExtra("startFrp", 0);
if (!TextUtils.isEmpty(server)) {
mServer = server;
}
}
state_switch.setChecked(mBound || (startFrp != 0));
} }
private final void setListener() { private final void setListener() {
@ -150,11 +171,19 @@ public class MainActivity extends AppCompatActivity {
public final void checkConfig() { public final void checkConfig() {
// Intrinsics.checkNotNullExpressionValue(var12, "resources"); // Intrinsics.checkNotNullExpressionValue(var12, "resources");
AssetManager assetmanager = getResources().getAssets(); AssetManager assetmanager = getResources().getAssets();
File confFile = new File(getDataDir(), "conf");
if (!confFile.exists()) {
confFile.mkdirs();
}
File file = new File(new File(getDataDir(), "conf"), "config.toml");
FileOutputStream fileOutputStream = null; FileOutputStream fileOutputStream = null;
try { try {
fileOutputStream = this.openFileOutput("config.toml", 0); fileOutputStream = new FileOutputStream(file);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} }
if (fileOutputStream == null) { if (fileOutputStream == null) {
@ -163,13 +192,15 @@ public class MainActivity extends AppCompatActivity {
InputStream inputStream = null; InputStream inputStream = null;
byte[] bytes = new byte[256]; byte[] bytes = new byte[256];
int bytesRead = -1;
try { try {
inputStream = assetmanager.open("config.toml"); inputStream = assetmanager.open("config.toml");
// Intrinsics.checkNotNullExpressionValue(var10001, "assetmanager.open((BuildConfig.ConfigFileName))"); // Intrinsics.checkNotNullExpressionValue(var10001, "assetmanager.open((BuildConfig.ConfigFileName))");
int bytesRead = inputStream.read(bytes); while ((bytesRead = inputStream.read(bytes)) != -1) {
if (bytesRead > 0) { if (bytesRead > 0) {
fileOutputStream.write(bytes, 0, bytesRead); fileOutputStream.write(bytes, 0, bytesRead);
} }
}
// Unit var11 = Unit.INSTANCE; // Unit var11 = Unit.INSTANCE;
} catch (Throwable ex) { } catch (Throwable ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -178,6 +209,20 @@ public class MainActivity extends AppCompatActivity {
closeFinally(inputStream); closeFinally(inputStream);
} }
try {
// Toml toml = new Toml();
// File file = new File(getDataDir(), "config.toml");
// toml.read(file);
// int aa = 0;
// String someValue = toml.getString("someKey");
// Date someDate = toml.getDate("someTable.someDate");
// MyClass myClass = toml.to(MyClass.class);
// TomlWriter.Builder tomlBuilder = new TomlWriter.Builder();
// tomlBuilder.
} catch (Exception ex) {
ex.printStackTrace();
}
} }
private static final void closeFinally(Closeable closable) { private static final void closeFinally(Closeable closable) {

@ -11,6 +11,7 @@ import android.os.Binder;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -53,18 +54,22 @@ public class ShellService extends Service {
public int onStartCommand(@Nullable Intent intent, int flags, int startId) { public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
String filename = ""; String fileName = "";
File confFile = new File(getDataDir(), "conf");
confFile = new File(confFile, "config.toml");
if (this.mProcessThread != null) { if (this.mProcessThread != null) {
Log.w("adx", "process isn't null,service won't start"); Log.w("adx", "process isn't null,service won't start");
Toast.makeText((Context)this, (CharSequence)"process isn't null,service won't start", Toast.LENGTH_SHORT).show(); Toast.makeText((Context)this, (CharSequence)"process isn't null,service won't start", Toast.LENGTH_SHORT).show();
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} else if (intent != null) { } else if (intent != null) {
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
Object var8 = extras != null ? extras.get("filename") : null; fileName = extras != null ? extras.getString("filename") : null;
if (var8 == null) { if (TextUtils.isEmpty(fileName)) {
throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
} else { } else {
filename = (String)var8;
ApplicationInfo applicationInfo = null; ApplicationInfo applicationInfo = null;
try { try {
applicationInfo = this.getPackageManager().getApplicationInfo(this.getPackageName(), PackageManager.GET_SHARED_LIBRARY_FILES); applicationInfo = this.getPackageManager().getApplicationInfo(this.getPackageName(), PackageManager.GET_SHARED_LIBRARY_FILES);
@ -75,11 +80,11 @@ public class ShellService extends Service {
Log.d("adx", "native library dir " + applicationInfo.nativeLibraryDir); Log.d("adx", "native library dir " + applicationInfo.nativeLibraryDir);
try { try {
String var10001 = applicationInfo.nativeLibraryDir + '/' + filename + " -c config.toml"; String cmd = applicationInfo.nativeLibraryDir + '/' + fileName + " -c " + confFile.getAbsolutePath();
String[] var10002 = new String[]{""}; String[] params = new String[]{""};
File var10003 = this.getFilesDir(); File workDir = this.getFilesDir();
// Intrinsics.checkNotNullExpressionValue(var10003, "this.filesDir"); // Intrinsics.checkNotNullExpressionValue(var10003, "this.filesDir");
this.runCommand(var10001, var10002, var10003); this.runCommand(cmd, params, workDir);
} catch (Exception ex) { } catch (Exception ex) {
// Log.e("adx", ExceptionsKt.stackTraceToString((Throwable)var7)); // Log.e("adx", ExceptionsKt.stackTraceToString((Throwable)var7));
ex.printStackTrace(); ex.printStackTrace();
@ -93,9 +98,9 @@ public class ShellService extends Service {
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} }
} else { } else {
filename = "Error:filename unknown!!!"; fileName = "Error:filename unknown!!!";
Log.e("adx", filename); Log.e("adx", fileName);
Toast.makeText((Context)this, (CharSequence)filename, Toast.LENGTH_SHORT).show(); Toast.makeText((Context)this, (CharSequence)fileName, Toast.LENGTH_SHORT).show();
this.stopSelf(); this.stopSelf();
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} }

@ -57,7 +57,7 @@
<Space <Space
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40sp" /> android:layout_height="16sp" />
<TextView <TextView
android:id="@+id/textView5" android:id="@+id/textView5"

Loading…
Cancel
Save