-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Pm retrofit #2890
Open
pm-dimagi
wants to merge
8
commits into
connect_qa
Choose a base branch
from
pm_retrofit
base: connect_qa
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pm retrofit #2890
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a6efad0
-retrofit implementation
pm-dimagi e9832b4
-retrofit implementation
pm-dimagi 93b6467
Merge branch 'connect_qa' of https://github.com/dimagi/commcare-andro…
OrangeAndGreen ec9d3ba
Merge branch 'connect_qa' of https://github.com/dimagi/commcare-andro…
OrangeAndGreen e146111
Cleaned up some obsolete strings, and fixed a path with a double slash
OrangeAndGreen b3cea59
Removed unused imports
OrangeAndGreen e369698
Fixed a couple compile errors after merge.
OrangeAndGreen 84546a2
Merge branch 'connect_qa' into pm_retrofit
OrangeAndGreen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
388 changes: 221 additions & 167 deletions
388
app/src/org/commcare/connect/network/ApiConnectId.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,10 +272,11 @@ public void checkPhoneNumber() { | |
binding.errorTextView.setText(getString(R.string.connect_phone_not_alt)); | ||
} else { | ||
//Make sure the number isn't already in use | ||
phone = phone.replaceAll("\\+", "%2b"); | ||
// phone = phone.replaceAll("\\+", "%2b"); | ||
binding.errorTextView.setVisibility(View.VISIBLE); | ||
binding.errorTextView.setText(getString(R.string.connect_phone_checking)); | ||
boolean isBusy = !ApiConnectId.checkPhoneAvailable(getContext(), phone, | ||
|
||
ApiConnectId.checkPhoneAvailable(getContext(), phone, | ||
new IApiCallback() { | ||
@Override | ||
public void processSuccess(int responseCode, InputStream responseData) { | ||
|
@@ -293,6 +294,12 @@ public void processSuccess(int responseCode, InputStream responseData) { | |
@Override | ||
public void processFailure(int responseCode, IOException e) { | ||
skipPhoneNumberCheck = false; | ||
if(responseCode==406){ | ||
skipPhoneNumberCheck = false; | ||
updateButtonEnabled(); | ||
binding.errorTextView.setVisibility(View.VISIBLE); | ||
binding.errorTextView.setText(getString(R.string.recovery_network_outdated)); | ||
} | ||
if (e != null) { | ||
Logger.exception("Checking phone number", e); | ||
} | ||
|
@@ -327,9 +334,6 @@ public void processOldApiError() { | |
} | ||
}); | ||
|
||
if (isBusy) { | ||
Toast.makeText(getContext(), R.string.busy_message, Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} | ||
case ConnectConstants.CONNECT_UNLOCK_ALT_PHONE_CHANGE -> { | ||
|
@@ -357,7 +361,7 @@ public void createAccount() { | |
binding.nameTextValue.getText().toString(), ""); | ||
|
||
final Context context = getActivity(); | ||
boolean isBusy = !ApiConnectId.registerUser(requireActivity(), tempUser.getUserId(), tempUser.getPassword(), | ||
ApiConnectId.registerUser(requireActivity(), tempUser.getUserId(), tempUser.getPassword(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate user credentials upon registration. |
||
tempUser.getName(), phoneNo, new IApiCallback() { | ||
@Override | ||
public void processSuccess(int responseCode, InputStream responseData) { | ||
|
@@ -407,10 +411,6 @@ public void processOldApiError() { | |
Toast.makeText(requireActivity(), R.string.recovery_network_outdated, Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
|
||
if (isBusy) { | ||
Toast.makeText(requireActivity(), R.string.busy_message, Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
|
||
private String generateUserId() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/org/commcare/network/connectId/network/ApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.commcare.network.connectId.network; | ||
|
||
import org.commcare.connect.network.ApiConnectId; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import okhttp3.Interceptor; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import okhttp3.logging.HttpLoggingInterceptor; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
|
||
///Todo retry part of the api fails | ||
|
||
public class ApiClient { | ||
private static final String BASE_URL = "https://connectid.dimagi.com"; // Replace with actual base URL | ||
private static final String API_VERSION = ApiConnectId.API_VERSION_CONNECT_ID; // Replace with actual version value | ||
|
||
private static Retrofit retrofit; | ||
|
||
public static Retrofit getClient() { | ||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); | ||
// set your desired log level | ||
logging.setLevel(HttpLoggingInterceptor.Level.BODY); | ||
if (retrofit == null) { | ||
OkHttpClient okHttpClient = new OkHttpClient.Builder() | ||
.addInterceptor(logging) | ||
.addInterceptor(new Interceptor() { | ||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request originalRequest = chain.request(); | ||
Request requestWithHeaders = originalRequest.newBuilder() | ||
.header("Accept", "application/json;version=" + API_VERSION) | ||
.build(); | ||
return chain.proceed(requestWithHeaders); | ||
} | ||
}) | ||
.connectTimeout(30, TimeUnit.SECONDS) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.writeTimeout(30, TimeUnit.SECONDS) | ||
.build(); | ||
|
||
retrofit = new Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build(); | ||
} | ||
return retrofit; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Android SDK 35 is not yet released, update required
The verification confirms that
compileSdk 35
is indeed used in bothapp/build.gradle
andcommcare-support-library/build.gradle
. As of January 2025, Android 14 (API 34) is the latest stable release, making SDK 35 an invalid configuration that will cause build failures.app/build.gradle
: Line containingcompileSdk 35
commcare-support-library/build.gradle
: Line containingcompileSdk 35
Both files need to be updated to use
compileSdk 34
to ensure compatibility with the latest stable Android SDK.🔗 Analysis chain
Verify Android SDK compatibility.
The project is configured to use
compileSdk 35
, but Android 14 (API 34) is the latest release. This might cause build issues or unexpected behavior.Consider updating the
compileSdk
version in the build configuration:Let me verify the Android SDK version configuration in the build files.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
Length of output: 302
💡 Codebase verification
The logging interceptor is currently unconditionally enabled with BODY level logging, which could expose sensitive information in production. The implementation in
app/src/org/commcare/network/connectId/network/ApiClient.java
needs to be updated to enable logging only in debug builds.ApiClient.java
to conditionally enable logging:🔗 Analysis chain
LGTM with a security consideration.
The Retrofit dependencies are appropriate for implementing type-safe HTTP client functionality. However, ensure that the OkHttp logging interceptor is only enabled in debug builds to prevent potential sensitive information leakage in production.
Run this script to verify if logging interceptor configuration exists in the codebase:
If no configuration is found, consider adding a debug-only configuration for the logging interceptor.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 88
Script:
Length of output: 655
Script:
Length of output: 800