diff options
| author | 2023-05-10 17:58:28 +0800 | |
|---|---|---|
| committer | 2023-05-10 17:58:28 +0800 | |
| commit | f12b45f33518474142e9510f7556346e821005a2 (patch) | |
| tree | c403f6b227b39c34d107fb2c77b103fe3bc7ed17 | |
| parent | 706cc5848c07d4ab29b5c5ebbc624df41d19468b (diff) | |
Refine getIndex and getType of InsetsSource
The methods used "%" to clear higher bits, but it wouldn't work if the
integer is negative. This CLs uses "&" to clear bits that we don't want.
Fix: 281709596
Test: atest InsetsSourceTest
Change-Id: I845926f8b7d784d82b3f020736b478adf9482910
| -rw-r--r-- | core/java/android/view/InsetsSource.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/java/android/view/InsetsSource.java b/core/java/android/view/InsetsSource.java index 114f4ed04ee6..9fc42fff7084 100644 --- a/core/java/android/view/InsetsSource.java +++ b/core/java/android/view/InsetsSource.java @@ -293,16 +293,23 @@ public class InsetsSource implements Parcelable { * @see #createId(Object, int, int) */ public static int getIndex(int id) { - return (id % (1 << 16)) >> 5; + // start: ????????????????***********????? + // & 65535: 0000000000000000***********????? + // >> 5: 000000000000000000000*********** + return (id & 65535) >> 5; } /** * Gets the {@link InsetsType} from the ID. * * @see #createId(Object, int, int) + * @see WindowInsets.Type#indexOf(int) */ public static int getType(int id) { - return 1 << (id % 32); + // start: ???????????????????????????***** + // & 31: 000000000000000000000000000***** + // 1 <<: See WindowInsets.Type#indexOf + return 1 << (id & 31); } public static String flagsToString(@Flags int flags) { |