diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 0722406645..b6f53d4574 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -5,6 +5,7 @@ package io.flutter.plugin.platform; import android.app.Activity; +import android.app.ActivityManager.TaskDescription; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -185,13 +186,14 @@ public class PlatformPlugin implements MethodCallHandler, ActivityLifecycleListe color = color | 0xFF000000; // color must be opaque if set } - mActivity.setTaskDescription( - new android.app.ActivityManager.TaskDescription( - description.getString("label"), - null, - color - ) - ); + String label = description.getString("label"); + + @SuppressWarnings("deprecation") + TaskDescription taskDescription = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + ? new TaskDescription(label, 0, color) + : new TaskDescription(label, null, color); + + mActivity.setTaskDescription(taskDescription); } private int mEnabledOverlays; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index 82799421a9..43a6a611fd 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -334,6 +334,7 @@ public class FlutterView extends SurfaceView } } // Fallback single locale passing for android API < 24. Should work always. + @SuppressWarnings("deprecation") Locale locale = config.locale; // getScript() is gated because it is added in API 21. mFlutterLocalizationChannel.invokeMethod("setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry(), Build.VERSION.SDK_INT >= 21 ? locale.getScript() : "", locale.getVariant())); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java index a5fd6dd102..ae8376b8a8 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java @@ -9,6 +9,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.os.AsyncTask; +import android.os.Build; import android.util.Log; import io.flutter.util.PathUtils; import org.json.JSONException; @@ -32,6 +33,15 @@ class ResourceExtractor { private static final String TAG = "ResourceExtractor"; private static final String TIMESTAMP_PREFIX = "res_timestamp-"; + @SuppressWarnings("deprecation") + static long getVersionCode(PackageInfo packageInfo) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + return packageInfo.getLongVersionCode(); + } else { + return packageInfo.versionCode; + } + } + private class ExtractTask extends AsyncTask { private static final int BUFFER_SIZE = 16 * 1024; @@ -202,7 +212,7 @@ class ResourceExtractor { } String expectedTimestamp = - TIMESTAMP_PREFIX + packageInfo.versionCode + "-" + packageInfo.lastUpdateTime; + TIMESTAMP_PREFIX + getVersionCode(packageInfo) + "-" + packageInfo.lastUpdateTime; if (updateManifest != null) { String buildNumber = updateManifest.optString("buildNumber", null); @@ -216,8 +226,8 @@ class ResourceExtractor { } if (buildNumber != null && patchNumber != null) { - if (!buildNumber.equals(Integer.toString(packageInfo.versionCode))) { - Log.w(TAG, "Outdated update file for " + packageInfo.versionCode); + if (!buildNumber.equals(Long.toString(getVersionCode(packageInfo)))) { + Log.w(TAG, "Outdated update file for " + getVersionCode(packageInfo)); } else { final File updateFile = new File(FlutterMain.getUpdateInstallationPath()); expectedTimestamp += "-" + patchNumber + "-" + updateFile.lastModified(); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java index 66af727f3c..3a80a07d74 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java @@ -99,7 +99,7 @@ public final class ResourceUpdater { try { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); - return packageInfo == null ? null : Integer.toString(packageInfo.versionCode); + return packageInfo == null ? null : Long.toString(ResourceExtractor.getVersionCode(packageInfo)); } catch (PackageManager.NameNotFoundException e) { return null;