@@ -12,73 +12,74 @@ import org.microg.gms.constellation.core.proto.ChallengeResponse
1212
1313private const val TAG = " CarrierIdVerifier"
1414
15- class CarrierIdVerifier (private val context : Context , private val subId : Int ) {
16- fun verify (challenge : Challenge ? ): ChallengeResponse ? {
17- val carrierChallenge = challenge?.carrier_id_challenge ? : return null
18- val challengeData = carrierChallenge.isim_request.takeIf { it.isNotEmpty() }
19- ? : return failure(
20- CarrierIdError .CARRIER_ID_ERROR_UNKNOWN_ERROR ,
21- " Carrier challenge data missing"
22- )
23- if (subId == - 1 ) return failure(
24- CarrierIdError .CARRIER_ID_ERROR_NO_SIM ,
25- " No active subscription for carrier auth"
15+ fun Challenge.verifyCarrierId (context : Context , subId : Int ): ChallengeResponse {
16+ val carrierChallenge = carrier_id_challenge ? : return failure(
17+ CarrierIdError .CARRIER_ID_ERROR_UNKNOWN_ERROR ,
18+ " Carrier challenge data missing"
19+ )
20+ val challengeData = carrierChallenge.isim_request.takeIf { it.isNotEmpty() }
21+ ? : return failure(
22+ CarrierIdError .CARRIER_ID_ERROR_UNKNOWN_ERROR ,
23+ " Carrier challenge data missing"
2624 )
25+ if (subId == - 1 ) return failure(
26+ CarrierIdError .CARRIER_ID_ERROR_NO_SIM ,
27+ " No active subscription for carrier auth"
28+ )
2729
28- val appType = carrierChallenge.app_type
29- val authType = carrierChallenge.auth_type
30-
31- return try {
32- val telephonyManager = context.getSystemService<TelephonyManager >()
33- ? : return failure(
34- CarrierIdError .CARRIER_ID_ERROR_NOT_SUPPORTED ,
35- " TelephonyManager unavailable"
36- )
37- val targetManager = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
38- telephonyManager.createForSubscriptionId(subId)
39- } else {
40- telephonyManager
41- }
30+ val appType = carrierChallenge.app_type
31+ val authType = carrierChallenge.auth_type
4232
43- val response = targetManager.getIccAuthentication(appType, authType, challengeData)
44- if (response.isNullOrEmpty()) {
45- failure(CarrierIdError .CARRIER_ID_ERROR_NULL_RESPONSE , " Null ISIM response" )
46- } else {
47- ChallengeResponse (
48- carrier_id_response = CarrierIdChallengeResponse (
49- isim_response = response,
50- carrier_id_error = CarrierIdError .CARRIER_ID_ERROR_NO_ERROR
51- )
52- )
53- }
54- } catch (e: SecurityException ) {
55- Log .w(TAG , " Unable to read subscription for carrier auth" , e)
56- failure(
57- CarrierIdError .CARRIER_ID_ERROR_UNABLE_TO_READ_SUBSCRIPTION ,
58- e.message ? : " SecurityException"
59- )
60- } catch (e: UnsupportedOperationException ) {
61- Log .w(TAG , " Carrier auth API unavailable" , e)
62- failure(
33+ return try {
34+ val telephonyManager = context.getSystemService<TelephonyManager >()
35+ ? : return failure(
6336 CarrierIdError .CARRIER_ID_ERROR_NOT_SUPPORTED ,
64- e.message ? : " UnsupportedOperationException"
65- )
66- } catch (e: Exception ) {
67- Log .e(TAG , " Carrier auth failed" , e)
68- failure(
69- CarrierIdError .CARRIER_ID_ERROR_REFLECTION_ERROR ,
70- e.message ? : " Reflection or platform error"
37+ " TelephonyManager unavailable"
7138 )
39+ val targetManager = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
40+ telephonyManager.createForSubscriptionId(subId)
41+ } else {
42+ telephonyManager
7243 }
73- }
7444
75- private fun failure (status : CarrierIdError , message : String ): ChallengeResponse {
76- Log .w(TAG , message)
77- return ChallengeResponse (
78- carrier_id_response = CarrierIdChallengeResponse (
79- isim_response = " " ,
80- carrier_id_error = status
45+ val response = targetManager.getIccAuthentication(appType, authType, challengeData)
46+ if (response.isNullOrEmpty()) {
47+ failure(CarrierIdError .CARRIER_ID_ERROR_NULL_RESPONSE , " Null ISIM response" )
48+ } else {
49+ ChallengeResponse (
50+ carrier_id_response = CarrierIdChallengeResponse (
51+ isim_response = response,
52+ carrier_id_error = CarrierIdError .CARRIER_ID_ERROR_NO_ERROR
53+ )
8154 )
55+ }
56+ } catch (e: SecurityException ) {
57+ Log .w(TAG , " Unable to read subscription for carrier auth" , e)
58+ failure(
59+ CarrierIdError .CARRIER_ID_ERROR_UNABLE_TO_READ_SUBSCRIPTION ,
60+ e.message ? : " SecurityException"
61+ )
62+ } catch (e: UnsupportedOperationException ) {
63+ Log .w(TAG , " Carrier auth API unavailable" , e)
64+ failure(
65+ CarrierIdError .CARRIER_ID_ERROR_NOT_SUPPORTED ,
66+ e.message ? : " UnsupportedOperationException"
67+ )
68+ } catch (e: Exception ) {
69+ Log .e(TAG , " Carrier auth failed" , e)
70+ failure(
71+ CarrierIdError .CARRIER_ID_ERROR_REFLECTION_ERROR ,
72+ e.message ? : " Reflection or platform error"
8273 )
8374 }
8475}
76+
77+ private fun failure (status : CarrierIdError , message : String ): ChallengeResponse {
78+ Log .w(TAG , message)
79+ return ChallengeResponse (
80+ carrier_id_response = CarrierIdChallengeResponse (
81+ isim_response = " " ,
82+ carrier_id_error = status
83+ )
84+ )
85+ }
0 commit comments