| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.window; |
| 18 |
|
| 19 |
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 20 |
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
| 21 |
import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 22 |
|
| 23 |
import android.annotation.NonNull; |
| 24 |
import android.annotation.Nullable; |
| 25 |
import android.content.res.Configuration; |
| 26 |
import android.os.Parcelable; |
| 27 |
import android.util.SparseIntArray; |
| 28 |
|
| 29 |
import com.android.internal.annotations.VisibleForTesting; |
| 30 |
import com.android.internal.util.DataClass; |
| 31 |
|
| 32 |
import java.util.Arrays; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
@DataClass(genAidl = true) |
| 45 |
public final class SizeConfigurationBuckets implements Parcelable { |
| 46 |
|
| 47 |
|
| 48 |
@Nullable |
| 49 |
private final int[] mHorizontal; |
| 50 |
|
| 51 |
|
| 52 |
@Nullable |
| 53 |
private final int[] mVertical; |
| 54 |
|
| 55 |
|
| 56 |
@Nullable |
| 57 |
private final int[] mSmallest; |
| 58 |
|
| 59 |
|
| 60 |
@Nullable |
| 61 |
private final int[] mScreenLayoutSize; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
private final boolean mScreenLayoutLongSet; |
| 69 |
|
| 70 |
public SizeConfigurationBuckets(Configuration[] sizeConfigurations) { |
| 71 |
SparseIntArray horizontal = new SparseIntArray(); |
| 72 |
SparseIntArray vertical = new SparseIntArray(); |
| 73 |
SparseIntArray smallest = new SparseIntArray(); |
| 74 |
SparseIntArray screenLayoutSize = new SparseIntArray(); |
| 75 |
int curScreenLayoutSize; |
| 76 |
boolean screenLayoutLongSet = false; |
| 77 |
for (int i = sizeConfigurations.length - 1; i >= 0; i--) { |
| 78 |
Configuration config = sizeConfigurations[i]; |
| 79 |
if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
| 80 |
vertical.put(config.screenHeightDp, 0); |
| 81 |
} |
| 82 |
if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
| 83 |
horizontal.put(config.screenWidthDp, 0); |
| 84 |
} |
| 85 |
if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
| 86 |
smallest.put(config.smallestScreenWidthDp, 0); |
| 87 |
} |
| 88 |
if ((curScreenLayoutSize = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) |
| 89 |
!= Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| 90 |
screenLayoutSize.put(curScreenLayoutSize, 0); |
| 91 |
} |
| 92 |
if (!screenLayoutLongSet && (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) |
| 93 |
!= Configuration.SCREENLAYOUT_LONG_UNDEFINED) { |
| 94 |
screenLayoutLongSet = true; |
| 95 |
} |
| 96 |
} |
| 97 |
mHorizontal = horizontal.copyKeys(); |
| 98 |
mVertical = vertical.copyKeys(); |
| 99 |
mSmallest = smallest.copyKeys(); |
| 100 |
mScreenLayoutSize = screenLayoutSize.copyKeys(); |
| 101 |
mScreenLayoutLongSet = screenLayoutLongSet; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public static int filterDiff(int diff, @NonNull Configuration oldConfig, |
| 109 |
@NonNull Configuration newConfig, @Nullable SizeConfigurationBuckets buckets) { |
| 110 |
if (buckets == null) { |
| 111 |
return diff; |
| 112 |
} |
| 113 |
|
| 114 |
final boolean nonSizeLayoutFieldsUnchanged = |
| 115 |
areNonSizeLayoutFieldsUnchanged(oldConfig.screenLayout, newConfig.screenLayout); |
| 116 |
if ((diff & CONFIG_SCREEN_SIZE) != 0) { |
| 117 |
final boolean crosses = buckets.crossesHorizontalSizeThreshold(oldConfig.screenWidthDp, |
| 118 |
newConfig.screenWidthDp) |
| 119 |
|| buckets.crossesVerticalSizeThreshold(oldConfig.screenHeightDp, |
| 120 |
newConfig.screenHeightDp); |
| 121 |
if (!crosses) { |
| 122 |
diff &= ~CONFIG_SCREEN_SIZE; |
| 123 |
} |
| 124 |
} |
| 125 |
if ((diff & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
| 126 |
final int oldSmallest = oldConfig.smallestScreenWidthDp; |
| 127 |
final int newSmallest = newConfig.smallestScreenWidthDp; |
| 128 |
if (!buckets.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
| 129 |
diff &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
| 130 |
} |
| 131 |
} |
| 132 |
if ((diff & CONFIG_SCREEN_LAYOUT) != 0 && nonSizeLayoutFieldsUnchanged) { |
| 133 |
if (!buckets.crossesScreenLayoutSizeThreshold(oldConfig, newConfig) |
| 134 |
&& !buckets.crossesScreenLayoutLongThreshold(oldConfig.screenLayout, |
| 135 |
newConfig.screenLayout)) { |
| 136 |
diff &= ~CONFIG_SCREEN_LAYOUT; |
| 137 |
} |
| 138 |
} |
| 139 |
return diff; |
| 140 |
} |
| 141 |
|
| 142 |
private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) { |
| 143 |
return crossesSizeThreshold(mHorizontal, firstDp, secondDp); |
| 144 |
} |
| 145 |
|
| 146 |
private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) { |
| 147 |
return crossesSizeThreshold(mVertical, firstDp, secondDp); |
| 148 |
} |
| 149 |
|
| 150 |
private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) { |
| 151 |
return crossesSizeThreshold(mSmallest, firstDp, secondDp); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
@VisibleForTesting |
| 158 |
public boolean crossesScreenLayoutSizeThreshold(@NonNull Configuration firstConfig, |
| 159 |
@NonNull Configuration secondConfig) { |
| 160 |
|
| 161 |
|
| 162 |
if ((firstConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) |
| 163 |
== (secondConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)) { |
| 164 |
return false; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
if (!secondConfig.isLayoutSizeAtLeast(firstConfig.screenLayout |
| 170 |
& Configuration.SCREENLAYOUT_SIZE_MASK)) { |
| 171 |
return true; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
if (mScreenLayoutSize != null) { |
| 176 |
for (int screenLayoutSize : mScreenLayoutSize) { |
| 177 |
if (firstConfig.isLayoutSizeAtLeast(screenLayoutSize) |
| 178 |
!= secondConfig.isLayoutSizeAtLeast(screenLayoutSize)) { |
| 179 |
return true; |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
return false; |
| 184 |
} |
| 185 |
|
| 186 |
private boolean crossesScreenLayoutLongThreshold(int firstScreenLayout, |
| 187 |
int secondScreenLayout) { |
| 188 |
final int firstScreenLayoutLongValue = firstScreenLayout |
| 189 |
& Configuration.SCREENLAYOUT_LONG_MASK; |
| 190 |
final int secondScreenLayoutLongValue = secondScreenLayout |
| 191 |
& Configuration.SCREENLAYOUT_LONG_MASK; |
| 192 |
return mScreenLayoutLongSet && firstScreenLayoutLongValue != secondScreenLayoutLongValue; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
@VisibleForTesting |
| 202 |
public static boolean areNonSizeLayoutFieldsUnchanged(int oldScreenLayout, |
| 203 |
int newScreenLayout) { |
| 204 |
final int nonSizeRelatedFields = Configuration.SCREENLAYOUT_LAYOUTDIR_MASK |
| 205 |
| Configuration.SCREENLAYOUT_ROUND_MASK | Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 206 |
return (oldScreenLayout & nonSizeRelatedFields) == (newScreenLayout & nonSizeRelatedFields); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
@VisibleForTesting |
| 224 |
public static boolean crossesSizeThreshold(int[] thresholds, int firstDp, |
| 225 |
int secondDp) { |
| 226 |
if (thresholds == null) { |
| 227 |
return false; |
| 228 |
} |
| 229 |
for (int i = thresholds.length - 1; i >= 0; i--) { |
| 230 |
final int threshold = thresholds[i]; |
| 231 |
if ((firstDp < threshold && secondDp >= threshold) |
| 232 |
|| (firstDp >= threshold && secondDp < threshold)) { |
| 233 |
return true; |
| 234 |
} |
| 235 |
} |
| 236 |
return false; |
| 237 |
} |
| 238 |
|
| 239 |
@Override |
| 240 |
public String toString() { |
| 241 |
return Arrays.toString(mHorizontal) + " " + Arrays.toString(mVertical) + " " |
| 242 |
+ Arrays.toString(mSmallest) + " " + Arrays.toString(mScreenLayoutSize) + " " |
| 243 |
+ mScreenLayoutLongSet; |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
@DataClass.Generated.Member |
| 278 |
public SizeConfigurationBuckets( |
| 279 |
@Nullable int[] horizontal, |
| 280 |
@Nullable int[] vertical, |
| 281 |
@Nullable int[] smallest, |
| 282 |
@Nullable int[] screenLayoutSize, |
| 283 |
boolean screenLayoutLongSet) { |
| 284 |
this.mHorizontal = horizontal; |
| 285 |
this.mVertical = vertical; |
| 286 |
this.mSmallest = smallest; |
| 287 |
this.mScreenLayoutSize = screenLayoutSize; |
| 288 |
this.mScreenLayoutLongSet = screenLayoutLongSet; |
| 289 |
|
| 290 |
|
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
@DataClass.Generated.Member |
| 297 |
public @Nullable int[] getHorizontal() { |
| 298 |
return mHorizontal; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
@DataClass.Generated.Member |
| 305 |
public @Nullable int[] getVertical() { |
| 306 |
return mVertical; |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
@DataClass.Generated.Member |
| 313 |
public @Nullable int[] getSmallest() { |
| 314 |
return mSmallest; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
@DataClass.Generated.Member |
| 321 |
public @Nullable int[] getScreenLayoutSize() { |
| 322 |
return mScreenLayoutSize; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
@DataClass.Generated.Member |
| 331 |
public boolean isScreenLayoutLongSet() { |
| 332 |
return mScreenLayoutLongSet; |
| 333 |
} |
| 334 |
|
| 335 |
@Override |
| 336 |
@DataClass.Generated.Member |
| 337 |
public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
byte flg = 0; |
| 342 |
if (mScreenLayoutLongSet) flg |= 0x10; |
| 343 |
if (mHorizontal != null) flg |= 0x1; |
| 344 |
if (mVertical != null) flg |= 0x2; |
| 345 |
if (mSmallest != null) flg |= 0x4; |
| 346 |
if (mScreenLayoutSize != null) flg |= 0x8; |
| 347 |
dest.writeByte(flg); |
| 348 |
if (mHorizontal != null) dest.writeIntArray(mHorizontal); |
| 349 |
if (mVertical != null) dest.writeIntArray(mVertical); |
| 350 |
if (mSmallest != null) dest.writeIntArray(mSmallest); |
| 351 |
if (mScreenLayoutSize != null) dest.writeIntArray(mScreenLayoutSize); |
| 352 |
} |
| 353 |
|
| 354 |
@Override |
| 355 |
@DataClass.Generated.Member |
| 356 |
public int describeContents() { return 0; } |
| 357 |
|
| 358 |
|
| 359 |
@SuppressWarnings({"unchecked", "RedundantCast"}) |
| 360 |
@DataClass.Generated.Member |
| 361 |
SizeConfigurationBuckets(@NonNull android.os.Parcel in) { |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
byte flg = in.readByte(); |
| 366 |
boolean screenLayoutLongSet = (flg & 0x10) != 0; |
| 367 |
int[] horizontal = (flg & 0x1) == 0 ? null : in.createIntArray(); |
| 368 |
int[] vertical = (flg & 0x2) == 0 ? null : in.createIntArray(); |
| 369 |
int[] smallest = (flg & 0x4) == 0 ? null : in.createIntArray(); |
| 370 |
int[] screenLayoutSize = (flg & 0x8) == 0 ? null : in.createIntArray(); |
| 371 |
|
| 372 |
this.mHorizontal = horizontal; |
| 373 |
this.mVertical = vertical; |
| 374 |
this.mSmallest = smallest; |
| 375 |
this.mScreenLayoutSize = screenLayoutSize; |
| 376 |
this.mScreenLayoutLongSet = screenLayoutLongSet; |
| 377 |
|
| 378 |
|
| 379 |
} |
| 380 |
|
| 381 |
@DataClass.Generated.Member |
| 382 |
public static final @NonNull Parcelable.Creator<SizeConfigurationBuckets> CREATOR |
| 383 |
= new Parcelable.Creator<SizeConfigurationBuckets>() { |
| 384 |
@Override |
| 385 |
public SizeConfigurationBuckets[] newArray(int size) { |
| 386 |
return new SizeConfigurationBuckets[size]; |
| 387 |
} |
| 388 |
|
| 389 |
@Override |
| 390 |
public SizeConfigurationBuckets createFromParcel(@NonNull android.os.Parcel in) { |
| 391 |
return new SizeConfigurationBuckets(in); |
| 392 |
} |
| 393 |
}; |
| 394 |
|
| 395 |
@DataClass.Generated( |
| 396 |
time = 1628273704583L, |
| 397 |
codegenVersion = "1.0.23", |
| 398 |
sourceFile = "frameworks/base/core/java/android/window/SizeConfigurationBuckets.java", |
| 399 |
inputSignatures = "private final @android.annotation.Nullable int[] mHorizontal\nprivate final @android.annotation.Nullable int[] mVertical\nprivate final @android.annotation.Nullable int[] mSmallest\nprivate final @android.annotation.Nullable int[] mScreenLayoutSize\nprivate final boolean mScreenLayoutLongSet\npublic static int filterDiff(int,android.content.res.Configuration,android.content.res.Configuration,android.window.SizeConfigurationBuckets)\nprivate boolean crossesHorizontalSizeThreshold(int,int)\nprivate boolean crossesVerticalSizeThreshold(int,int)\nprivate boolean crossesSmallestSizeThreshold(int,int)\npublic @com.android.internal.annotations.VisibleForTesting boolean crossesScreenLayoutSizeThreshold(android.content.res.Configuration,android.content.res.Configuration)\nprivate boolean crossesScreenLayoutLongThreshold(int,int)\npublic static @com.android.internal.annotations.VisibleForTesting boolean areNonSizeLayoutFieldsUnchanged(int,int)\npublic static @com.android.internal.annotations.VisibleForTesting boolean crossesSizeThreshold(int[],int,int)\npublic @java.lang.Override java.lang.String toString()\nclass SizeConfigurationBuckets extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genAidl=true)") |
| 400 |
@Deprecated |
| 401 |
private void __metadata() {} |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
} |