Skip to content

Commit 87fa942

Browse files
committed
Merge branch 'master' of https://github.com/dimagi/commcare-android into feature/connect
2 parents ae51e7f + 5b36f15 commit 87fa942

File tree

13 files changed

+133
-49
lines changed

13 files changed

+133
-49
lines changed

app/res/values-es/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
<string name="connect_button_logged_in">Ir al menú Conectar</string>
189189
<string name="personalid_generic_error">Ocurrió un problema con la base de datos, recupera tu cuenta.</string>
190190
<string name="connect_registration_title">Registro de PersonalId</string>
191-
<string name="connect_consent_message_1">He leído y acepto la política de privacidad, los términos de servicio, el acuerdo comercial y la política de uso aceptable de Dimagi.</string>
191+
<string name="connect_consent_message_1">He leído y acepto la <a href="https://www.dimagi.com/terms/latest/privacy/">Política de Privacidad</a>, los <a href="https://www.dimagi.com/terms/latest/tos/">Términos de Servicio</a>, el <a href="https://www.dimagi.com/terms/latest/ba/">Acuerdo Comercial</a> y la <a href="https://www.dimagi.com/terms/latest/aup/">Política de Uso Aceptable</a> de Dimagi.</string>
192192
<string name="connect_phone_country_code_default">+1</string>
193193
<string name="connect_phone_number_hint">0000000000</string>
194194
<string name="connect_otp_sent">OTP enviado</string>

app/res/values-fr/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ License.
250250
<string name="connect_button_logged_in">Accéder au menu Connecter</string>
251251
<string name="personalid_generic_error">Un problème est survenu avec la base de données, veuillez récupérer votre compte.</string>
252252
<string name="connect_registration_title">Inscription PersonalId</string>
253-
<string name="connect_consent_message_1">J\'ai lu et j\'accepte la politique de confidentialité, les conditions de service, l\'accord commercial et la politique d\'utilisation acceptable de Dimagi.</string>
253+
<string name="connect_consent_message_1">J\'ai lu et j\'accepte la <a href="https://www.dimagi.com/terms/latest/privacy/">politique de confidentialité</a>, les <a href="https://www.dimagi.com/terms/latest/tos/">conditions de service</a>, l\'<a href="https://www.dimagi.com/terms/latest/ba/">accord commercial</a> et la <a href="https://www.dimagi.com/terms/latest/aup/">politique d\'utilisation acceptable</a> de Dimagi.</string>
254254
<string name="connect_phone_country_code_default">+1</string>
255255
<string name="connect_phone_number_hint">0000000000</string>
256256
<string name="connect_otp_sent">OTP envoyé</string>

app/res/values-hi/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ License.
250250
<string name="connect_button_logged_in">कनेक्ट मेनू पर जाएं</string>
251251
<string name="personalid_generic_error">डेटाबेस के साथ कोई समस्या हुई है, कृपया अपना खाता पुनर्प्राप्त करें।</string>
252252
<string name="connect_registration_title">PersonalId पंजीकरण</string>
253-
<string name="connect_consent_message_1">मैंने डिमागी की गोपनीयता नीति, सेवा की शर्तें, व्यावसायिक समझौता और स्वीकार्य उपयोग नीति पढ़ ली है और मैं उनसे सहमत हूं।</string>
253+
<string name="connect_consent_message_1">मैंने डिमागी की <a href="https://www.dimagi.com/terms/latest/privacy/">गोपनीयता नीति</a>, <a href="https://www.dimagi.com/terms/latest/tos/">सेवा की शर्तें</a>, <a href="https://www.dimagi.com/terms/latest/ba/">व्यावसायिक समझौता</a> और <a href="https://www.dimagi.com/terms/latest/aup/">स्वीकार्य उपयोग नीति</a> पढ़ ली है और मैं उनसे सहमत हूं।</string>
254254
<string name="connect_phone_country_code_default">+91</string>
255255
<string name="connect_phone_number_hint">0000000000</string>
256256
<string name="connect_otp_sent">OTP भेजा गया</string>

