Skip to content

Commit c90d6e8

Browse files
committed
prevent ClassCastExceptions in RotationControl
1 parent dd19f7f commit c90d6e8

File tree

1 file changed

+11
-1
lines changed
  • RotationControl/src/main/java/com/programminghoch10/RotationControl

1 file changed

+11
-1
lines changed

RotationControl/src/main/java/com/programminghoch10/RotationControl/XposedHook.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.programminghoch10.RotationControl;
22

33
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.ContextWrapper;
46
import android.content.pm.ActivityInfo;
57
import android.view.Window;
68

@@ -24,7 +26,15 @@ protected void beforeHookedMethod(MethodHookParam param) {
2426
"generateLayout", "com.android.internal.policy.DecorView", new XC_MethodHook() {
2527
@Override
2628
protected void beforeHookedMethod(MethodHookParam param) {
27-
((Activity) ((Window) param.thisObject).getContext()).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
29+
Context context = ((Window) param.thisObject).getContext();
30+
31+
while (context instanceof ContextWrapper) {
32+
if (context instanceof Activity activity) {
33+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
34+
return;
35+
}
36+
context = ((ContextWrapper) context).getBaseContext();
37+
}
2838
}
2939
}
3040
);

0 commit comments

Comments
 (0)