Android service daemon ,keep background service alive

Overview

安卓后台保活2021新姿势

适配华为大部分系列手机,vivo,OPPO 部分机型,小米的不支持,可见小米在对抗后台自保上做得最好
本项目原本是给某个公司合作开发的,最后给了对方SDK之后由于付款问题闹得很郁闷,想着这个代码拿在自己手上也没用,就发出来给大家参考参考。目前分析的结果来看,这个是全网目前还能使用的保活方案,曝光之后很有可能活不到明年,如果你的公司恰好使用了这种方案,那么是时候开始研究新的方案了。最后说一下这种想白拿的公司,说实话我不是靠Android技术谋生的,最多就少了点零花钱,但是这个方案被封之后,你还有多少个机会白拿?

原理

安卓后台保活前前后后网上出了好多公开的方案,但是到目前为止(2021年5月),还能广泛使用的并没有,我通过了研究了一下网上几个大厂的APP(APP名字就不点名了),整理实现了这个方案
虽然本方案看似集成了好几个保活的方案,比如一像素,JOB,等等,但是对于新版本android真正起作用的还是双进程守护。双进程守护的代码网上一搜一大堆,但是自己试过就知道了,现在的很多ROM已经封杀了这个方案,那些代码只能在原生系统上玩玩。 这里大概说一下双进程守护的逻辑,同时启动A进程和B进程,相互守护,检测到对方退出就再次启动对方,大部分公开的方案都是使用startservice启动,网上有好几个改进版,甚至有的都在native层自己实现和service manger的通信逻辑来启动服务,为的就是能在被杀时候第一时间再次启动。但是,改到native层也没有用,现在大部分rom已经封杀了startservice,我大概研究了下样本,发现样本使用的是startInstrumentation来启动进程,对于Instrumentation不了解的同学可以自行百度。 所以只需要在MarsDaemon基础上做一下小改动即可:

@Override
    public void onDaemonDead() {
        Log.d(TAG, "on daemon dead!");
        if (startServiceByAmsBinder()) {

            int pid = Process.myPid();
            Log.d(TAG, "mPid: " + mPid + " current pid: " + pid);
            Daemon.context.startInstrumentation(mApp,null,null);
            android.os.Process.killProcess(mPid);
        }
    }

2步集成使用

1、 打开library的AndroidManifest.xml找 如下位置:

        android:name="com.daemon.DInstrumentation"
        android:targetPackage="com.daemonLibrary.demo"
        android:targetProcesses="com.daemonLibrary.demo,com.daemonLibrary.demo:service" />
<application>

将包名替换成自己的包名

2、在app的Application中添加启动代码,并实现配置接口和回调接口

override fun attachBaseContext(base: Context?) {
       super.attachBaseContext(base)
       //DaemonLog.d("Application onCrearte")
       Daemon.startWork(this, DaemonConfigurationImplement(this), DaemonCallbackImplement())
}
You might also like...

