banner
RustyNail

RustyNail

coder. 【blog】https://rustynail.me 【nostr】wss://ts.relays.world/ wss://relays.world/nostr

Not easily killed.

I don't want to die#

image

I wrote a network floating window for the Android platform, but it is often killed by the system (Android Oreo).

I searched a lot about how to prevent an Android app from being easily killed, like rogue security manager.

I did the following work:

When the service is killed, send a broadcast to revive itself#

 @Override
    public void onDestroy() {
        stopForeground(true);
        Intent intent = new Intent(getString(R.string.BACK_SERVICE_NAME));
        sendBroadcast(intent);
        super.onDestroy();
    }

public class ProtectBroadcast extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(context.getString(R.string.BACK_SERVICE_NAME))) {
            Toast.makeText(context, "Traffic Service Restarting..", Toast.LENGTH_SHORT).show();
            Intent intentStart = new Intent();
            intentStart.setClass(context, BackService.class);
            context.startService(intent);
        }
    }
}

But it seems to have no effect because the destroy method is not executed in time...

Service startup command#

Change it to Sticky

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
    }

Start a daemon process#

Start two services to wake each other up

It seems to have no effect on Android 8.0...

Finally#

No solution

I downloaded a software to convert the app into a system app... It's quite difficult to make a rogue software.

image

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.