2016-01-15 09:18:19 -05:00
|
|
|
package eu.kanade.tachiyomi.util;
|
2015-11-02 11:25:06 -05:00
|
|
|
|
|
|
|
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 class AndroidComponentUtil {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|