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;
|
package org.lsposed.lspd.service;
|
||||||
|
|
||||||
import android.app.ActivityThread;
|
import android.app.ActivityThread;
|
||||||
|
import android.app.Notification;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.ddm.DdmHandleAppName;
|
import android.ddm.DdmHandleAppName;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
|
@ -39,8 +40,10 @@ import androidx.annotation.RequiresApi;
|
||||||
import com.android.internal.os.BinderInternal;
|
import com.android.internal.os.BinderInternal;
|
||||||
|
|
||||||
import org.lsposed.daemon.BuildConfig;
|
import org.lsposed.daemon.BuildConfig;
|
||||||
|
import org.lsposed.lspd.util.FakeContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.AbstractMethodError;
|
||||||
import java.lang.Class;
|
import java.lang.Class;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
@ -152,8 +155,7 @@ public class ServiceManager {
|
||||||
|
|
||||||
ConfigFileManager.reloadConfiguration();
|
ConfigFileManager.reloadConfiguration();
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
notificationWorkaround();
|
||||||
notificationWorkaround();
|
|
||||||
|
|
||||||
BridgeService.send(mainService, new BridgeService.Listener() {
|
BridgeService.send(mainService, new BridgeService.Listener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -242,15 +244,26 @@ public class ServiceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void notificationWorkaround() {
|
private static void notificationWorkaround() {
|
||||||
try {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||||
Class feature = Class.forName("android.app.FeatureFlagsImpl");
|
try {
|
||||||
Field systemui_is_cached = feature.getDeclaredField("systemui_is_cached");
|
Class feature = Class.forName("android.app.FeatureFlagsImpl");
|
||||||
systemui_is_cached.setAccessible(true);
|
Field systemui_is_cached = feature.getDeclaredField("systemui_is_cached");
|
||||||
systemui_is_cached.set(null, true);
|
systemui_is_cached.setAccessible(true);
|
||||||
Log.d(TAG, "set flag systemui_is_cached to true");
|
systemui_is_cached.set(null, true);
|
||||||
} catch (Throwable e) {
|
Log.d(TAG, "set flag systemui_is_cached to true");
|
||||||
Log.e(TAG, "failed to change feature flags", e);
|
} catch (Throwable e) {
|
||||||
|
Log.e(TAG, "failed to change feature flags", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 class BinderProxy extends Binder {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ import hidden.HiddenApiBridge;
|
||||||
public class FakeContext extends ContextWrapper {
|
public class FakeContext extends ContextWrapper {
|
||||||
static ApplicationInfo systemApplicationInfo = null;
|
static ApplicationInfo systemApplicationInfo = null;
|
||||||
static Resources.Theme theme = null;
|
static Resources.Theme theme = null;
|
||||||
|
|
||||||
|
public static Boolean nullProvider = false;
|
||||||
|
|
||||||
private String packageName = "android";
|
private String packageName = "android";
|
||||||
public FakeContext() {
|
public FakeContext() {
|
||||||
super(null);
|
super(null);
|
||||||
|
|
@ -59,8 +62,11 @@ public class FakeContext extends ContextWrapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContentResolver getContentResolver() {
|
public ContentResolver getContentResolver() {
|
||||||
return new ContentResolver(this) {
|
if (nullProvider) {
|
||||||
};
|
return null;
|
||||||
|
} else {
|
||||||
|
return new ContentResolver(this) {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUserId() {
|
public int getUserId() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue