Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@
<string name="personalid_recovery_failed_message">Parece que olvidaste tu código de respaldo, estamos creando una nueva cuenta para ti</string>
<string name="personalid_recovery_lockout_message">Ha ingresado el código de respaldo incorrecto demasiadas veces. Su cuenta ha sido bloqueada. Comuníquese con el soporte para desbloquear su cuenta.</string>
<string name="personalid_wrong_backup_message">Ha introducido el código de seguridad incorrecto. Inténtelo de nuevo. Su cuenta se bloqueará después de %d intentos incorrectos más.</string>
<string name="personalid_second_device_login_title">Iniciar sesión en un segundo dispositivo</string>
<string name="personalid_second_device_login_message">Sesión cerrada en %s, último uso: %s. Solo se puede iniciar sesión con PersonalID en un dispositivo a la vez.</string>
<string name="personalid_second_device_login_message_no_date">Se ha cerrado la sesión en %s. Solo se puede iniciar sesión con PersonalID en un dispositivo a la vez.</string>
<string name="personalid_camera_permission_title">Permiso de cámara</string>
<string name="personalid_camera_permission_msg">Para tomar una foto, CommCare necesita permiso para usar la cámara de tu dispositivo.</string>
<string name="personalid_capture_photo">Tomar foto</string>
Expand Down
3 changes: 3 additions & 0 deletions app/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ License.
<string name="personalid_recovery_failed_message">Il semble que vous ayez oublié votre code de sauvegarde, nous créons un nouveau compte pour vous</string>
<string name="personalid_recovery_lockout_message">Vous avez saisi un code de secours incorrect un trop grand nombre de fois. Votre compte a été bloqué. Veuillez contacter le support pour débloquer votre compte.</string>
<string name="personalid_wrong_backup_message">Vous avez saisi un code de sauvegarde incorrect. Veuillez réessayer. Votre compte sera bloqué après %d tentatives incorrectes supplémentaires.</string>
<string name="personalid_second_device_login_title">Connexion sur un deuxième appareil</string>
<string name="personalid_second_device_login_message">Vous avez été déconnecté(e) de %s, dernière utilisation le %s. L\'identifiant PersonalID ne peut être utilisé que sur un seul appareil à la fois.</string>
<string name="personalid_second_device_login_message_no_date">Vous avez été déconnecté(e) de %s. L\'identifiant PersonalID ne peut être utilisé que sur un seul appareil à la fois.</string>
<string name="personalid_camera_permission_title">Autorisation pour la caméra</string>
<string name="personalid_camera_permission_msg">Afin de prendre une photo, CommCare a besoin de l\'autorisation d\'utiliser l\'appareil photo de votre appareil.</string>
<string name="personalid_capture_photo">Prendre une photo</string>
Expand Down
3 changes: 3 additions & 0 deletions app/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ License.
<string name="personalid_recovery_failed_message">ऐसा लगता है कि आप अपना बैकअप कोड भूल गए हैं, हम आपके लिए एक नया खाता बना रहे हैं</string>
<string name="personalid_recovery_lockout_message">आपने बहुत बार गलत बैकअप कोड दर्ज किया है। आपका खाता लॉक कर दिया गया है। अपना अकाउंट अनलॉक करने के लिए कृपया सपोर्ट से संपर्क करें।</string>
<string name="personalid_wrong_backup_message">आपने गलत बैकअप कोड डाला है। कृपया फिर से कोशिश करें। %d और गलत कोशिशों के बाद आपका अकाउंट लॉक हो जाएगा।</string>
<string name="personalid_second_device_login_title">दूसरे डिवाइस पर लॉग इन करें</string>
<string name="personalid_second_device_login_message">%s से लॉग आउट किया गया, आखिरी बार %s इस्तेमाल किया गया था। PersonalID से एक समय में सिर्फ़ एक डिवाइस पर लॉग इन किया जा सकता है।</string>
<string name="personalid_second_device_login_message_no_date">%s से लॉग आउट कर दिया गया है। PersonalID से एक समय में सिर्फ़ एक डिवाइस पर ही लॉग इन किया जा सकता है।</string>
<string name="personalid_camera_permission_title">कैमरे के लिए अनुमति</string>
<string name="personalid_camera_permission_msg">तस्वीर लेने के लिए, CommCare को आपके डिवाइस के कैमरे का उपयोग करने की अनुमति चाहिए।</string>
<string name="personalid_capture_photo">तस्वीर लें</string>
Expand Down
3 changes: 3 additions & 0 deletions app/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@
<string name="personalid_recovery_failed_message">Parece que se esqueceu do seu código de backup, estamos a criar uma nova conta para si</string>
<string name="personalid_recovery_lockout_message">Você inseriu o código de backup incorreto muitas vezes. A sua conta foi bloqueada. Entre em contacto com o suporte para desbloquear a sua conta.</string>
<string name="personalid_wrong_backup_message">Introduziu o código de segurança incorretamente. Tente novamente. A sua conta será bloqueada após %d tentativas incorretas.</string>
<string name="personalid_second_device_login_title">Iniciar sessão no segundo dispositivo</string>
<string name="personalid_second_device_login_message">Sessão encerrada em %s, último acesso em %s. O PersonalID só pode ser utilizado num dispositivo de cada vez.</string>
<string name="personalid_second_device_login_message_no_date">Sessão encerrada de %s. O PersonalID só pode ser acedido num dispositivo de cada vez.</string>
<string name="personalid_camera_permission_title">Permissão para câmara</string>
<string name="personalid_camera_permission_msg">Para tirar uma fotografia, o CommCare precisa de permissão para utilizar a câmara do seu dispositivo.</string>
<string name="personalid_capture_photo">Capturar foto</string>
Expand Down
3 changes: 3 additions & 0 deletions app/res/values-sw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@
<string name="personalid_recovery_lockout_title">Akaunti Imefungwa</string>
<string name="personalid_recovery_failed_message">Inaonekana umesahau Nambari yako ya Hifadhi Nambari, tunakuundia akaunti mpya</string>
<string name="personalid_wrong_backup_message">Umeingiza Nambari ya Kuhifadhi Nakala Isiyo sahihi. Tafadhali jaribu tena. Akaunti yako itafungwa baada ya majaribio %d zaidi yasiyo sahihi.</string>
<string name="personalid_second_device_login_title">Ingia kwenye Kifaa cha Pili</string>
<string name="personalid_second_device_login_message">Imetoka kwenye %s, imetumika mara ya mwisho %s. Kitambulisho cha Kibinafsi kinaweza kuingia kwenye kifaa kimoja tu kwa wakati mmoja.</string>
<string name="personalid_second_device_login_message_no_date">Umetoka kwenye %s. Kitambulisho cha Kibinafsi kinaweza kuingia kwenye kifaa kimoja tu kwa wakati mmoja.</string>
<string name="personalid_recovery_lockout_message">Umeweka msimbo wa akiba usio sahihi mara nyingi sana. Akaunti yako imefungwa. Tafadhali wasiliana na usaidizi ili kufungua akaunti yako.</string>
<string name="personalid_camera_permission_title">Ruhusa ya kamera</string>
<string name="personalid_camera_permission_msg">Ili kupiga picha, CommCare inahitaji ruhusa ya kutumia kamera ya kifaa chako.</string>
Expand Down
3 changes: 3 additions & 0 deletions app/res/values-ti/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@
<string name="personalid_recovery_failed_message">Backup Code ናትካ ዝረሳዕካዮ ይመስል፣ ሓድሽ ኣካውንት ንፈጥር ኣለና።</string>
<string name="personalid_recovery_lockout_message">ንስኻ ነቲ ናይ ምትካእ ኮድ ብጌጋ ብዙሕ ግዜ ኣእቲኻዮ። ሕሳብካ ተዓጽዩ ኣሎ። ኣካውንትኩም ንምኽፋት በጃኹም ምስ ደገፍ ተወከሱ።</string>
<string name="personalid_wrong_backup_message">ጌጋ Backup Code ኣእቲኻ ኣለኻ። በጃኹም ደጊምኩም ፈትኑ። ድሕሪ %d ዝያዳ ጌጋ ፈተነታት ኣካውንትካ ክዕጾ እዩ።</string>
<string name="personalid_second_device_login_title">ኣብ ካልኣይ መሳርሒ እቶ</string>
<string name="personalid_second_device_login_message">ካብ %s ወጺኡ፣ ንመወዳእታ ግዜ ዝተጠቕመሉ %s። PersonalID ኣብ ሓደ እዋን ኣብ ሓደ መሳርሒ ጥራይ እዩ ክኣቱ ዝኽእል።</string>
<string name="personalid_second_device_login_message_no_date">ካብ %s ወጺኡ። PersonalID ኣብ ሓደ እዋን ኣብ ሓደ መሳርሒ ጥራይ እዩ ክኣቱ ዝኽእል።</string>
<string name="personalid_camera_permission_title">ፍቓድ ንካሜራ</string>
<string name="personalid_camera_permission_msg">ስእሊ ንምውሳድ፡ ኮምኬር ናይ መሳርሒኻ ካሜራ ንኽጥቀም ፍቓድ የድልዮ።</string>
<string name="personalid_capture_photo">ስእሊ ምቕራጽ</string>
Expand Down
3 changes: 3 additions & 0 deletions app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@
<string name="personalid_recovery_failed_message">Looks like you’ve forgotten your Backup Code, we’re creating a new account for you</string>
<string name="personalid_recovery_lockout_message">You have entered the wrong Backup Code too many times. Your account has been locked. Please contact support to unlock your account.</string>
<string name="personalid_wrong_backup_message">You have entered the wrong Backup Code. Please try again. Your account will be locked after %d more incorrect attempts.</string>
<string name="personalid_second_device_login_title">Login on Second Device</string>
<string name="personalid_second_device_login_message">Logged out of %s, last used %s. PersonalID can only be logged in on one device at a time.</string>
<string name="personalid_second_device_login_message_no_date">Logged out of %s. PersonalID can only be logged in on one device at a time.</string>
<string name="personalid_camera_permission_title">Permission for camera</string>
<string name="personalid_camera_permission_msg">In order to take a picture, CommCare needs permission to use your device camera.</string>
<string name="personalid_capture_photo">Capture Photo</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.commcare.android.database.connect.models

