mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0c1f0f281 | ||
|
|
678057d727 | ||
|
|
ae94009382 | ||
|
|
fd93a35b72 | ||
|
|
12fa3ac343 |
No files matched your search
@@ -1993,11 +1993,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
}
|
||||
|
||||
val askAllFiles = Build.VERSION.SDK_INT >= 30 && com.droiddeck.launcher.files.AllFilesAccess.missing() &&
|
||||
!SessionPrefs.allFilesAsked(this)
|
||||
if (savedInstanceState == null) {
|
||||
if (!askAllFiles) ui.post { startSteamAtStartupIfEnabled(cold = true) }
|
||||
}
|
||||
if (savedInstanceState == null) ui.post { startSteamAtStartupIfEnabled(cold = true) }
|
||||
saved?.let { state ->
|
||||
restoreCompatLaunch(state)
|
||||
pendingSwitch = savedIntent(state, KEY_PENDING_SWITCH)
|
||||
@@ -2005,13 +2001,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
val wanted = ArrayList<String>()
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
// From targetSdk 30, shared storage outside the app's own folders is all-files access or nothing.
|
||||
if (askAllFiles) {
|
||||
SessionPrefs.setAllFilesAsked(this)
|
||||
com.droiddeck.launcher.files.AllFilesAccess.open(this)
|
||||
}
|
||||
} else if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
// From Android 11, shared storage outside the app's own folders is all-files access, which the file picker asks for when a shared drive is opened.
|
||||
if (Build.VERSION.SDK_INT < 30 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
wanted.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
}
|
||||
if (SessionPrefs.micEnabled(this) && !SessionPrefs.micAsked(this)
|
||||
@@ -2020,6 +2011,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
SessionPrefs.setMicAsked(this)
|
||||
}
|
||||
if (wanted.isNotEmpty()) requestPermissions(wanted.toTypedArray(), 1)
|
||||
com.droiddeck.launcher.session.Onboarding.onFirstRunReady = firstRunReady
|
||||
Thread({ com.droiddeck.launcher.stores.StoreAccounts.encryptAll(this) }, "store-credentials").start()
|
||||
if (!SessionState.running) Thread({
|
||||
com.droiddeck.launcher.session.LogMigration.run(this)
|
||||
@@ -2299,7 +2291,22 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
@Volatile private var inFront = false
|
||||
private var autoSteamPending = false
|
||||
|
||||
/** Runs on the worker thread that finishes setup, so the foreground state is read as setup completes, not when the UI thread gets to it. */
|
||||
private val firstRunReady: () -> Unit = {
|
||||
val front = inFront
|
||||
runOnUiThread { if (front) autoStartSteam() }
|
||||
}
|
||||
|
||||
private fun autoStartSteam() {
|
||||
if (isFinishing || isDestroyed || SessionState.running || !inFront) return
|
||||
if (busy) autoSteamPending = true else playSteam()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
inFront = false
|
||||
stopRightStickScroll()
|
||||
compatLaunchVisible = false
|
||||
if (android.os.Build.VERSION.SDK_INT >= 29) com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, true)
|
||||
@@ -2308,6 +2315,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
inFront = true
|
||||
if (!homeChoiceOpen) {
|
||||
HomeApp.releaseUnusedHomeEntry(this)
|
||||
refreshHomeAppState()
|
||||
@@ -2443,6 +2451,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
|
||||
override fun onDestroy() {
|
||||
// The queued launch was saved before this; a restored activity keeps its copy, and this one must not start it too.
|
||||
if (com.droiddeck.launcher.session.Onboarding.onFirstRunReady === firstRunReady) com.droiddeck.launcher.session.Onboarding.onFirstRunReady = null
|
||||
queuedLaunchRunner.destroy()
|
||||
triggerKeys.cancel()
|
||||
launchCoordinator.cancelAll()
|
||||
@@ -3742,6 +3751,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
refresh()
|
||||
com.droiddeck.launcher.agent.AgentHost.refresh(this)
|
||||
if (ok == true && LinuxRuntime.isInstalled(this)) { protons.checkUpdates(); protons.ensureSteamClient() }
|
||||
if (autoSteamPending) { autoSteamPending = false; autoStartSteam() }
|
||||
}
|
||||
}, "runtime-operation").start()
|
||||
}
|
||||
|
||||
@@ -3888,7 +3888,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
else -> return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
if (com.droiddeck.launcher.input.PointerCapture.isMouse(event) && !drawerOpen) {
|
||||
if ((event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD)) && !drawerOpen) {
|
||||
if (appUiOwnsPointer()) {
|
||||
if (super.dispatchGenericMotionEvent(event)) return true
|
||||
if (touchEditorOpen) return false
|
||||
@@ -5400,7 +5401,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private fun handleTouch(event: MotionEvent): Boolean {
|
||||
val pen = PenStream.penIndex(event)
|
||||
val penRouted = if (pen >= 0) routePen(event, pen).takeIf { it != PenRouter.Route.TOUCH } else null
|
||||
if (penRouted == null && com.droiddeck.launcher.input.PointerCapture.isMouse(event)) return onMouse(event)
|
||||
if (penRouted == null && (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD))) return onMouse(event)
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
sessionTouchDown = true
|
||||
@@ -6832,8 +6834,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private fun onBottomGameHover(event: MotionEvent): Boolean {
|
||||
val pen = PenStream.penIndex(event)
|
||||
if (pipUi) return false
|
||||
if (pen < 0) return onBottomGameMouse(event)
|
||||
if (pipUi || pen < 0) return false
|
||||
return when (routePen(event, pen)) {
|
||||
PenRouter.Route.TOUCH -> false
|
||||
PenRouter.Route.PEN -> {
|
||||
@@ -6845,16 +6846,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
|
||||
private fun onBottomGameMouse(event: MotionEvent): Boolean {
|
||||
if (PenStream.penIndex(event) >= 0 || !com.droiddeck.launcher.input.PointerCapture.isMouse(event)) return false
|
||||
notePress(event)
|
||||
onMouse(event)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun onBottomGameTouch(event: MotionEvent): Boolean {
|
||||
if (pipUi) return true
|
||||
if (onBottomGameMouse(event)) return true
|
||||
if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN) && PenStream.penIndex(event) < 0) return false
|
||||
notePress(event)
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
|
||||
@@ -8,9 +8,18 @@ import android.os.Environment
|
||||
import android.provider.Settings
|
||||
|
||||
object AllFilesAccess {
|
||||
private val VOLUME = Regex("^(/storage/emulated/\\d+|/storage/[^/]+|/sdcard)(/.*)?$")
|
||||
private val APP_FOLDERS = listOf("/Android/data", "/Android/obb")
|
||||
|
||||
fun missing(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean =
|
||||
sdk >= Build.VERSION_CODES.R && !granted()
|
||||
|
||||
/** Whether reading [path] takes all-files access: shared storage, outside the per-app folders directly under a volume's root, which Android always lets the app use. */
|
||||
fun covers(path: String): Boolean {
|
||||
val inside = VOLUME.matchEntire(path)?.groupValues?.get(2) ?: return false
|
||||
return APP_FOLDERS.none { inside == it || inside.startsWith("$it/") }
|
||||
}
|
||||
|
||||
fun open(context: Context) {
|
||||
val app = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:" + context.packageName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
|
||||
@@ -504,13 +504,15 @@ fun FileManagerScreen(
|
||||
}
|
||||
val drives = remember(storageTick) { StorageRoots.list(context) }
|
||||
var accessDrive by remember { mutableStateOf<String?>(null) }
|
||||
var accessWasMissing by remember { mutableStateOf(AllFilesAccess.missing()) }
|
||||
var accessDeclined by remember { mutableStateOf(false) }
|
||||
fun unreadable(drive: StorageRoot) {
|
||||
if (AllFilesAccess.missing()) accessDrive = drive.label
|
||||
else Toast.makeText(context, context.getString(R.string.fm_drive_not_readable, drive.label), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
accessDrive?.let { label ->
|
||||
OutlinedAlertDialog(
|
||||
onDismissRequest = { accessDrive = null },
|
||||
onDismissRequest = { accessDrive = null; accessDeclined = true },
|
||||
title = { Text(stringResource(R.string.fm_drive_access_title, label)) },
|
||||
text = { Text(stringResource(R.string.fm_drive_access_text)) },
|
||||
confirmButton = {
|
||||
@@ -519,9 +521,17 @@ fun FileManagerScreen(
|
||||
AllFilesAccess.open(context)
|
||||
}, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.upd_open_settings)) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { accessDrive = null }, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } },
|
||||
dismissButton = { TextButton(onClick = { accessDrive = null; accessDeclined = true }, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } },
|
||||
)
|
||||
}
|
||||
LaunchedEffect(currentDir, storageTick) {
|
||||
if (!AllFilesAccess.missing()) {
|
||||
if (accessWasMissing) { accessWasMissing = false; loadDirectory(currentDir, resetScroll = false, record = false) }
|
||||
} else {
|
||||
accessWasMissing = true
|
||||
if (!accessDeclined && accessDrive == null && AllFilesAccess.covers(currentDir.path)) accessDrive = drives.firstOrNull { currentDir.path.startsWith(it.dir.path) }?.label ?: context.getString(R.string.fm_drive_internal)
|
||||
}
|
||||
}
|
||||
val linuxRoot = remember(storageTick) {
|
||||
com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context).takeIf { File(it, "usr").isDirectory }
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class PadBridge {
|
||||
private final PadState[] playerStates = new PadState[SLOTS];
|
||||
private final float[][] rawSticks = new float[SLOTS][4];
|
||||
private final Map<Integer, Boolean> rightStickLayouts = new HashMap<>();
|
||||
private final boolean[][] keyTriggers = new boolean[SLOTS][2];
|
||||
private final TriggerKey[][] keyTriggers = TriggerKey.slots(SLOTS);
|
||||
private final int[] retainedSticks = new int[SLOTS];
|
||||
private final PadState effectiveState = new PadState();
|
||||
private final PadState homeGuideReport = new PadState();
|
||||
@@ -484,7 +484,7 @@ public final class PadBridge {
|
||||
stateFor(slot).clear();
|
||||
retainedSticks[slot] = 0;
|
||||
Arrays.fill(rawSticks[slot], 0f);
|
||||
Arrays.fill(keyTriggers[slot], false);
|
||||
for (TriggerKey key : keyTriggers[slot]) key.reset();
|
||||
}
|
||||
|
||||
private void mutateState(java.util.function.Consumer<PadState> mutation) {
|
||||
@@ -570,26 +570,76 @@ public final class PadBridge {
|
||||
return true;
|
||||
}
|
||||
|
||||
static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog, boolean[] held, int side) {
|
||||
static final class TriggerKey {
|
||||
static final float RELEASE_FROM_PEAK = 0.05f;
|
||||
boolean held;
|
||||
boolean handoff;
|
||||
boolean axisLive;
|
||||
boolean axisMovedWhilePressed;
|
||||
float peak;
|
||||
float axis;
|
||||
|
||||
static TriggerKey[][] slots(int count) {
|
||||
TriggerKey[][] keys = new TriggerKey[count][2];
|
||||
for (TriggerKey[] pair : keys) {
|
||||
pair[0] = new TriggerKey();
|
||||
pair[1] = new TriggerKey();
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
held = false;
|
||||
handoff = false;
|
||||
axisLive = false;
|
||||
axisMovedWhilePressed = false;
|
||||
peak = 0f;
|
||||
axis = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog, TriggerKey[] keys, int side) {
|
||||
TriggerKey key = keys[side];
|
||||
if (repeatCount > 0) return current;
|
||||
if (!analog) {
|
||||
held[side] = pressed;
|
||||
key.held = pressed;
|
||||
return pressed ? 1f : 0f;
|
||||
}
|
||||
if (pressed) {
|
||||
if (current != 0f) return current;
|
||||
held[side] = true;
|
||||
key.axisMovedWhilePressed = false;
|
||||
if (key.axisLive || current != 0f) return current;
|
||||
key.held = true;
|
||||
return 1f;
|
||||
}
|
||||
if (!held[side]) return current;
|
||||
held[side] = false;
|
||||
if (!key.axisMovedWhilePressed) key.axisLive = false;
|
||||
if (key.handoff) {
|
||||
key.handoff = false;
|
||||
return key.axis;
|
||||
}
|
||||
if (!key.held) return current;
|
||||
key.held = false;
|
||||
return 0f;
|
||||
}
|
||||
|
||||
static float axisTrigger(float value, boolean[] held, int side) {
|
||||
if (!held[side]) return value;
|
||||
if (value == 0f) return 1f;
|
||||
held[side] = false;
|
||||
static float axisTrigger(float value, TriggerKey[] keys, int side) {
|
||||
TriggerKey key = keys[side];
|
||||
key.axis = value;
|
||||
if (value != 0f) {
|
||||
key.axisLive = true;
|
||||
key.axisMovedWhilePressed = true;
|
||||
}
|
||||
if (key.held) {
|
||||
if (value == 0f) return 1f;
|
||||
key.held = false;
|
||||
key.handoff = true;
|
||||
key.peak = value;
|
||||
return 1f;
|
||||
}
|
||||
if (key.handoff) {
|
||||
key.peak = Math.max(key.peak, value);
|
||||
if (value > key.peak - TriggerKey.RELEASE_FROM_PEAK) return 1f;
|
||||
key.handoff = false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,6 @@ object PointerCapture {
|
||||
|
||||
fun isTouchpad(event: MotionEvent): Boolean = event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
|
||||
|
||||
fun isMouse(event: MotionEvent): Boolean =
|
||||
event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
|
||||
|
||||
fun delta(event: MotionEvent): FloatArray {
|
||||
var dx = event.x
|
||||
var dy = event.y
|
||||
|
||||
@@ -29,6 +29,10 @@ object Onboarding {
|
||||
/** The setup screens belong to the first run; later runtime, Proton and Steam client updates keep the usual Play button. */
|
||||
val firstRun = MutableStateFlow(true)
|
||||
|
||||
/** Called once, when this process finishes the first-run downloads itself; not when everything was already in place. */
|
||||
@Volatile var onFirstRunReady: (() -> Unit)? = null
|
||||
@Volatile private var worked = false
|
||||
|
||||
fun attach(context: Context) {
|
||||
appContext = context.applicationContext
|
||||
val prefs = context.applicationContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
@@ -52,8 +56,10 @@ object Onboarding {
|
||||
|
||||
private fun markFirstRunDone() {
|
||||
val context = appContext ?: return
|
||||
val live = firstRun.value && worked
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(KEY_FIRST_RUN_DONE, true).apply()
|
||||
firstRun.value = false
|
||||
if (live) onFirstRunReady?.invoke()
|
||||
}
|
||||
|
||||
/** Keeps the process in the foreground, with one notification, while a step downloads and the runtime installer is not already doing so. */
|
||||
@@ -90,6 +96,7 @@ object Onboarding {
|
||||
}
|
||||
|
||||
fun report(step: Step, label: String, percent: Int) {
|
||||
worked = true
|
||||
failed.value = failed.value - step
|
||||
active.value = active.value + (step to Progress(label, percent))
|
||||
keepAlive()
|
||||
|
||||
@@ -960,12 +960,6 @@ object SessionPrefs {
|
||||
|
||||
fun micAsked(context: Context): Boolean = prefs(context).getBoolean("micAsked", false)
|
||||
|
||||
fun allFilesAsked(context: Context): Boolean = prefs(context).getBoolean("allFilesAsked", false)
|
||||
|
||||
fun setAllFilesAsked(context: Context) {
|
||||
prefs(context).edit().putBoolean("allFilesAsked", true).apply()
|
||||
}
|
||||
|
||||
fun bluetoothAsked(context: Context): Boolean = prefs(context).getBoolean("bluetoothAsked", false)
|
||||
|
||||
fun setBluetoothAsked(context: Context) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.os.Bundle
|
||||
import android.view.Display
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import android.view.PointerIcon
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.SurfaceView
|
||||
import android.view.View
|
||||
@@ -45,7 +44,6 @@ class BottomGameScreen(
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
surfaceView.pointerIcon = PointerIcon.getSystemIcon(context, PointerIcon.TYPE_NULL)
|
||||
surfaceView.setOnTouchListener { _, event -> onTouch(event) }
|
||||
surfaceView.holder.addCallback(callback)
|
||||
}
|
||||
|
||||
@@ -21,4 +21,20 @@ class AllFilesAccessTest {
|
||||
assertTrue(AllFilesAccess.missing(sdk = 35) { false })
|
||||
assertFalse(AllFilesAccess.missing(sdk = 35) { true })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onlySharedStorageNeedsIt() {
|
||||
assertTrue(AllFilesAccess.covers("/storage/emulated/0"))
|
||||
assertTrue(AllFilesAccess.covers("/storage/1A2B-3C4D/Games"))
|
||||
assertTrue(AllFilesAccess.covers("/sdcard/Download"))
|
||||
assertFalse(AllFilesAccess.covers("/storage/emulated/0/Android/data"))
|
||||
assertFalse(AllFilesAccess.covers("/storage/1A2B-3C4D/Android/obb"))
|
||||
assertTrue(AllFilesAccess.covers("/storage/emulated/0/Android"))
|
||||
assertTrue(AllFilesAccess.covers("/storage/emulated/0/Android/database"))
|
||||
assertTrue(AllFilesAccess.covers("/storage/emulated/0/Download/Android/data"))
|
||||
assertTrue(AllFilesAccess.covers("/storage/1A2B-3C4D/Games/Android/obb/x"))
|
||||
assertFalse(AllFilesAccess.covers("/storage/emulated/0/Android/data/com.droiddeck.launcher/files"))
|
||||
assertFalse(AllFilesAccess.covers("/storage/1A2B-3C4D/Android/obb/com.droiddeck.launcher"))
|
||||
assertFalse(AllFilesAccess.covers("/data/user/0/com.droiddeck.launcher/files"))
|
||||
}
|
||||
}
|
||||
@@ -259,7 +259,7 @@ class PadPartialAxesTest {
|
||||
}
|
||||
|
||||
@Test fun keyTriggerDecision() {
|
||||
val held = BooleanArray(2)
|
||||
val held = PadBridge.TriggerKey.slots(1)[0]
|
||||
assertEquals(1f, PadBridge.keyTrigger(0f, true, 0, false, held, 0))
|
||||
assertEquals(0f, PadBridge.keyTrigger(1f, false, 0, false, held, 0))
|
||||
assertEquals(0.25f, PadBridge.keyTrigger(0.25f, true, 1, false, held, 0))
|
||||
@@ -271,6 +271,64 @@ class PadPartialAxesTest {
|
||||
assertEquals(0f, PadBridge.axisTrigger(0f, held, 1))
|
||||
}
|
||||
|
||||
@Test fun keyBeforeAxisOnAFullPullIsOnePress() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
for (value in listOf(0.1f, 0.3f, 0.6f, 1f, 0.98f)) {
|
||||
motion(device, MotionEvent.AXIS_GAS to value)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
}
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.7f)
|
||||
assertEquals(0.7f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0.7f, pad().rightTrigger)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun releasingDuringTheHandoffFollowsTheAxis() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.4f)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0.4f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun movingTriggerAxisStaysAnalogWhenItsKeyFiresFirst() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.5f)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.1f)
|
||||
assertEquals(0.1f, pad().rightTrigger)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.35f)
|
||||
assertEquals(0.35f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun triggerSwitchedToDigitalPressesAgainAfterOneSilentPress() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.5f)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
motion(device)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
motion(device)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun silentTriggerAxesLetTheirKeysPress() {
|
||||
val device = device(MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER)
|
||||
motion(device)
|
||||
@@ -294,11 +352,15 @@ class PadPartialAxesTest {
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
assertEquals(1f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0.4f)
|
||||
assertEquals(0.4f, pad().leftTrigger)
|
||||
assertEquals(1f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0f)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0.4f)
|
||||
assertEquals(0.4f, pad().leftTrigger)
|
||||
}
|
||||
|
||||
private fun pad(): PadState = requireNotNull(JoyConPadTest.RecordingWriter.pads[0])
|
||||
|
||||
@@ -54,37 +54,6 @@ class PointerCaptureTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aHoveringMouseOrTouchpadDrivesThePointer() {
|
||||
listOf(
|
||||
event(MotionEvent.ACTION_HOVER_MOVE, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_BUTTON_PRESS, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_SCROLL, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_HOVER_MOVE, InputDevice.SOURCE_TOUCHPAD, x = 640f, y = 360f),
|
||||
).forEach { event ->
|
||||
try {
|
||||
assertTrue(PointerCapture.isMouse(event))
|
||||
} finally {
|
||||
event.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun touchesPensControllersAndCapturedMiceAreNotAHoveringMouse() {
|
||||
listOf(
|
||||
InputDevice.SOURCE_TOUCHSCREEN,
|
||||
InputDevice.SOURCE_STYLUS,
|
||||
InputDevice.SOURCE_JOYSTICK,
|
||||
InputDevice.SOURCE_MOUSE_RELATIVE,
|
||||
).forEach { source ->
|
||||
val event = event(MotionEvent.ACTION_MOVE, source, x = 640f, y = 360f)
|
||||
try {
|
||||
assertFalse(PointerCapture.isMouse(event))
|
||||
} finally {
|
||||
event.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun touchpadTravelMatchesTheSameDistanceOnScreen() {
|
||||
assertEquals(0.5f, PointerCapture.touchpadScale(unitsPerMm = 20f, padWidth = 2000f, pixelsPerMm = 10f, screenWidth = 1920), 0.001f)
|
||||
}
|
||||
|
||||
@@ -157,42 +157,10 @@ class SessionPenRoutingTest {
|
||||
SessionPrefs.setPenSetting(activity, "pen", SessionPrefs.PEN_TOUCH)
|
||||
invoke("readPrefs")
|
||||
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 30, pen to 500f)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 40, finger to 500f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 40, finger to 500f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertEquals(listOf(PEN_IN, PEN_IN or PEN_TIP, 0), CompositorShadow.pens.map { it.flags })
|
||||
}
|
||||
|
||||
@Test fun aMouseOnTheOtherScreensGameMovesTheSessionPointer() {
|
||||
fun hover(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameHover",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
fun touch(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameTouch",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
val mouse = MotionEvent.TOOL_TYPE_MOUSE
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 10, mouse to 250f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_BUTTON_PRESS, 20, mouse to 250f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_DOWN, 20, mouse to 250f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_MOVE, 30, mouse to 750f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_UP, 40, mouse to 750f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 50, finger to 600f, source = InputDevice.SOURCE_TOUCHPAD)))
|
||||
assertEquals(
|
||||
listOf(InputSpace.x(250f, 1000), InputSpace.x(250f, 1000), InputSpace.x(750f, 1000), InputSpace.x(600f, 1000)),
|
||||
CompositorShadow.pointers.map { it.second },
|
||||
)
|
||||
assertTrue(CompositorShadow.pointers.all { it.first == 1 && it.third == InputSpace.y(300f, 600) })
|
||||
assertTrue(CompositorShadow.pens.isEmpty())
|
||||
assertTrue(CompositorShadow.touches.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aControllerOnTheOtherScreensGameIsNotTakenAsAMouse() {
|
||||
fun hover(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameHover",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
assertFalse(hover(event(MotionEvent.ACTION_MOVE, 10, finger to 500f, source = InputDevice.SOURCE_JOYSTICK)))
|
||||
assertTrue(CompositorShadow.pointers.isEmpty())
|
||||
assertTrue(CompositorShadow.pens.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun glassesAProgramPointerLockAndAppUiDropPenHover() {
|
||||
state<Boolean>("glassesOutputActive").value = true
|
||||
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f))
|
||||
|
||||
@@ -1594,6 +1594,15 @@ STEAM_EA_STATE = ".droiddeck-ea-steam.json"
|
||||
STEAM_EA_CLIENT = "drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/EADesktop.exe"
|
||||
STEAM_EA_OFFER = re.compile(r"^(Origin\.OFR\.[0-9]+\.[0-9]+)\.dat$", re.IGNORECASE)
|
||||
REPLACED = 13
|
||||
STEAM_EA_LOCALES = {
|
||||
"arabic": ("ar_SA",), "brazilian": ("pt_BR",), "bulgarian": ("bg_BG",), "czech": ("cs_CZ",), "danish": ("da_DK",),
|
||||
"dutch": ("nl_NL",), "english": ("en_US",), "finnish": ("fi_FI",), "french": ("fr_FR",), "german": ("de_DE",),
|
||||
"greek": ("el_GR",), "hungarian": ("hu_HU",), "indonesian": ("id_ID",), "italian": ("it_IT",), "japanese": ("ja_JP",),
|
||||
"koreana": ("ko_KR",), "latam": ("es_MX",), "malay": ("ms_MY",), "norwegian": ("no_NO", "nb_NO"), "polish": ("pl_PL",),
|
||||
"portuguese": ("pt_PT",), "romanian": ("ro_RO",), "russian": ("ru_RU",), "schinese": ("zh_CN",), "spanish": ("es_ES",),
|
||||
"swedish": ("sv_SE",), "tchinese": ("zh_TW", "zh_HK"), "thai": ("th_TH",), "turkish": ("tr_TR",), "ukrainian": ("uk_UA",),
|
||||
"vietnamese": ("vi_VN",),
|
||||
}
|
||||
|
||||
|
||||
def steam_ea_link(argv):
|
||||
@@ -1623,6 +1632,7 @@ def ea_manifest(folder):
|
||||
launcher = next((l for l in launchers if not l[2]), launchers[0] if launchers else None)
|
||||
version = root.find("buildMetaData/gameVersion")
|
||||
titles = {e.get("locale"): (e.text or "").strip() for e in root.iter("gameTitle") if e.get("locale")}
|
||||
listed = [l.strip() for l in (root.findtext("installMetaData/locales") or "").split(",") if l.strip()]
|
||||
exe = None
|
||||
if launcher is not None:
|
||||
relative = re.sub(r"^\[[^\]]*\]", "", launcher[0]).replace("{installLocation}", "").lstrip("\\/")
|
||||
@@ -1633,6 +1643,7 @@ def ea_manifest(folder):
|
||||
"parameters": launcher[1] if launcher else "",
|
||||
"version": version.get("version", "") if version is not None else "",
|
||||
"title": titles.get("en_US") or next(iter(titles.values()), "") or Path(folder).name,
|
||||
"locales": listed or list(titles),
|
||||
}
|
||||
|
||||
|
||||
@@ -1645,6 +1656,27 @@ def steam_ea_offers(folder):
|
||||
return [m.group(1) for m in map(STEAM_EA_OFFER.match, names) if m]
|
||||
|
||||
|
||||
def steam_game_language(folder, appid):
|
||||
try:
|
||||
text = decode_output((Path(folder).parent.parent / ("appmanifest_%s.acf" % appid)).read_bytes())
|
||||
except OSError:
|
||||
text = ""
|
||||
found = re.search(r'"UserConfig"\s*\{[^{}]*?"language"\s*"([^"]+)"', text, re.IGNORECASE)
|
||||
return found.group(1) if found else os.environ.get("DD_STEAM_LANGUAGE", "")
|
||||
|
||||
|
||||
def steam_ea_locale(available, language):
|
||||
wanted = STEAM_EA_LOCALES.get(language.strip().lower(), ("en_US",))
|
||||
for want in wanted:
|
||||
exact = [l for l in available if l.casefold() == want.casefold()]
|
||||
if exact:
|
||||
return exact[0]
|
||||
prefix = lambda l: l.casefold().split("_", 1)[0]
|
||||
same = [l for l in available if prefix(l) == prefix(wanted[0])]
|
||||
english = [l for l in available if prefix(l) == "en"]
|
||||
return (same or english or ["en_US"])[0]
|
||||
|
||||
|
||||
def batch_text(value):
|
||||
return value.replace("%", "%%").replace('"', "")
|
||||
|
||||
@@ -1691,10 +1723,12 @@ def prepare_steam_ea(argv, compat_data, launch_dir):
|
||||
log("steam ea: no channel to DroidDeck, left to the EA app")
|
||||
return 0
|
||||
exe = manifest["exe"]
|
||||
appid = STEAM_EA_LINK.match(steam_ea_link(argv).strip().strip('"')).group(1)
|
||||
locale = steam_ea_locale(manifest["locales"], steam_game_language(folder, appid))
|
||||
sidecar = {"store": "ea", "id": offers[0], "title": manifest["title"],
|
||||
"extra": {"contentIds": ",".join(manifest["contentIds"]), "displayName": manifest["title"], "locale": "en_US"}}
|
||||
"extra": {"contentIds": ",".join(manifest["contentIds"]), "displayName": manifest["title"], "locale": locale}}
|
||||
steam = {"folder": str(folder), "offers": offers, "contentIds": manifest["contentIds"], "title": manifest["title"],
|
||||
"version": manifest["version"], "locale": "en_US", "exe": str(exe.relative_to(folder))}
|
||||
"version": manifest["version"], "locale": locale, "exe": str(exe.relative_to(folder))}
|
||||
answer = prepare_ea(folder, sidecar, compat_data, launch_dir, steam)
|
||||
env = answer.get("env") if answer and answer.get("ok") else None
|
||||
if not isinstance(env, dict):
|
||||
@@ -1712,7 +1746,7 @@ def prepare_steam_ea(argv, compat_data, launch_dir):
|
||||
except OSError as error:
|
||||
log("steam ea: launcher not written (%s), left to the EA app" % type(error).__name__)
|
||||
return 0
|
||||
log("steam ea: %s starts %s directly as %s" % (manifest["title"], exe.name, answer.get("id") or offers[0]))
|
||||
log("steam ea: %s starts %s directly as %s in %s" % (manifest["title"], exe.name, answer.get("id") or offers[0], locale))
|
||||
return REPLACED
|
||||
|
||||
|
||||
|
||||
@@ -515,6 +515,7 @@ class SteamEa(unittest.TestCase):
|
||||
with patch.dict(os.environ, env), patch.object(store, 'prepare_ea', side_effect=prepare):
|
||||
self.assertEqual(store.REPLACED, store.main(['steam2ea://launchgame/1237970?platform=steam&theme=tf2']))
|
||||
steam = asked[0][4]
|
||||
self.assertEqual('en_US', steam['locale'])
|
||||
self.assertEqual(['Origin.OFR.50.0001452', 'Origin.OFR.50.0001456'], steam['offers'])
|
||||
self.assertEqual(['1039093'], steam['contentIds'])
|
||||
self.assertEqual('Titanfall2.exe', steam['exe'])
|
||||
@@ -532,6 +533,47 @@ class SteamEa(unittest.TestCase):
|
||||
self.assertEqual(0, store.main(['--exited', 'steam2ea://launchgame/1237970']))
|
||||
self.assertEqual([{'op': 'ea-exited', 'store': 'ea', 'id': 'Origin.OFR.50.0001452'}], asked)
|
||||
|
||||
def launch_locale(self, root, locales, appmanifest=None, steam_language=None):
|
||||
folder, data = self.steam_copy(root)
|
||||
if locales is not None:
|
||||
text = MANIFEST.replace('<runtime>', '<installMetaData><locales>%s</locales></installMetaData>\n <runtime>' % locales)
|
||||
(folder / '__Installer/installerdata.xml').write_bytes(b'\xff\xfe' + text.encode('utf-16-le'))
|
||||
if appmanifest is not None:
|
||||
(Path(root) / 'steamapps/appmanifest_1237970.acf').write_text(appmanifest)
|
||||
asked = []
|
||||
prepare = lambda *a: asked.append(a) or {'ok': False, 'reason': 'signed-out'}
|
||||
env = {'STEAM_COMPAT_INSTALL_PATH': str(folder), 'STEAM_COMPAT_DATA_PATH': str(data), 'DD_LAUNCH_DIR': str(Path(root) / 'session')}
|
||||
cleared = {k: v for k, v in os.environ.items() if k != 'DD_STEAM_LANGUAGE'}
|
||||
if steam_language is not None:
|
||||
cleared['DD_STEAM_LANGUAGE'] = steam_language
|
||||
with patch.dict(os.environ, dict(cleared, **env), clear=True), patch.object(store, 'prepare_ea', side_effect=prepare):
|
||||
store.main(['steam2ea://launchgame/1237970?platform=steam'])
|
||||
self.assertEqual(asked[0][1]['extra']['locale'], asked[0][4]['locale'])
|
||||
return asked[0][4]['locale']
|
||||
|
||||
def test_the_game_starts_in_the_language_steam_set_for_it(self):
|
||||
acf = '"AppState"\n{\n\t"appid"\t\t"1237970"\n\t"UserConfig"\n\t{\n\t\t"language"\t\t"french"\n\t}\n}\n'
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
self.assertEqual('fr_FR', self.launch_locale(root, 'en_US,de_DE,fr_FR', acf, 'german'))
|
||||
|
||||
def test_without_a_language_for_the_game_steams_own_language_is_used(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
self.assertEqual('de_DE', self.launch_locale(root, 'en_US,de_DE,fr_FR', None, 'german'))
|
||||
|
||||
def test_a_language_the_game_lacks_falls_back_to_english(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
self.assertEqual('en_GB', self.launch_locale(root, 'en_GB,de_DE', None, 'french'))
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
self.assertEqual('en_US', self.launch_locale(root, None, None, 'french'))
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
self.assertEqual('en_US', self.launch_locale(root, 'en_US,fr_FR', None, None))
|
||||
|
||||
def test_the_locale_prefers_the_exact_regional_variant_then_the_same_language(self):
|
||||
self.assertEqual('zh_HK', store.steam_ea_locale(['zh_CN', 'zh_HK'], 'tchinese'))
|
||||
self.assertEqual('es_ES', store.steam_ea_locale(['en_US', 'es_ES'], 'latam'))
|
||||
self.assertEqual('pt_BR', store.steam_ea_locale(['pt_PT', 'pt_BR'], 'brazilian'))
|
||||
self.assertEqual('en_US', store.steam_ea_locale(['en_US', 'fr_FR'], 'unknown'))
|
||||
|
||||
def test_the_manifests_launch_parameters_keep_their_quotes(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder, data = self.steam_copy(root)
|
||||
|
||||
Reference in new issue
Block a user