Skip to content

Commit

Permalink
fix(#308): Add unit tests for the changes and change the content for the
Browse files Browse the repository at this point in the history
domain verification request popup
  • Loading branch information
sugat009 committed Apr 16, 2024
1 parent 0e09bd3 commit 7420b9c
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,33 @@

import static org.medicmobile.webapp.mobile.MedicLog.trace;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.content.pm.verify.domain.DomainVerificationUserState;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import java.util.Map;

public class DomainVerificationActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
trace(this, "onCreate()");

if (!this.checkIfDomainsAreVerified()) {
setContentView(R.layout.request_app_domain_association);
} else {
finish();
}
}

private boolean checkIfDomainsAreVerified() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Context context = getApplicationContext();
DomainVerificationManager manager =
context.getSystemService(DomainVerificationManager.class);
try {
DomainVerificationUserState userState =
manager.getDomainVerificationUserState(context.getPackageName());

Map<String, Integer> hostToStateMap = userState.getHostToStateMap();

for (String stateValue : hostToStateMap.values()) {
setContentView(R.layout.request_app_domain_association);

if (stateValue != DomainVerificationUserState.DOMAIN_STATE_VERIFIED && stateValue != DomainVerificationUserState.DOMAIN_STATE_SELECTED) {
return false;
}
}
} catch (PackageManager.NameNotFoundException e) {
return true;
}
}
return true;
String appName = getResources().getString(R.string.app_name);
String title = getResources().getString(R.string.domainAppAssociationTitle);
TextView field = findViewById(R.id.domainAppAssociationTitleText);
field.setText(String.format(title, appName));
}

