Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

230 - Removing simprints #241

Merged
merged 27 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b5d524d
Added handling for denied localisation
latin-panda Dec 9, 2021
89c172d
Increase minSDKVersion to 21 and initial removal of xwalk support
latin-panda Dec 9, 2021
61c0fec
Removing xwalk support and changing android.support by androidx
latin-panda Dec 10, 2021
d4e2074
Fixing support for Android 5
latin-panda Dec 10, 2021
93e9d05
Update .github/workflows/publish.yml
latin-panda Dec 10, 2021
3018905
Update .github/workflows/publish.yml
latin-panda Dec 10, 2021
f2dc424
Fixing support for Android 5 and lint
latin-panda Dec 13, 2021
3c917d5
Fix comment, the support added is for android sdk 21 & 22 (Android 5)
latin-panda Dec 13, 2021
15b6f31
Removing webview version and merging it in main. Removed "webview" na…
latin-panda Dec 14, 2021
80388c7
fixing brand name
latin-panda Dec 15, 2021
a203c25
Merge branch '169-remove-android-4-support' of https://github.com/med…
latin-panda Dec 15, 2021
9891d94
Fixed imports
latin-panda Dec 15, 2021
9ae939d
Update call to angular function
latin-panda Dec 15, 2021
1665965
Merge branch 'master' of https://github.com/medic/medic-android into …
latin-panda Jan 4, 2022
474b4b0
Adding some unit tests
latin-panda Jan 4, 2022
bd7e1b7
Merge branch 'master' of https://github.com/medic/medic-android into …
latin-panda Jan 4, 2022
dd6965a
Merge branch '169-remove-android-4-support' of https://github.com/med…
latin-panda Jan 4, 2022
a246f29
Unit test for location permission handling
latin-panda Jan 5, 2022
c4a7332
turning off this check because the latest version of this lib is for …
latin-panda Jan 5, 2022
04dd455
fix
latin-panda Jan 5, 2022
16369b4
NPE
latin-panda Jan 5, 2022
554d449
Initial removal of simprints
latin-panda Jan 6, 2022
734f279
unit test - no intents started
latin-panda Jan 6, 2022
0d3f2c9
Merge branch '189-handle-location-permission' of https://github.com/m…
latin-panda Jan 7, 2022
89824a2
Feedback
latin-panda Jan 11, 2022
08ba7f1
Feedback about optional
latin-panda Jan 11, 2022
c59ba6c
Merge branch 'master' of https://github.com/medic/medic-android into …
latin-panda Feb 8, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ void startIntent(ChtExternalApp chtExternalApp) {
if (ContextCompat.checkSelfPermission(this.context, READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
trace(this, "ChtExternalAppHandler :: Requesting storage permissions to process image files taken from external apps");
this.lastIntent = intent; // Saving intent to start it when permission is granted.
ActivityCompat.requestPermissions(this.context, PERMISSIONS_STORAGE, RequestCode.ACCESS_STORAGE_PERMISSION);
ActivityCompat.requestPermissions(
this.context,
PERMISSIONS_STORAGE,
RequestCode.ACCESS_STORAGE_PERMISSION.getCode()
);
return;
}

Expand All @@ -79,7 +83,7 @@ void resumeActivity() {
private void startActivity(Intent intent) {
try {
trace(this, "ChtExternalAppHandler :: Starting activity %s %s", intent, intent.getExtras());
this.context.startActivityForResult(intent, RequestCode.CHT_EXTERNAL_APP_ACTIVITY);
this.context.startActivityForResult(intent, RequestCode.CHT_EXTERNAL_APP_ACTIVITY.getCode());

} catch (Exception exception) {
error(exception, "ChtExternalAppHandler :: Error when starting the activity %s %s", intent, intent.getExtras());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import androidx.core.content.ContextCompat;

import java.util.Arrays;
import java.util.Optional;

@SuppressWarnings({ "PMD.GodClass", "PMD.TooManyMethods" })
public class EmbeddedBrowserActivity extends LockableActivity {
Expand Down Expand Up @@ -192,38 +193,39 @@ protected void onStop() {
backButtonHandler);
}

@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
String requestCodeLabel = RequestCode.requestCodeToString(requestCode);
@Override protected void onActivityResult(int requestCd, int resultCode, Intent intent) {
RequestCode requestCode = RequestCode.valueOf(requestCd).get();
latin-panda marked this conversation as resolved.
Show resolved Hide resolved

try {
trace(this, "onActivityResult() :: requestCode=%s, resultCode=%s", requestCodeLabel, resultCode);
trace(this, "onActivityResult() :: requestCode=%s, resultCode=%s", requestCode.name(), resultCode);

switch (requestCode) {
case RequestCode.GRAB_PHOTO_ACTIVITY:
case GRAB_PHOTO_ACTIVITY:
photoGrabber.process(requestCode, resultCode, intent);
return;
case RequestCode.GRAB_MRDT_PHOTO_ACTIVITY:
case GRAB_MRDT_PHOTO_ACTIVITY:
processMrdtResult(requestCode, resultCode, intent);
return;
case RequestCode.DISCLOSURE_LOCATION_ACTIVITY:
case DISCLOSURE_LOCATION_ACTIVITY:
processLocationPermissionResult(resultCode);
return;
case RequestCode.CHT_EXTERNAL_APP_ACTIVITY:
case CHT_EXTERNAL_APP_ACTIVITY:
processChtExternalAppResult(resultCode, intent);
return;
default:
trace(this, "onActivityResult() :: no handling for requestCode=%s", requestCodeLabel);
trace(this, "onActivityResult() :: no handling for requestCode=%s", requestCode.name());
}
} catch(Exception ex) {
String action = intent == null ? null : intent.getAction();
warn(ex, "Problem handling intent %s (%s) with requestCode=%s & resultCode=%s",
intent, action, requestCodeLabel, resultCode);
intent, action, requestCode.name(), resultCode);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
public void onRequestPermissionsResult(int requestCd, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCd, permissions, grantResults);
RequestCode requestCode = RequestCode.valueOf(requestCd).get();
boolean granted = grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED;

if (requestCode == RequestCode.ACCESS_LOCATION_PERMISSION) {
Expand Down Expand Up @@ -305,7 +307,7 @@ public boolean getLocationPermissions() {

trace(this, "getLocationPermissions() :: location not granted before, requesting access...");
Intent intent = new Intent(this, RequestPermissionActivity.class);
startActivityForResult(intent, RequestCode.DISCLOSURE_LOCATION_ACTIVITY);
startActivityForResult(intent, RequestCode.DISCLOSURE_LOCATION_ACTIVITY.getCode());
return false;
}

Expand All @@ -320,15 +322,19 @@ private void processChtExternalAppResult(int resultCode, Intent intentData) {
evaluateJavascript(script);
}

private void processMrdtResult(int requestCode, int resultCode, Intent intent) {
String js = mrdt.process(requestCode, resultCode, intent);
private void processMrdtResult(RequestCode requestCode, int resultCode, Intent intent) {
String js = mrdt.process(requestCode, intent);
trace(this, "Executing JavaScript: %s", js);
evaluateJavascript(js);
}

private void processLocationPermissionResult(int resultCode) {
if (resultCode == RESULT_OK) {
ActivityCompat.requestPermissions(this, LOCATION_PERMISSIONS, RequestCode.ACCESS_LOCATION_PERMISSION);
ActivityCompat.requestPermissions(
this,
LOCATION_PERMISSIONS,
RequestCode.ACCESS_LOCATION_PERMISSION.getCode()
);
} else if (resultCode == RESULT_CANCELED) {
processGeolocationDeniedStatus();
}
Expand Down Expand Up @@ -443,32 +449,31 @@ private void registerRetryConnectionBroadcastReceiver() {
registerReceiver(broadcastReceiver, new IntentFilter("retryConnection"));
}

//> CLASSES
public static class RequestCode {
static final int ACCESS_LOCATION_PERMISSION = 100;
static final int ACCESS_STORAGE_PERMISSION = 101;
static final int CHT_EXTERNAL_APP_ACTIVITY = 102;
static final int DISCLOSURE_LOCATION_ACTIVITY = 103;
static final int GRAB_MRDT_PHOTO_ACTIVITY = 104;
static final int GRAB_PHOTO_ACTIVITY = 105;
//> ENUMS
public enum RequestCode {
ACCESS_LOCATION_PERMISSION(100),
ACCESS_STORAGE_PERMISSION(101),
CHT_EXTERNAL_APP_ACTIVITY(102),
DISCLOSURE_LOCATION_ACTIVITY(103),
GRAB_MRDT_PHOTO_ACTIVITY(104),
GRAB_PHOTO_ACTIVITY(105);

static String requestCodeToString(int requestCode) {
switch (requestCode) {
case ACCESS_LOCATION_PERMISSION:
return "ACCESS_LOCATION_PERMISSION";
case ACCESS_STORAGE_PERMISSION:
return "ACCESS_STORAGE_PERMISSION";
case CHT_EXTERNAL_APP_ACTIVITY:
return "CHT_EXTERNAL_APP_ACTIVITY";
case DISCLOSURE_LOCATION_ACTIVITY:
return "DISCLOSURE_LOCATION_ACTIVITY";
case GRAB_MRDT_PHOTO_ACTIVITY:
return "GRAB_MRDT_PHOTO_ACTIVITY";
case GRAB_PHOTO_ACTIVITY:
return "GRAB_PHOTO_ACTIVITY";
default:
return String.valueOf(requestCode);
}
private final int requestCode;

RequestCode(int requestCode) {
this.requestCode = requestCode;
}

public static Optional<RequestCode> valueOf(int code) {
return Arrays
.stream(RequestCode.values())
.filter(e -> e.getCode() == code)
.findFirst();
}

public int getCode() {
return requestCode;
}
}

}
12 changes: 6 additions & 6 deletions src/main/java/org/medicmobile/webapp/mobile/MrdtSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ boolean isAppInstalled() {
}

void startVerify() {
ctx.startActivityForResult(verifyIntent(), RequestCode.GRAB_MRDT_PHOTO_ACTIVITY);
ctx.startActivityForResult(verifyIntent(), RequestCode.GRAB_MRDT_PHOTO_ACTIVITY.getCode());
}

String process(int requestCode, int resultCode, Intent i) {
trace(this, "process() :: requestCode=%s", requestCode);
String process(RequestCode requestCode, Intent i) {
trace(this, "process() :: requestCode=%s", requestCode.name());

switch(requestCode) {
case RequestCode.GRAB_MRDT_PHOTO_ACTIVITY: {
switch (requestCode) {
case GRAB_MRDT_PHOTO_ACTIVITY: {
try {
byte[] data = i.getByteArrayExtra("data");
String base64data = Base64.encodeToString(data, Base64.NO_WRAP);
Expand All @@ -51,7 +51,7 @@ String process(int requestCode, int resultCode, Intent i) {
}
}

default: throw new RuntimeException("Bad request type: " + requestCode);
default: throw new RuntimeException("Bad request type: " + requestCode.name());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/medicmobile/webapp/mobile/PhotoGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ void chooser(ValueCallback<Uri[]> callback, boolean capture) {
else pickImage();
}

void process(int requestCode, int resultCode, Intent i) {
void process(RequestCode requestCode, int resultCode, Intent i) {
if(uploadCallback == null) {
warn(this, "uploadCallback is null for requestCode %s", requestCode);
warn(this, "uploadCallback is null for requestCode %s", requestCode.name());
return;
}

Expand Down Expand Up @@ -112,14 +112,14 @@ public void run() {
}

private void takePhoto() {
a.startActivityForResult(cameraIntent(), RequestCode.GRAB_PHOTO_ACTIVITY);
a.startActivityForResult(cameraIntent(), RequestCode.GRAB_PHOTO_ACTIVITY.getCode());
}

private void pickImage() {
trace(this, "picking image intent");
Intent i = getPickImageIntent(a, a.getString(R.string.promptChooseImage));
trace(this, "starting activity :: %s", i);
a.startActivityForResult(i, RequestCode.GRAB_PHOTO_ACTIVITY);
a.startActivityForResult(i, RequestCode.GRAB_PHOTO_ACTIVITY.getCode());
}

private boolean canStartCamera() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void startIntent_withValidIntent_startsIntentCorrectly() {

//> THEN
verify(chtExternalApp).createIntent();
verify(mockContext).startActivityForResult(eq(intent), eq(RequestCode.CHT_EXTERNAL_APP_ACTIVITY));
verify(mockContext).startActivityForResult(eq(intent), eq(RequestCode.CHT_EXTERNAL_APP_ACTIVITY.getCode()));
}

@Test
Expand All @@ -197,7 +197,7 @@ public void startIntent_withException_catchesException() {

//> THEN
verify(chtExternalApp).createIntent();
verify(mockContext).startActivityForResult(eq(intent), eq(RequestCode.CHT_EXTERNAL_APP_ACTIVITY));
verify(mockContext).startActivityForResult(eq(intent), eq(RequestCode.CHT_EXTERNAL_APP_ACTIVITY.getCode()));
medicLogMock.verify(() -> MedicLog.error(
any(),
eq("ChtExternalAppHandler :: Error when starting the activity %s %s"),
Expand Down Expand Up @@ -227,7 +227,11 @@ public void startIntent_withoutStoragePermissions_requestsPermissions() {
//> THEN
verify(chtExternalApp).createIntent();
contextCompatMock.verify(() -> ContextCompat.checkSelfPermission(mockContext, READ_EXTERNAL_STORAGE));
activityCompatMock.verify(() -> ActivityCompat.requestPermissions(mockContext, new String[]{READ_EXTERNAL_STORAGE}, RequestCode.ACCESS_STORAGE_PERMISSION));
activityCompatMock.verify(() -> ActivityCompat.requestPermissions(
mockContext,
new String[]{READ_EXTERNAL_STORAGE},
RequestCode.ACCESS_STORAGE_PERMISSION.getCode()
));
verify(mockContext, never()).startActivityForResult(any(), anyInt());

}
Expand Down Expand Up @@ -260,8 +264,12 @@ public void resumeActivity_withLastIntent_startsIntentCorrectly() {
//> THEN
verify(chtExternalApp).createIntent();
contextCompatMock.verify(() -> ContextCompat.checkSelfPermission(mockContext, READ_EXTERNAL_STORAGE));
activityCompatMock.verify(() -> ActivityCompat.requestPermissions(mockContext, new String[]{READ_EXTERNAL_STORAGE}, RequestCode.ACCESS_STORAGE_PERMISSION));
verify(mockContext).startActivityForResult(eq(intent), eq(RequestCode.CHT_EXTERNAL_APP_ACTIVITY));
activityCompatMock.verify(() -> ActivityCompat.requestPermissions(
mockContext,
new String[]{READ_EXTERNAL_STORAGE},
RequestCode.ACCESS_STORAGE_PERMISSION.getCode()
));
verify(mockContext).startActivityForResult(eq(intent), eq(RequestCode.CHT_EXTERNAL_APP_ACTIVITY.getCode()));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void getLocationPermissions_withPermissionsDenied_requestPermissions() {
activityCompatMock.verify(() -> ActivityCompat.requestPermissions(
embeddedBrowserActivity,
LOCATION_PERMISSIONS,
RequestCode.ACCESS_LOCATION_PERMISSION
RequestCode.ACCESS_LOCATION_PERMISSION.getCode()
));

Intents.release();
Expand Down