package com.jaredrummler.android.processes;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build.VERSION;
import android.os.Process;
import android.util.Log;
import com.jaredrummler.android.processes.models.AndroidAppProcess;
import com.jaredrummler.android.processes.models.AndroidAppProcess.NotAndroidAppProcessException;
import com.jaredrummler.android.processes.models.AndroidProcess;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class ProcessManager
{
  public static final String TAG = "AndroidProcesses";
  private static boolean loggingEnabled;
  
  private ProcessManager()
  {
    throw new AssertionError("no instances");
  }
  
  public static List<ActivityManager.RunningAppProcessInfo> getRunningAppProcessInfo(Context paramContext)
  {
    if (Build.VERSION.SDK_INT >= 22)
    {
      paramContext = getRunningAppProcesses();
      ArrayList localArrayList = new ArrayList();
      Iterator localIterator = paramContext.iterator();
      for (;;)
      {
        paramContext = localArrayList;
        if (!localIterator.hasNext()) {
          break;
        }
        paramContext = (AndroidAppProcess)localIterator.next();
        ActivityManager.RunningAppProcessInfo localRunningAppProcessInfo = new ActivityManager.RunningAppProcessInfo(paramContext.name, paramContext.pid, null);
        localRunningAppProcessInfo.uid = paramContext.uid;
        localArrayList.add(localRunningAppProcessInfo);
      }
    }
    paramContext = ((ActivityManager)paramContext.getSystemService("activity")).getRunningAppProcesses();
    return paramContext;
  }
  
  /* Error */
  public static List<AndroidAppProcess> getRunningAppProcesses()
  {
    // Byte code:
    //   0: new 39	java/util/ArrayList
    //   3: dup
    //   4: invokespecial 40	java/util/ArrayList:<init>	()V
    //   7: astore_3
    //   8: new 98	java/io/File
    //   11: dup
    //   12: ldc 100
    //   14: invokespecial 103	java/io/File:<init>	(Ljava/lang/String;)V
    //   17: invokevirtual 107	java/io/File:listFiles	()[Ljava/io/File;
    //   20: astore 4
    //   22: aload 4
    //   24: arraylength
    //   25: istore_1
    //   26: iconst_0
    //   27: istore_0
    //   28: iload_0
    //   29: iload_1
    //   30: if_icmpge +76 -> 106
    //   33: aload 4
    //   35: iload_0
    //   36: aaload
    //   37: astore 5
    //   39: aload 5
    //   41: invokevirtual 110	java/io/File:isDirectory	()Z
    //   44: ifeq +27 -> 71
    //   47: aload 5
    //   49: invokevirtual 114	java/io/File:getName	()Ljava/lang/String;
    //   52: invokestatic 120	java/lang/Integer:parseInt	(Ljava/lang/String;)I
    //   55: istore_2
    //   56: aload_3
    //   57: new 58	com/jaredrummler/android/processes/models/AndroidAppProcess
    //   60: dup
    //   61: iload_2
    //   62: invokespecial 123	com/jaredrummler/android/processes/models/AndroidAppProcess:<init>	(I)V
    //   65: invokeinterface 77 2 0
    //   70: pop
    //   71: iload_0
    //   72: iconst_1
    //   73: iadd
    //   74: istore_0
    //   75: goto -47 -> 28
    //   78: astore 5
    //   80: goto -9 -> 71
    //   83: astore 5
    //   85: aload 5
    //   87: ldc 125
    //   89: iconst_1
    //   90: anewarray 4	java/lang/Object
    //   93: dup
    //   94: iconst_0
    //   95: iload_2
    //   96: invokestatic 129	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   99: aastore
    //   100: invokestatic 133	com/jaredrummler/android/processes/ProcessManager:log	(Ljava/lang/Throwable;Ljava/lang/String;[Ljava/lang/Object;)V
    //   103: goto -32 -> 71
    //   106: aload_3
    //   107: areturn
    //   108: astore 5
    //   110: goto -39 -> 71
    // Local variable table:
    //   start	length	slot	name	signature
    //   27	48	0	i	int
    //   25	6	1	j	int
    //   55	41	2	k	int
    //   7	100	3	localArrayList	ArrayList
    //   20	14	4	arrayOfFile	File[]
    //   37	11	5	localFile	File
    //   78	1	5	localNumberFormatException	NumberFormatException
    //   83	3	5	localIOException	IOException
    //   108	1	5	localNotAndroidAppProcessException	AndroidAppProcess.NotAndroidAppProcessException
    // Exception table:
    //   from	to	target	type
    //   47	56	78	java/lang/NumberFormatException
    //   56	71	83	java/io/IOException
    //   56	71	108	com/jaredrummler/android/processes/models/AndroidAppProcess$NotAndroidAppProcessException
  }
  
  public static List<AndroidAppProcess> getRunningForegroundApps(Context paramContext)
  {
    localArrayList = new ArrayList();
    File[] arrayOfFile = new File("/proc").listFiles();
    paramContext = paramContext.getPackageManager();
    int j = arrayOfFile.length;
    int i = 0;
    for (;;)
    {
      if (i >= j) {
        break label172;
      }
      Object localObject = arrayOfFile[i];
      if (((File)localObject).isDirectory()) {}
      for (;;)
      {
        int k;
        try
        {
          k = Integer.parseInt(((File)localObject).getName());
        }
        catch (NumberFormatException localNumberFormatException)
        {
          continue;
        }
        try
        {
          localObject = new AndroidAppProcess(k);
          if ((((AndroidAppProcess)localObject).foreground) && ((((AndroidAppProcess)localObject).uid < 1000) || (((AndroidAppProcess)localObject).uid > 9999)) && (!((AndroidAppProcess)localObject).name.contains(":")) && (paramContext.getLaunchIntentForPackage(((AndroidAppProcess)localObject).getPackageName()) != null)) {
            localArrayList.add(localObject);
          }
        }
        catch (IOException localIOException)
        {
          log(localIOException, "Error reading from /proc/%d.", new Object[] { Integer.valueOf(k) });
          continue;
          return localArrayList;
        }
        catch (AndroidAppProcess.NotAndroidAppProcessException localNotAndroidAppProcessException) {}
      }
      i += 1;
    }
  }
  
  public static List<AndroidProcess> getRunningProcesses()
  {
    ArrayList localArrayList = new ArrayList();
    File[] arrayOfFile = new File("/proc").listFiles();
    int j = arrayOfFile.length;
    int i = 0;
    for (;;)
    {
      if (i < j)
      {
        File localFile = arrayOfFile[i];
        if (localFile.isDirectory()) {}
        try
        {
          k = Integer.parseInt(localFile.getName());
        }
        catch (NumberFormatException localNumberFormatException)
        {
          try
          {
            localArrayList.add(new AndroidProcess(k));
            for (;;)
            {
              i += 1;
              break;
              localNumberFormatException = localNumberFormatException;
            }
          }
          catch (IOException localIOException)
          {
            for (;;)
            {
              int k;
              log(localIOException, "Error reading from /proc/%d.", new Object[] { Integer.valueOf(k) });
            }
          }
        }
      }
    }
    return localArrayList;
  }
  
  public static boolean isLoggingEnabled()
  {
    return loggingEnabled;
  }
  
  public static boolean isMyProcessInTheForeground()
  {
    Object localObject = getRunningAppProcesses();
    int i = Process.myPid();
    localObject = ((List)localObject).iterator();
    while (((Iterator)localObject).hasNext())
    {
      AndroidAppProcess localAndroidAppProcess = (AndroidAppProcess)((Iterator)localObject).next();
      if ((localAndroidAppProcess.pid == i) && (localAndroidAppProcess.foreground)) {
        return true;
      }
    }
    return false;
  }
  
  public static void log(String paramString, Object... paramVarArgs)
  {
    if (loggingEnabled) {
      if (paramVarArgs.length != 0) {
        break label19;
      }
    }
    for (;;)
    {
      Log.d("AndroidProcesses", paramString);
      return;
      label19:
      paramString = String.format(paramString, paramVarArgs);
    }
  }
  
  public static void log(Throwable paramThrowable, String paramString, Object... paramVarArgs)
  {
    if (loggingEnabled) {
      if (paramVarArgs.length != 0) {
        break label20;
      }
    }
    for (;;)
    {
      Log.d("AndroidProcesses", paramString, paramThrowable);
      return;
      label20:
      paramString = String.format(paramString, paramVarArgs);
    }
  }
  
  public static void setLoggingEnabled(boolean paramBoolean)
  {
    loggingEnabled = paramBoolean;
  }
  
  public static final class ProcessComparator
    implements Comparator<AndroidProcess>
  {
    public int compare(AndroidProcess paramAndroidProcess1, AndroidProcess paramAndroidProcess2)
    {
      return paramAndroidProcess1.name.compareToIgnoreCase(paramAndroidProcess2.name);
    }
  }
}


/* Location:              /home/enzo/Documents/hacking/malwares/viking-horde/classes.jar!/com/jaredrummler/android/processes/ProcessManager.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */