Java Code Examples for android.app.ActivityManager#getRunningServices()

The following examples show how to use android.app.ActivityManager#getRunningServices() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppUtils.java    From BmapLite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 判断某个服务是否正在运行的方法
 *
 * @param context
 * @param serviceName 是包名+服务的类名(例如:net.loonggg.testbackstage.TestService)
 * @return true 代表正在运行,false代表服务没有正在运行
 */
public static boolean isServiceWork(Context context, String serviceName) {
    boolean isWork = false;
    ActivityManager myAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> myList = myAM.getRunningServices(30);
    if (null == myList || myList.isEmpty()) {
        return false;
    }
    for (int i = 0; i < myList.size(); i++) {
        String mName = myList.get(i).service.getClassName();
        if (mName.equals(serviceName)) {
            isWork = true;
            break;
        }
    }
    return isWork;
}
 
Example 2
Source File: HookInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
private static boolean checkRunningProcesses(Context context) {
    boolean returnValue = false;
    // Get currently running application processes
    ActivityManager activityManager = (ActivityManager) (context.getSystemService(Context.ACTIVITY_SERVICE));

    List<ActivityManager.RunningServiceInfo> list = activityManager.getRunningServices(300);
    if (list != null) {
        String tempName;
        for (int i = 0; i < list.size(); ++i) {
            tempName = list.get(i).process;
            if (tempName.contains("fridaserver")) {
                returnValue = true;
            }
        }
    }
    return returnValue;
}
 
Example 3
Source File: BasicUtils.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the service is running
 *
 * @param context
 * @param cls
 * @return
 */
