All Projects → pranavpandey → dynamic-engine

pranavpandey / dynamic-engine

Licence: Apache-2.0 license
Monitor events in the background on Android.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to dynamic-engine

Monconn
A TCP connection monitoring tool written in Go.
Stars: ✭ 69 (+187.5%)
Mutual labels:  monitor, service
LockerScreen
Android lock screen,slide to unlock ! 安卓锁屏,上滑解锁,效果酷炫,值得拥有!
Stars: ✭ 81 (+237.5%)
Mutual labels:  service, lock
Quicklib
Quick development library (AutoMapper, LinQ, IOC Dependency Injection, MemoryCache, Scheduled tasks, Config, Serializers, etc) with crossplatform support for Delphi/Firemonkey (Windows,Linux,OSX/IOS/Android) and freepascal (Windows/Linux).
Stars: ✭ 274 (+1041.67%)
Mutual labels:  monitor, service
Remit
RabbitMQ-backed microservices supporting RPC, pubsub, automatic service discovery and scaling with no code changes.
Stars: ✭ 24 (+0%)
Mutual labels:  events, service
Samples
Community driven repository for Dapr samples
Stars: ✭ 104 (+333.33%)
Mutual labels:  events, service
homebridge-callmonitor
Signals incoming and outgoing calls using the call monitor facility in Fritz!Box devices via HomeKit
Stars: ✭ 25 (+4.17%)
Mutual labels:  monitor, call
Witness
Monitor file system events using Swift
Stars: ✭ 150 (+525%)
Mutual labels:  events, monitor
jetson-monitor
🚨 Jetson is an HTTP monitoring service used to notify by various messaging platforms such as Slack and Telegram
Stars: ✭ 45 (+87.5%)
Mutual labels:  monitor, service
focus-trap-vue
Vue component to trap the focus within a DOM element
Stars: ✭ 156 (+550%)
Mutual labels:  lock
gancio
a shared agenda for local communities (with activitypub support)
Stars: ✭ 21 (-12.5%)
Mutual labels:  events
Evilize
Parses Windows event logs files based on SANS Poster
Stars: ✭ 24 (+0%)
Mutual labels:  events
YappyGitHub
A github monitor bot for Discord
Stars: ✭ 64 (+166.67%)
Mutual labels:  monitor
optimistic lock coupling rs
🍋: A General Lock following paper "Optimistic Lock Coupling: A Scalable and Efficient General-Purpose Synchronization Method"
Stars: ✭ 21 (-12.5%)
Mutual labels:  lock
gitlit
A gui for Git LFS file locks
Stars: ✭ 14 (-41.67%)
Mutual labels:  lock
Alpine
Basic event system framework using functional interfaces
Stars: ✭ 79 (+229.17%)
Mutual labels:  events
tomodachi
💻 Microservice library / framework using Python's asyncio event loop with full support for HTTP + WebSockets, AWS SNS+SQS, RabbitMQ / AMQP, middleware, etc. Extendable for GraphQL, protobuf, gRPC, among other technologies.
Stars: ✭ 170 (+608.33%)
Mutual labels:  events
gl-bench
⏱ WebGL performance monitor with CPU/GPU load.
Stars: ✭ 146 (+508.33%)
Mutual labels:  monitor
jade
Asterisk based call center solution
Stars: ✭ 41 (+70.83%)
Mutual labels:  call
suchtube
🔍 📼 YouTube search as a service, with Slack integration and CLI
Stars: ✭ 25 (+4.17%)
Mutual labels:  service
uevloop
A fast and lightweight event loop for embedded platforms.
Stars: ✭ 61 (+154.17%)
Mutual labels:  events

Dynamic Engine

License Build Status Release

A collection of tasks to monitor various events including call, lock, headset, charging, dock and foreground app via service on Android 2.3 (API 9) and above.

