forked from BaronKiko/LauncherHijack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Adshead
authored and
Andy Adshead
committed
Jul 26, 2017
1 parent
4c7f6f2
commit 2970927
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/baronkiko/launcherhijack/BroadcastReceiverOnBootComplete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/baronkiko/launcherhijack/HomeButtonService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/baronkiko/launcherhijack/ServiceMan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |