nigatigga

Untitled

Oct 22nd, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 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 java.util.ArrayList;
  14. import java.util.List;
  15. import java.util.Map;
  16.  
  17.  
  18. public class HeartBeat extends Service {
  19.  
  20. ArrayList<String> packagezList;
  21. SharedPreferences sharedPrefs;
  22. Map<String, ?> allEntries;
  23. SharedPreferences sharedPrefsapp;
  24. SharedPreferences endTimerPreferences;
  25. long timerends;
  26.  
  27. @Override
  28. public IBinder onBind(Intent arg0) {
  29. return null;
  30. }
  31.  
  32.  
  33. @Override
  34. public int onStartCommand(Intent intent, int flags, int startId) {
  35.  
  36. //startService(new Intent(this, HeartBeat.class));
  37.  
  38. endTimerPreferences = getApplicationContext().getSharedPreferences("endservice", Context.MODE_PRIVATE);
  39. timerends= endTimerPreferences.getLong("endservice", 0);
  40.  
  41. //Log.e("MONOLO ", timerends + "");
  42.  
  43.  
  44. sharedPrefs = getApplicationContext().getSharedPreferences(getApplicationContext().getPackageName(), Context.MODE_PRIVATE);
  45. sharedPrefsapp = getApplicationContext().getSharedPreferences("appdb", Context.MODE_PRIVATE);
  46. allEntries= null;
  47. allEntries = sharedPrefsapp.getAll();
  48. packagezList= null;
  49.  
  50. packagezList = new ArrayList<String>();
  51.  
  52. for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
  53. //Log.e("right key: ", entry.getKey() + "right value: " + entry.getValue().toString() );
  54. packagezList.add(entry.getKey());
  55.  
  56. }
  57.  
  58. /*for(Object object: packagezList){
  59. Log.e("YO!", (String) object);
  60. }*/
  61.  
  62.  
  63. try {
  64. //List<RecentTaskInfo> recentTasks = activityManager.getRecentTasks(1, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
  65. ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
  66. List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
  67.  
  68.  
  69.  
  70.  
  71. //check the try
  72.  
  73. //Log.e("activity on Top", "" + activityOnTop);
  74. // Log.e(" My package name", "" + getApplicationContext().getPackageName());
  75.  
  76. //for (Object data : newArrayList) {
  77.  
  78. if(System.currentTimeMillis() < timerends ) {
  79.  
  80.  
  81. long second = (timerends / 1000) % 60;
  82. long minute = (timerends / (1000 * 60)) % 60;
  83. long hour = (timerends / (1000 * 60 * 60)) % 24;
  84.  
  85. String time = String.format("%02d:%02d:%02d", hour, minute, second);
  86.  
  87.  
  88. /* NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  89. Notification myNotification = new Notification(R.drawable.ic_launcher, "Apps now locked!", System.currentTimeMillis());
  90. Context context = getApplicationContext();
  91. String notificationTitle = "Apps blocked!";
  92. String notificationText = "Time Remaining: " + time;
  93. Intent myIntent = new Intent(HeartBeat.this, HeartBeat.class);
  94. PendingIntent pendingIntent = PendingIntent.getActivity(HeartBeat.this, 0, myIntent, Intent.FILL_IN_ACTION);
  95. myNotification.flags = Notification.FLAG_ONGOING_EVENT;
  96. myNotification.setLatestEventInfo(context, notificationTitle, notificationText, pendingIntent);
  97. notificationManager.notify(1, myNotification);*/
  98.  
  99.  
  100.  
  101. final String packageName = getApplicationContext().getPackageName();
  102.  
  103.  
  104. for (Object object : packagezList) {
  105.  
  106.  
  107. for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
  108.  
  109. if ((appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName))) {
  110. // Log.i("I JUST FEEL SORRY FOR WHOEVER NEEDS TO SWEEP UP YEAH", appProcess.processName);
  111.  
  112.  
  113. // Provide the packagename(s) of apps here, you want to show password activity
  114.  
  115. if (appProcess.processName.contains(getApplicationContext().getPackageName())) {
  116. }
  117.  
  118.  
  119. if (((appProcess.processName.contains((CharSequence) object)) &&
  120. (!appProcess.processName.contains(getApplicationContext().getPackageName()
  121. )) && (!appProcess.processName.equals(packageName)))) {
  122.  
  123. if( appProcess.processName.contains((CharSequence) object)){
  124.  
  125. if(!appProcess.processName.contains(getApplicationContext().getPackageName())){
  126.  
  127. if(!appProcess.processName.equals(packageName)){
  128.  
  129. }
  130.  
  131.  
  132. }
  133.  
  134.  
  135.  
  136.  
  137. }
  138.  
  139.  
  140.  
  141. // you have to make this check even better
  142. Log.e("Boom Motherfucker", getApplicationContext().getPackageName());
  143.  
  144. Log.e("Just Blocked: ", appProcess.processName);
  145.  
  146.  
  147.  
  148.  
  149. Intent i = new Intent(getApplicationContext(), LockScreenActivity.class);
  150. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
  151. i.putExtra("", "");
  152. startActivity(i);
  153.  
  154.  
  155. }
  156.  
  157. }
  158. }
  159. }
  160.  
  161. }
  162. } catch (Exception e) {
  163. // Log.e("Foreground App", e.getMessage(), e);
  164. }
  165.  
  166. Intent ishintent = new Intent(this, HeartBeat.class);
  167. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  168. AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  169. alarm.cancel(pintent);
  170. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5000, pintent);
  171.  
  172.  
  173.  
  174.  
  175. return START_STICKY;
  176.  
  177. }
  178.  
  179. // Log.i("LocalService", "Received start id " + startId + ": " +
  180. // intent);
  181. // We want this service to continue running until it is explicitly
  182. // stopped, so return sticky.
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189. @Override
  190. public void onDestroy() {
  191.  
  192. Intent in = new Intent();
  193. in.setAction("YouWillNeverKillMe");
  194. sendBroadcast(in);
  195.  
  196. Intent ishintent = new Intent(this, HeartBeat.class);
  197. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  198. AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  199. alarm.cancel(pintent);
  200. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5000, pintent);
  201.  
  202.  
  203.  
  204. //startService(new Intent(this, HeartBeat.class));
  205. }
  206.  
  207. // this.stopSelf();
  208. //startforeground goes here
  209.  
  210. }
Advertisement
Add Comment
Please, Sign In to add comment