Since v0.4.0, it uses 26.x.x support libraries so, minimum SDK will be Android 4.0 (API 14).
Since v2.0.0, it uses AndroidX so, first migrate your project to AndroidX.
Since v4.1.0, it is dependent on Java 8 due to the dependency on Dynamic Utils.


Contents


Installation

It can be installed by adding the following dependency to your build.gradle file:

dependencies {
    // For AndroidX enabled projects.
    implementation 'com.pranavpandey.android:dynamic-engine:4.3.1'

    // For legacy projects.
    implementation 'com.pranavpandey.android:dynamic-engine:1.3.0'
}

Usage

It is a collection of different tasks which can monitor various events by running a service in the background. Initially, it can monitor call, lock, headset, charging, dock and foreground app related events. I will do my best to add more tasks later.

For a complete reference, please read the documentation.

Special events

Extend the DynamicEngine service and implement the interface functions to monitor call, lock, headset, charging and dock related events.

On Android 6.0 (API 23) and above, READ_PHONE_STATE permission must be granted for the app package to monitor call events. If this permission is not granted then, onCallStateChange(isCall) method will never be called. For more information on the runtime permissions, please read official documentation here.

public class MonitorService extends DynamicEngine {

    ...
    
    /**
     * This method will be called on initializing the service so that we can get the current
     * charging, headset and dock state.
     *
     * @param charging {@code true} if the device is charging or connected to a power source.
     * @param headset {@code true} if the device is connected to a headset or a audio output
     *                device.
     * @param docked {@code true} if the device is docked.
     */
    @Override
    public void onInitialize(boolean charging, boolean headset, boolean docked) {
        super.onInitialize(charging, headset, docked);

        // TODO: Do any work here.        
    }

    /**
     * This method will be called when call state is changed. 
     * Either on call or the device is idle.
     *
     * @param call {@code true} if the device is on call.
     *             Either ringing or answered.
     */
    @Override
    public void onCallStateChange(boolean call) {
        super.onCallStateChange(call);

        // TODO: Do any work here.        
    }

    /**
     * This method will be called when screen state is changed. 
     * Either the device screen is off or on.
     *
     * @param screenOff {@code true} if the device screen is off.
     */
    @Override
    public void onScreenStateChange(boolean screenOff) {
        super.onScreenStateChange(screenOff);

        // TODO: Do any work here.        
    }

    /**
     * This method will be called when lock state is changed. 
     * Either the device is in the locked or unlocked state independent of the PIN, 
     * password or any other security lock.
     *
     * @param locked {@code true} if the device is in the locked state or the lock screen is shown.
     */
    @Override
    public void onLockStateChange(boolean locked) {
        super.onLockStateChange(locked);

        // TODO: Do any work here.        
    }

    /**
     * This method will be called when headset state is changed. 
     * Either the device is connected to a audio output device or volume is routed through 
     * the internal speaker.
     *
     * @param connected {@code true} if the device is connected to a headset or a audio output
     *                  device.
     */
    @Override
    public void onHeadsetStateChange(boolean connected) {
        super.onHeadsetStateChange(connected);

        // TODO: Do any work here.        
    }

    /**
     * This method will be called when charging state is changed. 
     * Either the device is connected to a power source using the battery.
     *
     * @param charging {@code true} if the device is charging or connected to a power source.
     */
    @Override
    public void onChargingStateChange(boolean charging) {
        super.onChargingStateChange(charging);

        // TODO: Do any work here.        
    }

    /**
     * This method will be called when dock state is changed. 
     * Either the device is docked or not.
     *
     * @param docked {@code true} if the device is docked.
     */
    @Override
    public void onDockStateChange(boolean docked) {
        super.onDockStateChange(docked);

        // TODO: Do any work here.  
    }
    
    ...
}

Foreground app

It can be used to monitor the foreground app to perform actions based on it. It is currently in beta stage so, more improvements will be done in the future.

It will not run by default to save resources. It should be started explicitly by calling the setAppMonitorTask(running).

