Skip to content

Commit

Permalink
fix(#308): Fix sonarlint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sugat009 committed Apr 25, 2024
1 parent 7420b9c commit fed9cd9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ 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()));
this.startActivity(intent);
finish();
}

@SuppressLint("unused")
public void onClickNegative(View view) {
trace(this, "DomainVerificationActivity :: User disagreed with prominent disclosure message.");
finish();
Expand Down
38 changes: 22 additions & 16 deletions src/main/java/org/medicmobile/webapp/mobile/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<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");
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<String, Integer> hostToStateMap) {
for (int stateValue : hostToStateMap.values()) {
if (stateValue != DomainVerificationUserState.DOMAIN_STATE_VERIFIED &&
stateValue != DomainVerificationUserState.DOMAIN_STATE_SELECTED) {
return false;
}
}
return true;
Expand Down

0 comments on commit fed9cd9

Please sign in to comment.