public void onClickOk(View view) {
trace(this, "DomainVerificationActivity :: User agreed with prominent disclosure message.");
Intent intent = new Intent(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, Uri.parse("package:" + this.getPackageName()));
@SuppressLint("InlinedApi") Intent intent = new Intent(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, Uri.parse("package:" + this.getPackageName()));
this.startActivity(intent);
finish();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.medicmobile.webapp.mobile;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;

import static org.medicmobile.webapp.mobile.MedicLog.trace;
import static org.medicmobile.webapp.mobile.Utils.createUseragentFrom;
Expand Down Expand Up @@ -32,7 +34,9 @@ private void configureAndStartNextActivity() {
}

private void startDomainVerificationActivity() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Context context = getApplicationContext();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !Utils.checkIfDomainsAreVerified(context)) {
Intent intent = new Intent(this, DomainVerificationActivity.class);
startActivity(intent);
finish();
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/org/medicmobile/webapp/mobile/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import static org.medicmobile.webapp.mobile.BuildConfig.APPLICATION_ID;
import static org.medicmobile.webapp.mobile.BuildConfig.DEBUG;
import static org.medicmobile.webapp.mobile.BuildConfig.VERSION_NAME;
import static org.medicmobile.webapp.mobile.MedicLog.warn;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.content.pm.verify.domain.DomainVerificationUserState;
import android.net.Uri;
import android.os.Build;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.Map;
import java.util.Optional;

final class Utils {
Expand Down Expand Up @@ -81,7 +87,7 @@ static String createUseragentFrom(String current) {
if(current.contains(APPLICATION_ID)) return current;

return String.format("%s %s/%s",
current, APPLICATION_ID, VERSION_NAME);
current, APPLICATION_ID, VERSION_NAME);
}

static void restartApp(Context context) {
Expand Down Expand Up @@ -117,4 +123,26 @@ static Optional<Uri> getUriFromFilePath(String path) {
static boolean isDebug() {
return DEBUG;
}

static boolean checkIfDomainsAreVerified(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
DomainVerificationManager manager =
context.getSystemService(DomainVerificationManager.class);
try {
DomainVerificationUserState userState =
manager.getDomainVerificationUserState(context.getPackageName());

Map<String, Integer> hostToStateMap = userState.getHostToStateMap();

for (Integer stateValue : hostToStateMap.values()) {
if (stateValue != DomainVerificationUserState.DOMAIN_STATE_VERIFIED && stateValue != DomainVerificationUserState.DOMAIN_STATE_SELECTED) {
return false;
}
}
} catch (PackageManager.NameNotFoundException e) {
warn(e, "Error while getting package name");
}
}
return true;
}
}
9 changes: 7 additions & 2 deletions src/main/res/layout/request_app_domain_association.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
style="@style/borderlessButton"
android:onClick="onClickNegative"
android:text="@string/domainAppAssociationRequestDenyButton"
tools:ignore="OnClick" />
tools:ignore="OnClick"
android:layout_marginTop="10dp"/>

<View
android:layout_width="0dp"
Expand All @@ -54,10 +55,14 @@

<Button
android:id="@+id/domainAppAssociationOkButton"
style="@style/borderlessButton"
style="@style/standardButton"
android:layout_width="137dp"
android:background="@android:color/holo_blue_dark"
android:onClick="onClickOk"
android:text="@string/domainAppAssociationRequestOkButton"
android:textColor="#ffffff"
tools:ignore="OnClick" />

</LinearLayout>

</RelativeLayout>
6 changes: 0 additions & 6 deletions src/main/res/values-bm/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@
<string name="locRequestOkButton">Awɔ</string>
<string name="locRequestDenyButton">Ayi man sɔn</string>
<string name="locRequestIconDescription">Icône de mon emplacement</string> <!-- leave it in fr, not relevant -->

<string name="domainAppAssociationTitle">Asosiyɛti Domɛn ni Ap</string>
<string name="domainAppAssociationMessage">Kɔnsɔn bɛ taali ɲuman ka ɛ saayaɲɔgɔn ladu ni domɛnnuw ye. O tɛ bɛ a to lonkuruw bɛ fere kɛ baara ra mɔgɔ musomɔgɔya ra. Ee bɛ fɛ ka ɛ saayaɲɔgɔn ladu ni domɛnnuw hɛɛrɛhɛrɛninw ye wa?</string>
<string name="domainAppAssociationIconDescription">Domɛn Ayikon</string>
<string name="domainAppAssociationRequestOkButton">Ɔwan</string>
<string name="domainAppAssociationRequestDenyButton">Ꝋ꙲ </string>
</resources>
6 changes: 0 additions & 6 deletions src/main/res/values-ceb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@
<string name="locRequestOkButton">Ablihan</string>
<string name="locRequestDenyButton">Dili lang, salamat</string>
<string name="locRequestIconDescription">Ang icon sa akong lokasyon</string>

<string name="domainAppAssociationTitle">I-asosiyo ang Domain sa App</string>
<string name="domainAppAssociationMessage">Alang sa labi pang maayong kasinatian, girekomemdar namo nga i-asosiyo kining app sa mga relevante nga domain. Kini masiguro nga ang mga link muabli sirectly sa app.\nGusto ba nimong i-asosiyo kining app sa gikinahanglan nga mga domain?</string>
<string name="domainAppAssociationIconDescription">Ikonikong Domain</string>
<string name="domainAppAssociationRequestOkButton">Oo</string>
<string name="domainAppAssociationRequestDenyButton">Dili</string>
</resources>
10 changes: 5 additions & 5 deletions src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

<string name="waitMigration">Por favor espere a que el proceso de migración haya finalizado</string>

<string name="domainAppAssociationTitle">Asociar Dominio con la Aplicación</string>
<string name="domainAppAssociationMessage">Para una mejor experiencia, recomendamos asociar esta aplicación con los dominios relevantes. Esto garantizará que los enlaces se abran directamente en la aplicación.\n¿Le gustaría asociar esta aplicación con los dominios necesarios?</string>
<string name="domainAppAssociationIconDescription">Icono de Dominio</string>
<string name="domainAppAssociationRequestOkButton">Sí</string>
<string name="domainAppAssociationRequestDenyButton">No</string>
<string name="domainAppAssociationTitle">¿Vincular dominio con %s?</string>
<string name="domainAppAssociationMessage">Esto garantiza que todos los enlaces se abrirán en su aplicación para mejor experiencia</string>
<string name="domainAppAssociationIconDescription">Icono del dominio</string>
<string name="domainAppAssociationRequestOkButton">Sí, vincule dominio</string>
<string name="domainAppAssociationRequestDenyButton">No vincular</string>
</resources>
8 changes: 4 additions & 4 deletions src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
<string name="waitMigration">Veuillez attendre que la migration de données termine</string>
<string name="usingTrainingApp">Utiliser uniquement pendant la formation</string>

<string name="domainAppAssociationTitle">Associer le Domaine avec l\'Application</string>
<string name="domainAppAssociationMessage">Pour une meilleure expérience, nous vous recommandons d\'associer cette application aux domaines pertinents. Cela garantira que les liens s\'ouvriront directement dans l\'application.\nSouhaitez-vous associer cette application aux domaines nécessaires ?</string>
<string name="domainAppAssociationTitle">Associer le domaine à %s ?</string>
<string name="domainAppAssociationMessage">Cela garantit que tous les liens s\'ouvriront dans votre application pour une meilleure expérience.</string>
<string name="domainAppAssociationIconDescription">Icône de domaine</string>
<string name="domainAppAssociationRequestOkButton">Oui</string>
<string name="domainAppAssociationRequestDenyButton">Non</string>
<string name="domainAppAssociationRequestOkButton">Oui, lier le domaine</string>
<string name="domainAppAssociationRequestDenyButton">Non, ne pas lier</string>
</resources>
10 changes: 5 additions & 5 deletions src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<string name="locRequestDenyButton">जी नहीं, धन्यवाद</string>
<string name="locRequestIconDescription">मेरा स्थान आइकन</string>

<string name="domainAppAssociationTitle">डोमेन को ऐप के साथ संबद्ध करें</string>
<string name="domainAppAssociationMessage">बेहतर अनुभव के लिए, हम इस ऐप को संबंधित डोमेन के साथ संबद्ध करने की अनुशंसा करते हैं। इससे यह सुनिश्चित होगा कि लिंक सीधे ऐप में खुलेंगे।\nक्या आप इस ऐप को आवश्यक डोमेन के साथ जोड़ना चाहेंगे?</string>
<string name="domainAppAssociationIconDescription">डोमेन चिह्न</string>
<string name="domainAppAssociationRequestOkButton">हाँ</string>
<string name="domainAppAssociationRequestDenyButton">नहीं</string>
<string name="domainAppAssociationTitle">डोमेन को %s से लिंक करें?</string>
<string name="domainAppAssociationMessage">यह सुनिश्चित करता है कि आपके ऐप में सभी लिंक खुलेंगे एक बेहतर अनुभव के लिए</string>
<string name="domainAppAssociationIconDescription">डोमेन का चिह्न</string>
<string name="domainAppAssociationRequestOkButton">हां, डोमेन लिंक करें</string>
<string name="domainAppAssociationRequestDenyButton">लिंक न करें</string>
</resources>
6 changes: 0 additions & 6 deletions src/main/res/values-hil/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@
<string name="locRequestOkButton">Buksan</string>
<string name="locRequestDenyButton">Indi na, Salamat nalang</string>
<string name="locRequestIconDescription">Ang icon sang lokasyon ko</string>

<string name="domainAppAssociationTitle">Ikapareho ang Domain sa App</string>
<string name="domainAppAssociationMessage">Para sa mas maayo nga eksperyensya, ginarekomendar namon nga ikapareho ang app ini sa mga nabaton nga mga dominyo. Ini magasiguro nga ang mga link magabukas diretso sa sulod sang app.\nGusto mo bala nga ikapareho ang app ini sa kinahanglanon nga mga dominyo?</string>
<string name="domainAppAssociationIconDescription">Icon sang Dominyo</string>
<string name="domainAppAssociationRequestOkButton">Oo</string>
<string name="domainAppAssociationRequestDenyButton">Indi</string>
</resources>
10 changes: 5 additions & 5 deletions src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<string name="locRequestDenyButton">Tidak, terima kasih</string>
<string name="locRequestIconDescription">Ikon lokasiku</string>

<string name="domainAppAssociationTitle">Asosiasikan Domain dengan Aplikasi</string>
<string name="domainAppAssociationMessage">Untuk pengalaman yang lebih baik, kami merekomendasikan untuk mengasosiasikan aplikasi ini dengan domain yang relevan. Hal ini akan memastikan bahwa tautan dibuka langsung di dalam aplikasi.\nApakah Anda ingin mengasosiasikan aplikasi ini dengan domain yang relevan?</string>
<string name="domainAppAssociationIconDescription">Icon Domain</string>
<string name="domainAppAssociationRequestOkButton">Ya</string>
<string name="domainAppAssociationRequestDenyButton">Tidak</string>
<string name="domainAppAssociationTitle">Tautkan domain dengan %s?</string>
<string name="domainAppAssociationMessage">Ini memastikan semua tautan akan terbuka di aplikasi Anda untuk pengalaman yang lebih baik.</string>
<string name="domainAppAssociationIconDescription">Ikon Domain</string>
<string name="domainAppAssociationRequestOkButton">Ya, tautkan domain</string>
<string name="domainAppAssociationRequestDenyButton">Jangan tautkan</string>
</resources>
8 changes: 4 additions & 4 deletions src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<string name="locRequestDenyButton">हुँदैन, धन्यबाद</string>
<string name="locRequestIconDescription">मेरो स्थान आइकन</string>

<string name="domainAppAssociationTitle">एप्लिकेशन साथ डोमेन संबद्ध गर्नुहोस्</string>
<string name="domainAppAssociationMessage">राम्रो अनुभवको लागि, हामी यस एप्लिकेशनलाई सम्बन्धित डोमेनहरूसँग जोड्न अनुरोध गर्छौं। यसले यो पक्षमा तत्त्वाधिकारी अनुसार खोल्नु हुनेछ। के तपाईं यस एप्लिकेशनलाई आवश्यक डोमेनहरूसँग जोड्न चाहनुहुन्छ?</string>
<string name="domainAppAssociationIconDescription">डोमेन आइकन</string>
<string name="domainAppAssociationRequestOkButton">हुन्छ</string>
<string name="domainAppAssociationTitle">%s डोमेन लिंक गर्नुहुन्छ?</string>
<string name="domainAppAssociationMessage">यसले राम्रो अनुभवको लागि तपाइँको एपमा सबै लिङ्कहरू खुल्ने सुनिश्चित गर्दछ।</string>
<string name="domainAppAssociationIconDescription">डोमेन चिन्ह</string>
<string name="domainAppAssociationRequestOkButton">हुन्छ, डोमेन लिङ्क गर्नुहोस्</string>
<string name="domainAppAssociationRequestDenyButton">हुदैन</string>
</resources>
8 changes: 4 additions & 4 deletions src/main/res/values-tl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<string name="locRequestDenyButton">Hindi na, Salamat na lang</string>
<string name="locRequestIconDescription">Ang icon ng lokasyon ko</string>

<string name="domainAppAssociationTitle">Iugnay ang Domain sa App</string>
<string name="domainAppAssociationMessage">Para sa mas magandang karanasan, inirerekomenda namin na iugnay ang aplikasyong ito sa mga naaangkop na domain. Ito ay magtitiyak na ang mga link ay magbubukas nang direkta sa loob ng aplikasyon.\nNais mo bang iugnay ang aplikasyong ito sa mga kinakailangang domain?</string>
<string name="domainAppAssociationTitle">I-link ang domain sa %s?</string>
<string name="domainAppAssociationMessage">Tinitiyak nito na magbubukas ang lahat ng link sa iyong app para sa mas magandang karanasan.</string>
<string name="domainAppAssociationIconDescription">Icon ng Domain</string>
<string name="domainAppAssociationRequestOkButton">Oo</string>
<string name="domainAppAssociationRequestDenyButton">Hindi</string>
<string name="domainAppAssociationRequestOkButton">Oo, i-link ang domain</string>
<string name="domainAppAssociationRequestDenyButton">Huwag i-link</string>
</resources>
8 changes: 4 additions & 4 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<string name="waitMigration">Please wait until the migration process is finished</string>
<string name="usingTrainingApp">Use only during training</string>

<string name="domainAppAssociationTitle">Associate Domain with App</string>
<string name="domainAppAssociationMessage">For a better experience, we recommend associating this app with the relevant domains. This will ensure that links open directly in the app.\nWould you like to associate this app with the necessary domains?</string>
<string name="domainAppAssociationTitle">Link domain with %s?</string>
<string name="domainAppAssociationMessage">This ensures all links will open in your app for a better experience.</string>
<string name="domainAppAssociationIconDescription">Domain Icon</string>
<string name="domainAppAssociationRequestOkButton">Yes</string>
<string name="domainAppAssociationRequestDenyButton">No</string>
<string name="domainAppAssociationRequestOkButton">Yes, link domain</string>
<string name="domainAppAssociationRequestDenyButton">Don\'t link</string>
</resources>
Loading

0 comments on commit 7420b9c

Please sign in to comment.