|
|
@@ -5,6 +5,8 @@ import static android.content.Context.POWER_SERVICE;
|
|
|
import android.content.Context;
|
|
|
import android.database.Cursor;
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
import android.net.Uri;
|
|
|
import android.os.CancellationSignal;
|
|
|
import android.os.Environment;
|
|
|
@@ -36,6 +38,7 @@ import java.nio.ByteOrder;
|
|
|
import java.nio.MappedByteBuffer;
|
|
|
import java.nio.channels.FileChannel;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.UUID;
|
|
|
@@ -62,7 +65,10 @@ public class ImageDeepDetector {
|
|
|
private static final int MEIZU_GALLERY_CACHE = 8;
|
|
|
private static final int HUAWEI_GALLERY_CACHE = 9;
|
|
|
|
|
|
+
|
|
|
public static Flowable<List<ImageFile>> detect(Context context) {
|
|
|
+ BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
+ options.inJustDecodeBounds = true;
|
|
|
return Flowable.create((FlowableOnSubscribe<XFile>) emitter -> {
|
|
|
try {
|
|
|
|
|
|
@@ -129,12 +135,22 @@ public class ImageDeepDetector {
|
|
|
return Flowable.empty();
|
|
|
}
|
|
|
})
|
|
|
+ .filter(file -> {
|
|
|
+ try (InputStream inputStream = file.newInputStream()) {
|
|
|
+ BitmapFactory.decodeStream(inputStream, null, options);
|
|
|
+ if (options.outWidth <= 0 || options.outHeight <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ })
|
|
|
.buffer(200, TimeUnit.MILLISECONDS)
|
|
|
.filter(imageFiles -> imageFiles != null && !imageFiles.isEmpty())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.doOnSubscribe(subscription -> {
|
|
|
subscription.request(Long.MAX_VALUE);
|
|
|
-
|
|
|
acquireWakeLock(context);
|
|
|
})
|
|
|
.doOnCancel(() -> releaseWakeLock(context))
|
|
|
@@ -190,7 +206,7 @@ public class ImageDeepDetector {
|
|
|
return true;
|
|
|
}
|
|
|
if ((path.contains("com.taobao.taobao") || path.contains("com.tmall.wireless")) && (path.endsWith("AVFSCache") ||
|
|
|
- path.endsWith("gs_fs"))) {
|
|
|
+ path.contains("gs_fs"))) {
|
|
|
return true;
|
|
|
}
|
|
|
if ((path.contains("com.baidu.BaiduMap")) && (path.endsWith("sticker"))) {
|