Skip to content

Commit 4403db6

Browse files
gabrielle-laucopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 830456717
1 parent 92db6e2 commit 4403db6

25 files changed

Lines changed: 1928 additions & 42 deletions

‎android_env/apps/java/com/google/androidenv/accessibilityforwarder/AndroidManifest.xml‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
// Copyright 2025 DeepMind Technologies Limited.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
151
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2025 DeepMind Technologies Limited.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.-->
15+
16+
1617

1718
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1819
package="com.google.androidenv.accessibilityforwarder">

‎android_env/apps/java/com/google/androidenv/accessibilityforwarder/AndroidManifest_lite.xml‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
// Copyright 2025 DeepMind Technologies Limited.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
151
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2025 DeepMind Technologies Limited.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.-->
15+
16+
1617

1718
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1819
package="com.google.androidenv.accessibilityforwarder">

‎android_env/apps/java/com/google/androidenv/accessibilityforwarder/res/xml/accessibility_forwarder_service.xml‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
// Copyright 2025 DeepMind Technologies Limited.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
151
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2025 DeepMind Technologies Limited.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.-->
15+
16+
1617

1718
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
1819
android:accessibilityEventTypes="typeAllMask"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2025 DeepMind Technologies Limited.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.-->
15+
16+
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
package="com.google.androidenv.catch">
20+
<uses-sdk android:minSdkVersion="26"
21+
android:targetSdkVersion="35"/>
22+
<application
23+
android:allowBackup="false"
24+
android:label="@string/app_name"
25+
android:supportsRtl="false"
26+
android:taskAffinity=""
27+
tools:ignore="AllowBackup">
28+
<activity
29+
android:name=".MainActivity"
30+
android:configChanges="orientation|keyboardHidden|screenSize"
31+
android:exported="true"
32+
android:hardwareAccelerated="true">
33+
<intent-filter>
34+
<action android:name="android.intent.action.MAIN" />
35+
<category android:name="android.intent.category.LAUNCHER" />
36+
</intent-filter>
37+
</activity>
38+
</application>
39+
</manifest>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2025 DeepMind Technologies Limited.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.androidenv.catch
16+
17+
import android.graphics.Canvas
18+
import android.view.MotionEvent
19+
import com.google.androidenv.catch.sprite.Background
20+
import com.google.androidenv.catch.sprite.Ball
21+
import com.google.androidenv.catch.sprite.LineSegment
22+
import com.google.androidenv.catch.sprite.Paddle
23+
import java.time.Duration
24+
import java.time.Instant
25+
import kotlin.random.Random
26+
27+
/** The class that contains the game logic. */
28+
open class GameLogic(
29+
// Expected number of frames per second.
30+
fps: Int = 60,
31+
// Pseudo random number generator.
32+
private val rand: Random = Random.Default,
33+
// Width and height of the game in pixels.
34+
private val width: Int,
35+
private val height: Int,
36+
// UI objects in the game.
37+
private var background: Background = Background(),
38+
private var ball: Ball = Ball(maxX = width, maxY = height, rand = rand),
39+
private var paddle: Paddle = Paddle(maxX = width, y = height),
40+
) {
41+
42+
private val sleepTime: Duration = Duration.ofMillis((1000.0 / fps).toLong())
43+
44+
/** Reinitializes the state of the game. */
45+
// Need to make this open to allow for testing.
46+
open fun reset() {
47+
this.ball.reset()
48+
}
49+
50+
/** Runs one "throw" of a [ball] that needs to be caught by the [paddle]. */
51+
// Need to make this open to allow for testing.
52+
open fun run(): Boolean {
53+
var lastTimestamp = Instant.now()
54+
do {
55+
Thread.sleep(sleepTime.toMillis())
56+
val now = Instant.now()
57+
val interval = Duration.between(lastTimestamp, now)
58+
lastTimestamp = now
59+
ball.update(interval)
60+
} while (!ball.isOutOfBounds())
61+
62+
return ball.intersects(LineSegment(paddle.topLeft(), paddle.topRight()))
63+
}
64+
65+
/** Processes a user event (e.g. a touchscreen event) and updates the [paddle] accordingly. */
66+
fun handleTouch(event: MotionEvent) {
67+
paddle.x = event.x.toInt()
68+
}
69+
70+
/** Renders the game on [c]. */
71+
open fun render(c: Canvas) {
72+
background.draw(c)
73+
ball.draw(c)
74+
paddle.draw(c)
75+
}
76+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2025 DeepMind Technologies Limited.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.androidenv.catch
16+
17+
import android.util.Log
18+
19+
/** A thread that continuously runs the game logic, resetting after each internal [run()]. */
20+
class GameLogicThread(private val game: GameLogic, private val loggingTag: String) : Thread() {
21+
22+
/** Whether this thread should continuously run. */
23+
private var shouldRun: Boolean = true
24+
/** A counter of game runs. */
25+
private var counter: Int = 0
26+
27+
/**
28+
* Lets the current [run()] iteration complete then break exit this [Thread].
29+
*
30+
* Notice that [shouldRun] cannot have a private getter with a public setter (please see
31+
* https://youtrack.jetbrains.com/issue/KT-3110 for details), hence this public function. Also
32+
* notice that we cannot call this function [stop()] since it would shadow [Thread.stop()].
33+
*/
34+
public fun finish() {
35+
shouldRun = false
36+
}
37+
38+
/** Continuously runs the [game] until [finish()] is called. */
39+
public override fun run() {
40+
while (shouldRun) {
41+
game.reset()
42+
Log.i(loggingTag, "${counter++} - ${game.run()}")
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)