From e2957bea09bfe007ad4b8a7313d15de5be6fd302 Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Tue, 9 Jan 2024 13:12:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4Java=E7=AB=AF=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=9A=84timer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/MicroPhoto.cpp | 17 ---- .../com/xypower/mpapp/MicroPhotoService.java | 82 ------------------- 2 files changed, 99 deletions(-) diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 68970995..f560c866 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -252,23 +252,6 @@ Java_com_xypower_mpapp_MicroPhotoService_sendHeartbeat( return JNI_TRUE; } -extern "C" JNIEXPORT jboolean JNICALL -Java_com_xypower_mpapp_MicroPhotoService_fireTimeout( - JNIEnv* env, - jobject pThis, jlong handler, jlong uid, jlong times) { - - CTerminal* pTerminal = reinterpret_cast(handler); - IDevice* dev = pTerminal->GetDevice(); - if (dev == NULL) - { - return JNI_FALSE; - } - - CPhoneDevice* phoneDevice = (CPhoneDevice *)dev; - return JNI_FALSE; - // return phoneDevice->FireTimer((IDevice::timer_uid_t)uid, static_cast(times)) ? JNI_TRUE : JNI_FALSE; -} - extern "C" JNIEXPORT void JNICALL Java_com_xypower_mpapp_MicroPhotoService_updatePosition( JNIEnv* env, diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index f13ccb32..760dc08d 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -100,7 +100,6 @@ public class MicroPhotoService extends Service { private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP"; private static final String ACTION_TAKE_PHOTO_MANUALLY = "com.xypower.mpapp.ACT_TP_M"; private static final String ACTION_HEARTBEAT_MANUALLY = "com.xypower.mpapp.ACT_HB_M"; - private static final String ACTION_TIMEOUT = "com.xypower.mpapp.ACT_TIMEOUT"; public static final String ACTION_VIDEO_FINISHED = "com.xypower.mpapp.ACT_V_FINISHED"; private static final String EXTRA_PARAM_CHANNEL = "Channel"; private static final String EXTRA_PARAM_PRESET = "Preset"; @@ -165,7 +164,6 @@ public class MicroPhotoService extends Service { mAlarmReceiver = new AlarmReceiver(this); IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT); intentFilter.addAction(ACTION_TAKE_PHOTO); - intentFilter.addAction(ACTION_TIMEOUT); intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY); intentFilter.addAction(ACTION_HEARTBEAT_MANUALLY); intentFilter.addAction(ACTION_MSG_BROADCAST); @@ -372,29 +370,6 @@ public class MicroPhotoService extends Service { Log.i(TAG, "Take Photo CH=" + channel + " PR=" + preset + " Mannually"); mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, photoOrVideo); - } else if (TextUtils.equals(ACTION_TIMEOUT, action)) { - long uid = intent.getLongExtra(EXTRA_PARAM_TIMER_UID, 0); - long expectedTimes = intent.getLongExtra(EXTRA_PARAM_TIMES, 0); - long elapsedTimes = intent.getLongExtra(EXTRA_PARAM_ELASPED_TIMES, 0); - elapsedTimes++; - - Log.i(TAG, "Timeout uid=" + uid + " expectedTimes=" + expectedTimes + " Times=" + elapsedTimes); - mService.fireTimeout(mService.mNativeHandle, uid, elapsedTimes); - - intent.putExtra(EXTRA_PARAM_ELASPED_TIMES, elapsedTimes); - - Long uidObj = Long.valueOf(uid); - if ((expectedTimes == 0) || (elapsedTimes < expectedTimes)) { - int timeout = intent.getIntExtra(EXTRA_PARAM_TIMEOUT, 0); - - PendingIntent pendingIntent = mService.mTimers.get(uidObj); - - if (pendingIntent != null) { - mService.registerTimer(pendingIntent, uid, timeout); - } - } else { - mService.mTimers.remove(uidObj); - } } else if (TextUtils.equals(ACTION_MSG_BROADCAST, action)) { int what = intent.getIntExtra("what", 0); @@ -483,62 +458,6 @@ public class MicroPhotoService extends Service { context.startActivity(intent); } - // private HashMap mTimers = new HashMap(); - public boolean registerTimer(long uid, int timeout, long times) { - - Context context = getApplicationContext(); - // 创建延迟意图 - Intent alarmIntent = new Intent(); - alarmIntent.setAction(ACTION_TIMEOUT); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - alarmIntent.setIdentifier(Long.toString(uid)); - } - alarmIntent.putExtra(EXTRA_PARAM_TIMER_UID, uid); - alarmIntent.putExtra(EXTRA_PARAM_TIMEOUT, timeout); - alarmIntent.putExtra(EXTRA_PARAM_TIMES, times); - alarmIntent.putExtra(EXTRA_PARAM_ELASPED_TIMES, 0L); - - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); - - mTimers.put(Long.valueOf(uid), pendingIntent); - return registerTimer(pendingIntent, uid, timeout); - } - - public boolean registerTimer(PendingIntent pendingIntent, long uid, int timeout) { - - AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); - - alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + timeout, pendingIntent); - - Log.i(TAG, "RegTimer:" + uid + " timeout=" + timeout); - return true; - } - - public boolean unregisterTimer(long uid) { - - /* - Context context = getApplicationContext(); - - AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - PendingIntent pendingIntent = PendingIntent.getService(context, 0, pendingIntent., PendingIntent.FLAG_NO_CREATE); - if (pendingIntent != null && alarmManager != null) { - alarmManager.cancel(pendingIntent); - } - */ - Long uidObj = Long.valueOf(uid); - PendingIntent pendingIntent = mTimers.get(uidObj); - - if (pendingIntent != null) { - AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); - - alarmManager.cancel(pendingIntent); - - mTimers.remove(uidObj); - Log.i(TAG, "UnregTimer:" + uid); - } - - return true; - } private boolean registerCaptureSchedule(long timeOfZeroPoint, long secondsOfToday) { long[] photoTimeData = getPhotoTimeData(mNativeHandle); @@ -1125,7 +1044,6 @@ cellSignalStrengthGsm.getDbm(); // protected native long[] getNextScheduleItem(long handler); protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, boolean photoOrVideo); protected native boolean sendHeartbeat(long handler); - protected native boolean fireTimeout(long handler, long uid, long times); protected native void updatePosition(long handler, double lon, double lat, long ts); protected native boolean uninit(long handler); protected native void recordingFinished(long handler, boolean result, String path, long videoId);