6.0.2 - 新增images.bilateralFilter() 修复toast多次调用/客户端及服务端模式开关/安卓7无法使用UI模式 部分插件及工具版本更新

This commit is contained in:
SuperMonster003
2022-02-05 16:45:25 +08:00
parent 3ce51e4a01
commit ec61eb5000
40 changed files with 1003 additions and 847 deletions

View File

@@ -1,16 +1,12 @@
plugins {
id "com.android.application"
id "com.jakewharton.butterknife"
id "kotlin-android"
id "kotlin-kapt"
id 'com.android.application'
id 'com.jakewharton.butterknife'
id 'kotlin-android'
id 'kotlin-kapt'
}
def annotationsVer = "4.8.0"
def butterKnifeVer = "10.2.3"
def leakcanaryVer = "2.7"
def properties = new Properties()
def propFile = new File("sign.properties")
def propFile = new File('sign.properties')
def isPropFileExists = propFile.exists()
isPropFileExists && properties.load(new FileInputStream(propFile))
@@ -22,32 +18,32 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
}
// tasks.withType(JavaCompile) {
// options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
// options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked'
// }
android {
signingConfigs {
isPropFileExists && release {
storeFile file(properties["storeFile"])
keyPassword properties["keyPassword"]
keyAlias properties["keyAlias"]
storePassword properties["storePassword"]
storeFile file(properties['storeFile'])
keyPassword properties['keyPassword']
keyAlias properties['keyAlias']
storePassword properties['storePassword']
}
}
compileSdkVersion versions.compile
compileSdkVersion versions.project.compile
defaultConfig {
applicationId "org.autojs.autojs"
minSdkVersion versions.mini
targetSdkVersion versions.target
versionCode versions.appVersionCode
versionName versions.appVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
applicationId 'org.autojs.autojs'
minSdkVersion versions.project.mini
targetSdkVersion versions.project.target
versionCode versions.project.appVersionCode
versionName versions.project.appVersionName
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"resourcePackageName": applicationId,
"androidManifestFile": "$projectDir/src/main/AndroidManifest.xml".toString()
'resourcePackageName': applicationId,
'androidManifestFile': "$projectDir/src/main/AndroidManifest.xml".toString()
]
}
}
@@ -56,7 +52,7 @@ android {
debug {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (isPropFileExists) {
signingConfig signingConfigs.release
}
@@ -68,7 +64,7 @@ android {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (isPropFileExists) {
signingConfig signingConfigs.release
}
@@ -77,17 +73,17 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_16
targetCompatibility JavaVersion.VERSION_16
encoding = "utf-8"
encoding = 'utf-8'
}
lintOptions {
abortOnError false
disable "MissingTranslation"
disable "ExtraTranslation"
disable 'MissingTranslation'
disable 'ExtraTranslation'
}
configurations.all {
resolutionStrategy.force "com.google.code.findbugs:jsr305:3.0.1"
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}
flavorDimensions "channel"
flavorDimensions 'channel'
splits {
// Configures multiple APKs based on ABI.
abi {
@@ -101,7 +97,7 @@ android {
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "armeabi-v7a"
include 'x86', 'armeabi-v7a'
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk false
@@ -109,14 +105,14 @@ android {
}
productFlavors {
common {
buildConfigField "String", "CHANNEL", "\"common\""
buildConfigField "String", "APP_SINCE_DATE", "\"${versions.appSinceDate}\""
buildConfigField 'String', 'CHANNEL', '"common"'
buildConfigField 'String', 'APP_SINCE_DATE', "\"${versions.project.appSinceDate}\""
}
}
applicationVariants.all { variant ->
variant.mergeAssetsProvider.configure {
doLast {
delete(fileTree(dir: outputDir, includes: ["declarations/**"]))
delete(fileTree(dir: outputDir, includes: ['declarations/**']))
}
}
}
@@ -128,103 +124,94 @@ repositories {
dependencies {
// JUnit
testImplementation "junit:junit:${junitVer}"
testImplementation "junit:junit:${versions.junit}"
// LeakCanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:${leakcanaryVer}"
debugImplementation "com.squareup.leakcanary:leakcanary-android:${versions.leakcanary}"
// Kotlin
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-native-mt"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-native-mt'
// Android Annotations
kapt "org.androidannotations:androidannotations:${annotationsVer}"
implementation "org.androidannotations:androidannotations-api:${annotationsVer}"
kapt "org.androidannotations:androidannotations:${versions.annotations}"
implementation "org.androidannotations:androidannotations-api:${versions.annotations}"
// ButterKnife
kapt "com.jakewharton:butterknife-compiler:${butterKnifeVer}"
implementation "com.jakewharton:butterknife:${butterKnifeVer}"
kapt "com.jakewharton:butterknife-compiler:${versions.butterKnife}"
implementation "com.jakewharton:butterknife:${versions.butterKnife}"
// Android supports
implementation "androidx.appcompat:appcompat:1.4.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation "com.google.android.material:material:1.6.0-alpha01"
implementation "androidx.multidex:multidex:2.0.1"
// Material Dialogs
implementation "com.afollestad.material-dialogs:core:0.9.6.0"
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
// SwipeRefreshLayout
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
// Common Markdown
implementation "com.github.atlassian:commonmark-java:commonmark-parent-0.9.0"
implementation 'com.github.atlassian:commonmark-java:commonmark-parent-0.9.0'
// Android issue reporter (a github issue reporter)
implementation "com.heinrichreimersoftware:android-issue-reporter:1.3.1"
implementation 'com.heinrichreimersoftware:android-issue-reporter:1.3.1'
// MultiLevelListView
implementation "com.github.hyb1996:android-multi-level-listview:1.1"
implementation 'com.github.hyb1996:android-multi-level-listview:1.1'
// Licenses Dialog
implementation "de.psdev.licensesdialog:licensesdialog:2.2.0"
implementation 'de.psdev.licensesdialog:licensesdialog:2.2.0'
// Expandable RecyclerView
implementation "com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1"
implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'
// FlexibleDivider
implementation "com.yqritc:recyclerview-flexibledivider:1.4.0"
implementation 'com.yqritc:recyclerview-flexibledivider:1.4.0'
// AVLoadingView
implementation "com.wang.avi:library:2.1.3"
implementation 'com.wang.avi:library:2.1.3'
// Commons Lang
implementation "org.apache.commons:commons-lang3:3.12.0"
implementation 'org.apache.commons:commons-lang3:3.12.0'
// Expandable RecyclerView
implementation "com.thoughtbot:expandablerecyclerview:1.3"
implementation 'com.thoughtbot:expandablerecyclerview:1.3'
implementation "com.github.hyb1996:Auto.js-ApkBuilder:1.0.1"
implementation 'com.github.hyb1996:Auto.js-ApkBuilder:1.0.1'
// RxJava
implementation "io.reactivex.rxjava2:rxjava:2.2.21"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation 'io.reactivex.rxjava2:rxjava:2.2.21'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
// Glide
kapt "com.github.bumptech.glide:compiler:4.12.0"
implementation "com.github.bumptech.glide:glide:4.12.0"
kapt "com.github.bumptech.glide:compiler:${versions.glide}"
// Joda Time
implementation "joda-time:joda-time:2.10.13"
implementation 'joda-time:joda-time:2.10.13'
// Tasker Plugin
implementation "com.twofortyfouram:android-plugin-client-sdk-for-locale:4.0.3"
implementation 'com.twofortyfouram:android-plugin-client-sdk-for-locale:4.0.3'
// Flurry
implementation "com.flurry.android:analytics:13.1.0"
// Material Dialogs
implementation "com.afollestad.material-dialogs:commons:0.9.6.0"
implementation 'com.flurry.android:analytics:13.1.0'
// Android Job
implementation "com.evernote:android-job:1.4.2"
implementation 'com.evernote:android-job:1.4.2'
// Extracted from com.github.hyb1996:MutableTheme:1.0.0
implementation "com.jrummyapps:colorpicker:2.1.7"
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "com.github.ozodrukh:CircularReveal:2.0.1"
implementation 'com.jrummyapps:colorpicker:2.1.7'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.github.ozodrukh:CircularReveal:2.0.1'
// Bugly
implementation project(":libs:com.tencent.bugly.crashreport-2.6.6")
implementation project(':libs:com.tencent.bugly.crashreport-2.6.6')
implementation project(":automator")
implementation project(":common")
implementation project(":autojs")
implementation project(':automator')
implementation project(':common')
implementation project(':autojs')
}
java {

View File

@@ -4,6 +4,25 @@
******
# v6.0.2
###### 2022/02/05
* `新增` images.bilateralFilter() 双边滤波图像处理方法
* `修复` 多次调用 toast 只生效最后一次调用的问题
* `修复` toast.dismiss() 可能无效的问题
* `修复` 客户端模式及服务端模式开关可能无法正常工作的问题
* `修复` 客户端模式及服务端模式开关状态不能正常刷新的问题
* `修复` Android 7 解析 UI 模式 text 元素异常 (Ref to TonyJiangWJ) _[`issue #4`](https://github.com/SuperMonster003/AutoJs6/issues/4)_
* `优化` 忽略 sleep() 的 ScriptInterruptedException 异常
* `优化` 附加 Androidx AppCompat (Legacy) 版本 1.0.2
* `优化` 升级 Androidx AppCompat 版本 1.4.0 -> 1.4.1
* `优化` 升级 Androidx Preference 版本 1.1.1 -> 1.2.0
* `优化` 升级 Okhttp3 版本 3.10.0 -> 5.0.0-alpha.3 -> 5.0.0-alpha.4
* `优化` 升级 Android Material 版本 1.6.0-alpha01 -> 1.6.0-alpha02
* `优化` 升级 Android Gradle 插件版本 7.2.0-alpha06 -> 7.2.0-beta01
* `优化` 升级 Gradle 发行版本 7.3.3 -> 7.4-rc-2
# v6.0.1
###### 2022/01/01

View File

@@ -961,7 +961,7 @@
<li>如果想要在电脑而不是手机上开发Auto.js可以使用VS Code以及相应的Auto.js插件使得在电脑上编辑的脚本能推送到手机运行参见<a href="https://github.com/hyb1996/Auto.js-VSCode-Extension">Auto.js-VSCode-Extension</a></li>
</ul>
<p>本文档的章节大致上是以模块来分的,总体上可以分成&quot;自动操作&quot;类模块(控件操作、触摸模拟、按键模拟等)和其他类模块(设备、应用、界面等)。</p>
<p>&quot;自动操作&quot;的部分又可以大致分为基于控件和基于坐标的操作。基于坐标的操作是传统按键精灵、触摸精灵等脚本软件采用的方式,通过屏幕坐标来点击、长按指定位置模拟操作,从而到达目的。例如<code>click(100, 200)</code>, <code>press(100, 200, 500)</code>等。这种方式在游戏类脚本中比较有可行性,结合找图找色、坐标放缩功能也能达到较好的兼容性。但是,这种方式对一般软件脚本却难以达到想要的效果,而且这种方式需要安卓7.0版本以上或者root权限才能执行。所以对于一般软件脚本(例如批量添加联系人、自动提取短信验证码等等),我们采用基于控件的模拟操作方式,结合通知事情、按键事情等达成更好的工作流。这些部分的文档参见<a href="widgets-based-automation.html">基于控件的操作</a><a href="coordinates-based-automation.html">基于坐标的操作</a></p>
<p>&quot;自动操作&quot;的部分又可以大致分为基于控件和基于坐标的操作。基于坐标的操作是传统按键精灵、触摸精灵等脚本软件采用的方式,通过屏幕坐标来点击、长按指定位置模拟操作,从而到达目的。例如<code>click(100, 200)</code>, <code>press(100, 200, 500)</code>等。这种方式在游戏类脚本中比较有可行性结合找图找色、坐标放缩功能也能达到较好的兼容性。但是这种方式对一般软件脚本却难以达到想要的效果而且这种方式需要root权限才能执行。所以对于一般软件脚本(例如批量添加联系人、自动提取短信验证码等等),我们采用基于控件的模拟操作方式,结合通知事情、按键事情等达成更好的工作流。这些部分的文档参见<a href="widgets-based-automation.html">基于控件的操作</a><a href="coordinates-based-automation.html">基于坐标的操作</a></p>
<p>其他部分主要包括:</p>
<ul>
<li>app: 应用。启动应用,卸载应用,使用应用查看、编辑文件、访问网页,发送应用间广播等。</li>

View File

@@ -88,7 +88,7 @@
<li>如果想要在电脑而不是手机上开发Auto.js可以使用VS Code以及相应的Auto.js插件使得在电脑上编辑的脚本能推送到手机运行参见<a href="https://github.com/hyb1996/Auto.js-VSCode-Extension">Auto.js-VSCode-Extension</a></li>
</ul>
<p>本文档的章节大致上是以模块来分的,总体上可以分成&quot;自动操作&quot;类模块(控件操作、触摸模拟、按键模拟等)和其他类模块(设备、应用、界面等)。</p>
<p>&quot;自动操作&quot;的部分又可以大致分为基于控件和基于坐标的操作。基于坐标的操作是传统按键精灵、触摸精灵等脚本软件采用的方式,通过屏幕坐标来点击、长按指定位置模拟操作,从而到达目的。例如<code>click(100, 200)</code>, <code>press(100, 200, 500)</code>等。这种方式在游戏类脚本中比较有可行性,结合找图找色、坐标放缩功能也能达到较好的兼容性。但是,这种方式对一般软件脚本却难以达到想要的效果,而且这种方式需要安卓7.0版本以上或者root权限才能执行。所以对于一般软件脚本(例如批量添加联系人、自动提取短信验证码等等),我们采用基于控件的模拟操作方式,结合通知事情、按键事情等达成更好的工作流。这些部分的文档参见<a href="widgets-based-automation.html">基于控件的操作</a><a href="coordinates-based-automation.html">基于坐标的操作</a></p>
<p>&quot;自动操作&quot;的部分又可以大致分为基于控件和基于坐标的操作。基于坐标的操作是传统按键精灵、触摸精灵等脚本软件采用的方式,通过屏幕坐标来点击、长按指定位置模拟操作,从而到达目的。例如<code>click(100, 200)</code>, <code>press(100, 200, 500)</code>等。这种方式在游戏类脚本中比较有可行性结合找图找色、坐标放缩功能也能达到较好的兼容性。但是这种方式对一般软件脚本却难以达到想要的效果而且这种方式需要root权限才能执行。所以对于一般软件脚本(例如批量添加联系人、自动提取短信验证码等等),我们采用基于控件的模拟操作方式,结合通知事情、按键事情等达成更好的工作流。这些部分的文档参见<a href="widgets-based-automation.html">基于控件的操作</a><a href="coordinates-based-automation.html">基于坐标的操作</a></p>
<p>其他部分主要包括:</p>
<ul>
<li>app: 应用。启动应用,卸载应用,使用应用查看、编辑文件、访问网页,发送应用间广播等。</li>

View File

@@ -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;
}
};

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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() {

View File

@@ -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));
}
}