Skip to content

Commit

Permalink
Never ending service
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Adshead authored and Andy Adshead committed Jul 26, 2017
1 parent 4c7f6f2 commit 2970927
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.baronkiko.launcherhijack">
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>

<application
android:allowBackup="true"
Expand All @@ -12,16 +13,35 @@
<activity android:name="com.baronkiko.launcherhijack.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service android:name="com.baronkiko.launcherhijack.AccServ"
android:label="To detect home button press"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>

<service android:name="com.baronkiko.launcherhijack.HomeButtonService" android:enabled="true"></service>

<receiver
android:name="com.baronkiko.launcherhijack.BroadcastReceiverOnBootComplete"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.baronkiko.launcherhijack;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BroadcastReceiverOnBootComplete extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)){// || intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED) || intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_REPLACED)) {
ServiceMan.Start(context);
}

}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.baronkiko.launcherhijack;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class HomeButtonService extends Service {

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
Log.d("A", "X");
}

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

@Override
public void onDestroy() {
super.onDestroy();
Log.i("EXIT", "ondestroy!");
ServiceMan.Stop(getApplicationContext());
ServiceMan.StartSlow(getApplicationContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private void UpdateList()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ServiceMan.Start(this);

setContentView(com.baronkiko.launcherhijack.R.layout.activity_main);

mListAppInfo = (ListView) findViewById(R.id.lvApps);
Expand Down
54 changes: 54 additions & 0 deletions app/src/main/java/com/baronkiko/launcherhijack/ServiceMan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.baronkiko.launcherhijack;

import android.app.ActivityManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.util.Timer;
import java.util.TimerTask;

/**
* Created by andy on 26/07/2017.
*/

public class ServiceMan {
private static Intent mServiceIntent;

private static boolean isMyServiceRunning(Class<?> serviceClass, Context c) {
ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
Log.i ("isMyServiceRunning?", true+"");
return true;
}
}
Log.i ("isMyServiceRunning?", false+"");
return false;
}

public static void StartSlow(final Context c) {
while (!Start(c)) {
try {
Thread.sleep(50);
} catch (Exception e) {
}
}
}

public static boolean Start(Context c)
{
mServiceIntent = new Intent(c, HomeButtonService.class);
if (!isMyServiceRunning(HomeButtonService.class, c)) {
c.startService(mServiceIntent);
return true;
}
return false;
}

public static void Stop(Context c)
{
c.stopService(mServiceIntent);
}
}

0 comments on commit 2970927

Please sign in to comment.