app/res/values-pt/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
<string name="connect_button_logged_in">Vá para o Conectar menu</string>
253253
<string name="personalid_generic_error">Ocorreu um problema. Configure sua conta PersonalID novamente.</string>
254254
<string name="connect_registration_title">Inscrição no Connect ID</string>
255-
<string name="connect_consent_message_1">Li e concordo com a Política de Privacidade, Termos de Serviço, Acordo Comercial e Política de Uso Aceitável da Dimagi</string>
255+
<string name="connect_consent_message_1">Li e concordo com a <a href="https://www.dimagi.com/terms/latest/privacy/">Política de Privacidade</a>, os <a href="https://www.dimagi.com/terms/latest/tos/">Termos de Serviço</a>, o <a href="https://www.dimagi.com/terms/latest/ba/">Contrato Comercial</a> e a <a href="https://www.dimagi.com/terms/latest/aup/">Política de Uso Aceitável</a> da Dimagi.</string>
256256
<string name="connect_phone_country_code_default">+1</string>
257257
<string name="connect_phone_number_hint">0000000000</string>
258258
<string name="connect_otp_sent">OTP enviado</string>

app/res/values-sw/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
<string name="connect_button_logged_in">Nenda kwenye menyu ya Unganisha</string>
252252
<string name="personalid_generic_error">Tatizo limetokea, tafadhali sanidi akaunti yako ya Kitambulisho cha Kibinafsi tena.</string>
253253
<string name="connect_registration_title">Usajili wa PersonalId</string>
254-
<string name="connect_consent_message_1">Nimesoma na kukubaliana na Sera ya Faragha ya Dimagi, Sheria na Masharti, Makubaliano ya Biashara na Sera ya Matumizi Yanayokubalika.</string>
254+
<string name="connect_consent_message_1">Nimesoma na kukubaliana na <a href="https://www.dimagi.com/terms/latest/privacy/">Sera ya Faragha</a> ya Dimagi, <a href="https://www.dimagi.com/terms/latest/tos/">Sheria na Masharti</a>, <a href="https://www.dimagi.com/terms/latest/ba/">Makubaliano ya Biashara</a> na <a href="https://www.dimagi.com/terms/latest/aup/">Sera ya Matumizi Yanayokubalika</a>.</string>
255255
<string name="connect_phone_country_code_default">+1</string>
256256
<string name="connect_phone_number_hint">0000000000</string>
257257
<string name="connect_otp_sent">OTP Imetumwa</string>

app/res/values-ti/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
<string name="connect_button_logged_in">ናብ Connect መማረፂ ኪድ</string>
241241
<string name="personalid_generic_error">ጸገም ኣጋጢሙ፡ በጃኻ PersonalID ኣካውንትካ እንደገና ኣወሃህቦ።</string>
242242
<string name="connect_registration_title">PersonalId ምዝገባ</string>
243-
<string name="connect_consent_message_1">ኣነ ፖሊሲ ውልቃዊ ሓበሬታውዕል ኣገልግሎትስምምዕ ንግዲን ፖሊሲ ቅቡል ኣጠቓቕማን Dimagi\'s/ ዲማጊ ኣንቢበን ተሰማሚዐን ኣለኹ።</string>
243+
<string name="connect_consent_message_1">ኣነ <a href="https://www.dimagi.com/terms/latest/privacy/">ፖሊሲ ውልቃዊ ሓበሬታ</a>፡ <a href="https://www.dimagi.com/terms/latest/tos/">ውዕል ኣገልግሎት</a>፡ <a href="https://www.dimagi.com/terms/latest/ba/">ስምምዕ ንግዲ</a>ን <a href="https://www.dimagi.com/terms/latest/aup/">ፖሊሲ ቅቡል ኣጠቓቕማን</a> Dimagi\'s/ ዲማጊ ኣንቢበን ተሰማሚዐን ኣለኹ።</string>
244244
<string name="connect_phone_country_code_default">1</string>
245245
<string name="connect_phone_number_hint">0</string>
246246
<string name="connect_otp_sent">ኦቲፒ ተላኢኹ</string>

