Skip to content

Commit

Permalink
Set provider of FakeContext as a workaround
Browse files Browse the repository at this point in the history
The ContentProvider of FakeContext is tricky, being null or not, it can
always break notification construction in some devices.
See #79 for details.
  • Loading branch information
JingMatrix committed Nov 24, 2024
1 parent 0a2f26f commit b3d771c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
29 changes: 21 additions & 8 deletions daemon/src/main/java/org/lsposed/lspd/service/ServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,8 +40,10 @@
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;
Expand Down Expand Up @@ -152,8 +155,7 @@ public static void start(String[] args) {

ConfigFileManager.reloadConfiguration();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
notificationWorkaround();
notificationWorkaround();

BridgeService.send(mainService, new BridgeService.Listener() {
@Override
Expand Down Expand Up @@ -242,15 +244,26 @@ private static void permissionManagerWorkaround() {
}

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");
systemui_is_cached.setAccessible(true);
systemui_is_cached.set(null, true);
Log.d(TAG, "set flag systemui_is_cached to true");
} catch (Throwable e) {
Log.e(TAG, "failed to change feature flags", e);
}
}

try {
Class feature = Class.forName("android.app.FeatureFlagsImpl");
Field systemui_is_cached = feature.getDeclaredField("systemui_is_cached");
systemui_is_cached.setAccessible(true);
systemui_is_cached.set(null, true);
Log.d(TAG, "set flag systemui_is_cached to true");
new Notification.Builder(new FakeContext(), "notification_workaround").build();
} catch (AbstractMethodError e) {
FakeContext.nullProvider = ! FakeContext.nullProvider;
} catch (Throwable e) {
Log.e(TAG, "failed to change feature flags", e);
Log.e(TAG, "failed to build notifications", e);
}

}

private static class BinderProxy extends Binder {
Expand Down
10 changes: 8 additions & 2 deletions daemon/src/main/java/org/lsposed/lspd/util/FakeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
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);
Expand Down Expand Up @@ -59,8 +62,11 @@ public ApplicationInfo getApplicationInfo() {

@Override
public ContentResolver getContentResolver() {
return new ContentResolver(this) {
};
if (nullProvider) {
return null;
} else {
return new ContentResolver(this) {};
}
}

public int getUserId() {
Expand Down

0 comments on commit b3d771c

Please sign in to comment.