update 推送图片

This commit is contained in:
gallonyin
2023-03-02 01:19:56 +08:00
parent a273434289
commit ba1535f39d
4 changed files with 1271 additions and 24 deletions

View File

@@ -3,6 +3,7 @@ package org.yameida.worktool.observer;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
@@ -12,8 +13,8 @@ import android.util.Log;
public class MultiFileObserver extends FileObserver { public class MultiFileObserver extends FileObserver {
public HashMap<String, Long> map = new HashMap<>(); public HashMap<String, Long> map = new HashMap<>();
public static String lastPicPath = ""; public static HashSet<String> createSet = new HashSet<>();
public static Long lastPicCreateTime = 0L; public static HashSet<String> finishSet = new HashSet<>();
/** Only modification events */ /** Only modification events */
public static int CHANGES_ONLY = CREATE | MODIFY | DELETE | CLOSE_WRITE public static int CHANGES_ONLY = CREATE | MODIFY | DELETE | CLOSE_WRITE
@@ -77,28 +78,35 @@ public class MultiFileObserver extends FileObserver {
mObservers = null; mObservers = null;
} }
@Override @Override
public void onEvent(int event, String path) { public void onEvent(int event, String path) {
switch (event) { switch (event) {
case FileObserver.ACCESS: case FileObserver.ACCESS:
case FileObserver.CLOSE_WRITE:
case FileObserver.CLOSE_NOWRITE: case FileObserver.CLOSE_NOWRITE:
if (path.endsWith(".0") && !map.containsKey(path)) { if (path.endsWith(".0") && !map.containsKey(path) && createSet.contains(path)) {
Log.i("RecursiveFileObserver", "发现新图片: " + path);
map.put(path, System.currentTimeMillis()); map.put(path, System.currentTimeMillis());
lastPicPath = path; Log.i("RecursiveFileObserver", "发现新图片: " + path);
finishSet.add(path);
// try {
// ImageInfo imageInfo = new ImageInfo();
// imageInfo.setDetermineImageNumber(true);
// ImageInfo.run(path, new FileInputStream(path), imageInfo, true);
// } catch (Exception e) { e.printStackTrace(); }
} }
break; break;
case FileObserver.CREATE: case FileObserver.CREATE:
Log.i("RecursiveFileObserver", "CREATE: " + path); Log.i("RecursiveFileObserver", "CREATE: " + path);
lastPicCreateTime = System.currentTimeMillis(); if (path.endsWith(".0")) {
createSet.add(path);
}
break; break;
case FileObserver.ATTRIB: case FileObserver.ATTRIB:
// Log.i("RecursiveFileObserver", "ATTRIB: " + path); // Log.i("RecursiveFileObserver", "ATTRIB: " + path);
break; break;
case FileObserver.CLOSE_WRITE: // case FileObserver.CLOSE_WRITE:
// Log.i("RecursiveFileObserver", "CLOSE_WRITE: " + path); // Log.i("RecursiveFileObserver", "CLOSE_WRITE: " + path);
break; // break;
case FileObserver.DELETE: case FileObserver.DELETE:
// Log.i("RecursiveFileObserver", "DELETE: " + path); // Log.i("RecursiveFileObserver", "DELETE: " + path);
break; break;

View File

@@ -545,33 +545,37 @@ object WeworkLoopImpl {
message = WeworkMessageBean.SubMessageBean(0, textType, itemMessageList, nameList) message = WeworkMessageBean.SubMessageBean(0, textType, itemMessageList, nameList)
//图片类型特殊处理 //图片类型特殊处理
if (doubleCheck && Constant.pushImage && textType == 2) { if (doubleCheck && Constant.pushImage && textType == 2) {
val lastPicCreateTime = MultiFileObserver.lastPicCreateTime MultiFileObserver.createSet.clear()
val lastPicPath = MultiFileObserver.lastPicPath MultiFileObserver.finishSet.clear()
LogUtils.d("发现图片类型应该点击") LogUtils.v("点击图片类型")
AccessibilityUtil.performClickWithSon(relativeLayoutContent) AccessibilityUtil.performClickWithSon(relativeLayoutContent)
AccessibilityExtraUtil.loadingPage("ShowImageController", Constant.CHANGE_PAGE_INTERVAL) AccessibilityExtraUtil.loadingPage("ShowImageController", Constant.CHANGE_PAGE_INTERVAL)
LogUtils.d("发现图片类型 查看图片检查有无新图片产生") LogUtils.v("发现图片类型 查看图片检查有无新图片产生")
if (MultiFileObserver.lastPicCreateTime > lastPicCreateTime) { if (MultiFileObserver.createSet.isNotEmpty()) {
LogUtils.d("正在下载图片...") LogUtils.d("正在下载图片...")
var downloading = true var downloading = true
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
var currentTime = startTime var currentTime = startTime
while (currentTime - startTime < Constant.LONG_INTERVAL) { while (currentTime - startTime < Constant.LONG_INTERVAL) {
if (!lastPicPath.equals(MultiFileObserver.lastPicPath)) { if (MultiFileObserver.createSet.size == MultiFileObserver.finishSet.size) {
LogUtils.d("下载图片完成") LogUtils.d("下载图片完成: ${MultiFileObserver.createSet.size}")
downloading = false downloading = false
try { try {
val df = SimpleDateFormat("MMdd_HHmmss") for (path in MultiFileObserver.finishSet) {
val targetPath = "${ val df = SimpleDateFormat("MMdd_HHmmss")
Utils.getApp().getExternalFilesDir("copy") val targetPath = "${
}/${df.format(Date())}/${File(MultiFileObserver.lastPicPath).name}.png" Utils.getApp().getExternalFilesDir("copy")
if (FileUtils.copy(MultiFileObserver.lastPicPath, targetPath)) { }/${df.format(Date())}/${File(path).name}.png"
LogUtils.d("复制图片完成: $targetPath") if (FileUtils.copy(path, targetPath)) {
} else { LogUtils.d("复制图片完成: $targetPath " + ImageDepthSizeUtil.checkRawImage(targetPath))
LogUtils.e("复制图片失败 请检查权限: $targetPath") log("复制图片完成: $targetPath")
} else {
LogUtils.e("复制图片失败 请检查权限: $targetPath")
}
} }
} catch (e: Exception) { } catch (e: Exception) {
LogUtils.e("接收图片出错", e) LogUtils.e("接收图片出错", e)
error("接收图片出错: ${e.message}")
} }
break break
} }

View File

@@ -74,12 +74,15 @@ class WeworkService : AccessibilityService() {
mFileObserver = mFileObserver =
MultiFileObserver("/storage/emulated/0/Android/data/com.tencent.wework/files/imagecache/imagemsg2"); MultiFileObserver("/storage/emulated/0/Android/data/com.tencent.wework/files/imagecache/imagemsg2");
mFileObserver?.startWatching() mFileObserver?.startWatching()
log("startWatching...")
} else { } else {
mFileObserver?.stopWatching() mFileObserver?.stopWatching()
mFileObserver?.startWatching() mFileObserver?.startWatching()
log("restartWatching...")
} }
} catch (e: Exception) { } catch (e: Exception) {
LogUtils.e(e) LogUtils.e(e)
error("initObserver startWatching error!: ${e.message}")
} }
} }

File diff suppressed because it is too large Load Diff