Audit and fix Android OS version checks, and introduce presubmits to prevent regressions |
|||||
Issue description
There are several problematic patterns that have been used to check aspects of which Android version we're running on, especially when checking for still-unreleased platform versions, which have caused bugs when moving to final SDKs.
We should audit master to find and fix problematic usages, and introduce presubmit checks which try to make it harder for people to accidentally do the wrong thing.
Some examples of things which are (or may be in some cases) incorrect:
1) Testing the value of Build.VERSION.CODENAME. This is a fragile check typically used for in-development versions of the platform, which can easily break due to changes in Android.. This should not be used in general Chromium code at all - we should centralise all of these checks in the class BuildInfo (by having other code call BuildInfo.isAtLeastO() or similarly-named methods), so that when the
exact check required changes it can be updated in a single place.
2) Some usages of Build.VERSION.SDK_INT; especially uses that compare to the latest platform version. This is trickier to explain, so here are some borderline examples given in the context of the present time, when the final O SDK is not yet available:
2a) Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1
This is fine, "older than N-MR1" is well-defined"
2b) Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1
Also fine, it's the inverse of 2a
2c) Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1
This is probably not OK. "newer than N-MR1" isn't well-defined until it's known which SDK_INT is O.
2d) Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1
Also not OK, it's the inverse of 2c
2e) Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1
Also not OK, it's asserting "only N-MR1 has some property" which might not be true if an MR2 happens
When the comparison is to an "older" SDK version (not the latest public SDK) then it's probably fine, but for consistency it might be easiest to just ban some of these usages entirely and rewrite the ones that are okay to be in the "safer" forms.
It's also important never to compare to CUR_DEVELOPMENT (or any other constant which evaluates to the same value, 10000, for example the Build.VERSION_CODES.O constant in the developer preview SDK which is 10000).
3) Same as 2) but for native code using sdk_int() from the native BuildInfo class.
4) Checks for ApplicationInfo.targetSdkVersion similarly. These are in basically all cases only used in WebView since Chrome's targetSdkVersion isn't variable, but they need all the same caution/care. Checks for unreleased versions in targetSdkVersion should also be indirected via BuildInfo, not done by implementing complex checks in multiple places in the code.
I think it's okay to err on the side of being conservative, and have a presubmit which looks for any usage of the relevant Build.VERSION properties and whitelists only things we know are okay, maybe?
,
May 23 2017
,
May 23 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/f494f8655828bca8094e8a71a9bda2ecdddd280d commit f494f8655828bca8094e8a71a9bda2ecdddd280d Author: torne <torne@chromium.org> Date: Tue May 23 18:42:50 2017 Android: tidy up outdated version checks. Fix various outdated version checks in the Android code: 1) Remove comparisons to Build.VERSION.CODENAME that refer to released SDKs and replace with correct SDK_INT comparisons instead. 2) Compare SDK_INT to constants instead of integer literals. 3) Remove old ICS-only code from NFC BeamCallback since we don't support pre-JB any more. BUG=724622 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel Review-Url: https://codereview.chromium.org/2895293002 Cr-Commit-Position: refs/heads/master@{#473998} [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/android_webview/glue/java/src/com/android/webview/chromium/DrawGLFunctor.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/android_webview/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/android_webview/java/src/org/chromium/android_webview/AwContents.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/ActionModeTest.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/base/android/java/src/org/chromium/base/CommandLineInitUtil.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/ChromeStrictMode.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/init/AsyncInitializationActivity.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/nfc/BeamCallback.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/notifications/StandardNotificationBuilder.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/media/base/android/media_codec_util.cc [modify] https://crrev.com/f494f8655828bca8094e8a71a9bda2ecdddd280d/media/gpu/android_video_decode_accelerator.cc
,
May 26 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/fc4e84a80b729297c446bc1bf3b0fce67ecfd65f commit fc4e84a80b729297c446bc1bf3b0fce67ecfd65f Author: torne <torne@chromium.org> Date: Fri May 26 16:52:36 2017 Update cbcs encryption version check for clarity. Make it clearer that the platform bug was fixed in N-MR1. The original check was correct, but it's easier to be sure that the author doesn't mean "fixed in O" if the check explicitly refers to N-MR1 instead of just writing ">N". BUG=724622 Review-Url: https://codereview.chromium.org/2896303006 Cr-Commit-Position: refs/heads/master@{#475034} [modify] https://crrev.com/fc4e84a80b729297c446bc1bf3b0fce67ecfd65f/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java
,
May 28 2018
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue. Sorry for the inconvenience if the bug really should have been left as Available. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
May 30 2018
@torne, is this still relevant?
,
May 30 2018
Yes, I just haven't had a chance to actually look at it :|
,
Sep 8
No longer on the Chrome team, e-mail me @google.com if any attention still required from me here, otherwise good luck! |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by nyquist@chromium.org
, May 22 2017