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

task(SDK-4057) - Revamped Timer Notification Template #682

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

Anush-Shand
Copy link
Contributor

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

  • The idea is such that the timer notification shown will be the compulsory FGS notification
  • The existing implementation has been used to prepare the notification builder for the timer template
  • If the service is not declared in the manifest, then the older approach is used to render the timer notification

@Anush-Shand Anush-Shand marked this pull request as ready for review November 12, 2024 09:02
Comment on lines 5 to 6
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to ask clients to put this permission as it might have some compliances on playstore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @CTLalit - this should be mentioned in the docs and needs to be optional. All the code related to FGS should be with a permission check with all cases handled properly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
Most SDK's are using these permissions and they are not as critical as like an AlarmManager, it was merged by default in the final manifest

Moving it to the app to be safe

@Anush-Shand
Copy link
Contributor Author

@darshanclevertap @piyush-kukadiya @CTLalit
Another caveat here is that Android enforces that a FGS must call startForeground within 5s https://stackoverflow.com/questions/44425584/context-startforegroundservice-did-not-then-call-service-startforeground/72754189#72754189

  • Image download can take time for a notification and hence this might lead to a crash

Options

  • Call startForeground with a placeholder notification and update/dismiss it after notification builder for timer template has been generated
  • Timebound notification builder for timer template to 4s. If it fails, skip the notification, call startForeground() and stopSelf()

@darshanclevertap
Copy link
Collaborator

@Anush-Shand - My suggestion is to go with option 1 - Call startForeground with a placeholder notification and update/dismiss it after the notification builder for the timer template has been generated.

Placeholders can have the title & message while the image & timer loads. Once the image loads, we have the notification ID to update the notification. If you could share a demo video of this on Slack, it would help.

Option 2 is risky because if some delay happens more than 4s, the app will crash. See the 2nd comment here -> https://stackoverflow.com/a/45047542/8301966

Bundle extras) {
CleverTapInstanceConfig config = coreState.getConfig();
try {
synchronized (coreState.getPushProviders().getPushRenderingLock()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid locking if there is only one push provider available?

Copy link

coderabbitai bot commented Jan 20, 2025

Important

Review skipped

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

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.


🪧 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. (Beta)
  • @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.

try {
synchronized (coreState.getPushProviders().getPushRenderingLock()) {
config.getLogger().verbose(config.getAccountId(),
"returning push on caller thread with id = " + Thread.currentThread().getId());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe print if its main thread.

Comment on lines +177 to +179
if (nb != null) {
return nb;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are masking the logic behind a nullable NotificationBuilder return method, ideally check from data itself if we should short circuit.

Comment on lines +234 to +235
baseDatabaseManager.loadDBAdapter(context)
.storeUninstallTimestamp();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might cause lag on main thread, confirm that is not happening.

.storeUninstallTimestamp();
String pingFreq = extras.getString("pf", "");
if (!TextUtils.isEmpty(pingFreq)) {
updatePingFrequencyIfNeeded(context, Integer.parseInt(pingFreq));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer.parseInt can throw, make sure it is handled.

Comment on lines +57 to +59
return ManifestValidator.isComponentPresentInManifest(applicationContext, "com.clevertap.android.pushtemplates.TimerTemplateService", ManifestValidator.ComponentType.SERVICE)
&& templateType == TemplateType.TIMER
&& areRevampedTimerTemplatePermissionsGranted(applicationContext);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templateType == TemplateType.TIMER can be first condition so short circuit happens without much computation

}

val intent = Intent(context, TimerTemplateService::class.java)
context.stopService(intent)
}, (delay - 100).toLong())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets see if we can solve for not using such a code in this task.

Comment on lines +20 to +24
val cleverTapAPI = CleverTapAPI.getGlobalInstance(
this@TimerTemplateService,
PushNotificationUtil.getAccountIdFromNotificationBundle(message)
)
val config: CleverTapInstanceConfig? = cleverTapAPI?.coreState?.config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we run this code inside the task itself?

Comment on lines 60 to +68
<meta-data
android:name="CLEVERTAP_ACCOUNT_ID"
android:value="YOUR ACCT ID" />
android:value="TEST-4RW-944-876Z" />
<meta-data
android:name="CLEVERTAP_TOKEN"
android:value="YOUR ACCT TOKEN" />
android:value="TEST-44c-024" />
<meta-data
android:name="CLEVERTAP_REGION"
android:value="YOUR ACCT REGION"/>
android:value="eu1" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete these details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants