Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -36168,6 +36168,7 @@ ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl.h + ..
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_lru.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_lru.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/Build.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/BuildConfig.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/FlutterInjector.java + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/io/flutter/Log.java + ../../../flutter/LICENSE
Expand Down Expand Up @@ -39022,6 +39023,7 @@ FILE: ../../../flutter/shell/platform/android/image_external_texture_vk.cc
FILE: ../../../flutter/shell/platform/android/image_external_texture_vk.h
FILE: ../../../flutter/shell/platform/android/image_lru.cc
FILE: ../../../flutter/shell/platform/android/image_lru.h
FILE: ../../../flutter/shell/platform/android/io/flutter/Build.java
FILE: ../../../flutter/shell/platform/android/io/flutter/BuildConfig.java
FILE: ../../../flutter/shell/platform/android/io/flutter/FlutterInjector.java
FILE: ../../../flutter/shell/platform/android/io/flutter/Log.java
Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ embedding_sources_jar_filename = "$embedding_artifact_id-sources.jar"
embedding_source_jar_path = "$root_out_dir/$embedding_sources_jar_filename"

android_java_sources = [
"io/flutter/Build.java",
"io/flutter/FlutterInjector.java",
"io/flutter/Log.java",
"io/flutter/app/FlutterActivity.java",
Expand Down
27 changes: 27 additions & 0 deletions shell/platform/android/io/flutter/Build.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter;

/** A replacement of utilities from android.os.Build. */
public class Build {
/** For use in place of the Android VERSION CODES class. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite the comment so if someone searched for the official class they would find this:

/** For use in place of Build.VERSION_CODES class */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but I'll have to special case the forbidden imports script to allow it in this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the linter detect that text is contained inside of a comment?

public static class API_LEVELS {
public static final int API_21 = 21;
public static final int API_22 = 22;
public static final int API_23 = 23;
public static final int API_24 = 24;
public static final int API_25 = 25;
public static final int API_26 = 26;
public static final int API_27 = 27;
public static final int API_28 = 28;
public static final int API_29 = 29;
public static final int API_30 = 30;
public static final int API_31 = 31;
public static final int API_32 = 32;
public static final int API_33 = 33;
public static final int API_34 = 34;
public static final int API_35 = 35;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.flutter.embedding.android;

import static io.flutter.Build.API_LEVELS;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Matrix;
Expand Down Expand Up @@ -427,7 +429,7 @@ private void addPointerForIndex(
}

private float getHorizontalScrollFactor(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_26) {
return ViewConfiguration.get(context).getScaledHorizontalScrollFactor();
} else {
// Vertical scroll factor is not a typo. This is what View.java does in android.
Expand All @@ -436,7 +438,7 @@ private float getHorizontalScrollFactor(@NonNull Context context) {
}

private float getVerticalScrollFactor(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_26) {
return getVerticalScrollFactorAbove26(context);
} else {
return getVerticalScrollFactorPre26(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.flutter.embedding.android;

import static io.flutter.Build.API_LEVELS;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.DART_ENTRYPOINT_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.DART_ENTRYPOINT_URI_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.DEFAULT_BACKGROUND_MODE;
Expand Down Expand Up @@ -654,7 +655,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
*/
@VisibleForTesting
public void registerOnBackInvokedCallback() {
if (Build.VERSION.SDK_INT >= 33) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_33) {
getOnBackInvokedDispatcher()
.registerOnBackInvokedCallback(
OnBackInvokedDispatcher.PRIORITY_DEFAULT, onBackInvokedCallback);
Expand All @@ -670,14 +671,14 @@ public void registerOnBackInvokedCallback() {
*/
@VisibleForTesting
public void unregisterOnBackInvokedCallback() {
if (Build.VERSION.SDK_INT >= 33) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_33) {
getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(onBackInvokedCallback);
hasRegisteredBackCallback = false;
}
}

private final OnBackInvokedCallback onBackInvokedCallback =
Build.VERSION.SDK_INT >= 33
Build.VERSION.SDK_INT >= API_LEVELS.API_33
? new OnBackInvokedCallback() {
// TODO(garyq): Remove SuppressWarnings annotation. This was added to workaround
// a google3 bug where the linter is not properly running against API 33, causing
Expand Down Expand Up @@ -1369,7 +1370,7 @@ public void onFlutterUiDisplayed() {
// * reportFullyDrawn behavior isn't tested on pre-Q versions.
// See https://github.com/flutter/flutter/issues/46172, and
// https://github.com/flutter/flutter/issues/88767.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_29) {
reportFullyDrawn();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.embedding.android;

import static io.flutter.Build.API_LEVELS;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
Expand Down Expand Up @@ -109,7 +111,7 @@ private static ImageReader createImageReader(int width, int height) {
logW("ImageReader height must be greater than 0, but given height=%d, set height=1", height);
height = 1;
}
if (android.os.Build.VERSION.SDK_INT >= 29) {
if (android.os.Build.VERSION.SDK_INT >= API_LEVELS.API_29) {
return ImageReader.newInstance(
width,
height,
Expand Down Expand Up @@ -253,7 +255,7 @@ private void closeCurrentImage() {

@TargetApi(29)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

private void updateCurrentBitmap() {
if (android.os.Build.VERSION.SDK_INT >= 29) {
if (android.os.Build.VERSION.SDK_INT >= API_LEVELS.API_29) {
final HardwareBuffer buffer = currentImage.getHardwareBuffer();
currentBitmap = Bitmap.wrapHardwareBuffer(buffer, ColorSpace.get(ColorSpace.Named.SRGB));
buffer.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.embedding.android;

import static io.flutter.Build.API_LEVELS;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
Expand Down Expand Up @@ -385,7 +387,7 @@ private void init() {
// FlutterView needs to be focusable so that the InputMethodManager can interact with it.
setFocusable(true);
setFocusableInTouchMode(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_26) {
setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_YES);
}
}
Expand Down Expand Up @@ -574,7 +576,7 @@ protected void setWindowInfoListenerDisplayFeatures(WindowLayoutInfo layoutInfo)

// Data from the DisplayCutout bounds. Cutouts for cameras and other sensors are
// populated here. DisplayCutout was introduced in API 28.
if (Build.VERSION.SDK_INT >= 28) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_28) {
WindowInsets insets = getRootWindowInsets();
if (insets != null) {
DisplayCutout cutout = insets.getDisplayCutout();
Expand Down Expand Up @@ -619,7 +621,7 @@ private ZeroSides calculateShouldZeroSides() {
return ZeroSides.RIGHT;
} else if (rotation == Surface.ROTATION_270) {
// In android API >= 23, the nav bar always appears on the "bottom" (USB) side.
return Build.VERSION.SDK_INT >= 23 ? ZeroSides.LEFT : ZeroSides.RIGHT;
return Build.VERSION.SDK_INT >= API_LEVELS.API_23 ? ZeroSides.LEFT : ZeroSides.RIGHT;
}
// Ambiguous orientation due to landscape left/right default. Zero both sides.
else if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
Expand Down Expand Up @@ -677,7 +679,7 @@ public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) {
WindowInsets newInsets = super.onApplyWindowInsets(insets);

// getSystemGestureInsets() was introduced in API 29 and immediately deprecated in 30.
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT == API_LEVELS.API_29) {
Insets systemGestureInsets = insets.getSystemGestureInsets();
viewportMetrics.systemGestureInsetTop = systemGestureInsets.top;
viewportMetrics.systemGestureInsetRight = systemGestureInsets.right;
Expand All @@ -689,7 +691,7 @@ public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) {
boolean navigationBarVisible =
(SYSTEM_UI_FLAG_HIDE_NAVIGATION & getWindowSystemUiVisibility()) == 0;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_30) {
int mask = 0;
if (navigationBarVisible) {
mask = mask | android.view.WindowInsets.Type.navigationBars();
Expand Down Expand Up @@ -956,7 +958,7 @@ public AccessibilityNodeProvider getAccessibilityNodeProvider() {
@SuppressLint("SoonBlockedPrivateApi")
@Nullable
public View findViewByAccessibilityIdTraversal(int accessibilityId) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT < API_LEVELS.API_29) {
return findViewByAccessibilityIdRootedAtCurrentView(accessibilityId, this);
}
// Android Q or later doesn't call this method.
Expand Down Expand Up @@ -1032,8 +1034,8 @@ private void resetWillNotDraw(boolean isAccessibilityEnabled, boolean isTouchExp

// -------- Start: Mouse -------
@Override
@TargetApi(Build.VERSION_CODES.N)
@RequiresApi(Build.VERSION_CODES.N)
@TargetApi(24)
@RequiresApi(24)
@NonNull
public PointerIcon getSystemPointerIcon(int type) {
return PointerIcon.getSystemIcon(getContext(), type);
Expand Down Expand Up @@ -1098,7 +1100,7 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) {

// Initialize various components that know how to process Android View I/O
// in a way that Flutter understands.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_24) {
mouseCursorPlugin = new MouseCursorPlugin(this, this.flutterEngine.getMouseCursorChannel());
}
textInputPlugin =
Expand Down Expand Up @@ -1412,7 +1414,7 @@ public void removeFlutterEngineAttachmentListener(
boolean isNativeSpellCheckServiceDefined = false;

if (textServicesManager != null) {
if (Build.VERSION.SDK_INT >= 31) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_31) {
List<SpellCheckerInfo> enabledSpellCheckerInfos =
textServicesManager.getEnabledSpellCheckerInfos();
boolean gboardSpellCheckerEnabled =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.embedding.engine;

import static io.flutter.Build.API_LEVELS;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -566,7 +568,7 @@ public static native void nativeImageHeaderCallback(
@VisibleForTesting
@Nullable
public static Bitmap decodeImage(@NonNull ByteBuffer buffer, long imageGeneratorAddress) {
if (Build.VERSION.SDK_INT >= 28) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_28) {
ImageDecoder.Source source = ImageDecoder.createSource(buffer);
try {
return ImageDecoder.decodeBitmap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.embedding.engine.loader;

import static io.flutter.Build.API_LEVELS;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
Expand Down Expand Up @@ -203,7 +205,7 @@ public InitResult call() {
}

private static boolean areValidationLayersOnByDefault() {
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= API_LEVELS.API_26) {
return Build.SUPPORTED_ABIS[0].equals("arm64-v8a");
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.embedding.engine.loader;

import static io.flutter.Build.API_LEVELS;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
Expand All @@ -28,7 +30,7 @@ class ResourceExtractor {
@SuppressWarnings("deprecation")
static long getVersionCode(@NonNull PackageInfo packageInfo) {
// Linter needs P (28) hardcoded or else it will fail these lines.
if (Build.VERSION.SDK_INT >= 28) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_28) {
return packageInfo.getLongVersionCode();
} else {
return packageInfo.versionCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.embedding.engine.renderer;

import static io.flutter.Build.API_LEVELS;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.ImageFormat;
Expand Down Expand Up @@ -185,7 +187,7 @@ public SurfaceProducer createSurfaceProducer() {
// version that is
// running Vulkan, so we don't have to worry about it not being supported.
final SurfaceProducer entry;
if (!debugForceSurfaceProducerGlTextures && Build.VERSION.SDK_INT >= 29) {
if (!debugForceSurfaceProducerGlTextures && Build.VERSION.SDK_INT >= API_LEVELS.API_29) {
final long id = nextTextureId.getAndIncrement();
final ImageReaderSurfaceProducer producer = new ImageReaderSurfaceProducer(id);
registerImageTexture(id, producer);
Expand Down Expand Up @@ -694,7 +696,7 @@ private void maybeWaitOnFence(Image image) {
if (ignoringFence) {
return;
}
if (Build.VERSION.SDK_INT >= 33) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_33) {
// The fence API is only available on Android >= 33.
waitOnFence(image);
return;
Expand Down Expand Up @@ -841,9 +843,9 @@ private ImageReader createImageReader29() {
}

private ImageReader createImageReader() {
if (Build.VERSION.SDK_INT >= 33) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_33) {
return createImageReader33();
} else if (Build.VERSION.SDK_INT >= 29) {
} else if (Build.VERSION.SDK_INT >= API_LEVELS.API_29) {
return createImageReader29();
}
throw new UnsupportedOperationException(
Expand Down Expand Up @@ -944,7 +946,7 @@ private void maybeWaitOnFence(Image image) {
if (ignoringFence) {
return;
}
if (Build.VERSION.SDK_INT >= 33) {
if (Build.VERSION.SDK_INT >= API_LEVELS.API_33) {
// The fence API is only available on Android >= 33.
waitOnFence(image);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.flutter.embedding.engine.systemchannels;

import static io.flutter.Build.API_LEVELS;

import android.annotation.SuppressLint;
import android.os.Build;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -37,7 +39,7 @@ public SettingsChannel(@NonNull DartExecutor dartExecutor) {

@SuppressLint("AnnotateVersionCheck")
public static boolean hasNonlinearTextScalingSupport() {
return Build.VERSION.SDK_INT >= 34;
return Build.VERSION.SDK_INT >= API_LEVELS.API_34;
}

// This method will only be called on Flutter's UI thread.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.flutter.embedding.engine.systemchannels;

import static io.flutter.Build.API_LEVELS;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
Expand Down Expand Up @@ -542,7 +544,7 @@ public static Autofill fromJson(@NonNull JSONObject json)

@NonNull
private static String translateAutofillHint(@NonNull String hint) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT < API_LEVELS.API_26) {
return hint;
}
switch (hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.plugin.editing;

import static io.flutter.Build.API_LEVELS;

import android.annotation.TargetApi;
import android.content.ClipData;
import android.content.ClipboardManager;
Expand Down Expand Up @@ -480,7 +482,7 @@ public boolean performEditorAction(int actionCode) {
@RequiresApi(25)
public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
// Ensure permission is granted.
if (Build.VERSION.SDK_INT >= 25
if (Build.VERSION.SDK_INT >= API_LEVELS.API_25
&& (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
Expand Down
Loading