mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove the ResourceCleaner from the Android embedding (flutter/engine#18072)
This commit is contained in:
parent
af4784e0e5
commit
e2907d3089
@ -702,9 +702,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/D
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformMessageHandler.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/ResourceCleaner.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/ResourceExtractor.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/ResourcePaths.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/FlutterPlugin.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/PluginRegistry.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityAware.java
|
||||
|
||||
@ -152,9 +152,7 @@ android_java_sources = [
|
||||
"io/flutter/embedding/engine/dart/DartMessenger.java",
|
||||
"io/flutter/embedding/engine/dart/PlatformMessageHandler.java",
|
||||
"io/flutter/embedding/engine/loader/FlutterLoader.java",
|
||||
"io/flutter/embedding/engine/loader/ResourceCleaner.java",
|
||||
"io/flutter/embedding/engine/loader/ResourceExtractor.java",
|
||||
"io/flutter/embedding/engine/loader/ResourcePaths.java",
|
||||
"io/flutter/embedding/engine/plugins/FlutterPlugin.java",
|
||||
"io/flutter/embedding/engine/plugins/PluginRegistry.java",
|
||||
"io/flutter/embedding/engine/plugins/activity/ActivityAware.java",
|
||||
|
||||
@ -295,8 +295,6 @@ public class FlutterLoader {
|
||||
|
||||
/** Extract assets out of the APK that need to be cached as uncompressed files on disk. */
|
||||
private void initResources(@NonNull Context applicationContext) {
|
||||
new ResourceCleaner(applicationContext).start();
|
||||
|
||||
if (BuildConfig.DEBUG || BuildConfig.JIT_RELEASE) {
|
||||
final String dataDirPath = PathUtils.getDataDirectory(applicationContext);
|
||||
final String packageName = applicationContext.getPackageName();
|
||||
|
||||
@ -1,91 +0,0 @@
|
||||
// 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.embedding.engine.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import io.flutter.BuildConfig;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/** A class to clean up orphaned resource directories after unclean shutdowns. */
|
||||
class ResourceCleaner {
|
||||
private static final String TAG = "ResourceCleaner";
|
||||
private static final long DELAY_MS = 5000;
|
||||
|
||||
private static class CleanTask extends AsyncTask<Void, Void, Void> {
|
||||
private final File[] mFilesToDelete;
|
||||
|
||||
CleanTask(File[] filesToDelete) {
|
||||
mFilesToDelete = filesToDelete;
|
||||
}
|
||||
|
||||
boolean hasFilesToDelete() {
|
||||
return mFilesToDelete != null && mFilesToDelete.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... unused) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "Cleaning " + mFilesToDelete.length + " resources.");
|
||||
}
|
||||
for (File file : mFilesToDelete) {
|
||||
if (file.exists()) {
|
||||
deleteRecursively(file);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void deleteRecursively(File parent) {
|
||||
if (parent.isDirectory()) {
|
||||
for (File child : parent.listFiles()) {
|
||||
deleteRecursively(child);
|
||||
}
|
||||
}
|
||||
parent.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
ResourceCleaner(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
void start() {
|
||||
File cacheDir = mContext.getCacheDir();
|
||||
if (cacheDir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CleanTask task =
|
||||
new CleanTask(
|
||||
cacheDir.listFiles(
|
||||
new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
boolean result = name.startsWith(ResourcePaths.TEMPORARY_RESOURCE_PREFIX);
|
||||
return result;
|
||||
}
|
||||
}));
|
||||
|
||||
if (!task.hasFilesToDelete()) {
|
||||
return;
|
||||
}
|
||||
|
||||
new Handler()
|
||||
.postDelayed(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
},
|
||||
DELAY_MS);
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
// 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.embedding.engine.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
class ResourcePaths {
|
||||
// The filename prefix used by Chromium temporary file APIs.
|
||||
public static final String TEMPORARY_RESOURCE_PREFIX = ".org.chromium.Chromium.";
|
||||
|
||||
// Return a temporary file that will be cleaned up by the ResourceCleaner.
|
||||
public static File createTempFile(Context context, String suffix) throws IOException {
|
||||
return File.createTempFile(TEMPORARY_RESOURCE_PREFIX, "_" + suffix, context.getCacheDir());
|
||||
}
|
||||
}
|
||||
@ -74,8 +74,6 @@
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/FlutterMain.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/ResourceExtractor.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/TextureRegistry.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/ResourcePaths.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/ResourceCleaner.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/FlutterRunArguments.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/view/AccessibilityViewEmbedder.java" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user