Skip to content

Commit

Permalink
Adjustments to Samsung (12-) and Pixel overlay detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Chainfire committed Nov 18, 2022
1 parent c99f1ca commit eadbfd5
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.view.accessibility.AccessibilityNodeInfo;

import java.util.List;
Expand All @@ -29,18 +28,17 @@
import eu.chainfire.holeylight.misc.Slog;

public class AreaFinderGoogle extends AreaFinder {
// we switched to requesting unimportant nodes for Android 13, so filter them out on older
private static boolean a13 = Build.VERSION.SDK_INT >= 33;

private Rect clockArea = null;

private void inspectNode(AccessibilityNodeInfo node, Rect outerBounds, int level) {
if (
(node == null) ||
(node.getClassName() == null) ||
(!a13 && !node.isImportantForAccessibility()) ||
(!Settings.DEBUG && (
(!node.getClassName().equals("android.widget.FrameLayout")) &&
(!node.getClassName().equals("android.widget.GridLayout")) &&
(!node.getClassName().equals("android.widget.LinearLayout")) &&
(!node.getClassName().equals("android.widget.RelativeLayout")) &&
(!node.getClassName().equals("com.android.internal.widget.ViewPager"))
))
) {
Expand All @@ -61,24 +59,54 @@ private void inspectNode(AccessibilityNodeInfo node, Rect outerBounds, int level
Slog.d(TAG, "Node " + l + node.getClassName().toString() + " " + bounds.toString() + " " + node.getViewIdResourceName());
}

if (level == 2 && (node.getViewIdResourceName() == null || !node.getViewIdResourceName().startsWith("com.android.systemui:id/keyguard_"))) {
if (node.getViewIdResourceName() != null && node.getViewIdResourceName().equals("com.android.systemui:id/default_clock_view")) {
// named text view with clock
if (bounds.left >= 0 && bounds.top >= 0 && bounds.width() > 0 && bounds.height() > 0) {
clockArea = new Rect(bounds);
}
} else if (clockArea != null && node.getClassName() != null && node.getClassName().equals("android.widget.TextView")) {
// unnamed text views below clock with date and weather
if (bounds.top == clockArea.bottom) {
clockArea.bottom = bounds.bottom;
}
}
if (
!(
bounds.left == 0 &&
bounds.top == 0
) &&
(
level == 2 || (
node.getViewIdResourceName() != null &&
node.getViewIdResourceName().equals("com.android.systemui:id/clock_notification_icon_container")
)
) &&
(
node.getViewIdResourceName() == null ||
(
!node.getViewIdResourceName().startsWith("com.android.systemui:id/keyguard_") ||
node.getViewIdResourceName().equals("com.android.systemui:id/keyguard_status_view")
)
)
) {
if ((bounds.left >= 0) && (bounds.right >= 0) && ((outerBounds.left == -1) || (bounds.left < outerBounds.left))) outerBounds.left = bounds.left;
if ((bounds.top >= 0) && (bounds.bottom >= 0) && ((outerBounds.top == -1) || (bounds.top < outerBounds.top))) outerBounds.top = bounds.top;
if ((bounds.left >= 0) && (bounds.right >= 0) && ((outerBounds.right == -1) || (bounds.right > outerBounds.right))) outerBounds.right = bounds.right;
if ((bounds.top >= 0) && (bounds.bottom >= 0) && ((outerBounds.bottom == -1) || (bounds.bottom > outerBounds.bottom))) outerBounds.bottom = bounds.bottom;
Slog.d(TAG, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
} else if (node.getClassName().equals("android.widget.FrameLayout") || Settings.DEBUG) {
}

if (node.getViewIdResourceName() != null && node.getViewIdResourceName().equals("com.android.systemui:id/default_clock_view")) {
// named text view with clock
if (bounds.left >= 0 && bounds.top >= 0 && bounds.width() > 0 && bounds.height() > 0) {
clockArea = new Rect(bounds);
Slog.d(TAG, "+++++++++++++++++++++++++++++++++++++++++++++++++++");
}
// This doesn't highlight the overlay area so something is still very wrong, but it works on my Pixel2XL ? TODO FIXME
// } else if (clockArea != null && node.getClassName() != null && node.getClassName().equals("android.widget.TextView")) {
// // unnamed text views below clock with date and weather
// if (bounds.top == clockArea.bottom) {
// clockArea.bottom = bounds.bottom;
// Slog.d(TAG, "+++++++++++++++++++++++++++++++++++++++++++++++++++");
// }
}

if (
node.getClassName().equals("android.widget.FrameLayout") ||
node.getClassName().equals("android.widget.GridLayout") ||
node.getClassName().equals("android.widget.LinearLayout") ||
node.getClassName().equals("android.widget.RelativeLayout") ||
Settings.DEBUG
) {
for (int i = 0; i < node.getChildCount(); i++) {
inspectNode(node.getChild(i), outerBounds, level + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
*/

public class AreaFinderSamsung extends AreaFinder {
// We switched to requesting unimportant nodes for Android 13, so filter them out on older
private static boolean a13 = Build.VERSION.SDK_INT >= 33;

private String previousNodeClass = null;
private boolean seenXViewPager = false;
private boolean haveSeenContainer = false; // if seen, accept no substitute
Expand All @@ -59,7 +56,7 @@ private void logNode(int level, AccessibilityNodeInfo node, Rect bounds) {
}
}

private void inspectClockNode(AccessibilityNodeInfo node, int level, Rect outerBounds) {
private void inspectClockNode(AccessibilityNodeInfo node, int level, Rect outerBounds, boolean forceChildren) {
for (int i = 0; i < node.getChildCount(); i++) {
AccessibilityNodeInfo child = node.getChild(i);
String childId = child.getViewIdResourceName();
Expand Down Expand Up @@ -89,10 +86,10 @@ private void inspectClockNode(AccessibilityNodeInfo node, int level, Rect outerB
} else {
logNode(level, child, childBounds);
}
} else if (childId != null && childId.equals("com.samsung.android.app.aodservice:id/common_clock_widget_container")) {
} else if (forceChildren || (childId != null && childId.equals("com.samsung.android.app.aodservice:id/common_clock_widget_container"))) {
Rect childBounds = new Rect();
logNode(level, child, childBounds);
inspectClockNode(child, level + 1, outerBounds);
inspectClockNode(child, level + 1, outerBounds, true);
} else if (Settings.DEBUG) {
Rect childBounds = new Rect();
child.getBoundsInScreen(childBounds);
Expand All @@ -110,9 +107,11 @@ private void inspectNode(AccessibilityNodeInfo node, Rect outerBounds, int level
if (
(node == null) ||
(node.getClassName() == null) ||
(!a13 && !node.isImportantForAccessibility()) ||
(!Settings.DEBUG && (
(!node.getClassName().equals("android.widget.FrameLayout")) &&
(!node.getClassName().equals("android.widget.GridLayout")) &&
(!node.getClassName().equals("android.widget.LinearLayout")) &&
(!node.getClassName().equals("android.widget.RelativeLayout")) &&
(!node.getClassName().equals("com.android.internal.widget.ViewPager")) &&
(!"com.samsung.android.app.aodservice:id/common_battery_text".equals(node.getViewIdResourceName()))
))
Expand All @@ -133,27 +132,39 @@ private void inspectNode(AccessibilityNodeInfo node, Rect outerBounds, int level
if ("com.samsung.android.app.aodservice:id/common_battery_text".equals(node.getViewIdResourceName())) {
overlayBottom = bounds.top - 1;
Slog.d(TAG, "|||||||||||||||||||||||||||||||||||||||||||||||||||");
} else if (node.getClassName().equals("com.android.internal.widget.ViewPager") || (
a11 &&
node.getClassName().equals("android.widget.FrameLayout") && (
(
outerBounds.left == -1 && (
} else if (
(
!(
bounds.left == 0 &&
bounds.top == 0
) &&
node.getViewIdResourceName() != null &&
!"com.android.systemui:id/lock_star_punch_hole_vi_animation_view".equals(node.getViewIdResourceName()) &&
!"com.android.systemui:id/lock_icon_view".equals(node.getViewIdResourceName())
) && (
node.getClassName().equals("com.android.internal.widget.ViewPager") || (
a11 &&
node.getClassName().equals("android.widget.FrameLayout") && (
(
previousNodeClass != null &&
previousNodeClass.equals("android.widget.ImageView")
) || (
seenXViewPager &&
level == 2
outerBounds.left == -1 && (
(
previousNodeClass != null &&
previousNodeClass.equals("android.widget.ImageView")
) || (
seenXViewPager &&
level == 2
) || (
node.getViewIdResourceName() != null &&
node.getViewIdResourceName().equals("com.samsung.android.app.aodservice:id/common_clock_widget_container")
)
)
) || (
node.getViewIdResourceName() != null &&
node.getViewIdResourceName().equals("com.samsung.android.app.aodservice:id/common_clock_widget_container")
outerBounds.left >= 0
)
)
) || (
outerBounds.left >= 0
)
)
)) {
) {
if (outerBounds.left == -1 && !seenXViewPager && haveSeenContainer && isTapToShow && !(node.getViewIdResourceName() != null && node.getViewIdResourceName().equals("com.samsung.android.app.aodservice:id/common_clock_widget_container"))) {
// skip
} else {
Expand All @@ -164,9 +175,15 @@ private void inspectNode(AccessibilityNodeInfo node, Rect outerBounds, int level
if ((bounds.top >= 0) && (bounds.bottom >= 0) && ((outerBounds.bottom == -1) || (bounds.bottom > outerBounds.bottom))) outerBounds.bottom = bounds.bottom;
Slog.d(TAG, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");

inspectClockNode(node, level + 1, outerBounds);
inspectClockNode(node, level + 1, outerBounds, node.getViewIdResourceName().equals("com.samsung.android.app.aodservice:id/common_clock_widget_container"));
}
} else if (node.getClassName().equals("android.widget.FrameLayout") || Settings.DEBUG) {
} else if (
node.getClassName().equals("android.widget.FrameLayout") ||
node.getClassName().equals("android.widget.GridLayout") ||
node.getClassName().equals("android.widget.LinearLayout") ||
node.getClassName().equals("android.widget.RelativeLayout") ||
Settings.DEBUG
) {
for (int i = 0; i < node.getChildCount(); i++) {
inspectNode(node.getChild(i), outerBounds, level + 1, a11, isTapToShow);
}
Expand Down

0 comments on commit eadbfd5

Please sign in to comment.