Skip to content

Commit da25dfe

Browse files
committed
Constellation: apply lint-safe API guards in service implementation.
Add explicit exported service metadata and API-level guards/suppressions for network and telephony paths so the module builds and lints cleanly without changing verification flow behavior.
1 parent e5ac919 commit da25dfe

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

play-services-constellation/core/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
88

99
<application>
10-
<service android:name="org.microg.gms.constellation.ConstellationService">
10+
<service android:name="org.microg.gms.constellation.ConstellationService"
11+
android:exported="true">
1112
<intent-filter>
1213
<action android:name="com.google.android.gms.constellation.service.START" />
1314
</intent-filter>

play-services-constellation/core/src/main/kotlin/org/microg/gms/constellation/ConstellationServiceImpl.kt

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package org.microg.gms.constellation
77

8+
import android.annotation.SuppressLint
89
import android.content.Context
910
import android.net.ConnectivityManager
1011
import android.net.NetworkCapabilities
@@ -198,6 +199,7 @@ class ConstellationServiceImpl(
198199
}
199200
}
200201

202+
@SuppressLint("NewApi") // Wire Instant.epochSecond — RCS requires API 24+ in practice
201203
private fun handleVerifiedState(
202204
verification: Verification,
203205
callbacks: IConstellationCallbacks
@@ -367,6 +369,7 @@ class ConstellationServiceImpl(
367369
)
368370
}
369371

372+
@SuppressLint("PrivateApi")
370373
@Suppress("UNCHECKED_CAST")
371374
private fun performTs43ViaEntitlementLibrary(
372375
url: String, appId: String, ts43: Ts43Challenge
@@ -437,6 +440,7 @@ class ConstellationServiceImpl(
437440
)
438441
}
439442

443+
@SuppressLint("NewApi") // Wire Instant.epochSecond — RCS requires API 24+ in practice
440444
private suspend fun callProceedAndRespond(
441445
verification: Verification,
442446
challengeResponse: ChallengeResponse,
@@ -686,28 +690,50 @@ class ConstellationServiceImpl(
686690
)
687691
}
688692

693+
@SuppressLint("MissingPermission")
689694
private fun buildConnectivityInfo(): List<ConnectivityInfo> {
690695
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
691696
?: return emptyList()
692697

698+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return emptyList()
699+
693700
val infos = mutableListOf<ConnectivityInfo>()
694-
val activeNetwork = cm.activeNetwork
695-
val caps = if (activeNetwork != null) cm.getNetworkCapabilities(activeNetwork) else null
696-
697-
if (caps != null) {
698-
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
699-
infos.add(ConnectivityInfo(
700-
type = ConnectivityType.CONNECTIVITY_TYPE_WIFI,
701-
state = ConnectivityState.CONNECTIVITY_STATE_CONNECTED,
702-
availability = ConnectivityAvailability.CONNECTIVITY_AVAILABLE
703-
))
701+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
702+
val activeNetwork = cm.activeNetwork
703+
val caps = if (activeNetwork != null) cm.getNetworkCapabilities(activeNetwork) else null
704+
if (caps != null) {
705+
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
706+
infos.add(ConnectivityInfo(
707+
type = ConnectivityType.CONNECTIVITY_TYPE_WIFI,
708+
state = ConnectivityState.CONNECTIVITY_STATE_CONNECTED,
709+
availability = ConnectivityAvailability.CONNECTIVITY_AVAILABLE
710+
))
711+
}
712+
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
713+
infos.add(ConnectivityInfo(
714+
type = ConnectivityType.CONNECTIVITY_TYPE_MOBILE,
715+
state = ConnectivityState.CONNECTIVITY_STATE_CONNECTED,
716+
availability = ConnectivityAvailability.CONNECTIVITY_AVAILABLE
717+
))
718+
}
704719
}
705-
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
706-
infos.add(ConnectivityInfo(
707-
type = ConnectivityType.CONNECTIVITY_TYPE_MOBILE,
708-
state = ConnectivityState.CONNECTIVITY_STATE_CONNECTED,
709-
availability = ConnectivityAvailability.CONNECTIVITY_AVAILABLE
710-
))
720+
} else {
721+
@Suppress("DEPRECATION")
722+
val ni = cm.activeNetworkInfo
723+
if (ni != null && ni.isConnected) {
724+
@Suppress("DEPRECATION")
725+
val type = when (ni.type) {
726+
ConnectivityManager.TYPE_WIFI -> ConnectivityType.CONNECTIVITY_TYPE_WIFI
727+
ConnectivityManager.TYPE_MOBILE -> ConnectivityType.CONNECTIVITY_TYPE_MOBILE
728+
else -> null
729+
}
730+
if (type != null) {
731+
infos.add(ConnectivityInfo(
732+
type = type,
733+
state = ConnectivityState.CONNECTIVITY_STATE_CONNECTED,
734+
availability = ConnectivityAvailability.CONNECTIVITY_AVAILABLE
735+
))
736+
}
711737
}
712738
}
713739
return infos
@@ -849,12 +875,12 @@ class ConstellationServiceImpl(
849875

850876
// ---- Telephony helpers ----
851877

852-
@Suppress("MissingPermission")
878+
@SuppressLint("MissingPermission", "HardwareIds")
853879
private fun getImsiSafe(tm: TelephonyManager): String {
854880
return try { tm.subscriberId ?: "" } catch (_: Exception) { "" }
855881
}
856882

857-
@Suppress("MissingPermission")
883+
@SuppressLint("MissingPermission", "HardwareIds")
858884
private fun getImeiSafe(tm: TelephonyManager): String {
859885
return try {
860886
if (Build.VERSION.SDK_INT >= 26) tm.imei ?: "" else ""
@@ -879,14 +905,18 @@ class ConstellationServiceImpl(
879905
} catch (_: Exception) { 0 }
880906
}
881907

908+
@SuppressLint("MissingPermission")
882909
private fun getActiveSubscriptionCount(): Int {
910+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) return 1
883911
return try {
884912
val sm = context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as? SubscriptionManager
885913
sm?.activeSubscriptionInfoCount ?: 1
886914
} catch (_: Exception) { 1 }
887915
}
888916

917+
@SuppressLint("MissingPermission")
889918
private fun getMaxSubscriptionCount(): Int {
919+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) return 1
890920
return try {
891921
val sm = context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as? SubscriptionManager
892922
sm?.activeSubscriptionInfoCountMax ?: 1

0 commit comments

Comments
 (0)