Skip to content

Commit f8428c9

Browse files
committed
Refactoring
1 parent 2d83ad4 commit f8428c9

File tree

17 files changed

+503
-236
lines changed

17 files changed

+503
-236
lines changed

play-services-asterism/build.gradle

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
apply plugin: 'com.android.library'
77
apply plugin: 'maven-publish'
8-
apply plugin: 'kotlin-android'
9-
apply plugin: 'kotlin-parcelize'
10-
apply plugin: 'kotlin-kapt'
118
apply plugin: 'signing'
129

1310
android {
@@ -30,23 +27,14 @@ android {
3027
sourceCompatibility JavaVersion.VERSION_1_8
3128
targetCompatibility JavaVersion.VERSION_1_8
3229
}
33-
34-
kotlinOptions {
35-
jvmTarget = 1.8
36-
}
3730
}
3831

3932
apply from: '../gradle/publish-android.gradle'
4033

41-
description = 'microG service implementation for play-services-asterism'
34+
description = 'microG implementation of play-services-asterism'
4235

4336
dependencies {
44-
implementation project(':play-services-base-core')
45-
implementation project(':play-services-constellation')
46-
implementation project(':play-services-iid')
47-
48-
implementation project(':play-services-droidguard')
49-
implementation project(':play-services-tasks-ktx')
37+
implementation project(':play-services-basement')
5038

51-
kapt project(":safe-parcel-processor")
39+
annotationProcessor project(":safe-parcel-processor")
5240
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026, microG Project Team
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
apply plugin: 'com.android.library'
7+
apply plugin: 'maven-publish'
8+
apply plugin: 'kotlin-android'
9+
apply plugin: 'signing'
10+
11+
android {
12+
namespace "org.microg.gms.asterism.core"
13+
14+
compileSdkVersion androidCompileSdk
15+
buildToolsVersion "$androidBuildVersionTools"
16+
17+
buildFeatures {
18+
aidl = true
19+
}
20+
21+
defaultConfig {
22+
versionName version
23+
minSdkVersion androidMinSdk
24+
targetSdkVersion androidTargetSdk
25+
}
26+
27+
sourceSets {
28+
main.java.srcDirs += 'src/main/kotlin'
29+
}
30+
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
36+
kotlinOptions {
37+
jvmTarget = 1.8
38+
}
39+
}
40+
41+
apply from: '../../gradle/publish-android.gradle'
42+
43+
description = 'microG service implementation for play-services-asterism'
44+
45+
dependencies {
46+
api project(':play-services-asterism')
47+
48+
implementation project(':play-services-base-core')
49+
implementation project(':play-services-constellation-core')
50+
implementation project(':play-services-iid')
51+
52+
implementation project(':play-services-droidguard')
53+
implementation project(':play-services-tasks-ktx')
54+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ SPDX-FileCopyrightText: 2026, microG Project Team
3+
~ SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
7+
8+
<application>
9+
<service android:name=".AsterismApiService">
10+
<intent-filter>
11+
<action android:name="com.google.android.gms.asterism.service.START" />
12+
</intent-filter>
13+
</service>
14+
</application>
15+
</manifest>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.google.android.gms.asterism
2+
3+
import org.microg.gms.constellation.core.proto.AsterismClient
4+
import org.microg.gms.constellation.core.proto.Consent
5+
import org.microg.gms.constellation.core.proto.ConsentVersion
6+
7+
val GetAsterismConsentRequest.asterismClient: AsterismClient
8+
get() = AsterismClient.fromValue(asterismClientValue) ?: AsterismClient.UNKNOWN_CLIENT
9+
10+
fun getAsterismConsentResponse(
11+
requestCode: Int,
12+
consentState: Consent,
13+
gmscoreIidToken: String?,
14+
fid: String?,
15+
consentVersion: ConsentVersion
16+
): GetAsterismConsentResponse {
17+
val consentStateValue =
18+
if (consentState == Consent.CONSENTED || consentState == Consent.CONSENT_UNKNOWN) {
19+
consentState.value
20+
} else {
21+
Consent.NO_CONSENT.value
22+
}
23+
24+
return GetAsterismConsentResponse(
25+
requestCode,
26+
consentStateValue,
27+
gmscoreIidToken,
28+
fid,
29+
consentVersion.value
30+
)
31+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.google.android.gms.asterism
2+
3+
import org.microg.gms.constellation.core.proto.AsterismClient
4+
import org.microg.gms.constellation.core.proto.Consent
5+
import org.microg.gms.constellation.core.proto.ConsentSource
6+
import org.microg.gms.constellation.core.proto.ConsentVersion
7+
import org.microg.gms.constellation.core.proto.FlowContext
8+
9+
enum class SetAsterismConsentRequestStatus(val value: Int) {
10+
RCS_DEFAULT(0),
11+
RCS_LEGAL_FYI(1),
12+
DEVICE_PNVR(2),
13+
ON_DEMAND(3),
14+
EXPIRED(4);
15+
16+
companion object {
17+
fun fromValue(value: Int): SetAsterismConsentRequestStatus =
18+
entries.find { it.value == value } ?: EXPIRED
19+
}
20+
}
21+
22+
val SetAsterismConsentRequest.asterismClient: AsterismClient
23+
get() = AsterismClient.fromValue(asterismClientValue) ?: AsterismClient.UNKNOWN_CLIENT
24+
25+
val SetAsterismConsentRequest.consent: Consent
26+
get() = Consent.fromValue(consentValue) ?: Consent.CONSENT_UNKNOWN
27+
28+
val SetAsterismConsentRequest.rcsFlowContext: FlowContext
29+
get() = FlowContext.fromValue(rcsFlowContextValue) ?: FlowContext.FLOW_CONTEXT_UNSPECIFIED
30+
31+
val SetAsterismConsentRequest.deviceConsentSource: ConsentSource
32+
get() = ConsentSource.fromValue(deviceConsentSourceValue) ?: ConsentSource.SOURCE_UNSPECIFIED
33+
34+
val SetAsterismConsentRequest.deviceConsentVersion: ConsentVersion
35+
get() = ConsentVersion.fromValue(deviceConsentVersionValue).let {
36+
if (it == null || it == ConsentVersion.CONSENT_VERSION_UNSPECIFIED) {
37+
ConsentVersion.PHONE_VERIFICATION_DEFAULT
38+
} else {
39+
it
40+
}
41+
}
42+
43+
val SetAsterismConsentRequest.status: SetAsterismConsentRequestStatus
44+
get() = SetAsterismConsentRequestStatus.fromValue(statusValue)
45+
46+
fun SetAsterismConsentRequest.isDevicePnvrFlow(): Boolean {
47+
return asterismClient == AsterismClient.CONSTELLATION &&
48+
deviceConsentSourceValue > 0 &&
49+
deviceConsentVersionValue > 0
50+
}

play-services-asterism/src/main/kotlin/org/microg/gms/asterism/AsterismApiService.kt renamed to play-services-asterism/core/src/main/kotlin/org/microg/gms/asterism/core/AsterismApiService.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package org.microg.gms.asterism
1+
package org.microg.gms.asterism.core
22

33
import android.content.Context
4+
import android.os.Build
45
import android.util.Log
56
import com.google.android.gms.asterism.GetAsterismConsentRequest
67
import com.google.android.gms.asterism.SetAsterismConsentRequest
@@ -67,18 +68,21 @@ class AsterismApiServiceImpl(
6768
) {
6869
Log.i(TAG, "getAsterismConsent(): $request")
6970
if (cb == null || request == null) return
71+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
7072
serviceScope.launch { handleGetAsterismConsent(context, cb, request) }
7173
}
7274

7375
override fun setAsterismConsent(cb: IAsterismCallbacks?, request: SetAsterismConsentRequest?) {
7476
Log.i(TAG, "setAsterismConsent(): $request")
7577
if (cb == null || request == null) return
78+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
7679
serviceScope.launch { handleSetAsterismConsent(context, cb, request) }
7780
}
7881

7982
override fun getIsPnvrConstellationDevice(cb: IAsterismCallbacks?) {
8083
Log.i(TAG, "getIsPnvrConstellationDevice()")
8184
if (cb == null) return
85+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
8286
serviceScope.launch { handleGetIsPnvrConstellationDevice(context, cb) }
8387
}
8488
}

play-services-asterism/src/main/kotlin/org/microg/gms/asterism/GetAsterismConsentHandler.kt renamed to play-services-asterism/core/src/main/kotlin/org/microg/gms/asterism/core/GetAsterismConsentHandler.kt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
package org.microg.gms.asterism
1+
@file:RequiresApi(Build.VERSION_CODES.O)
2+
3+
package org.microg.gms.asterism.core
24

35
import android.content.Context
6+
import android.os.Build
47
import android.util.Log
8+
import androidx.annotation.RequiresApi
59
import com.google.android.gms.asterism.GetAsterismConsentRequest
6-
import com.google.android.gms.asterism.GetAsterismConsentResponse
10+
import com.google.android.gms.asterism.asterismClient
11+
import com.google.android.gms.asterism.getAsterismConsentResponse
712
import com.google.android.gms.asterism.internal.IAsterismCallbacks
813
import com.google.android.gms.common.api.Status
914
import kotlinx.coroutines.Dispatchers
1015
import kotlinx.coroutines.withContext
11-
import org.microg.gms.constellation.AuthManager
12-
import org.microg.gms.constellation.ConstellationStateStore
13-
import org.microg.gms.constellation.RpcClient
14-
import org.microg.gms.constellation.proto.Consent
15-
import org.microg.gms.constellation.proto.ConsentVersion
16-
import org.microg.gms.constellation.proto.DeviceID
17-
import org.microg.gms.constellation.proto.GetConsentRequest
18-
import org.microg.gms.constellation.proto.RequestHeader
19-
import org.microg.gms.constellation.proto.builders.buildRequestContext
20-
import org.microg.gms.constellation.proto.builders.invoke
16+
import org.microg.gms.constellation.core.ConstellationStateStore
17+
import org.microg.gms.constellation.core.RpcClient
18+
import org.microg.gms.constellation.core.authManager
19+
import org.microg.gms.constellation.core.proto.Consent
20+
import org.microg.gms.constellation.core.proto.ConsentVersion
21+
import org.microg.gms.constellation.core.proto.DeviceID
22+
import org.microg.gms.constellation.core.proto.GetConsentRequest
23+
import org.microg.gms.constellation.core.proto.RequestHeader
24+
import org.microg.gms.constellation.core.proto.builder.buildRequestContext
25+
import org.microg.gms.constellation.core.proto.builder.invoke
2126
import java.util.UUID
2227

2328
private const val ASTERISM_TAG = "GetAsterismConsent"
@@ -29,7 +34,7 @@ suspend fun handleGetAsterismConsent(
2934
request: GetAsterismConsentRequest
3035
) = withContext(Dispatchers.IO) {
3136
try {
32-
val authManager = AuthManager.get(context)
37+
val authManager = context.authManager
3338
val buildContext = buildRequestContext(context, authManager)
3439
val response = RpcClient.phoneDeviceVerificationClient.GetConsent().execute(
3540
GetConsentRequest(
@@ -50,7 +55,7 @@ suspend fun handleGetAsterismConsent(
5055

5156
callbacks.onConsentFetched(
5257
Status.SUCCESS,
53-
GetAsterismConsentResponse(
58+
getAsterismConsentResponse(
5459
request.requestCode,
5560
consentValue,
5661
buildContext.iidToken,
@@ -62,7 +67,7 @@ suspend fun handleGetAsterismConsent(
6267
Log.e(ASTERISM_TAG, "getAsterismConsent failed", e)
6368
callbacks.onConsentFetched(
6469
Status.INTERNAL_ERROR,
65-
GetAsterismConsentResponse(
70+
getAsterismConsentResponse(
6671
request.requestCode,
6772
Consent.CONSENT_UNKNOWN,
6873
null,

0 commit comments

Comments
 (0)