mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1525dcfb52 |
No files matched your search
@@ -1993,7 +1993,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) ui.post { startSteamAtStartupIfEnabled(cold = true) }
|
||||
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) }
|
||||
}
|
||||
saved?.let { state ->
|
||||
restoreCompatLaunch(state)
|
||||
pendingSwitch = savedIntent(state, KEY_PENDING_SWITCH)
|
||||
@@ -2001,8 +2005,13 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
val wanted = ArrayList<String>()
|
||||
// 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) {
|
||||
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) {
|
||||
wanted.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
}
|
||||
if (SessionPrefs.micEnabled(this) && !SessionPrefs.micAsked(this)
|
||||
@@ -2011,7 +2020,6 @@ 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)
|
||||
@@ -2291,22 +2299,7 @@ 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)
|
||||
@@ -2315,7 +2308,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
inFront = true
|
||||
if (!homeChoiceOpen) {
|
||||
HomeApp.releaseUnusedHomeEntry(this)
|
||||
refreshHomeAppState()
|
||||
@@ -2451,7 +2443,6 @@ 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()
|
||||
@@ -3751,7 +3742,6 @@ 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()
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ import com.droiddeck.launcher.stores.StoreAchievements
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import com.droiddeck.launcher.stores.StoreLaunchRequests
|
||||
import com.droiddeck.launcher.stores.epic.EpicClient
|
||||
import com.droiddeck.launcher.ui.extendIntoCutout
|
||||
import com.droiddeck.launcher.ui.SessionAchievements
|
||||
import com.droiddeck.launcher.ui.screenIsOff
|
||||
import com.droiddeck.launcher.gpu.Cardboard
|
||||
@@ -7097,13 +7098,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
window.attributes = window.attributes.apply {
|
||||
layoutInDisplayCutoutMode = if (Build.VERSION.SDK_INT >= 30)
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
||||
else WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
}
|
||||
}
|
||||
window.extendIntoCutout()
|
||||
}
|
||||
|
||||
private val endListener: (Int) -> Unit = { status -> onSessionEnded(status) }
|
||||
|
||||
@@ -8,18 +8,9 @@ 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,15 +504,13 @@ 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; accessDeclined = true },
|
||||
onDismissRequest = { accessDrive = null },
|
||||
title = { Text(stringResource(R.string.fm_drive_access_title, label)) },
|
||||
text = { Text(stringResource(R.string.fm_drive_access_text)) },
|
||||
confirmButton = {
|
||||
@@ -521,17 +519,9 @@ fun FileManagerScreen(
|
||||
AllFilesAccess.open(context)
|
||||
}, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.upd_open_settings)) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { accessDrive = null; accessDeclined = true }, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } },
|
||||
dismissButton = { TextButton(onClick = { accessDrive = null }, 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 TriggerKey[][] keyTriggers = TriggerKey.slots(SLOTS);
|
||||
private final boolean[][] keyTriggers = new boolean[SLOTS][2];
|
||||
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);
|
||||
for (TriggerKey key : keyTriggers[slot]) key.reset();
|
||||
Arrays.fill(keyTriggers[slot], false);
|
||||
}
|
||||
|
||||
private void mutateState(java.util.function.Consumer<PadState> mutation) {
|
||||
@@ -570,76 +570,26 @@ public final class PadBridge {
|
||||
return true;
|
||||
}
|
||||
|
||||
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];
|
||||
static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog, boolean[] held, int side) {
|
||||
if (repeatCount > 0) return current;
|
||||
if (!analog) {
|
||||
key.held = pressed;
|
||||
held[side] = pressed;
|
||||
return pressed ? 1f : 0f;
|
||||
}
|
||||
if (pressed) {
|
||||
key.axisMovedWhilePressed = false;
|
||||
if (key.axisLive || current != 0f) return current;
|
||||
key.held = true;
|
||||
if (current != 0f) return current;
|
||||
held[side] = true;
|
||||
return 1f;
|
||||
}
|
||||
if (!key.axisMovedWhilePressed) key.axisLive = false;
|
||||
if (key.handoff) {
|
||||
key.handoff = false;
|
||||
return key.axis;
|
||||
}
|
||||
if (!key.held) return current;
|
||||
key.held = false;
|
||||
if (!held[side]) return current;
|
||||
held[side] = false;
|
||||
return 0f;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
static float axisTrigger(float value, boolean[] held, int side) {
|
||||
if (!held[side]) return value;
|
||||
if (value == 0f) return 1f;
|
||||
held[side] = false;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,6 @@ 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)
|
||||
@@ -56,10 +52,8 @@ 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. */
|
||||
@@ -96,7 +90,6 @@ 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,6 +960,12 @@ 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,6 +7,7 @@ import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.Display
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
@@ -480,6 +481,15 @@ private class SurfaceEditorPresentation(private val host: ComponentActivity, dis
|
||||
internal fun Window.prepareInputEditor() {
|
||||
addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)
|
||||
extendIntoCutout()
|
||||
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
}
|
||||
|
||||
internal fun Window.extendIntoCutout() {
|
||||
if (Build.VERSION.SDK_INT < 28) return
|
||||
attributes = attributes.apply {
|
||||
layoutInDisplayCutoutMode = if (Build.VERSION.SDK_INT >= 30) WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
||||
else WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
}
|
||||
}
|
||||
@@ -21,20 +21,4 @@ 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 = PadBridge.TriggerKey.slots(1)[0]
|
||||
val held = BooleanArray(2)
|
||||
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,64 +271,6 @@ 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)
|
||||
@@ -352,15 +294,11 @@ class PadPartialAxesTest {
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
assertEquals(1f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0.4f)
|
||||
assertEquals(1f, pad().leftTrigger)
|
||||
assertEquals(0.4f, 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])
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.view.InputDevice
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import com.droiddeck.launcher.input.InputControl
|
||||
import com.droiddeck.launcher.input.InputLibraries
|
||||
import com.droiddeck.launcher.input.InputSurfaceElement
|
||||
@@ -22,6 +23,7 @@ import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
@@ -90,6 +92,22 @@ class InputSurfaceEditorViewTest {
|
||||
|
||||
private fun InputSurfaceEditorView.centre(id: String) = rendered().first { it.id == id }.let { (it.x + it.width / 2) * width to (it.y + it.height / 2) * height }
|
||||
|
||||
private fun editorCutoutMode(): Int {
|
||||
val activity = Robolectric.buildActivity(android.app.Activity::class.java).setup().get()
|
||||
val dialog = android.app.Dialog(activity)
|
||||
dialog.window!!.prepareInputEditor()
|
||||
return dialog.window!!.attributes.layoutInDisplayCutoutMode
|
||||
}
|
||||
|
||||
@Test fun theEditorLaysOutIntoTheCutoutLikeTheSession() {
|
||||
assertEquals(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS, editorCutoutMode())
|
||||
}
|
||||
|
||||
@Config(sdk = [29])
|
||||
@Test fun theEditorLaysOutIntoShortEdgeCutoutsOnOlderAndroid() {
|
||||
assertEquals(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES, editorCutoutMode())
|
||||
}
|
||||
|
||||
@Test fun editingStartsInTheDisplayedFrame() {
|
||||
val view = view()
|
||||
var started: Pair<List<InputSurfaceElement>, Float>? = null
|
||||
|
||||
@@ -1594,15 +1594,6 @@ 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):
|
||||
@@ -1632,7 +1623,6 @@ 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("\\/")
|
||||
@@ -1643,7 +1633,6 @@ 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),
|
||||
}
|
||||
|
||||
|
||||
@@ -1656,27 +1645,6 @@ 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('"', "")
|
||||
|
||||
@@ -1723,12 +1691,10 @@ 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": locale}}
|
||||
"extra": {"contentIds": ",".join(manifest["contentIds"]), "displayName": manifest["title"], "locale": "en_US"}}
|
||||
steam = {"folder": str(folder), "offers": offers, "contentIds": manifest["contentIds"], "title": manifest["title"],
|
||||
"version": manifest["version"], "locale": locale, "exe": str(exe.relative_to(folder))}
|
||||
"version": manifest["version"], "locale": "en_US", "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):
|
||||
@@ -1746,7 +1712,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 in %s" % (manifest["title"], exe.name, answer.get("id") or offers[0], locale))
|
||||
log("steam ea: %s starts %s directly as %s" % (manifest["title"], exe.name, answer.get("id") or offers[0]))
|
||||
return REPLACED
|
||||
|
||||
|
||||
|
||||
@@ -515,7 +515,6 @@ 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'])
|
||||
@@ -533,47 +532,6 @@ 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