import androidx.annotation.StringDef
import java.io.Serializable
import java.util.Date

/**
* Data holder for personal identification session state during Personal ID flows.
Expand Down Expand Up @@ -42,6 +43,10 @@ data class PersonalIdSessionData(
var otpFallback: Boolean = false,
// the total number of times we attempted to send the user an OTP
var otpAttempts: Int = 0,
// identifier of the device that was previously configured for this user
var previousDevice: String? = null,
// timestamp of the last time this account was accessed from the previous device
var lastAccessed: Date? = null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda wish this name was different but I think it's good to keep this as-is to match server's last_accessed 👍

) : Serializable {
/**
* Annotation to restrict accepted authentication types used by the device.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.commcare.connect.network.connectId.parser;

import com.google.common.base.Strings;

import org.commcare.android.database.connect.models.PersonalIdSessionData;
import org.commcare.utils.JsonExtensions;
import org.javarosa.core.model.utils.DateUtils;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -43,7 +46,12 @@ public void parse(JSONObject json, PersonalIdSessionData sessionData) throws JSO
sessionData.setOauthPassword(password);

sessionData.setInvitedUser(json.optBoolean("invited_user", false));
}

sessionData.setPreviousDevice(JsonExtensions.optStringSafe(json, "previous_device", null));
String lastAccessedString = JsonExtensions.optStringSafe(json, "last_accessed", null);
if(!Strings.isNullOrEmpty(lastAccessedString)) {
sessionData.setLastAccessed(DateUtils.parseDate(lastAccessedString));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import androidx.navigation.NavDirections;
import androidx.navigation.Navigation;

import org.commcare.CommCareNoficationManager;
import org.commcare.activities.connect.viewmodel.PersonalIdSessionDataViewModel;
import org.commcare.android.database.connect.models.ConnectUserRecord;
import org.commcare.android.database.connect.models.PersonalIdSessionData;
Expand All @@ -29,6 +30,8 @@
import org.commcare.google.services.analytics.FirebaseAnalyticsUtil;
import org.commcare.utils.KeyboardHelper;
import org.commcare.utils.MediaUtil;
import org.commcare.utils.NotificationUtil;
import org.javarosa.core.model.utils.DateUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -226,6 +229,7 @@ private void handleSuccessfulRecovery() {
personalIdSessionData.getInvitedUser());
ConnectUserDatabaseUtil.storeUser(requireActivity(), user);
logRecoveryResult(true);
handleSecondDeviceLogin();
navigateToSuccess();
}

Expand All @@ -251,6 +255,28 @@ private void logRecoveryResult(boolean success) {
FirebaseAnalyticsUtil.reportPersonalIdAccountRecovered(success, AnalyticsParamValue.CCC_RECOVERY_METHOD_BACKUPCODE);
}

private void handleSecondDeviceLogin() {
if(personalIdSessionData.getPreviousDevice() != null) {
int titleId = R.string.personalid_second_device_login_title;
String message;
if (personalIdSessionData.getLastAccessed() != null) {
message = getString(R.string.personalid_second_device_login_message,
personalIdSessionData.getPreviousDevice(),
DateUtils.getShortStringValue(personalIdSessionData.getLastAccessed()));
} else {
message = getString(R.string.personalid_second_device_login_message_no_date,
personalIdSessionData.getPreviousDevice());
}

NotificationUtil.showNotification(requireContext(),
CommCareNoficationManager.NOTIFICATION_CHANNEL_SERVER_COMMUNICATIONS_ID,
titleId,
getString(titleId),
message,
null);
}
}

private void navigateWithMessage(String titleRes, String msgRes, int phase) {
navigateToMessageDisplay(titleRes, msgRes, false, phase, R.string.ok);
}
Expand Down
14 changes: 8 additions & 6 deletions app/src/org/commcare/utils/NotificationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@
public class NotificationUtil {
public static void showNotification(Context context, String notificationChannel, int notificationId,
String notificationTitle, String notificationText, Intent actionIntent) {

int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, actionIntent, pendingIntentFlags);

NotificationCompat.Builder notification =
new NotificationCompat.Builder(context, notificationChannel)
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.commcare_actionbar_logo)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis());

if(actionIntent != null) {
int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, actionIntent, pendingIntentFlags);
notification.setContentIntent(contentIntent);
}

((NotificationManager) context.getSystemService(NOTIFICATION_SERVICE))
.notify(notificationId, notification.build());
}
Expand Down