Skip to content

Commit

Permalink
Merge branch 'master' into exit-out-of-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurKun21 committed Aug 19, 2024
2 parents 55d2ac5 + 9691afe commit d8074ba
Show file tree
Hide file tree
Showing 35 changed files with 199 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ jobs:
with:
name: bundle
path: app/build/outputs/bundle/release/app-release.aab
if: ${{ !cancelled() }}

- name: Upload De-obfuscation mapping file
uses: actions/upload-artifact@v4
with:
name: mapping-release
path: app/build/outputs/mapping/release/mapping.txt
if: ${{ !cancelled() }}

# Release master branch
github_release:
Expand Down
10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ GEM
base64
nkf
rexml
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.907.0)
aws-sdk-core (3.191.6)
aws-partitions (1.963.0)
aws-sdk-core (3.201.4)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.78.0)
aws-sdk-core (~> 3, >= 3.191.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.146.1)
aws-sdk-core (~> 3, >= 3.191.0)
aws-sdk-kms (1.88.0)
aws-sdk-core (~> 3, >= 3.201.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.157.0)
aws-sdk-core (~> 3, >= 3.201.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
aws-sigv4 (1.8.0)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.9.1)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
base64 (0.2.0)
Expand All @@ -38,7 +38,7 @@ GEM
domain_name (0.6.20240107)
dotenv (2.8.1)
emoji_regex (3.2.3)
excon (0.110.0)
excon (0.111.0)
faraday (1.10.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
Expand All @@ -60,15 +60,15 @@ GEM
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http (1.0.2)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.3.1)
fastlane (2.220.0)
fastlane (2.222.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -126,7 +126,7 @@ GEM
google-apis-core (>= 0.11.0, < 2.a)
google-apis-storage_v1 (0.31.0)
google-apis-core (>= 0.11.0, < 2.a)
google-cloud-core (1.7.0)
google-cloud-core (1.7.1)
google-cloud-env (>= 1.0, < 3.a)
google-cloud-errors (~> 1.0)
google-cloud-env (1.6.0)
Expand All @@ -147,32 +147,32 @@ GEM
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
highline (2.0.3)
http-cookie (1.0.5)
http-cookie (1.0.6)
domain_name (~> 0.5)
httpclient (2.8.3)
jmespath (1.6.2)
json (2.7.2)
jwt (2.8.1)
jwt (2.8.2)
base64
mini_magick (4.12.0)
mini_magick (4.13.2)
mini_mime (1.1.5)
multi_json (1.15.0)
multipart-post (2.4.0)
multipart-post (2.4.1)
nanaimo (0.3.0)
naturally (2.2.1)
nkf (0.2.0)
optparse (0.4.0)
optparse (0.5.0)
os (1.1.4)
plist (3.7.1)
public_suffix (5.0.5)
rake (13.2.0)
public_suffix (5.1.1)
rake (13.2.1)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.8)
strscan (>= 3.0.9)
rexml (3.3.4)
strscan
rouge (2.0.7)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand All @@ -197,13 +197,13 @@ GEM
uber (0.1.0)
unicode-display_width (2.5.0)
word_wrap (1.0.0)
xcodeproj (1.24.0)
xcodeproj (1.25.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
rexml (>= 3.3.2, < 4.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.1)
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
defaultConfig {
applicationId = "io.github.fate_grand_automata"
minSdk = 24
targetSdk = 33
targetSdk = 34
versionCode = System.getenv("FGA_VERSION_CODE")?.toInt() ?: 1
versionName = System.getenv("FGA_VERSION_NAME") ?: System.getenv("FGA_VERSION_CODE") ?: "0.1.0"
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<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 @@ -23,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 @@ -2,6 +2,7 @@ package io.github.fate_grand_automata.imaging

import android.annotation.SuppressLint
import android.graphics.PixelFormat
import android.hardware.display.VirtualDisplay
import android.media.ImageReader
import android.media.projection.MediaProjection
import io.github.fate_grand_automata.util.StorageProvider
Expand Down Expand Up @@ -31,7 +32,13 @@ class MediaProjectionScreenshotService(

@SuppressLint("WrongConstant")
private val imageReader = ImageReader.newInstance(imageSize.width, imageSize.height, PixelFormat.RGBA_8888, 2)
private val virtualDisplay = mediaProjection.createVirtualDisplay(
private val virtualDisplay: VirtualDisplay? = mediaProjection.apply {
this.registerCallback(object : MediaProjection.Callback() {
override fun onStop() {
close()
}
}, null)
}.createVirtualDisplay(
"ScreenCapture",
imageSize.width, imageSize.height, screenDensity,
0, imageReader.surface, null, null
Expand Down Expand Up @@ -67,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 @@ -3,6 +3,7 @@ package io.github.fate_grand_automata.runner
import android.app.Activity
import android.content.Intent
import android.media.projection.MediaProjectionManager
import android.os.Build
import dagger.hilt.android.scopes.ServiceScoped
import io.github.fate_grand_automata.imaging.MediaProjectionScreenshotService
import io.github.fate_grand_automata.root.RootScreenshotService
Expand Down Expand Up @@ -55,6 +56,11 @@ class ScreenshotServiceHolder @Inject constructor(
val mediaProjection =
mediaProjectionManager.getMediaProjection(Activity.RESULT_OK, token)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// not allowed to reuse tokens on Android 14
ScriptRunnerService.mediaProjectionToken = null
}

val scaledSize = size * (scale ?: 1.0)
val scaledDensity = (landscapeMetrics.densityDpi / (scale ?: 1.0)).roundToInt()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
Expand Down Expand Up @@ -102,17 +103,36 @@ 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)
.setContentIntent(activityIntent)
.addAction(stopAction)
}

fun show() {
fun show(useRootForScreenshots: Boolean) {
val builder = startBuildNotification()

service.startForeground(Ids.foregroundNotification, builder.build())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
var foregroundServiceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
if (!useRootForScreenshots) {
foregroundServiceType = foregroundServiceType.or(ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION)
}

service.startForeground(
Ids.foregroundNotification,
builder.build(),
foregroundServiceType
)
} else {
service.startForeground(
Ids.foregroundNotification,
builder.build()
)
}
}

fun message(msg: String) {
Expand All @@ -135,17 +155,17 @@ class ScriptRunnerNotification @Inject constructor(
vibrate(100.milliseconds)
}

private fun vibrate(Duration: Duration) {
private fun vibrate(duration: Duration) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(
VibrationEffect.createOneShot(
Duration.inWholeMilliseconds,
duration.inWholeMilliseconds,
VibrationEffect.DEFAULT_AMPLITUDE
)
)
} else {
@Suppress("DEPRECATION")
vibrator.vibrate(Duration.inWholeMilliseconds)
vibrator.vibrate(duration.inWholeMilliseconds)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.os.IBinder
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -40,7 +41,9 @@ class ScriptRunnerService: Service() {
var mediaProjectionToken: Intent? = null
set(value) {
field = value
instance?.controller?.onNewMediaProjectionToken()
if (value != null) {
instance?.controller?.onNewMediaProjectionToken()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ScriptRunnerServiceController @Inject constructor(

fun onCreate() {
Timber.i("Script runner service created")
notification.show()
notification.show(prefs.useRootForScreenshots)

screenOffReceiver.register(service) {
Timber.v("SCREEN OFF")
Expand Down
Loading

0 comments on commit d8074ba

Please sign in to comment.