Advertisement
nigatigga

Untitled

Oct 22nd, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 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. final String packageName = getApplicationContext().getPackageName();
  101.  
  102.  
  103. for (Object object : packagezList) {
  104.  
  105.  
  106. for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
  107.  
  108.  
  109.  
  110. boolean b= appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
  111.  
  112. if (b) {
  113. // Log.i("I JUST FEEL SORRY FOR WHOEVER NEEDS TO SWEEP UP YEAH", appProcess.processName);
  114. Log.e("is in foreground", getApplicationContext().getPackageName());
  115.  
  116.  
  117. // Provide the packagename(s) of apps here, you want to show password activity
  118.  
  119. if (((appProcess.processName.contains((CharSequence) object)) &&
  120. (!appProcess.processName.contains(getApplicationContext().getPackageName()
  121. )) && (!appProcess.processName.equals(packageName)))) {
  122.  
  123.  
  124. /* // you have to make this check even better
  125. Log.e("Boom Motherfucker3", getApplicationContext().getPackageName());
  126.  
  127. Log.e("Just Blocked: ", appProcess.processName);
  128.  
  129.  
  130. Intent i = new Intent(getApplicationContext(), LockScreenActivity.class);
  131. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
  132. i.putExtra("", "");
  133. startActivity(i);*/
  134.  
  135. }
  136.  
  137.  
  138. }
  139.  
  140.  
  141. }
  142.  
  143.  
  144. }
  145.  
  146. }
  147. } catch (Exception e) {
  148. // Log.e("Foreground App", e.getMessage(), e);
  149. }
  150.  
  151. Intent ishintent = new Intent(this, HeartBeat.class);
  152. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  153. AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  154. alarm.cancel(pintent);
  155. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5000, pintent);
  156.  
  157.  
  158.  
  159.  
  160. return START_STICKY;
  161.  
  162. }
  163.  
  164. // Log.i("LocalService", "Received start id " + startId + ": " +
  165. // intent);
  166. // We want this service to continue running until it is explicitly
  167. // stopped, so return sticky.
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. @Override
  175. public void onDestroy() {
  176.  
  177. Intent in = new Intent();
  178. in.setAction("YouWillNeverKillMe");
  179. sendBroadcast(in);
  180.  
  181. Intent ishintent = new Intent(this, HeartBeat.class);
  182. PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  183. AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  184. alarm.cancel(pintent);
  185. alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5000, pintent);
  186.  
  187.  
  188.  
  189. //startService(new Intent(this, HeartBeat.class));
  190. }
  191.  
  192. // this.stopSelf();
  193. //startforeground goes here
  194.  
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement