diff --git a/app/build.gradle b/app/build.gradle index 35f63c6..fa5939d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.xypower.frpandroid" minSdk 25 targetSdk 32 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -54,9 +54,11 @@ android { dependencies { + //noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:2.0.4' implementation 'org.jetbrains:annotations:15.0' + implementation 'com.moandjiezana.toml:toml4j:0.7.2' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 08e57a4..c904298 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,7 +31,8 @@ + android:exported="true" + android:screenOrientation="landscape" > diff --git a/app/src/main/assets/config.toml b/app/src/main/assets/config.toml index 488975e..5f88c00 100644 --- a/app/src/main/assets/config.toml +++ b/app/src/main/assets/config.toml @@ -3,11 +3,9 @@ serverPort = 7000 dnsServer = "114.114.114.114" auth.method = "token" auth.token = "mint" -transport.tls.enable=false +transport.tls.enable = false transport.tls.disableCustomTLSFirstByte = false - - [log] level = "debug" disablePrintColor = true diff --git a/app/src/main/java/com/xypower/frpandroid/MainActivity.java b/app/src/main/java/com/xypower/frpandroid/MainActivity.java index 8b1c5e8..dfa7a6f 100644 --- a/app/src/main/java/com/xypower/frpandroid/MainActivity.java +++ b/app/src/main/java/com/xypower/frpandroid/MainActivity.java @@ -15,6 +15,7 @@ import android.os.IBinder; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.SwitchCompat; +import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Button; @@ -22,9 +23,13 @@ import android.widget.CompoundButton; import android.widget.Switch; import android.widget.TextView; +import com.moandjiezana.toml.Toml; +import com.moandjiezana.toml.TomlWriter; + import org.jetbrains.annotations.NotNull; import java.io.Closeable; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; @@ -38,6 +43,9 @@ public class MainActivity extends AppCompatActivity { private ShellService mService; private boolean mBound; + private String mServer = "61.169.135.146"; + private int mPort = 7000; + private final ServiceConnection connection = new ServiceConnection() { public void onServiceConnected(@NotNull ComponentName className, @NotNull IBinder service) { // Intrinsics.checkNotNullParameter(className, "className"); @@ -69,15 +77,15 @@ public class MainActivity extends AppCompatActivity { TextView titleText = (TextView)this.findViewById(R.id.titleText); // Intrinsics.checkNotNullExpressionValue(titleText, "titleText"); titleText.setText((CharSequence)("frp for Android - " + versionName + "/0.58.0")); - this.checkConfig(); - this.checkNotificationPermission(); - this.createBGNotificationChannel(); - this.mBound = this.isServiceRunning(ShellService.class); + + checkConfig(); + checkNotificationPermission(); + createBGNotificationChannel(); + + mBound = isServiceRunning(ShellService.class); state_switch = (Switch)this.findViewById(R.id.state_switch); // Intrinsics.checkNotNullExpressionValue(var10001, "findViewById(R.id.state_switch)"); - state_switch.setChecked(this.mBound); - state_switch.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener)(new CompoundButton.OnCheckedChangeListener() { public final void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { @@ -89,7 +97,6 @@ public class MainActivity extends AppCompatActivity { } })); - final SharedPreferences editor = this.getSharedPreferences("data", 0); auto_start_switch = (Switch) this.findViewById(R.id.auto_start_switch); // Intrinsics.checkNotNullExpressionValue(var10001, "findViewById(R.id.auto_start_switch)"); @@ -103,12 +110,26 @@ public class MainActivity extends AppCompatActivity { editorx.apply(); } })); - if (this.mBound) { + + if (mBound) { Intent intent = new Intent((Context)this, ShellService.class); this.bindService(intent, (ServiceConnection)this.connection, 1); } 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() { @@ -150,11 +171,19 @@ public class MainActivity extends AppCompatActivity { public final void checkConfig() { // Intrinsics.checkNotNullExpressionValue(var12, "resources"); 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; try { - fileOutputStream = this.openFileOutput("config.toml", 0); + fileOutputStream = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); + } catch (Exception ex) { + ex.printStackTrace(); } if (fileOutputStream == null) { @@ -163,12 +192,14 @@ public class MainActivity extends AppCompatActivity { InputStream inputStream = null; byte[] bytes = new byte[256]; + int bytesRead = -1; try { inputStream = assetmanager.open("config.toml"); // Intrinsics.checkNotNullExpressionValue(var10001, "assetmanager.open((BuildConfig.ConfigFileName))"); - int bytesRead = inputStream.read(bytes); - if (bytesRead > 0) { - fileOutputStream.write(bytes, 0, bytesRead); + while ((bytesRead = inputStream.read(bytes)) != -1) { + if (bytesRead > 0) { + fileOutputStream.write(bytes, 0, bytesRead); + } } // Unit var11 = Unit.INSTANCE; } catch (Throwable ex) { @@ -178,6 +209,20 @@ public class MainActivity extends AppCompatActivity { 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) { diff --git a/app/src/main/java/com/xypower/frpandroid/ShellService.java b/app/src/main/java/com/xypower/frpandroid/ShellService.java index f397f19..5fbf77d 100644 --- a/app/src/main/java/com/xypower/frpandroid/ShellService.java +++ b/app/src/main/java/com/xypower/frpandroid/ShellService.java @@ -11,6 +11,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.support.annotation.Nullable; +import android.text.TextUtils; import android.util.Log; import android.widget.Toast; @@ -53,18 +54,22 @@ public class ShellService extends Service { 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) { 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(); return Service.START_NOT_STICKY; } else if (intent != null) { Bundle extras = intent.getExtras(); - Object var8 = extras != null ? extras.get("filename") : null; - if (var8 == null) { + fileName = extras != null ? extras.getString("filename") : null; + if (TextUtils.isEmpty(fileName)) { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } else { - filename = (String)var8; + ApplicationInfo applicationInfo = null; try { 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); try { - String var10001 = applicationInfo.nativeLibraryDir + '/' + filename + " -c config.toml"; - String[] var10002 = new String[]{""}; - File var10003 = this.getFilesDir(); + String cmd = applicationInfo.nativeLibraryDir + '/' + fileName + " -c " + confFile.getAbsolutePath(); + String[] params = new String[]{""}; + File workDir = this.getFilesDir(); // Intrinsics.checkNotNullExpressionValue(var10003, "this.filesDir"); - this.runCommand(var10001, var10002, var10003); + this.runCommand(cmd, params, workDir); } catch (Exception ex) { // Log.e("adx", ExceptionsKt.stackTraceToString((Throwable)var7)); ex.printStackTrace(); @@ -93,9 +98,9 @@ public class ShellService extends Service { return Service.START_NOT_STICKY; } } else { - filename = "Error:filename unknown!!!"; - Log.e("adx", filename); - Toast.makeText((Context)this, (CharSequence)filename, Toast.LENGTH_SHORT).show(); + fileName = "Error:filename unknown!!!"; + Log.e("adx", fileName); + Toast.makeText((Context)this, (CharSequence)fileName, Toast.LENGTH_SHORT).show(); this.stopSelf(); return Service.START_NOT_STICKY; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0e2c856..62a39f6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -57,7 +57,7 @@ + android:layout_height="16sp" />