Attempt to fix Xiaomi

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-02-19 03:28:15 +01:00
parent 2b2ec99e2d
commit c59a003d2a

View file

@ -22,13 +22,11 @@ package com.nextcloud.talk.utils;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,20 +46,11 @@ public class DeviceUtils {
if (result instanceof Integer) { if (result instanceof Integer) {
Integer integerResult = (Integer) result; Integer integerResult = (Integer) result;
if (integerResult == 0) { if (integerResult == 0) {
Class<ApplicationInfo> clazz = ApplicationInfo.class; Method setApplicationAutoStartMethod = aClass.getDeclaredMethod("setApplicationAutoStart",
Field[] fields = clazz.getDeclaredFields(); Context.class, String.class, Boolean.TYPE);
if (setApplicationAutoStartMethod != null) {
for (Field field : fields) { setApplicationAutoStartMethod.invoke(aClass, applicationContext, applicationContext.getPackageName(),
field.setAccessible(true); Boolean.TRUE);
if (field.getName().equals("FLAG_DISABLE_AUTOSTART")) {
int value = field.getInt(ApplicationInfo.class);
if (value != 0) {
field.setInt(ApplicationInfo.class, 0);
field.setAccessible(false);
}
break;
}
field.setAccessible(false);
} }
} }
} }