Repository to keep up with ViaVersion on MCP (Originally from https://github.com/LaVache-FR/ViaMCP)

ViaMCP-Reborn Repository to keep up with ViaVersion on MCP (Originally from https://github.com/LaVache-FR/ViaMCP) 1.7.x Protocols Yes, i know they are

Dec 28, 2022

We keep evolving™

NOTICE This repository contains the public FTC SDK for the Freight Frenzy (2021-2022) competition season. Welcome! This GitHub repository contains the

Oct 2, 2021

🍬A set of tools that keep Java sweet.

🍬A set of tools that keep Java sweet.

🍬 A set of tools that keep Java sweet. 👉 https://hutool.cn/ 👈 🌎 English Documentation 📚 简介 Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Ja

Dec 30, 2022

100 Days of Code Learning program to keep a habit of coding daily and learn things at your own pace with help from our remote community.

100 Days of Code Learning program to keep a habit of coding daily and learn things at your own pace with help from our remote community.

100 Days of Code Learning program to keep a habit of coding daily and learn things at your own pace with help from our remote community.

Dec 30, 2022

PronounMC is a Minecraft plugin designed to make it easier to keep track of pronouns.

PronounMC PronounMC is a Minecraft plugin designed to make it easier to keep track of pronouns. Supported pronouns He She They It Any Other Ask Userna

Dec 10, 2022

Angular Final Assignment - Keep Note frontend

Angular Final Assignment - Keep Note frontend Objective The Objective of this level of Keep is to cover the following areas : Components Design Compon

Jan 29, 2022

KeepMyPassword for Desktop - keep your passwords locally and secure.

KeepMyPassword for Desktop - keep your passwords locally and secure.

KeepMyPassword is an open-source project under MIT license. Its aim is to provide a REAL secure place to store all your sensitive data. Everything is stored locally on your device. No one apart from YOU will ever have access to your passwords. Code is available to see whenever you need it.

Dec 15, 2022

Keep up to date with your legal speedrunning mods!

ModCheck Keep up to date with your legal speedrunning mods! If you are just starting out, you can use this to download all legal mods! Or, you can use

Apr 10, 2022

Sidekick is a live application debugger that lets you troubleshoot your applications while they keep on running

Sidekick is a live application debugger that lets you troubleshoot your applications while they keep on running

Explore Docs » Quick Start Tutorial » Table of Contents What is Sidekick? Sidekick Actions Why Sidekick? Features Who should use Sidekick? How does Si

Jan 6, 2023

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.

pact-jvm JVM implementation of the consumer driven contract library pact. From the Ruby Pact website: Define a pact between service consumers and prov

Dec 31, 2022

A service that executes binaries for Kodi's addon Elementum on Android without a W^X violation.

ElementumService A service that executes binaries for Kodi's addon Elementum on Android without a W^X violation. Download Use source https://StefanIlc

Dec 31, 2022

This is an open source android based Music Player application developed in Android Studio

This is an open source android based Music Player application developed in Android Studio

Pulse Music An offline music player android app, with modern UI and powerful features If you liked this repo, fork it and leave a STAR. Your support m

Apr 11, 2022

🌄 Image editor using native modules for iOS and Android. Inherit from 2 available libraries, Brightroom (iOS) and PhotoEditor (Android)

🌄 Image editor using native modules for iOS and Android. Inherit from 2 available libraries, Brightroom (iOS) and PhotoEditor (Android)

React Native Photo Editor (RNPE) 🌄 Image editor using native modules for iOS and Android. Inherit from 2 available libraries, Brightroom (iOS) and Ph

Jan 4, 2023

SceneView is a 3D/AR Android View with ARCore and Google Filament. This is the newest way to make your Android 3D/AR app.

SceneView is a 3D/AR Android View with ARCore and Google Filament This is Sceneform replacement Features Use SceneView for 3D only or ArSceneView for

Jan 4, 2023

This app brings Privacy dashboard features from Android 12 to older android devices.

This app brings Privacy dashboard features from Android 12 to older android devices.

PrivacyDashboard This app brings Privacy dashboard features from Android 12 to older android devices. Have you ever thought which apps are accessing y

Jan 7, 2023

Share food-Android- - Food donation coded in native android with firebase, google maps api and php server xampp

Share food-Android- - Food donation coded in native android with firebase, google maps api and php server xampp

share_food-Android- Instructions: 1. Create a firebase account and link it with the project via google-services.json. 2. This project also uses a XAMP

Dec 28, 2021

CodeLocator is a toolset that includes Android SDK and Android Studio plugins

CodeLocator is a toolset that includes Android SDK and Android Studio plugins

CodeLocator is a toolset that includes Android SDK and Android Studio plugins. It has the following functions(Support Mac Only):

Jan 5, 2023

Cordova plugin for Android Serial USB communication (easily connect an Arduino board to an Android device).

PR-DC cordova-plugin-serialusb Cordova plugin for Android Serial USB communication. This plugin makes a connection to the external board trivial, for

May 8, 2022

Simple Android app during a coding night. Just Learning Firebase and Android

Simple Android app during a coding night. Just Learning Firebase and Android

KUI-App Simple Android app during a coding night. Just Learning Firebase and Android What we learned: Some basics of Android Basic setup of Firebase:

Aug 28, 2022
Owner
null
A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Square 41k Jan 5, 2023
Dynamic Daemon Node for instancing of Minecraft Servers.

DashDynamicDaemon DashDynamicDaemon: A Sharded Minecraft Server hosting system. Purpose This system was originally created to host automatically scala

BattleDash 4 Apr 25, 2022
Govern Service is a lightweight, low-cost service registration, service discovery, and configuration service SDK.

Govern Service is a lightweight, low-cost service registration, service discovery, and configuration service SDK. By using Redis in the existing infrastructure (I believe you have already deployed Redis), it doesn’t need to bring extra to the operation and maintenance deployment. Cost and burden. With the high performance of Redis, Govern Service provides ultra-high TPS&QPS (10W+/s JMH Benchmark).

Ahoo Wang 61 Nov 22, 2022
An extremely easy way to perform background processing in Java. Backed by persistent storage. Open and free for commercial use.

The ultimate library to perform background processing on the JVM. Dead simple API. Extensible. Reliable. Distributed and backed by persistent storage.

JobRunr 1.3k Jan 6, 2023
A game made in Javafx that includes animation, background music, and view leaderboards

A game made in Javafx that includes animation, background music, and view leaderboards. To keep the game alive, a player has to move the ball up/down by pressing the up/down arrow so that the ball only touches different rotating obstacles with the same color. ..

Bijendar Prasad 3 Nov 19, 2022
NPM Package - A react native component that let you to add a wavy background UI.

react-native-wavy-background A react native component that let you to add a wavy background UI. Installation npm install react-native-wavy-background

Shevon Soyza 10 Oct 19, 2022
CoSky is a lightweight, low-cost service registration, service discovery, and configuration service SDK.

High-performance, low-cost microservice governance platform. Service Discovery and Configuration Service

Ahoo Wang 61 Nov 22, 2022
Android Auto Apps Downloader (AAAD) is an app for Android Phones that downloads popular Android Auto 3rd party apps and installs them in the correct way to have them in Android Auto.

Android Auto Apps Downloader (AAAD) is an app for Android Phones that downloads popular Android Auto 3rd party apps and installs them in the correct way to have them in Android Auto.

Gabriele Rizzo 865 Jan 2, 2023
A React Native project starter with Typescript, a theme provider with hook to easy styling component, a folder architecture ready and some configs to keep a codebase clean.

React Native Boilerplate Folder structure : src ├── assets │   ├── audios │   ├── fonts │   ├── icons │   └── images ├── components │   ├── Layout.tsx

LazyRabbit 23 Sep 1, 2022