Skip to content

Commit

Permalink
Also declare special use foreground service
Browse files Browse the repository at this point in the history
  • Loading branch information
reconman committed Aug 12, 2024
1 parent 0d27085 commit b0565d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Expand All @@ -24,7 +25,10 @@

<service
android:name=".runner.ScriptRunnerService"
android:foregroundServiceType="mediaProjection" />
android:foregroundServiceType="mediaProjection|specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Shows a Play button in front of apps in landscape mode so farming can be started while Fate/Grand Order is open."/>
</service>

<service
android:name=".accessibility.TapperService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MediaProjectionScreenshotService(

@SuppressLint("WrongConstant")
private val imageReader = ImageReader.newInstance(imageSize.width, imageSize.height, PixelFormat.RGBA_8888, 2)
private val virtualDisplay = mediaProjection.apply {
private val virtualDisplay: VirtualDisplay? = mediaProjection.apply {
this.registerCallback(object : MediaProjection.Callback() {
override fun onStop() {
close()
Expand Down Expand Up @@ -74,13 +74,16 @@ class MediaProjectionScreenshotService(
}

override fun close() {
if (virtualDisplay == null) {
return
}
bufferMat.release()
grayscaleMat.release()
grayscalePattern.close()
colorMat.release()
colorPattern.close()

virtualDisplay.release()
virtualDisplay?.release()

imageReader.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class ScriptRunnerNotification @Inject constructor(
.setOngoing(true)
.setContentTitle(service.getString(R.string.app_name))
.setContentText(service.getString(R.string.overlay_notification_text))
// show full message on expand
.setStyle(NotificationCompat.BigTextStyle()
.bigText(service.getString(R.string.overlay_notification_text)))
.setSmallIcon(R.mipmap.notification_icon)
.setColor(service.getColor(R.color.colorBusterWeak))
.setPriority(NotificationManager.IMPORTANCE_LOW)
Expand All @@ -117,7 +120,7 @@ class ScriptRunnerNotification @Inject constructor(
service.startForeground(
Ids.foregroundNotification,
builder.build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE or ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
)
} else {
service.startForeground(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Copy or rename it if you want to keep it."</string>
<string name="p_support_class_berserker">"Berserker"</string>
<string name="p_support_class_extra">"Extra"</string>
<string name="p_support_class_mix">"Mix"</string>
<string name="overlay_notification_text">"Overlay service running"</string>
<string name="overlay_notification_text">"The FGA service is currently running to show the Play button and to take screenshots if needed."</string>
<string name="notification_stop">"Stop"</string>
<string name="accessibility_service">"Accessibility Service: "</string>
<string name="accessibility_enabled">"ENABLED"</string>
Expand Down

0 comments on commit b0565d8

Please sign in to comment.