Set provider of FakeContext as a workaround
The ContentProvider of FakeContext is tricky, being null or not, it can always break notification construction in some devices. Close #79 as fixed.
This commit is contained in:
parent
0a2f26fef9
commit
85b8fa17fb
|
|
@ -20,6 +20,7 @@
|
|||
package org.lsposed.lspd.service;
|
||||
|
||||
import android.app.ActivityThread;
|
||||
import android.app.Notification;
|
||||
import android.content.Context;
|
||||
import android.ddm.DdmHandleAppName;
|
||||
import android.os.Binder;
|
||||
|
|
@ -39,8 +40,10 @@ import androidx.annotation.RequiresApi;
|
|||
import com.android.internal.os.BinderInternal;
|
||||
|
||||
import org.lsposed.daemon.BuildConfig;
|
||||
import org.lsposed.lspd.util.FakeContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.AbstractMethodError;
|
||||
import java.lang.Class;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
|
@ -152,7 +155,6 @@ public class ServiceManager {
|
|||
|
||||
ConfigFileManager.reloadConfiguration();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
||||
notificationWorkaround();
|
||||
|
||||
BridgeService.send(mainService, new BridgeService.Listener() {
|
||||
|
|
@ -242,6 +244,7 @@ public class ServiceManager {
|
|||
}
|
||||
|
||||
private static void notificationWorkaround() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
try {
|
||||
Class feature = Class.forName("android.app.FeatureFlagsImpl");
|
||||
Field systemui_is_cached = feature.getDeclaredField("systemui_is_cached");
|
||||
|
|
@ -253,6 +256,16 @@ public class ServiceManager {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new Notification.Builder(new FakeContext(), "notification_workaround").build();
|
||||
} catch (AbstractMethodError e) {
|
||||
FakeContext.nullProvider = ! FakeContext.nullProvider;
|
||||
} catch (Throwable e) {
|
||||
Log.e(TAG, "failed to build notifications", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class BinderProxy extends Binder {
|
||||
private static final Method rawGetService;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ import hidden.HiddenApiBridge;
|
|||
public class FakeContext extends ContextWrapper {
|
||||
static ApplicationInfo systemApplicationInfo = null;
|
||||
static Resources.Theme theme = null;
|
||||
|
||||
public static Boolean nullProvider = false;
|
||||
|
||||
private String packageName = "android";
|
||||
public FakeContext() {
|
||||
super(null);
|
||||
|
|
@ -59,8 +62,11 @@ public class FakeContext extends ContextWrapper {
|
|||
|
||||
@Override
|
||||
public ContentResolver getContentResolver() {
|
||||
return new ContentResolver(this) {
|
||||
};
|
||||
if (nullProvider) {
|
||||
return null;
|
||||
} else {
|
||||
return new ContentResolver(this) {};
|
||||
}
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue