Advertisement
nigatigga

Untitled

Oct 27th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 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. import android.util.Log;
  12.  
  13. import com.spicycurryman.getdisciplined10.app.ApplicationCheck;
  14.  
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. import java.util.Map;
  18.  
  19.  
  20. public class HeartBeat extends Service {
  21.  
  22. ArrayList<String> packagezList;
  23. SharedPreferences sharedPrefs;
  24. Map<String, ?> allEntries;
  25. SharedPreferences sharedPrefsapp;
  26. SharedPreferences endTimerPreferences;
  27. long timerends;
  28.  
  29. @Override
  30. public IBinder onBind(Intent arg0) {
  31. return null;
  32. }
  33.  
  34.  
  35. @Override
  36. public int onStartCommand(Intent intent, int flags, int startId) {
  37.  
  38. //startService(new Intent(this, HeartBeat.class));
  39.  
  40. endTimerPreferences = getApplicationContext().getSharedPreferences("endservice", Context.MODE_PRIVATE);
  41. timerends = endTimerPreferences.getLong("endservice", 0);
  42.  
  43. //Log.e("MONOLO ", timerends + "");
  44.  
  45.  
  46. sharedPrefs = getApplicationContext().getSharedPreferences(getApplicationContext().getPackageName(), Context.MODE_PRIVATE);
  47. sharedPrefsapp = getApplicationContext().getSharedPreferences("appdb", Context.MODE_PRIVATE);
  48. allEntries = null;
  49. allEntries = sharedPrefsapp.getAll();
  50. packagezList = null;
  51.  
  52. packagezList = new ArrayList<String>();
  53.  
  54. for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
  55. //Log.e("right key: ", entry.getKey() + "right value: " + entry.getValue().toString() );
  56. packagezList.add(entry.getKey());
  57.  
  58. }
  59.  
  60. /*for(Object object: packagezList){
  61. Log.e("YO!", (String) object);
  62. }*/
  63.  
  64.  
  65. try {
  66. //List<RecentTaskInfo> recentTasks = activityManager.getRecentTasks(1, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
  67. ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
  68. List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
  69.  
  70.  
  71.  
  72. //check the try
  73.  
  74. //Log.e("activity on Top", "" + activityOnTop);
  75. // Log.e(" My package name", "" + getApplicationContext().getPackageName());
  76.  
  77. //for (Object data : newArrayList) {
  78.  
  79. if (System.currentTimeMillis() < timerends) {
  80.  
  81.  
  82. long second = (timerends / 1000) % 60;
  83. long minute = (timerends / (1000 * 60)) % 60;
  84. long hour = (timerends / (1000 * 60 * 60)) % 24;
  85.  
  86. final String packageName = getApplicationContext().getPackageName();
  87.  
  88. for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
  89.  
  90.  
  91. for (Object object : packagezList) {
  92.  
  93. // Provide the packagename(s) of apps here, you want to show password activity
  94. if (((appProcess.processName.contains((CharSequence) object) && !appProcess.processName.contains("com.spicycurryman.getdisciplined10.app"))
  95. )) {
  96.  
  97. if(appProcess.processName.contains( "com.spicycurryman.getdisciplined10.app" ) && !appProcess.processName.contains((CharSequence) object) ){
  98. android.os.Process.killProcess(android.os.Process.myPid());
  99.  
  100.  
  101. if(!ApplicationCheck.isActivityVisible()) {
  102.  
  103. Intent i = new Intent(getApplicationContext(), LockScreenActivity.class);
  104. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
  105. i.putExtra("", "");
  106. startActivity(i);
  107.  
  108. }
  109.  
  110.  
  111. }
  112.  
  113.  
  114. Log.e("IS IT", appProcess.processName);
  115.  
  116. Log.e("OH SHOOT ", String.valueOf(appProcess.pid));
  117. if(ApplicationCheck.isActivityVisible()) {
  118. android.os.Process.killProcess(android.os.Process.myPid());
  119.  
  120.  
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127. }
  128. }
  129. }
  130. }
  131.  
  132. }catch(Exception e){
  133. }
  134.  
  135. Intent ishintent = new Intent(this, HeartBeat.class);
  136. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  137. AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  138. alarm.cancel(pintent);
  139. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 5000, pintent);
  140.  
  141.  
  142. return START_STICKY;
  143.  
  144.  
  145. // Log.i("LocalService", "Received start id " + startId + ": " +
  146. // intent);
  147. // We want this service to continue running until it is explicitly
  148. // stopped, so return sticky.
  149.  
  150.  
  151.  
  152. }
  153.  
  154.  
  155. @Override
  156. public void onDestroy() {
  157.  
  158. Intent in = new Intent();
  159. in.setAction("YouWillNeverKillMe");
  160. sendBroadcast(in);
  161.  
  162. Intent ishintent = new Intent(this, HeartBeat.class);
  163. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  164. AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  165. alarm.cancel(pintent);
  166. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5000, pintent);
  167.  
  168.  
  169.  
  170. //startService(new Intent(this, HeartBeat.class));
  171. }
  172.  
  173. // this.stopSelf();
  174. //startforeground goes here
  175.  
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement