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

Support service processes #69

Merged
merged 6 commits into from
Mar 25, 2024
Merged

Support service processes #69

merged 6 commits into from
Mar 25, 2024

Conversation

jobhh
Copy link
Contributor

@jobhh jobhh commented Feb 29, 2024

Fixes #24

What was done per commit:

  1. Move the PhoenixActivity code into a separate (Kotlin) class.
  2. Migrate ProcessPhoenix class to Kotlin.
  3. Add triggerRebirth(Context, Class<?>) with Service rebirth support and triggerServiceRebirth(Context, Intent).
  4. Change from Service to IntentService and remove NotificationBuilder from library.
  5. Some cleanup.
  6. Added Service support to the existing triggerRebirth(context, vararg nextIntents) function.

The ProcessPhoenix class is now Kotlin, but all public functions are annotated with @JvmStatic.
If this is undesired I can implement it in Java, but since Kotlin is my preference I started like this.

I changed from Service to IntentService (in commit 4) because this also seemed to be functional and IntentService's are meant to be short-lived, which the PhoenixService certainly is.

The sample has been updated to allow a easy test of this functionality.

One important side-node (which is also mentioned in the Service classes):
Restarting a Service multiple times will result in an increasingly long delay between restart times. Android seems to register the restart of this service as a crashed service and probably doesn't want to infinitely restart a crashing service, so that makes sense.
The increasing delay periods seem to follow the pattern: 4^x, with x being the restart attempt minus 1. I observed 1s, 4s, 16s, 64s, 256s and 1024s on the Zebra Android 11 device i used to test.

@JakeWharton
Copy link
Owner

Thanks, but I would prefer to keep the library written in Java. Believe me, I love Kotlin as much as the next person, but this library doesn't really need it and I'd rather not bother with it at this point. Your change is the biggest the library has seen in like a decade, and I doubt anyone will add anything for another decade once this lands.

@jobhh
Copy link
Contributor Author

jobhh commented Mar 1, 2024

Alrighty, Java it is :)

Any feedback?

@JakeWharton
Copy link
Owner

I didn't review the implementation, but will today.

@jobhh
Copy link
Contributor Author

jobhh commented Mar 1, 2024

Cool, no hurry. Let me know if anything needs to change.

* <p>
* Behavior of the current process after invoking this method is undefined.
*/
public static void triggerRebirth(Context context, Class<?> targetClass) {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't really like this from an API design standpoint. I cannot imagine the case where you have either an activity or a service and need to call some general-purpose method to recreate it. Chances are you know what you have at the call-site. Someone that actually doesn't know can write the assignable check themselves.

If we want to offer Class-accepting methods then we can overload the specific methods with Class<? extends Activity> and Class<? extends Service>.

Copy link
Contributor Author

@jobhh jobhh Mar 19, 2024

Choose a reason for hiding this comment

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

I based this on your input here: #24 (comment)

But, I do agree :) The caller should know whether an Activity or Service is to be restarted when they call this method.

Copy link
Owner

Choose a reason for hiding this comment

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

Ahaha ouch. Bad 7-year-ago Jake!

sample/src/main/AndroidManifest.xml Outdated Show resolved Hide resolved
jobhh and others added 3 commits March 19, 2024 09:12
# Conflicts:
#	process-phoenix/src/main/java/com/jakewharton/processphoenix/ProcessPhoenix.java
#	sample/src/main/java/com/jakewharton/processphoenix/sample/MainActivity.java
@jobhh
Copy link
Contributor Author

jobhh commented Mar 20, 2024

@JakeWharton The triggerRebirth(Context context, Intent... nextIntents) method already existed in previous versions, but it also added an Activity vs Service check in this pull request.

I've now removed these checks and opted to keep the previously existing methods Activity-only and add methods like triggerServiceRebirth(Context context, Intent nextIntent) for Service restarting.

Would this be ok?

@jobhh jobhh force-pushed the trunk branch 2 times, most recently from b6f9097 to 15440fd Compare March 20, 2024 13:33
@JakeWharton JakeWharton merged commit 21907fb into JakeWharton:trunk Mar 25, 2024
1 check passed
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.

Restart only service process.
2 participants