On Android 5.0 (API 21) and above, PACKAGE_USAGE_STATS permission must be granted for the app package to monitor foreground app. If this permission is not granted then, onAppChange(dynamicAppInfo) method will never be called. For more information on UsageStatsManager, please read the official documentation here.

public class MonitorService extends DynamicEngine {

    ...
    
    /**
     * Enable or disable the foreground app monitor task.
     *
     * @param running {@code true} to start monitoring the foreground app and receive
     *                listener callback.
     */
    setAppMonitorTask(boolean running);
    
    ...
    
    /**
     * This method will be called when foreground app is changed. 
     * Use it to provide the app specific functionality in the app.
     *
     * @param dynamicAppInfo The dynamic app info of the foreground package.
     */
    @Override
    public void onAppChange(@Nullable DynamicAppInfo dynamicAppInfo) {
        super.onAppChange(dynamicAppInfo);

        // TODO: Do any work here.
    }
    
    ...
}

Package state

It can be used to monitor app updates or new installs.

public class MonitorService extends DynamicEngine {

    ...
    
    /**
     * This method will be called when an app package is added or changed. 
     * Useful to show a notification if an app is updated or a new app is installed.
     *
     * @param dynamicAppInfo The dynamic app info of the updated or added package.
     * @param newPackage {@code true} if the package is newly added.
     */
    @Override
    public void onPackageUpdated(@Nullable DynamicAppInfo dynamicAppInfo, boolean newPackage) {
        // TODO: Do any work here.
    }

    /**
     * This method will be called when an app package is removed. 
     * Useful to show some work when a package is removed.
     *
     * @param packageName The package which was removed.
     */
    @Override
    public void onPackageRemoved(@Nullable String packageName) {
        // TODO: Do any work here.
    }
    
    ...
}

Events priority

It can be used to manage priority of the different events in case two or more events will occur simultaneously. Use DynamicPriority class to set or retrieve events priority.

public class DynamicPriority {
    
    ...

    /**
     * Default priority for the events.
     *
     * 1. Call (highest)
     * 2. Lock
     * 3. Headset
     * 4. Charging
     * 5. Dock
     * 6. App (lowest)
     */
    
    /**
     * Save events priority.
     *
     * @param context The context to get shared preferences.
     * @param eventsPriority ArrayList containing events priority.
     */
    public static void saveEventsPriority(@NonNull Context context, 
        @NonNull ArrayList<String> eventsPriority);
    
    /**
     * Get saved events priority after checking the device for telephony and per app 
     * functionality.
     *
     * @param context The context to get shared preferences.
     *
     * @return The saved events priority.
     */
    public static @NonNull ArrayList<String> getEventsPriority(@NonNull Context context);
    
    /**
     * Reset events priority to default.
     *
     * @param context The context to get shared preferences.
     */
    public static void resetPriority(@NonNull Context context);
    
    ...

}

DynamicEngine has some useful functions to perform operations based on the events priority.

public abstract class DynamicEngine {
    ...
    
    /**
     * Retrieve the current ongoing events.
     *
     * @return The list of current ongoing events.
     */
    protected @NonNull ArrayList<String> getCurrentEvents();
    
    /**
     * Get the event with highest priority.
     *
     * @return The highest priority event that has been occurred.
     */
    protected @DynamicEvent String getHighestPriorityEvent();

    ...
}

Accessibility

It has support for accessibility service to provide a better experience. It also provides more accurate results when detecting the foreground app.

Dependency

It depends on the dynamic-utils to perform various internal operations. So, its functions can also be used to perform other useful operations.


Apps using Dynamic Engine

Please email me if you are using this library and want to feature your app here. Also, please checkout the Rotation app to experience the full potential of this library.


Author

Pranav Pandey

GitHub Follow on Twitter Donate via PayPal


License

Copyright 2017-2022 Pranav Pandey

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].