/*
 * Copyright (C) 2013 nohana, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.amalgam.app;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.Service;
import android.content.Context;

import java.util.List;

/**
 * Utility for activity manager.
 * @author KeithYokoma
 */
@SuppressWarnings("unused") // public APIs
public final class ActivityManagerUtils {
    /**
     * Do NOT instantiate this class.
     */
    private ActivityManagerUtils() {}

    /**
     * Checks if the specified service is currently running or not.
     * @param context
     * @param service
     * @return
     */
    public static final boolean isServiceRunning(Context context, Class<? extends Service> service) {
        return isServiceRunning(context, service, Integer.MAX_VALUE);
    }

    /**
     * Checks if the specified service is currently running or not.
     * @param context
     * @param service
     * @param maxCheckCount
     * @return
     */
    public static final boolean isServiceRunning(Context context, Class<? extends Service> service, int maxCheckCount) {
        if (context == null || service == null) {
            return false;
        }

        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningServiceInfo> list = manager.getRunningServices(maxCheckCount);
        for (RunningServiceInfo info : list) {
            if (service.getCanonicalName().equals(info.service.getClassName())) {
                return true;
            }
        }
        return false;
    }

    /**
     * Get package name of the process id.
     * @param context
     * @param pid
     * @return
     */
    public static final String getPackageNameFromPid(Context context, int pid) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> processes = am.getRunningAppProcesses();
        for (RunningAppProcessInfo info : processes) {
            if (info.pid == pid) {
                String[] packages = info.pkgList;
                if (packages.length > 0) {
                    return packages[0];
                }
                break;
            }
        }
        return null;
    }
}
@@ -639,16 +639,53 @@
 m.app;%0A%0A
+import android.annotation.TargetApi;%0A
 import a
@@ -712,16 +712,16 @@
 anager;%0A
-
 import a
@@ -884,16 +884,72 @@
 Context;
+%0Aimport android.os.Build;%0Aimport android.text.TextUtils;
 %0A%0Aimport
@@ -1205,16 +1205,57 @@
 tils() %7B
+%0A        throw new AssertionError();%0A    
 %7D%0A%0A    /
@@ -1402,38 +1402,32 @@
   public static 
-final 
 boolean isServic
@@ -1754,22 +1754,16 @@
  static 
-final 
 boolean 
@@ -2328,32 +2328,1015 @@
 n false;%0A    %7D%0A%0A
+    public static boolean isApplicationRunning(Context context, String packageName) %7B%0A        return isApplicationRunning(context, packageName, Integer.MAX_VALUE);%0A    %7D%0A%0A    public static boolean isApplicationRunning(Context context, String packageName, int maxCheckCount) %7B%0A        if (TextUtils.isEmpty(packageName)) %7B%0A            return false;%0A        %7D%0A%0A        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);%0A        List%3CActivityManager.RunningTaskInfo%3E list = manager.getRunningTasks(maxCheckCount);%0A        for (ActivityManager.RunningTaskInfo info : list) %7B%0A            if (packageName.equals(info.baseActivity.getPackageName())) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A    @TargetApi(Build.VERSION_CODES.HONEYCOMB)%0A    public static void moveTaskToFront(ActivityManager manager, ActivityManager.RunningTaskInfo info) %7B%0A        manager.moveTaskToFront(info.id, 0x10000000);%0A    %7D%0A%0A
     /**%0A     * G
@@ -3425,32 +3425,32 @@
 @return%0A     */%0A
+
     public stati
@@ -3451,22 +3451,16 @@
  static 
-final 
 String g

Add running app checks and task move method