diff --git a/src/main/java/org/medicmobile/webapp/mobile/DomainVerificationActivity.java b/src/main/java/org/medicmobile/webapp/mobile/DomainVerificationActivity.java index c4fcfcf5..58168542 100644 --- a/src/main/java/org/medicmobile/webapp/mobile/DomainVerificationActivity.java +++ b/src/main/java/org/medicmobile/webapp/mobile/DomainVerificationActivity.java @@ -26,6 +26,7 @@ public void onCreate(Bundle savedInstanceState) { field.setText(String.format(title, appName)); } + @SuppressLint("unused") public void onClickOk(View view) { trace(this, "DomainVerificationActivity :: User agreed with prominent disclosure message."); @SuppressLint("InlinedApi") Intent intent = new Intent(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, Uri.parse("package:" + this.getPackageName())); @@ -33,6 +34,7 @@ public void onClickOk(View view) { finish(); } + @SuppressLint("unused") public void onClickNegative(View view) { trace(this, "DomainVerificationActivity :: User disagreed with prominent disclosure message."); finish(); diff --git a/src/main/java/org/medicmobile/webapp/mobile/Utils.java b/src/main/java/org/medicmobile/webapp/mobile/Utils.java index 210dd240..3784d7ea 100644 --- a/src/main/java/org/medicmobile/webapp/mobile/Utils.java +++ b/src/main/java/org/medicmobile/webapp/mobile/Utils.java @@ -125,22 +125,28 @@ static boolean isDebug() { } 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 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"); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + return true; + } + + DomainVerificationManager manager = + context.getSystemService(DomainVerificationManager.class); + try { + DomainVerificationUserState userState = + manager.getDomainVerificationUserState(context.getPackageName()); + + return areAllDomainsVerifiedOrSelected(userState.getHostToStateMap()); + } catch (PackageManager.NameNotFoundException e) { + warn(e, "Error while getting package name"); + } + return true; + } + + private static boolean areAllDomainsVerifiedOrSelected(Map hostToStateMap) { + for (int stateValue : hostToStateMap.values()) { + if (stateValue != DomainVerificationUserState.DOMAIN_STATE_VERIFIED && + stateValue != DomainVerificationUserState.DOMAIN_STATE_SELECTED) { + return false; } } return true;