app/src/org/commcare/android/integrity/IntegrityTokenViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
77
import androidx.lifecycle.Observer
88
import com.google.android.play.core.integrity.IntegrityManagerFactory
99
import com.google.android.play.core.integrity.StandardIntegrityException
10+
import com.google.android.play.core.integrity.StandardIntegrityManager
1011
import com.google.android.play.core.integrity.StandardIntegrityManager.PrepareIntegrityTokenRequest
1112
import com.google.android.play.core.integrity.StandardIntegrityManager.StandardIntegrityTokenProvider
1213
import com.google.android.play.core.integrity.StandardIntegrityManager.StandardIntegrityTokenRequest
@@ -66,7 +67,8 @@ class IntegrityTokenViewModel(application: Application) : AndroidViewModel(appli
6667
.build()
6768
)
6869
integrityTokenResponse
69-
.addOnSuccessListener { response -> callback.onTokenReceived(response.token(), requestHash) }
70+
.addOnSuccessListener { response ->
71+
callback.onTokenReceived(requestHash,response) }
7072
.addOnFailureListener { exception ->
7173
handleRequestFailureAndRetry(exception, requestHash, callback, hasRetried)
7274
}
@@ -115,7 +117,7 @@ class IntegrityTokenViewModel(application: Application) : AndroidViewModel(appli
115117
}
116118

117119
interface IntegrityTokenCallback {
118-
fun onTokenReceived(token: String, requestHash: String)
120+
fun onTokenReceived(requestHash: String, integrityTokenResponse: StandardIntegrityManager.StandardIntegrityToken)
119121
fun onTokenFailure(exception: java.lang.Exception)
120122
}
121123
}

app/src/org/commcare/connect/network/base/BaseApiCallback.kt

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.commcare.connect.network.base
22

33

