未验证 提交 663bfe8d 编写于 作者: J Jason Simmons 提交者: GitHub

Remove the ResourceCleaner from the Android embedding (#18072)

上级 763d5207
......@@ -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();
......
// 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);
}
}
// 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" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册