6.0.2 - 新增images.bilateralFilter() 修复toast多次调用/客户端及服务端模式开关/安卓7无法使用UI模式 部分插件及工具版本更新
This commit is contained in:
@@ -32,6 +32,9 @@ import org.autojs.autojs.ui.floating.layoutinspector.LayoutHierarchyFloatyWindow
|
||||
import org.autojs.autojs.ui.log.LogActivity_;
|
||||
import org.autojs.autojs.ui.settings.SettingsActivity_;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
@@ -41,11 +44,13 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
||||
|
||||
private static AutoJs instance;
|
||||
|
||||
// @Thank to Zen2H
|
||||
private final ExecutorService printExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
public static AutoJs getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public synchronized static void initInstance(Application application) {
|
||||
if (instance != null) {
|
||||
return;
|
||||
@@ -108,11 +113,18 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
||||
|
||||
@Override
|
||||
protected GlobalConsole createGlobalConsole() {
|
||||
DevPluginService devPluginService = DevPluginService.getInstance();
|
||||
return new GlobalConsole(getUiHandler()) {
|
||||
@Override
|
||||
public String println(int level, CharSequence charSequence) {
|
||||
String log = super.println(level, charSequence);
|
||||
new Thread(() -> DevPluginService.getInstance().print(log)).start();
|
||||
|
||||
// FIXME by SuperMonster003 on Feb 2, 2022
|
||||
// ! When running in 'ui' thread (`ui.run`, `ui.post`),
|
||||
// ! android.os.NetworkOnMainThreadException may happen.
|
||||
// ! Further more, dunno if a thread executor is a good idea.
|
||||
printExecutor.submit(() -> devPluginService.print(log));
|
||||
|
||||
return log;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -80,7 +80,7 @@ public class DevPluginService {
|
||||
|
||||
private volatile JsonSocketClient mJsonSocketClient;
|
||||
private volatile JsonSocketServer mJsonSocketServer;
|
||||
private volatile ServerSocket mAJServerSocket;
|
||||
private volatile ServerSocket mServerSocket;
|
||||
|
||||
public DevPluginService() {
|
||||
File cache = new File(GlobalAppContext.get().getCacheDir(), "remote_project");
|
||||
@@ -97,6 +97,11 @@ public class DevPluginService {
|
||||
return mJsonSocketServer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ServerSocket getServerSocket() {
|
||||
return mServerSocket;
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
public Observable<JsonSocketClient> connectToRemoteServer(String host) {
|
||||
int port = Port.PC_SERVER;
|
||||
@@ -135,11 +140,11 @@ public class DevPluginService {
|
||||
.doOnNext(jsonSocketServer -> {
|
||||
try {
|
||||
mJsonSocketServer = jsonSocketServer;
|
||||
mAJServerSocket = jsonSocketServer.getServerSocket();
|
||||
if (mAJServerSocket != null) {
|
||||
mServerSocket = jsonSocketServer.getServerSocket();
|
||||
if (mServerSocket != null) {
|
||||
jsonSocketServer
|
||||
.setStateConnected()
|
||||
.setSocket(mAJServerSocket.accept())
|
||||
.setSocket(mServerSocket.accept())
|
||||
.subscribeMessage()
|
||||
.monitorMessage()
|
||||
.sayHello();
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.stardust.autojs.runtime.api.Device;
|
||||
import com.stardust.util.MapBuilder;
|
||||
|
||||
import org.autojs.autojs.BuildConfig;
|
||||
import org.autojs.autojs.tool.IOTool;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
@@ -196,13 +195,12 @@ abstract public class JsonSocket extends Socket {
|
||||
|
||||
public void monitorMessage(Socket socket, JsonSocket jsonSocket) {
|
||||
new Thread(() -> {
|
||||
InputStream inputStream = null;
|
||||
InputStreamReader inputStreamReader = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
inputStream = socket.getInputStream();
|
||||
inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
bufferedReader = new BufferedReader(inputStreamReader);
|
||||
// try (AutoCloseable) { ... }
|
||||
// @Thank to Zen2H
|
||||
try (InputStream inputStream = socket.getInputStream();
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)
|
||||
) {
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
String readLine;
|
||||
Log.d(TAG, "bufferedReader is reading lines...");
|
||||
@@ -216,9 +214,6 @@ abstract public class JsonSocket extends Socket {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOTool.close(bufferedReader);
|
||||
IOTool.close(inputStreamReader);
|
||||
IOTool.close(inputStream);
|
||||
try {
|
||||
jsonSocket.switchOff();
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.google.gson.JsonObject;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.subjects.PublishSubject;
|
||||
@@ -20,6 +22,8 @@ public class JsonSocketClient extends JsonSocket {
|
||||
|
||||
private static final String TAG = JsonSocketClient.class.getSimpleName();
|
||||
|
||||
private final ExecutorService jsonSocketExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
public static final PublishSubject<DevPluginService.State> cxnState = PublishSubject.create();
|
||||
|
||||
private final PublishSubject<JsonElement> mJsonElementPublishSubject = PublishSubject.create();
|
||||
@@ -32,14 +36,14 @@ public class JsonSocketClient extends JsonSocket {
|
||||
|
||||
// @Constructor
|
||||
public JsonSocketClient(String host, int port) {
|
||||
new Thread(() -> {
|
||||
jsonSocketExecutor.submit(() -> {
|
||||
try {
|
||||
setStateConnecting();
|
||||
mSocket = new Socket(host, port);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isSocketReady() {
|
||||
@@ -80,6 +84,7 @@ public class JsonSocketClient extends JsonSocket {
|
||||
mSocket.close();
|
||||
mSocket = null;
|
||||
}
|
||||
jsonSocketExecutor.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,8 +12,8 @@ public class ThreadTool {
|
||||
try {
|
||||
//noinspection BusyWait
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException ignore) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
result.set(true);
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -185,7 +186,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
stopService(new Intent(view.getContext(), FloatyService.class));
|
||||
AutoJs.getInstance().getScriptEngineService().stopAll();
|
||||
finish();
|
||||
Runtime.getRuntime().exit(0);
|
||||
Process.killProcess(Process.myPid());
|
||||
}
|
||||
|
||||
@Click(R.id.restart)
|
||||
@@ -199,7 +200,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
}
|
||||
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
|
||||
context.startActivity(mainIntent);
|
||||
Runtime.getRuntime().exit(0);
|
||||
Process.killProcess(Process.myPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
@@ -408,33 +409,58 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
|
||||
}
|
||||
|
||||
private void toggleRemoteServerCxn(DrawerMenuItemViewHolder holder) throws IOException {
|
||||
JsonSocketClient jsonSocketClient = devPlugin.getJsonSocketClient();
|
||||
boolean disconnected = jsonSocketClient == null || !jsonSocketClient.isSocketReady();
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
|
||||
if (checked) {
|
||||
if (disconnected) {
|
||||
inputRemoteHost();
|
||||
}
|
||||
private void toggleRemoteServerCxn(DrawerMenuItemViewHolder holder) {
|
||||
boolean isChecked = holder.getSwitchCompat().isChecked();
|
||||
boolean isDisconnected = !isJsonSocketClientConnected();
|
||||
if (isChecked && isDisconnected) {
|
||||
inputRemoteHost();
|
||||
} else {
|
||||
if (jsonSocketClient != null) {
|
||||
jsonSocketClient.switchOff();
|
||||
disconnectJsonSocketClientIFN();
|
||||
}
|
||||
}
|
||||
|
||||
private void disconnectJsonSocketClientIFN() {
|
||||
JsonSocketClient client = devPlugin.getJsonSocketClient();
|
||||
if (client != null) {
|
||||
try {
|
||||
client.switchOff();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private void toggleLocalServerCxn(DrawerMenuItemViewHolder holder) throws IOException {
|
||||
JsonSocketServer jsonSocketServer = devPlugin.getJsonSocketServer();
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
private boolean isJsonSocketClientConnected() {
|
||||
JsonSocketClient client = devPlugin.getJsonSocketClient();
|
||||
return client != null && client.isSocketReady();
|
||||
}
|
||||
|
||||
if (checked) {
|
||||
devPlugin.enableLocalServer()
|
||||
@SuppressLint("CheckResult")
|
||||
private void toggleLocalServerCxn(DrawerMenuItemViewHolder holder) {
|
||||
boolean isChecked = holder.getSwitchCompat().isChecked();
|
||||
boolean isDisconnected = !isServerSocketConnected();
|
||||
|
||||
if (isChecked && isDisconnected) {
|
||||
devPlugin
|
||||
.enableLocalServer()
|
||||
.subscribe(Observers.emptyConsumer(), this::onAJServerConnectException);
|
||||
} else {
|
||||
if (jsonSocketServer != null) {
|
||||
jsonSocketServer.switchOff();
|
||||
disconnectServerSocketIFN();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isServerSocketConnected() {
|
||||
ServerSocket serverSocket = devPlugin.getServerSocket();
|
||||
return serverSocket != null && !serverSocket.isClosed();
|
||||
}
|
||||
|
||||
private void disconnectServerSocketIFN() {
|
||||
ServerSocket serverSocket = devPlugin.getServerSocket();
|
||||
if (serverSocket != null) {
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -511,6 +537,8 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
setChecked(mDisplayOverOtherAppsItem, FloatingPermission.canDrawOverlays(context));
|
||||
setChecked(mWriteSystemSettingsItem, Settings.System.canWrite(getContext()));
|
||||
setChecked(mWriteSecuritySettingsItem, hasWriteSecureSettingsAccess());
|
||||
setChecked(mClientModeItem, isJsonSocketClientConnected());
|
||||
setChecked(mServerModeItem, isServerSocketConnected());
|
||||
}
|
||||
|
||||
private boolean isAccessibilityServiceEnabled() {
|
||||
|
||||
@@ -10,9 +10,11 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
@@ -65,8 +67,8 @@ public class ShortcutCreateActivity extends AppCompatActivity {
|
||||
private void showDialog() {
|
||||
View view = View.inflate(this, R.layout.shortcut_create_dialog, null);
|
||||
ButterKnife.bind(this, view);
|
||||
mUseAndroidNShortcut.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
|
||||
View.VISIBLE : View.GONE);
|
||||
mUseAndroidNShortcut.setVisibility(Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1
|
||||
? View.VISIBLE : View.GONE);
|
||||
mName.setText(mScriptFile.getSimplifiedName());
|
||||
new ThemeColorMaterialDialogBuilder(this)
|
||||
.customView(view, false)
|
||||
@@ -90,7 +92,7 @@ public class ShortcutCreateActivity extends AppCompatActivity {
|
||||
|
||||
@SuppressLint("NewApi") //for fool android studio
|
||||
private void createShortcut() {
|
||||
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && mUseAndroidNShortcut.isChecked())
|
||||
if ((Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 && mUseAndroidNShortcut.isChecked())
|
||||
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createShortcutByShortcutManager();
|
||||
return;
|
||||
@@ -132,7 +134,7 @@ public class ShortcutCreateActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@SuppressLint({"CheckResult", "MissingSuperCall"})
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode != RESULT_OK) {
|
||||
@@ -149,7 +151,7 @@ public class ShortcutCreateActivity extends AppCompatActivity {
|
||||
return;
|
||||
}
|
||||
Uri uri = data.getData();
|
||||
if(uri == null){
|
||||
if (uri == null) {
|
||||
return;
|
||||
}
|
||||
Observable.fromCallable(() -> BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)))
|
||||
@@ -158,9 +160,7 @@ public class ShortcutCreateActivity extends AppCompatActivity {
|
||||
.subscribe((bitmap -> {
|
||||
mIcon.setImageBitmap(bitmap);
|
||||
mIsDefaultIcon = false;
|
||||
}), error -> {
|
||||
Log.e(LOG_TAG, "decode stream", error);
|
||||
});
|
||||
}), error -> Log.e(LOG_TAG, "decode stream", error));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user