-
Notifications
You must be signed in to change notification settings - Fork 1
Improved fallback mechanism when user is not using hilt/dagger #43
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef5ccdf
Improved fallback mechanism when user is not using hilt/dagger
mrajatttt 45295d9
Update ci.yml
mrajatttt ac161f2
Update ci.yml with artifact version
mrajatttt c08b820
fixed failing unit tests
mrajatttt 488a2db
Update semgrep.yaml
mrajatttt 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -36,32 +36,50 @@ object ChatSessionProvider { | |
} | ||
} | ||
|
||
// Private method to initialize ChatSession using Hilt or manual fallback | ||
private fun initializeChatSession(context: Context): ChatSession { | ||
return if (isHiltAvailable()) { | ||
// Use Hilt's EntryPoint mechanism if Hilt is available | ||
val entryPoint = EntryPointAccessors.fromApplication( | ||
context.applicationContext, | ||
ChatModule.ChatSessionEntryPoint::class.java | ||
) | ||
entryPoint.getChatSession() | ||
} else { | ||
// Fallback to manual initialization | ||
createChatSessionManually(context) | ||
} | ||
} | ||
|
||
// Method to check if Hilt is available | ||
private fun isHiltAvailable(): Boolean { | ||
return try { | ||
Class.forName("dagger.hilt.EntryPoints") | ||
// Check for the presence of Hilt's core class | ||
val hiltClass = Class.forName("dagger.hilt.android.EntryPointAccessors") | ||
SDKLogger.logger.logDebug { "Hilt detected: $hiltClass" } | ||
true | ||
} catch (e: ClassNotFoundException) { | ||
SDKLogger.logger.logDebug {"Hilt is not available"} | ||
SDKLogger.logger.logDebug { "Hilt is not available: ${e.message}" } | ||
false | ||
} catch (e: Exception) { | ||
// Catch any unexpected issues during class detection | ||
SDKLogger.logger.logDebug { "Error while checking Hilt availability: ${e.message}" } | ||
false | ||
} | ||
} | ||
|
||
private fun initializeChatSession(context: Context): ChatSession { | ||
return try { | ||
if (isHiltAvailable()) { | ||
SDKLogger.logger.logDebug { "Attempting Hilt-based ChatSession initialization." } | ||
val entryPoint = EntryPointAccessors.fromApplication( | ||
context.applicationContext, | ||
ChatModule.ChatSessionEntryPoint::class.java | ||
) | ||
entryPoint.getChatSession().also { | ||
SDKLogger.logger.logDebug { "ChatSession initialized using Hilt." } | ||
} | ||
} else { | ||
SDKLogger.logger.logDebug { "Hilt not available. Falling back to manual initialization." } | ||
createChatSessionManually(context).also { | ||
SDKLogger.logger.logDebug { "ChatSession initialized manually." } | ||
} | ||
} | ||
} catch (e: Exception) { | ||
// Handle unexpected errors during initialization | ||
SDKLogger.logger.logDebug { "Error initializing ChatSession: ${e.message}" } | ||
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. Is this as debug statement correct? 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. Yes we aim to print it as a debug which won't interrupt the flow |
||
SDKLogger.logger.logDebug { "Falling back to manual initialization due to error." } | ||
createChatSessionManually(context).also { | ||
SDKLogger.logger.logDebug { "ChatSession initialized manually after Hilt failure." } | ||
} | ||
} | ||
} | ||
|
||
// Manual initialization of ChatSession for non-Hilt users | ||
private fun createChatSessionManually(context: Context): ChatSession { | ||
val appContext = context.applicationContext | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
sdkVersion=1.0.5 | ||
sdkVersion=1.0.6 | ||
groupId=software.aws.connect | ||
artifactId=amazon-connect-chat-android |
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.
why this is logged as Debug not err ?