public static boolean isServiceRunning(Context context, Class<?> cls) {
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> services = activityManager
            .getRunningServices(Integer.MAX_VALUE);

    for (ActivityManager.RunningServiceInfo serviceInfo : services) {
        ComponentName componentName = serviceInfo.service;
        String serviceName = componentName.getClassName();
        if (serviceName.equals(cls.getName())) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: NotificationService.java    From OpenFit with MIT License 6 votes vote down vote up
public void checkNotificationListenerService() {
    Log.d(LOG_TAG, "checkNotificationListenerService");
    boolean isNotificationListenerRunning = false;
    ComponentName thisComponent = new ComponentName(this, NotificationService.class);
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    List<ActivityManager.RunningServiceInfo> runningServices = manager.getRunningServices(Integer.MAX_VALUE);
    if(runningServices == null) {
        Log.d(LOG_TAG, "running services is null");
        return;
    }
    for(ActivityManager.RunningServiceInfo service : runningServices) {
        if(service.service.equals(thisComponent)) {
            Log.d(LOG_TAG, "checkNotificationListenerService service - pid: " + service.pid + ", currentPID: " + Process.myPid() + ", clientPackage: " + service.clientPackage + ", clientCount: " + service.clientCount + ", clientLabel: " + ((service.clientLabel == 0) ? "0" : "(" + getResources().getString(service.clientLabel) + ")"));
            if(service.pid == Process.myPid() /*&& service.clientCount > 0 && !TextUtils.isEmpty(service.clientPackage)*/) {
                isNotificationListenerRunning = true;
            }
        }
    }
    if(isNotificationListenerRunning) {
        Log.d(LOG_TAG, "NotificationListenerService is running");
        return;
    }
    Log.d(LOG_TAG, "NotificationListenerService is not running, trying to start");
    this.toggleNotificationListenerService();
}
 
Example 5
Source File: DownloadService.java    From AndroidDownloader with Apache License 2.0 6 votes vote down vote up
private static boolean isServiceRunning(Context context) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> serviceList = activityManager
            .getRunningServices(Integer.MAX_VALUE);

    if (serviceList == null || serviceList.size() == 0) {
        return false;
    }

    for (int i = 0; i < serviceList.size(); i++) {
        if (serviceList.get(i).service.getClassName().equals(
                DownloadService.class.getName())) {
            isRunning = true;
            break;
        }
    }
    return isRunning;
}
 
Example 6
Source File: AccessChecker.java    From NotificationPeekPort with Apache License 2.0 5 votes vote down vote up
public static boolean isNotificationAccessEnabled(Context context) {
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager
            .getRunningServices(Integer.MAX_VALUE)) {
        if (NotificationService.class.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: MizLib.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
public static boolean isMovieLibraryBeingUpdated(Context c) {
    ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE);
    int count = services.size();
    for (int i = 0; i < count; i++) {
        if (MovieLibraryUpdate.class.getName().equals(services.get(i).service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: CondomCore.java    From condom with Apache License 2.0 5 votes vote down vote up
BackgroundUidFilter() {
	final ActivityManager am = (ActivityManager) mBase.getSystemService(ACTIVITY_SERVICE);
	if (am == null) {
		running_services = null;
		running_processes = null;
	} else if (SDK_INT >= LOLLIPOP_MR1) {		// getRunningAppProcesses() is limited on Android 5.1+.
		running_services = am.getRunningServices(64);	// Too many services are never healthy, thus ignored intentionally.
		running_processes = null;
	} else {
		running_services = null;
		running_processes = am.getRunningAppProcesses();
	}
}
 
Example 9
Source File: ContextReference.java    From Navigator with Apache License 2.0 5 votes vote down vote up
static String isAlive(Service candidate) {
    if (candidate == null)
        return "Service reference null";
    ActivityManager manager = (ActivityManager) candidate.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE);
    if (services == null)
        return "Could not retrieve services from service manager";
    for (ActivityManager.RunningServiceInfo service : services) {
        if (candidate.getClass().getName().equals(service.service.getClassName())) {
            return null;
        }
    }
    return "Service stopped";
}
 
Example 10
Source File: UIManager3x.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected boolean isSystemUIRunning() {
    final Context ctx = BaseDroidApp.context;
    final ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningServiceInfo> rsiList = am.getRunningServices(1000);

    for (final RunningServiceInfo rsi : rsiList) {
        LCTX.d("Service: " + rsi.service);
        if (SYS_UI.equals(rsi.service)) {
            LCTX.e("System UI service found");
            return true;
        }
    }
    return false;
}
 
Example 11
Source File: SettingsFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * サービスに起動確認を行う.
 *
 * @param c コンテキスト
 * @param cls クラス
 * @return 起動中の場合はtrue、それ以外はfalse
 */
private boolean isServiceRunning(final Context c, final Class<?> cls) {
    ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> runningService = am.getRunningServices(Integer.MAX_VALUE);
    for (RunningServiceInfo i : runningService) {
        if (cls.getName().equals(i.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example 12
Source File: ToolBox.java    From privacy-friendly-netmonitor with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isAnalyzerServiceRunning() {
    ActivityManager manager = (ActivityManager) RunStore.getContext().getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (PassiveService.class.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: Service.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of currently running Services.
 *
 * @param context the Context.
 * @return Returns a list of currently running Services.
 */
public static List<RunningServiceInfo> getRunningServiceInfo(Context context) {
    if (runningServiceInfo != null && runningServiceInfo.get() != null) {
        return runningServiceInfo.get();
    }

    ActivityManager manager =
            (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
    List<RunningServiceInfo> runningServices = manager.getRunningServices(255);
    runningServiceInfo = new WeakReference<>(runningServices);

    return runningServices;
}
 
Example 14
Source File: FeedsActivity.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
private
boolean isServiceRunning()
{
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for(ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
    {
        if(ServiceUpdate.class.getName().equals(service.service.getClassName()))
        {
            return true;
        }
    }
    return false;
}
 
Example 15
Source File: ClientsController.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
protected boolean isThreadsServiceRunning() {
    final ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    for (final ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (service.service.getClassName().equals(clientsServiceClassName)) {
            return true;
        }
    }
    return false;
}
 
Example 16
Source File: AppStateTracker.java    From hover with Apache License 2.0 5 votes vote down vote up
public List<ServiceState> getServiceStates() {
    ActivityManager activityManager = (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> runningServices = activityManager.getRunningServices(100);
    List<ServiceState> serviceStates = new ArrayList<>(runningServices.size());
    for (ActivityManager.RunningServiceInfo runningServiceInfo : runningServices) {
        if (runningServiceInfo.pid == android.os.Process.myPid()) {
            serviceStates.add(new ServiceState(runningServiceInfo.service.getShortClassName()));
        }
    }
    return serviceStates;
}
 
Example 17
Source File: TrustActivity.java    From trust with Apache License 2.0 5 votes vote down vote up
private boolean isMyServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("eu.thedarken.trust.TrustService".equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example 18
Source File: RouterServiceValidator.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This method will determine if our supplied component name is really running. 
 * @param context
 * @param service
 * @return
 */
protected boolean isServiceRunning(Context context, ComponentName service){
	 ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	    for (RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
	        if (serviceInfo.service.equals(service)) {
	            return true;
	        }
	    }
	return false;
}
 
Example 19
Source File: AppApplicationMgr.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 服务是否在运行
 *
 * @param context
 * @param className
 * @return
 */
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    for (ActivityManager.RunningServiceInfo si : servicesList) {
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}
 
Example 20
Source File: Settingsss.java    From QuranAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function to check service running of not
 *
 * @param context      Application context
 * @param serviceClass Service class
 * @return Service running or not
 */
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) {

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager
            .getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}