From b1af0bd01d05dca8ca44d2726780bd7feffcff81 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 3 Nov 2023 16:30:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AA=E9=80=80bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xypower/mpapp/AppMaster.java | 9 +++-- .../com/xypower/mpapp/MicroPhotoService.java | 36 +++++++++---------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/AppMaster.java b/app/src/main/java/com/xypower/mpapp/AppMaster.java index 6b0bccc8..c249b4ef 100644 --- a/app/src/main/java/com/xypower/mpapp/AppMaster.java +++ b/app/src/main/java/com/xypower/mpapp/AppMaster.java @@ -42,8 +42,13 @@ public class AppMaster { @Override protected void finalize() { - if (mWakelock != null) { - mWakelock.release(); + try { + if (mWakelock != null) { + mWakelock.release(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { mWakelock = null; } mService = null; diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 1e4c2683..2df4a6b0 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -30,7 +30,6 @@ import android.os.SystemClock; import androidx.core.app.NotificationCompat; -import android.telephony.CellSignalStrength; import android.telephony.SignalStrength; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; @@ -44,7 +43,6 @@ import com.dev.devapi.api.SysApi; import java.io.File; import java.lang.reflect.Method; -import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -417,7 +415,7 @@ public class MicroPhotoService extends Service { return true; } - private boolean registerCaptureSchedule(long startTime, long baseTime) { + private boolean registerCaptureSchedule(long timeOfZeroPoint, long secondsOfToday) { long[] photoTimeData = getPhotoTimeData(mNativeHandle); if (photoTimeData == null) { @@ -431,7 +429,7 @@ public class MicroPhotoService extends Service { long val = 0L; // int maxDuration = mHeartbeatDuration * 2 / 1000; int maxDuration = 35 * 60 * 1000 + 1000; - int currentTs = 0; + int currentTs = -1; List schedules = new ArrayList<>(); int offset = 0; for (int day = 0; day < 2; day++, offset += 86400) { @@ -439,15 +437,15 @@ public class MicroPhotoService extends Service { val = photoTimeData[idx]; ts = (int) ((val & 0x00FFFFFF00000000L) >> 32) + offset; - if (ts < baseTime) { + if (ts < secondsOfToday) { continue; } - if ((ts - baseTime) > maxDuration) { + if ((ts - secondsOfToday) > maxDuration) { break; } - if (currentTs == 0) { + if (currentTs == -1) { currentTs = ts; channel = (short) ((val & 0xFF0000L) >> 16); preset = (short) ((val & 0xFF00L) >> 8); @@ -473,11 +471,11 @@ public class MicroPhotoService extends Service { } if (!schedules.isEmpty()) { - long expectedTs = startTime + ts; - Date date = new Date(expectedTs * 1000); - // Log.d(TAG, "Register Photo Time: " + date.toString() + " BaseTime=" + baseTime + " ts=" + ts + " startTime=" + startTime + " expectedTs=" + expectedTs); + long expectedTs = timeOfZeroPoint + ts; + // Date date = new Date(expectedTs * 1000); + // Log.d(TAG, "Register Photo Time: " + date.toString() + " BaseTime=" + secondsOfToday + " ts=" + ts + " startTime=" + startTime + " expectedTs=" + expectedTs); - registerPhotoTimer(channel, preset, currentTs, (currentTs - baseTime) * 1000, schedules); + registerPhotoTimer(channel, preset, expectedTs, expectedTs * 1000 - System.currentTimeMillis(), schedules); } return true; @@ -487,12 +485,13 @@ public class MicroPhotoService extends Service { List schedules = new ArrayList<>(); long ts = System.currentTimeMillis() / 1000; - long val = (ts << 24); + // long val = (ts << 24); + long val = 0; val |= ((long)channel << 16); val |= ((long)preset << 8); schedules.add(Long.valueOf(val)); - registerPhotoTimer(context, channel, preset, System.currentTimeMillis() / 1000, 0, schedules); + registerPhotoTimer(context, channel, preset, 0, 0, schedules); } @Override @@ -545,7 +544,6 @@ public class MicroPhotoService extends Service { } - // registerPhotoTimer(); break; case ACTION_STOP: unregisterReceiver(mScreenaAtionReceiver); @@ -822,10 +820,12 @@ public class MicroPhotoService extends Service { SignalStrength ss = telephonyManager.getSignalStrength(); // List css = ss.getCellSignalStrengths(); - int signalLevel = ss.getLevel(); - sb.append("&Signal4G=" + signalLevel); - sb.append("&Signal2G=" + signalLevel); - sb.append("&SL=" + signalLevel); + if (ss != null) { + int signalLevel = ss.getLevel(); + sb.append("&Signal4G=" + signalLevel); + sb.append("&Signal2G=" + signalLevel); + sb.append("&SL=" + signalLevel); + } if (isXyPlatform) { java.text.DecimalFormat fmt=new java.text.DecimalFormat("0.0");