From 8da1ee6a6ac51d40aac16a7610ef7dad6d9dfafd Mon Sep 17 00:00:00 2001 From: Chen Guangming Date: Tue, 14 May 2024 21:44:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=82=E9=85=8DAndroid14=E5=AF=B9?= =?UTF-8?q?=E6=88=AA=E5=B1=8F=E7=9A=84=E4=B8=A5=E6=A0=BC=E8=A6=81=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 ++ .../image/capture/ScreenCaptureRequester.java | 16 ++++++++++---- .../capture/ScreenCaptureRequesterImpl.java | 3 --- .../ScreenCapturerForegroundService.java | 3 ++- .../MainActivityForegroundService.kt | 2 +- .../autojs/util/ForegroundServiceUtils.java | 21 ++++++++++++++++++- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f3809e14..6e3cef2b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -122,6 +122,8 @@ + + onResult(resultCode, data)); } - } abstract class AbstractScreenCaptureRequester implements ScreenCaptureRequester { @@ -75,7 +85,5 @@ public void cancel() { if (mCallback != null) mCallback.onRequestResult(Activity.RESULT_CANCELED, null); } - } - } diff --git a/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCaptureRequesterImpl.java b/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCaptureRequesterImpl.java index 26db762c..0e11c98e 100644 --- a/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCaptureRequesterImpl.java +++ b/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCaptureRequesterImpl.java @@ -4,7 +4,6 @@ import org.autojs.autojs.AbstractAutoJs; import org.autojs.autojs.app.OnActivityResultDelegate; -import org.autojs.autojs.util.ForegroundServiceUtils; public class ScreenCaptureRequesterImpl extends ScreenCaptureRequester.AbstractScreenCaptureRequester { @@ -25,8 +24,6 @@ public void setOnActivityResultCallback(Callback callback) { @Override public void request() { - ForegroundServiceUtils.requestIfNeeded(mAutoJs.getApplicationContext(), ScreenCapturerForegroundService.class); - Activity activity = mAutoJs.getAppUtils().getCurrentActivity(); if (activity instanceof OnActivityResultDelegate.DelegateHost) { diff --git a/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCapturerForegroundService.java b/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCapturerForegroundService.java index 3c93cfd5..c6a08f85 100644 --- a/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCapturerForegroundService.java +++ b/app/src/main/java/org/autojs/autojs/core/image/capture/ScreenCapturerForegroundService.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ServiceInfo; +import android.os.Binder; import android.os.Build; import android.os.IBinder; @@ -38,7 +39,7 @@ public void onCreate() { @Nullable @Override public IBinder onBind(Intent intent) { - return null; + return new Binder(); } private void startForeground() { diff --git a/app/src/main/java/org/autojs/autojs/external/foreground/MainActivityForegroundService.kt b/app/src/main/java/org/autojs/autojs/external/foreground/MainActivityForegroundService.kt index 73df4723..c407446c 100644 --- a/app/src/main/java/org/autojs/autojs/external/foreground/MainActivityForegroundService.kt +++ b/app/src/main/java/org/autojs/autojs/external/foreground/MainActivityForegroundService.kt @@ -33,7 +33,7 @@ class MainActivityForegroundService : Service() { .create() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - ForegroundServiceUtils.startForeground(foregroundServiceCreator, ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED) + ForegroundServiceUtils.startForeground(foregroundServiceCreator, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE) } else { ForegroundServiceUtils.startForeground(foregroundServiceCreator) } diff --git a/app/src/main/java/org/autojs/autojs/util/ForegroundServiceUtils.java b/app/src/main/java/org/autojs/autojs/util/ForegroundServiceUtils.java index 114fd20d..ab5e011d 100644 --- a/app/src/main/java/org/autojs/autojs/util/ForegroundServiceUtils.java +++ b/app/src/main/java/org/autojs/autojs/util/ForegroundServiceUtils.java @@ -6,10 +6,12 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.pm.ServiceInfo; +import android.content.ServiceConnection; import android.os.Build; +import android.os.IBinder; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -36,6 +38,23 @@ public static void request(Context context, Class className) { } } + public static void requestReadyIfNeeded(Context context, Class className, Runnable runnable) { + if (isRunning(context, className)) { + runnable.run(); + } else { + context.bindService(getService(context, className), new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + runnable.run(); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + } + }, Context.BIND_AUTO_CREATE); + } + } + public static boolean startService(Context context, Class className) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return context.startForegroundService(getService(context, className)) != null; From 76644de7057394129249fde22984a9ae81d8632e Mon Sep 17 00:00:00 2001 From: Chen Guangming Date: Tue, 14 May 2024 21:58:56 +0800 Subject: [PATCH 2/2] use large heap --- app/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6e3cef2b..b799ab44 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -132,7 +132,7 @@ android:hardwareAccelerated="true" android:icon="${icon}" android:label="${appName}" - android:largeHeap="false" + android:largeHeap="true" android:requestLegacyExternalStorage="true" android:supportsRtl="true" android:theme="@style/AppTheme"