clevertap-android-sdk icon indicating copy to clipboard operation
clevertap-android-sdk copied to clipboard

Task/sdk 3925/strict mode violations

Open Anush-Shand opened this issue 9 months ago • 1 comments

https://wizrocket.atlassian.net/browse/SDK-3925

Anush-Shand avatar Mar 25 '25 06:03 Anush-Shand

[!IMPORTANT]

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • \b(master|main|develop)(_\w*)?

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This set of changes refactors the handling of file and in-app notification resources, context usage, and device information retrieval in the CleverTap Android SDK. It introduces singleton access patterns for FileResourceProvider, replaces direct dependency injection with provider functions, and shifts synchronous operations such as frequency cap checks and resource cleanup to asynchronous execution using executors or coroutines. Device information retrieval is consolidated and modernized for newer Android APIs. Network requests are now tagged for traffic statistics. Test code is updated to accommodate these refactors, and sample app logic is modified to use asynchronous preference handling and updated in-app notification controls.

Changes

File(s) / Path(s) Change Summary
CleverTapAPI.java Reordered logic in instanceWithConfig; added @WorkerThread annotations to resource-clear methods.
CleverTapFactory.kt Asynchronous initialization of FileResourceProvider; removed direct passing to VarCache and InAppController.
DeviceInfo.java, MockDeviceInfo.kt Refactored device dimension/DPI retrieval into a consolidated method/class; removed pixel getter methods; updated tests accordingly.
InAppFCManager.java Made impression recording/count increment asynchronous via IO executor.
InAppController.java Refactored in-app notification display logic: frequency cap checks are now asynchronous; removed direct FileResourceProvider field and parameter; updated related methods to instance methods.
VarCache.java, CTVariablesTest.kt, ParserTest.kt, VarCacheTest.kt Removed direct FileResourceProvider dependency; now uses singleton; file cache checks and callbacks are asynchronous; updated tests for constructor changes and mocking.
FileResourceProvider.kt Introduced thread-safe singleton pattern via getInstance.
FileCleanupStrategy.kt, FileCleanupStrategyCoroutine.kt, FileCleanupStrategyExecutors.kt, Changed fileResourceProvider from direct instance to provider function; updated usage accordingly.
FilePreloaderStrategy.kt, FilePreloaderCoroutine.kt, FilePreloaderExecutors.kt Changed fileResourceProvider from direct instance to provider function; updated usage accordingly.
FileResourcesRepoFactory.kt Passes lambda for provider function instead of direct instance to strategies.
CTInAppBaseFragment.java Removed provider field; now always uses singleton FileResourceProvider.
CTInAppNotification.java Removed empty didDismiss(FileResourceProvider) method.
BitmapDownloader.kt, UrlConnectionHttpClient.kt Added Android TrafficStats tagging for network requests.
MediaPlayerRecyclerView.kt, HomeScreenFragment.kt Changed context usage from application context to direct context.
HomeScreenActivity.kt Refactored preference checks and writes to be asynchronous using coroutines; extracted dialog logic.
FileVarsData.kt Commented out variable value appending in log output.
HomeScreenModel.kt Updated in-app and file type variable lists.
HomeScreenViewModel.kt Replaced event pushes with direct in-app notification control methods; added file resource clearing command.
Test files: FileCleanupStrategyCoroutineTest.kt, FileCleanupStrategyExecutorsTest.kt, Updated to use provider functions for FileResourceProvider; added/updated tests for empty lists; switched from Mockito to MockK in some cases.
FilePreloaderCoroutineTest.kt, FilePreloaderExecutorsTest.kt Updated to use provider function for FileResourceProvider.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant InAppController
    participant InAppFCManager
    participant Listener
    participant FileResourceProvider

    UI->>InAppController: displayNotification()
    InAppController->>InAppFCManager: canShow() (async)
    InAppFCManager-->>InAppController: result (via callback)
    alt Can show
        InAppController->>Listener: beforeShow()
        alt Listener approves
            InAppController->>FileResourceProvider: getInstance()
            InAppController->>UI: showInApp()
        else Listener rejects
            InAppController->>UI: skip in-app
        end
    else Cannot show
        InAppController->>UI: skip in-app
    end

Possibly related PRs

  • #763: Refactors DeviceInfo.java for window size/DPI retrieval, directly related to similar changes here.
  • #770: Changes context usage in MediaPlayerRecyclerView, matching context refactor in this PR.
  • #776: Refactors FileResourceProvider initialization and usage, directly related to the singleton/provider pattern introduced here.

Suggested labels

ptv2.0.0

Suggested reviewers

  • piyush-kukadiya
  • CTLalit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 25 '25 06:03 coderabbitai[bot]

@coderabbitai review

CTLalit avatar Apr 15 '25 11:04 CTLalit

:white_check_mark: Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Apr 15 '25 11:04 coderabbitai[bot]