Git Product home page Git Product logo

venom's Introduction

Venom

Venom is a lightweight tool that simplifies testing of the process death scenario for your android application.

🎞️ Click to show the preview…

Why Venom?

The Android Run Time aggressively manages its resources and occasionally terminates background applications while the user is away interacting with other apps. In such a case, all the activities are destroyed along with application scope objects and background tasks.

When the user relaunches the app, the top stack activity is restored from the saved instance state. Knowing this, your applications should always present a consistent interface and be tested against the process death scenario.

Venom makes it possible to kill the app process from the notification drawer making the testing easier and more straightforward versus the traditional ways like setting the background processes limit in Developer Options or using the stop process button in Android Studio, especially for a QA team.

Setup

The setup is pretty simple:

  1. Initialize the library in Application.onCreate:
val venom = Venom.createInstance(this)
venom.initialize()
  1. Call start/stop whenever you need:
venom.start()
// or
venom.stop()

See the sample app for an example.

Customize the notification

Use the builder to customize the notification:

val notification = NotificationConfig.Builder(this)
    .buttonCancel(R.string.venom_notification_button_cancel_override)
    .buttonKill(getString(R.string.venom_notification_button_kill_override))
    .buttonRestart(getString(R.string.venom_notification_button_restart_override))
    .build()   
venom.initialize(notification)

Notification Permission

Android 13 has introduced a new runtime permission POST_NOTIFICATIONS which is required to display any kind of notifications including ones for foreground services. Note that this permission is required for Venom to function properly.

Venom doesn't manage the notification permission on your behalf to keep the library flexible. Please, see an example of handling that in the sample app.

Download

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    debugImplementation "com.github.YarikSOffice.Venom:venom:0.7.1"
    releaseImplementation "com.github.YarikSOffice.Venom:venom-no-op:0.7.1"
}

License

The MIT License (MIT)

Copyright 2020 Yaroslav Berezanskyi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

venom's People

Contributors

ivkil avatar simonmarquis avatar skyyo avatar tfcporciuncula avatar ustav avatar yariksoffice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

venom's Issues

Expose isActive state

Venom uses its own SharedPreferences file to store its active state: VenomPreferenceManager.kt.
Unfortunately this state is private and leads to some issues.
For instance, suppose my app is bundled with a dedicated debug panel where you can toggle features.
There is currently no way (other than hardcoding the same SharedPreferences file name and key) to sync with Venom internal state.
Disabling Venom with the cancel notification action will not change the host setting, and vice-versa. Which means that, when the app is later re-started, my host will try to start Venom again.
It would be great to allow the host to get, or even set this internal state. Maybe setActive/isActive isn't the right wording for that.

Possible to kill process but not auto restart?

This would an ideal tool for our QA team for testing events that happen after the process has been destroyed. Things like handling push notifications that trigger a cold start for instance.

When I kill process, it auto restarts. Is there a way to block the restart part of it?

Update README.md to match current release

And showcase the new kill vs restart feature.

  • notification screenshot (and gif)
  • code snippet for the configuration
  • detail effects of both actions

Do you need some help to update those elements?

In Android 14 system throws an exception for Venom Service

In Android 14 on init of Venom Service system throws an exception:
java.lang.RuntimeException: Unable to create service com.github.venom.service.VenomService: android.app.MissingForegroundServiceTypeException: Starting FGS without a type ... targetSDK=34

https://developer.android.com/about/versions/14/changes/fgs-types-required
If your app targets Android 14, it must specify appropriate foreground service types.

Like in example

      <service
          android:name=".MyMediaPlaybackService"
          android:foregroundServiceType="mediaPlayback"
          android:exported="false">
      </service>

I created a pull request with a fix #51

Using venom results in "App keeps stopping" dialog

I keep getting a "RollerToaster keeps stopping" dialog even though my app is closed. I also don't see venom in the notication tray. I believe I hit the "cancel" button in the notifaction tray.

Now like every minute or so I get this dialog, so I looked in logout. I have this same stacktrace over and over and over.

2022-01-26 22:46:51.785 17245-17245/com.rollertoaster.app.free E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.rollertoaster.app.free, PID: 17245
    java.lang.RuntimeException: Unable to create application com.rollertoaster.app.MyApplication: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.rollertoaster.app.free/com.github.venom.service.VenomService
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6730)
        at android.app.ActivityThread.access$1500(ActivityThread.java:247)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7839)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
     Caused by: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.rollertoaster.app.free/com.github.venom.service.VenomService
        at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
        at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
        at android.os.Parcel.readParcelable(Parcel.java:3333)
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2420)
        at android.os.Parcel.createException(Parcel.java:2409)
        at android.os.Parcel.readException(Parcel.java:2392)
        at android.os.Parcel.readException(Parcel.java:2334)
        at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:5971)
        at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1847)
        at android.app.ContextImpl.startForegroundService(ContextImpl.java:1823)
        at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:779)
        at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:931)
        at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:703)
        at com.github.venom.service.ServiceDelegate.startService(ServiceDelegate.kt:12)
        at com.github.venom.Venom.start(Venom.kt:61)
        at com.github.venom.Venom.initialize(Venom.kt:52)
        at com.github.venom.Venom.initialize$default(Venom.kt:49)
        at com.github.venom.Venom.initialize(Unknown Source:2)
        at com.rollertoaster.app.MyApplication.onCreate(MyApplication.java:388)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1211)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6725)
        at android.app.ActivityThread.access$1500(ActivityThread.java:247) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7839) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
     Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:691)
        at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:616)
        at com.android.server.am.ActivityManagerService.startService(ActivityManagerService.java:11850)
        at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2519)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2498)
        ```

Can we do anything about it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.