优化停止frp服务

main
Matthew 11 months ago
parent 6b2b0cbddc
commit b8a7fa3602

@ -28,7 +28,9 @@
<service <service
android:name=".ShellService" android:name=".ShellService"
android:enabled="true" android:enabled="true"
android:exported="true" /> android:exported="false"
android:foregroundServiceType="dataSync" >
</service>
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"

@ -198,7 +198,7 @@ public class MainActivity extends AppCompatActivity {
logger.info("Server stopped"); logger.info("Server stopped");
try { try {
MainActivity.this.stopShell(); stopShell();
} catch (Exception ex) { } catch (Exception ex) {
logger.warning(ex.getMessage()); logger.warning(ex.getMessage());
} }
@ -214,6 +214,7 @@ public class MainActivity extends AppCompatActivity {
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
//
} }
private final void setListener() { private final void setListener() {

@ -13,7 +13,6 @@ import android.os.IBinder;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import java.io.File; import java.io.File;
import java.util.Random; import java.util.Random;
@ -74,7 +73,6 @@ public class ShellService extends Service {
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();
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();
@ -104,13 +102,13 @@ public class ShellService extends Service {
// Log.e("adx", ExceptionsKt.stackTraceToString((Throwable)var7)); // Log.e("adx", ExceptionsKt.stackTraceToString((Throwable)var7));
logger.warning(ex.getMessage()); logger.warning(ex.getMessage());
ex.printStackTrace(); ex.printStackTrace();
Toast.makeText((Context)this, (CharSequence)ex.getMessage(), Toast.LENGTH_SHORT).show(); // Toast.makeText((Context)this, (CharSequence)ex.getMessage(), Toast.LENGTH_SHORT).show();
this.stopSelf(); this.stopSelf();
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} }
logger.warning("Service has been started"); logger.warning("Service has been started");
Toast.makeText((Context)this, (CharSequence)"已启动frp服务", Toast.LENGTH_SHORT).show(); // Toast.makeText((Context)this, (CharSequence)"已启动frp服务", Toast.LENGTH_SHORT).show();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
this.startForeground(1, this.showNotification()); this.startForeground(1, this.showNotification());
} }
@ -119,19 +117,23 @@ public class ShellService extends Service {
} 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;
} }
} }
public void onDestroy() { public void onDestroy() {
if (mProcessThread != null) { try {
mProcessThread.interrupt(); if (mProcessThread != null) {
} mProcessThread.interrupt();
}
logger.warning("Service has been stopped"); logger.warning("Service has been stopped");
Toast.makeText((Context)this, (CharSequence)"已关闭frp服务", Toast.LENGTH_SHORT).show(); // Toast.makeText((Context)this, (CharSequence)"已关闭frp服务", Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
}
} }
private final void runCommand(String command, String[] envp, File dir) { private final void runCommand(String command, String[] envp, File dir) {

Loading…
Cancel
Save