mirror of
https://github.com/mihonapp/mihon.git
synced 2024-10-31 21:20:59 -04:00
37 lines
1.5 KiB
Java
37 lines
1.5 KiB
Java
package eu.kanade.tachiyomi.util;
|
|
|
|
import android.app.ActivityManager;
|
|
import android.app.ActivityManager.RunningServiceInfo;
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.pm.PackageManager;
|
|
|
|
import timber.log.Timber;
|
|
|
|
public final class AndroidComponentUtil {
|
|
|
|
private AndroidComponentUtil() throws InstantiationException {
|
|
throw new InstantiationException("This class is not for instantiation");
|
|
}
|
|
|
|
public static void toggleComponent(Context context, Class componentClass, boolean enable) {
|
|
Timber.i((enable ? "Enabling " : "Disabling ") + componentClass.getSimpleName());
|
|
ComponentName componentName = new ComponentName(context, componentClass);
|
|
PackageManager pm = context.getPackageManager();
|
|
pm.setComponentEnabledSetting(componentName,
|
|
enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
PackageManager.DONT_KILL_APP);
|
|
}
|
|
|
|
public static boolean isServiceRunning(Context context, Class serviceClass) {
|
|
ActivityManager manager =
|
|
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
if (serviceClass.getName().equals(service.service.getClassName())) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|