Skip to content

Commit 4660e1f

Browse files
committed
build: update the appfunctions to 1.0.0-alpha10
appfunctions 1.0.0-alpha10 introduced some breaking API changes: - library `appfunctions-service` is removed - `AppFunctionService` is declared explicitly in the app instead of auto-generated.
1 parent 6b4573e commit 4660e1f

6 files changed

Lines changed: 39 additions & 58 deletions

File tree

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ dependencies {
103103
implementation(libs.material)
104104
implementation(libs.kotlinx.serialization.json)
105105
implementation(libs.appfunctions)
106-
implementation(libs.appfunctions.service)
107106
ksp(libs.appfunctions.compiler)
108107
implementation(libs.guava.android)
109108
implementation(project(":CarLibSystemPackage"))

app/src/main/AndroidManifest.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@
9191
<property
9292
android:name="android.app.appfunctions.app_metadata"
9393
android:resource="@xml/app_metadata" />
94+
95+
<service
96+
android:name="org.autoharness.cartool.property.CarPropertyFunctionsService"
97+
android:exported="true"
98+
android:permission="android.permission.BIND_APP_FUNCTION_SERVICE">
99+
<property
100+
android:name="android.app.appfunctions.schema"
101+
android:value="app_functions_schema.xsd" />
102+
<property
103+
android:name="android.app.appfunctions.v2"
104+
android:value="car_property_functions_service.xml" />
105+
106+
<intent-filter>
107+
<action android:name="android.app.appfunctions.AppFunctionService" />
108+
</intent-filter>
109+
</service>
94110
</application>
95111

96112
</manifest>

app/src/main/java/org/autoharness/cartool/CarToolApplication.kt

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,31 @@ import android.app.Application
1111
import android.car.Car
1212
import android.car.hardware.property.CarPropertyManager
1313
import android.util.Log
14-
import androidx.appfunctions.service.AppFunctionConfiguration
15-
import org.autoharness.cartool.property.CarPropertyFunctions
1614
import org.autoharness.cartool.property.CarPropertyRepository
1715

18-
class CarToolApplication :
19-
Application(),
20-
AppFunctionConfiguration.Provider {
16+
class CarToolApplication : Application() {
2117
companion object {
2218
private const val TAG = "CarToolApplication"
2319
}
2420

2521
private lateinit var car: Car
2622
private lateinit var carPropertyManager: CarPropertyManager
23+
24+
@Volatile
25+
var carPropertyRepository: CarPropertyRepository? = null
26+
private set
27+
2728
private val carServiceLifecycleListener: Car.CarServiceLifecycleListener =
2829
Car.CarServiceLifecycleListener { car, ready ->
2930
if (ready) {
3031
carPropertyManager = car.getCarManager(Car.PROPERTY_SERVICE) as CarPropertyManager
32+
carPropertyRepository = CarPropertyRepository(carPropertyManager)
3133
} else {
3234
Log.e(TAG, "Car service is killed")
35+
carPropertyRepository = null
3336
}
3437
}
3538

36-
private val carPropertyFunctionsSingleton: CarPropertyFunctions by lazy {
37-
CarPropertyFunctions(CarPropertyRepository(carPropertyManager))
38-
}
39-
40-
override val appFunctionConfiguration: AppFunctionConfiguration
41-
get() = AppFunctionConfiguration.Builder()
42-
.addEnclosingClassFactory(CarPropertyFunctions::class.java) {
43-
carPropertyFunctionsSingleton
44-
}
45-
.build()
46-
4739
override fun onCreate() {
4840
super.onCreate()
4941
prepareCar()

app/src/main/java/org/autoharness/cartool/property/CarPropertyFunctions.kt renamed to app/src/main/java/org/autoharness/cartool/property/BaseCarPropertyFunctionsService.kt

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77
*/
88
package org.autoharness.cartool.property
99

10-
import androidx.appfunctions.AppFunctionContext
10+
import androidx.appfunctions.AppFunction
11+
import androidx.appfunctions.AppFunctionService
12+
import androidx.appfunctions.AppFunctionServiceEntryPoint
1113
import androidx.appfunctions.AppFunctionStringValueConstraint
12-
import androidx.appfunctions.service.AppFunction
14+
import org.autoharness.cartool.CarToolApplication
1315

14-
class CarPropertyFunctions(private val repository: CarPropertyRepository) :
16+
@AppFunctionServiceEntryPoint(
17+
serviceName = "CarPropertyFunctionsService",
18+
appFunctionXmlFileName = "car_property_functions_service",
19+
)
20+
abstract class BaseCarPropertyFunctionsService :
21+
AppFunctionService(),
1522
GetPropertyList,
1623
GetStringProperty,
1724
SetStringProperty,
@@ -30,6 +37,10 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
3037
GetFloatArrayProperty,
3138
SetFloatArrayProperty {
3239

40+
private val repository: CarPropertyRepository
41+
get() = (applicationContext as CarToolApplication).carPropertyRepository
42+
?: throw IllegalStateException("CarPropertyRepository is not initialized yet (Car service connection pending)")
43+
3344
/**
3445
* A list of supported vehicle properties, formatted as a JSON string.
3546
*
@@ -63,7 +74,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
6374
*/
6475
@AppFunction(isDescribedByKDoc = true)
6576
override fun getPropertyList(
66-
appFunctionContext: AppFunctionContext,
6777
@AppFunctionStringValueConstraint(
6878
enumValues = [
6979
"ALL_CATEGORIES",
@@ -87,7 +97,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
8797
*/
8898
@AppFunction(isDescribedByKDoc = true)
8999
override fun getStringProperty(
90-
appFunctionContext: AppFunctionContext,
91100
propertyName: String,
92101
areaId: Int,
93102
): String = repository.getStringProperty(propertyName, areaId)
@@ -102,7 +111,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
102111
*/
103112
@AppFunction(isDescribedByKDoc = true)
104113
override fun setStringProperty(
105-
appFunctionContext: AppFunctionContext,
106114
propertyName: String,
107115
areaId: Int,
108116
value: String,
@@ -117,7 +125,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
117125
*/
118126
@AppFunction(isDescribedByKDoc = true)
119127
override fun getBooleanProperty(
120-
appFunctionContext: AppFunctionContext,
121128
propertyName: String,
122129
areaId: Int,
123130
): String = repository.getBooleanProperty(propertyName, areaId)
@@ -132,7 +139,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
132139
*/
133140
@AppFunction(isDescribedByKDoc = true)
134141
override fun setBooleanProperty(
135-
appFunctionContext: AppFunctionContext,
136142
propertyName: String,
137143
areaId: Int,
138144
value: Boolean,
@@ -147,7 +153,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
147153
*/
148154
@AppFunction(isDescribedByKDoc = true)
149155
override fun getIntProperty(
150-
appFunctionContext: AppFunctionContext,
151156
propertyName: String,
152157
areaId: Int,
153158
): String = repository.getIntProperty(propertyName, areaId)
@@ -162,7 +167,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
162167
*/
163168
@AppFunction(isDescribedByKDoc = true)
164169
override fun setIntProperty(
165-
appFunctionContext: AppFunctionContext,
166170
propertyName: String,
167171
areaId: Int,
168172
value: Int,
@@ -177,7 +181,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
177181
*/
178182
@AppFunction(isDescribedByKDoc = true)
179183
override fun getIntArrayProperty(
180-
appFunctionContext: AppFunctionContext,
181184
propertyName: String,
182185
areaId: Int,
183186
): String = repository.getIntArrayProperty(propertyName, areaId)
@@ -192,7 +195,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
192195
*/
193196
@AppFunction(isDescribedByKDoc = true)
194197
override fun setIntArrayProperty(
195-
appFunctionContext: AppFunctionContext,
196198
propertyName: String,
197199
areaId: Int,
198200
value: IntArray,
@@ -207,7 +209,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
207209
*/
208210
@AppFunction(isDescribedByKDoc = true)
209211
override fun getLongProperty(
210-
appFunctionContext: AppFunctionContext,
211212
propertyName: String,
212213
areaId: Int,
213214
): String = repository.getLongProperty(propertyName, areaId)
@@ -222,7 +223,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
222223
*/
223224
@AppFunction(isDescribedByKDoc = true)
224225
override fun setLongProperty(
225-
appFunctionContext: AppFunctionContext,
226226
propertyName: String,
227227
areaId: Int,
228228
value: Long,
@@ -237,7 +237,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
237237
*/
238238
@AppFunction(isDescribedByKDoc = true)
239239
override fun getLongArrayProperty(
240-
appFunctionContext: AppFunctionContext,
241240
propertyName: String,
242241
areaId: Int,
243242
): String = repository.getLongArrayProperty(propertyName, areaId)
@@ -252,7 +251,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
252251
*/
253252
@AppFunction(isDescribedByKDoc = true)
254253
override fun setLongArrayProperty(
255-
appFunctionContext: AppFunctionContext,
256254
propertyName: String,
257255
areaId: Int,
258256
value: LongArray,
@@ -267,7 +265,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
267265
*/
268266
@AppFunction(isDescribedByKDoc = true)
269267
override fun getFloatProperty(
270-
appFunctionContext: AppFunctionContext,
271268
propertyName: String,
272269
areaId: Int,
273270
): String = repository.getFloatProperty(propertyName, areaId)
@@ -282,7 +279,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
282279
*/
283280
@AppFunction(isDescribedByKDoc = true)
284281
override fun setFloatProperty(
285-
appFunctionContext: AppFunctionContext,
286282
propertyName: String,
287283
areaId: Int,
288284
value: Float,
@@ -297,7 +293,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
297293
*/
298294
@AppFunction(isDescribedByKDoc = true)
299295
override fun getFloatArrayProperty(
300-
appFunctionContext: AppFunctionContext,
301296
propertyName: String,
302297
areaId: Int,
303298
): String = repository.getFloatArrayProperty(propertyName, areaId)
@@ -312,7 +307,6 @@ class CarPropertyFunctions(private val repository: CarPropertyRepository) :
312307
*/
313308
@AppFunction(isDescribedByKDoc = true)
314309
override fun setFloatArrayProperty(
315-
appFunctionContext: AppFunctionContext,
316310
propertyName: String,
317311
areaId: Int,
318312
value: FloatArray,

app/src/main/java/org/autoharness/cartool/property/CarPropertyApi.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@
77
*/
88
package org.autoharness.cartool.property
99

10-
import androidx.appfunctions.AppFunctionContext
1110
import androidx.appfunctions.AppFunctionSchemaDefinition
1211

1312
const val RESULT_SUCCESS = "success"
1413

1514
@AppFunctionSchemaDefinition(name = "getPropertyList", version = 1, category = "car-property-full")
1615
interface GetPropertyList {
1716
fun getPropertyList(
18-
appFunctionContext: AppFunctionContext,
1917
category: String? = "ALL_CATEGORIES",
2018
): String
2119
}
2220

2321
@AppFunctionSchemaDefinition(name = "getStringProperty", version = 1, category = "car-property-full")
2422
interface GetStringProperty {
2523
fun getStringProperty(
26-
appFunctionContext: AppFunctionContext,
2724
propertyName: String,
2825
areaId: Int,
2926
): String
@@ -32,7 +29,6 @@ interface GetStringProperty {
3229
@AppFunctionSchemaDefinition(name = "setStringProperty", version = 1, category = "car-property-full")
3330
interface SetStringProperty {
3431
fun setStringProperty(
35-
appFunctionContext: AppFunctionContext,
3632
propertyName: String,
3733
areaId: Int,
3834
value: String,
@@ -42,7 +38,6 @@ interface SetStringProperty {
4238
@AppFunctionSchemaDefinition(name = "getBooleanProperty", version = 1, category = "car-property-full")
4339
interface GetBooleanProperty {
4440
fun getBooleanProperty(
45-
appFunctionContext: AppFunctionContext,
4641
propertyName: String,
4742
areaId: Int,
4843
): String
@@ -51,7 +46,6 @@ interface GetBooleanProperty {
5146
@AppFunctionSchemaDefinition(name = "setBooleanProperty", version = 1, category = "car-property-full")
5247
interface SetBooleanProperty {
5348
fun setBooleanProperty(
54-
appFunctionContext: AppFunctionContext,
5549
propertyName: String,
5650
areaId: Int,
5751
value: Boolean,
@@ -61,7 +55,6 @@ interface SetBooleanProperty {
6155
@AppFunctionSchemaDefinition(name = "getIntProperty", version = 1, category = "car-property-full")
6256
interface GetIntProperty {
6357
fun getIntProperty(
64-
appFunctionContext: AppFunctionContext,
6558
propertyName: String,
6659
areaId: Int,
6760
): String
@@ -70,7 +63,6 @@ interface GetIntProperty {
7063
@AppFunctionSchemaDefinition(name = "setIntProperty", version = 1, category = "car-property-full")
7164
interface SetIntProperty {
7265
fun setIntProperty(
73-
appFunctionContext: AppFunctionContext,
7466
propertyName: String,
7567
areaId: Int,
7668
value: Int,
@@ -80,7 +72,6 @@ interface SetIntProperty {
8072
@AppFunctionSchemaDefinition(name = "getIntArrayProperty", version = 1, category = "car-property-full")
8173
interface GetIntArrayProperty {
8274
fun getIntArrayProperty(
83-
appFunctionContext: AppFunctionContext,
8475
propertyName: String,
8576
areaId: Int,
8677
): String
@@ -89,7 +80,6 @@ interface GetIntArrayProperty {
8980
@AppFunctionSchemaDefinition(name = "setIntArrayProperty", version = 1, category = "car-property-full")
9081
interface SetIntArrayProperty {
9182
fun setIntArrayProperty(
92-
appFunctionContext: AppFunctionContext,
9383
propertyName: String,
9484
areaId: Int,
9585
value: IntArray,
@@ -99,7 +89,6 @@ interface SetIntArrayProperty {
9989
@AppFunctionSchemaDefinition(name = "getLongProperty", version = 1, category = "car-property-full")
10090
interface GetLongProperty {
10191
fun getLongProperty(
102-
appFunctionContext: AppFunctionContext,
10392
propertyName: String,
10493
areaId: Int,
10594
): String
@@ -108,7 +97,6 @@ interface GetLongProperty {
10897
@AppFunctionSchemaDefinition(name = "setLongProperty", version = 1, category = "car-property-full")
10998
interface SetLongProperty {
11099
fun setLongProperty(
111-
appFunctionContext: AppFunctionContext,
112100
propertyName: String,
113101
areaId: Int,
114102
value: Long,
@@ -118,7 +106,6 @@ interface SetLongProperty {
118106
@AppFunctionSchemaDefinition(name = "getLongArrayProperty", version = 1, category = "car-property-full")
119107
interface GetLongArrayProperty {
120108
fun getLongArrayProperty(
121-
appFunctionContext: AppFunctionContext,
122109
propertyName: String,
123110
areaId: Int,
124111
): String
@@ -127,7 +114,6 @@ interface GetLongArrayProperty {
127114
@AppFunctionSchemaDefinition(name = "setLongArrayProperty", version = 1, category = "car-property-full")
128115
interface SetLongArrayProperty {
129116
fun setLongArrayProperty(
130-
appFunctionContext: AppFunctionContext,
131117
propertyName: String,
132118
areaId: Int,
133119
value: LongArray,
@@ -137,7 +123,6 @@ interface SetLongArrayProperty {
137123
@AppFunctionSchemaDefinition(name = "getFloatProperty", version = 1, category = "car-property-full")
138124
interface GetFloatProperty {
139125
fun getFloatProperty(
140-
appFunctionContext: AppFunctionContext,
141126
propertyName: String,
142127
areaId: Int,
143128
): String
@@ -146,7 +131,6 @@ interface GetFloatProperty {
146131
@AppFunctionSchemaDefinition(name = "setFloatProperty", version = 1, category = "car-property-full")
147132
interface SetFloatProperty {
148133
fun setFloatProperty(
149-
appFunctionContext: AppFunctionContext,
150134
propertyName: String,
151135
areaId: Int,
152136
value: Float,
@@ -156,7 +140,6 @@ interface SetFloatProperty {
156140
@AppFunctionSchemaDefinition(name = "getFloatArrayProperty", version = 1, category = "car-property-full")
157141
interface GetFloatArrayProperty {
158142
fun getFloatArrayProperty(
159-
appFunctionContext: AppFunctionContext,
160143
propertyName: String,
161144
areaId: Int,
162145
): String
@@ -165,7 +148,6 @@ interface GetFloatArrayProperty {
165148
@AppFunctionSchemaDefinition(name = "setFloatArrayProperty", version = 1, category = "car-property-full")
166149
interface SetFloatArrayProperty {
167150
fun setFloatArrayProperty(
168-
appFunctionContext: AppFunctionContext,
169151
propertyName: String,
170152
areaId: Int,
171153
value: FloatArray,

0 commit comments

Comments
 (0)