Update usage of some Android APIs that are deprecated in API level 28 (flutter/engine#7261)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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<Void, Void, Void> {
|
||||
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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user