4+
import org.commcare.android.database.connect.models.PersonalIdSessionData
45
import org.commcare.connect.network.IApiCallback
56
import org.commcare.connect.network.base.BaseApiHandler.PersonalIdOrConnectApiErrorCodes
7+
import org.commcare.util.LogTypes
68
import org.javarosa.core.io.StreamsUtil
79
import org.javarosa.core.services.Logger
810
import org.json.JSONObject
@@ -13,12 +15,10 @@ import java.io.InputStream
1315
* to define the error handling in all api handlers
1416
*/
1517
abstract class BaseApiCallback<T>(val baseApiHandler: BaseApiHandler<T>) :
16-
IApiCallback {
1718

19+
IApiCallback {
1820
override fun processFailure(responseCode: Int, errorResponse: InputStream?, url: String?) {
1921
// Common error_code handler used before checking error response code
20-
if (handleErrorCodeIfPresent(errorResponse)) return
21-
2222
when (responseCode) {
2323
401 -> baseApiHandler.onFailure(
2424
PersonalIdOrConnectApiErrorCodes.FAILED_AUTH_ERROR,
@@ -48,35 +48,6 @@ abstract class BaseApiCallback<T>(val baseApiHandler: BaseApiHandler<T>) :
4848
}
4949
}
5050

51-
/**
52-
* Checks for "error_code" in the API error response and handles known cases.
53-
* Returns true if the error was handled, otherwise false.
54-
*/
55-
private fun handleErrorCodeIfPresent(errorResponse: InputStream?): Boolean {
56-
if (errorResponse == null) return false
57-
58-
return try {
59-
errorResponse.use {
60-
val json =
61-
JSONObject(String(StreamsUtil.inputStreamToByteArray(it), Charsets.UTF_8))
62-
val errorCode = json.optString("error_code", "")
63-
64-
if (errorCode.equals("LOCKED_ACCOUNT", ignoreCase = true)) {
65-
baseApiHandler.onFailure(
66-
PersonalIdOrConnectApiErrorCodes.ACCOUNT_LOCKED_ERROR,
67-
null
68-
)
69-
true
70-
} else {
71-
false
72-
}
73-
}
74-
} catch (e: Exception) {
75-
Logger.exception("Error parsing error_code", e)
76-
false
77-
}
78-
}
79-
8051
override fun processNetworkFailure() {
8152
baseApiHandler.onFailure(
8253
PersonalIdOrConnectApiErrorCodes.NETWORK_ERROR,

app/src/org/commcare/connect/network/base/BaseApiHandler.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ abstract class BaseApiHandler<T> {
1515

1616
abstract fun onFailure(errorCode: PersonalIdOrConnectApiErrorCodes, t: Throwable?)
1717

18+
enum class PersonalIdApiSubErrorCodes {
19+
INTEGRITY_HEADERS,
20+
PHONE_NUMBER_REQUIRED,
21+
UNLICENSED_APP_ERROR,
22+
DEVICE_INTEGRITY_ERROR,
23+
APP_INTEGRITY_ERROR,
24+
INTEGRITY_REQUEST_ERROR;
25+
}
1826

1927
enum class PersonalIdOrConnectApiErrorCodes {
2028
UNKNOWN_ERROR,
@@ -28,11 +36,12 @@ abstract class BaseApiHandler<T> {
2836
FAILED_AUTH_ERROR,
2937
SERVER_ERROR,
3038
RATE_LIMIT_EXCEEDED_ERROR,
31-
ACCOUNT_LOCKED_ERROR;
39+
ACCOUNT_LOCKED_ERROR,
40+
INTEGRITY_ERROR;
3241

3342
fun shouldAllowRetry(): Boolean {
3443
return this == NETWORK_ERROR || (this == TOKEN_UNAVAILABLE_ERROR) || (this == SERVER_ERROR
35-
) || (this == UNKNOWN_ERROR)
44+
) || (this == UNKNOWN_ERROR) || (this == INTEGRITY_ERROR)
3645
}
3746
}
3847

app/src/org/commcare/connect/network/connectId/PersonalIdApiHandler.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
import org.commcare.connect.network.connectId.parser.ConfirmBackupCodeResponseParser;
1515
import org.commcare.connect.network.connectId.parser.PersonalIdApiResponseParser;
1616
import org.commcare.connect.network.connectId.parser.StartConfigurationResponseParser;
17+
import org.commcare.util.LogTypes;
1718
import org.javarosa.core.io.StreamsUtil;
1819
import org.javarosa.core.services.Logger;
1920
import org.json.JSONException;
2021
import org.json.JSONObject;
2122

23+
import java.io.ByteArrayInputStream;
2224
import java.io.IOException;
2325
import java.io.InputStream;
2426
import java.util.Map;
@@ -47,10 +49,45 @@ public void processSuccess(int responseCode, InputStream responseData) {
4749
onSuccess((T)sessionData);
4850
}
4951

50-
52+
@Override
53+
public void processFailure(int responseCode, InputStream errorResponse, String url) {
54+
if (!handleErrorCodeIfPresent(errorResponse, sessionData)) {
55+
super.processFailure(responseCode, null, url);
56+
}
57+
}
5158
};
5259
}
5360

61+
private boolean handleErrorCodeIfPresent(InputStream errorResponse, PersonalIdSessionData sessionData) {
62+
try {
63+
if (errorResponse != null) {
64+
byte[] errorBytes = StreamsUtil.inputStreamToByteArray(errorResponse);
65+
String jsonStr = new String(errorBytes, java.nio.charset.StandardCharsets.UTF_8);
66+
JSONObject json = new JSONObject(jsonStr);
67+
68+
String errorCode = json.optString("error_code", "");
69+
sessionData.setSessionFailureCode(errorCode);
70+
if ("LOCKED_ACCOUNT".equalsIgnoreCase(errorCode)) {
71+
onFailure(PersonalIdOrConnectApiErrorCodes.ACCOUNT_LOCKED_ERROR, null);
72+
return true;
73+
} else if ("INTEGRITY_ERROR".equalsIgnoreCase(errorCode)) {
74+
if (json.has("sub_code")) {
75+
String subErrorCode = json.optString("sub_code");
76+
Logger.log(LogTypes.TYPE_MAINTENANCE, "Integrity error with subcode " + subErrorCode);
77+
sessionData.setSessionFailureSubcode(subErrorCode);
78+
onFailure(PersonalIdOrConnectApiErrorCodes.INTEGRITY_ERROR, null);
79+
}
80+
return true;
81+
}
82+
}
83+
} catch (Exception e) {
84+
Logger.exception("Error parsing error_code", e);
85+
}
86+
return false;
87+
}
88+
89+
90+
5491
public void makeStartConfigurationCall(Activity activity,
5592
Map<String, String> body,
5693
String integrityToken,

0 commit comments

Comments
 (0)