Advertisement
nigatigga

close

Oct 27th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. package com.ibc.android.demo.appslist.app;
  2.  
  3. import android.app.ActivityManager;
  4. import android.app.AlarmManager;
  5. import android.app.PendingIntent;
  6. import android.app.Service;
  7. import android.content.Context;
  8. import android.content.Intent;
  9. import android.content.SharedPreferences;
  10. import android.os.IBinder;
  11.  
  12. import com.spicycurryman.getdisciplined10.app.ApplicationCheck;
  13.  
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import java.util.Map;
  17.  
  18.  
  19. public class HeartBeat extends Service {
  20.  
  21. ArrayList<String> packagezList;
  22. SharedPreferences sharedPrefs;
  23. Map<String, ?> allEntries;
  24. SharedPreferences sharedPrefsapp;
  25. SharedPreferences endTimerPreferences;
  26. long timerends;
  27.  
  28. @Override
  29. public IBinder onBind(Intent arg0) {
  30. return null;
  31. }
  32.  
  33.  
  34. @Override
  35. public int onStartCommand(Intent intent, int flags, int startId) {
  36.  
  37.  
  38. endTimerPreferences = getApplicationContext().getSharedPreferences("endservice", Context.MODE_PRIVATE);
  39. timerends = endTimerPreferences.getLong("endservice", 0);
  40.  
  41.  
  42.  
  43. sharedPrefs = getApplicationContext().getSharedPreferences(getApplicationContext().getPackageName(), Context.MODE_PRIVATE);
  44. sharedPrefsapp = getApplicationContext().getSharedPreferences("appdb", Context.MODE_PRIVATE);
  45. allEntries = null;
  46. allEntries = sharedPrefsapp.getAll();
  47. packagezList = null;
  48.  
  49. packagezList = new ArrayList<String>();
  50.  
  51. for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
  52. packagezList.add(entry.getKey());
  53.  
  54. }
  55.  
  56.  
  57. try {
  58. ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
  59. List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
  60.  
  61.  
  62.  
  63.  
  64.  
  65. if(timerends ==0){
  66. android.os.Process.killProcess(android.os.Process.myPid());
  67.  
  68. }
  69.  
  70. if (System.currentTimeMillis() < timerends) {
  71.  
  72. //activityManager.killBackgroundProcesses(getApplicationContext().getPackageName());
  73.  
  74.  
  75. for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
  76.  
  77.  
  78. for (Object object : packagezList) {
  79.  
  80. // Provide the packagename(s) of apps here, you want to show password activity
  81. if (((appProcess.processName.contains((CharSequence) object) && !appProcess.processName.contains("com.spicycurryman.getdisciplined10.app"))
  82. )) {
  83.  
  84. if(appProcess.processName.contains( "com.spicycurryman.getdisciplined10.app" ) && !appProcess.processName.contains((CharSequence) object) ){
  85. android.os.Process.killProcess(android.os.Process.myPid());
  86.  
  87.  
  88. }
  89.  
  90.  
  91. //Log.e("IS IT", appProcess.processName);
  92.  
  93. //Log.e("OH SHOOT ", String.valueOf(appProcess.pid));
  94. if(ApplicationCheck.isActivityVisible()) {
  95. android.os.Process.killProcess(android.os.Process.myPid());
  96.  
  97.  
  98. }
  99.  
  100.  
  101.  
  102. Intent i = new Intent(getApplicationContext(), LockScreenActivity.class);
  103. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
  104. i.putExtra("", "");
  105.  
  106. startActivity(i);
  107.  
  108. activityManager.killBackgroundProcesses(appProcess.processName);
  109.  
  110.  
  111.  
  112.  
  113. //android.os.Process.killProcess(android.os.Process.myPid());
  114.  
  115.  
  116.  
  117.  
  118.  
  119. }
  120. }
  121. }
  122. }
  123.  
  124. }catch(Exception e){
  125. }
  126.  
  127. Intent ishintent = new Intent(this, HeartBeat.class);
  128. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  129. AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  130. alarm.cancel(pintent);
  131. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 5000, pintent);
  132.  
  133.  
  134. return START_STICKY;
  135.  
  136.  
  137.  
  138. }
  139.  
  140.  
  141. @Override
  142. public void onDestroy() {
  143.  
  144. Intent in = new Intent();
  145. in.setAction("YouWillNeverKillMe");
  146. sendBroadcast(in);
  147.  
  148. Intent ishintent = new Intent(this, HeartBeat.class);
  149. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  150. AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  151. alarm.cancel(pintent);
  152. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5000, pintent);
  153.  
  154.  
  155.  
  156. }
  157.  
  158.  
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement