Created
December 6, 2019 13:32
-
-
Save TheScarastic/8ea8892208ad79e71beaa15585041b16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From dadcf0e790e60588f799630a2bab5f786f6b641c Mon Sep 17 00:00:00 2001 | |
From: TheScarastic <warabhishek@gmail.com> | |
Date: Fri, 30 Aug 2019 20:02:35 +0530 | |
Subject: [PATCH] core: Add camera intents for camera state [1/2] | |
Change-Id: Ib2e87a86d1f9d26c82f7de42c8cbfe526395ed9e | |
--- | |
core/res/AndroidManifest.xml | 3 ++ | |
.../server/camera/CameraServiceProxy.java | 39 ++++++++++++++++++- | |
2 files changed, 41 insertions(+), 1 deletion(-) | |
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml | |
index 7d099cbe077..e323677152b 100644 | |
--- a/core/res/AndroidManifest.xml | |
+++ b/core/res/AndroidManifest.xml | |
@@ -643,6 +643,9 @@ | |
<!-- Used for long press power torch feature - automatic turn off on timeout --> | |
<protected-broadcast android:name="com.android.server.policy.PhoneWindowManager.ACTION_TORCH_OFF" /> | |
+ <!-- Used to get camera status. --> | |
+ <protected-broadcast android:name="lineageos.intent.action.CAMERA_STATUS_CHANGED" /> | |
+ | |
<!-- ====================================================================== --> | |
<!-- RUNTIME PERMISSIONS --> | |
<!-- ====================================================================== --> | |
diff --git a/services/core/java/com/android/server/camera/CameraServiceProxy.java b/services/core/java/com/android/server/camera/CameraServiceProxy.java | |
index 6e22f8dd0de..09c6fe7deca 100644 | |
--- a/services/core/java/com/android/server/camera/CameraServiceProxy.java | |
+++ b/services/core/java/com/android/server/camera/CameraServiceProxy.java | |
@@ -32,6 +32,7 @@ import android.os.Process; | |
import android.os.RemoteException; | |
import android.os.SystemClock; | |
import android.os.SystemProperties; | |
+import android.os.UserHandle; | |
import android.os.UserManager; | |
import android.util.ArrayMap; | |
import android.util.ArraySet; | |
@@ -73,9 +74,12 @@ public class CameraServiceProxy extends SystemService | |
// Handler message codes | |
private static final int MSG_SWITCH_USER = 1; | |
+ private static final int MSG_CAMERA_CLOSED = 1001; | |
+ private static final int MSG_CAMERA_OPEN = 1002; | |
private static final int RETRY_DELAY_TIME = 20; //ms | |
private static final int RETRY_TIMES = 30; | |
+ private static final int CAMERA_EVENT_DELAY_TIME = 70; //ms | |
// Maximum entries to keep in usage history before dumping out | |
private static final int MAX_USAGE_HISTORY = 100; | |
@@ -103,6 +107,9 @@ public class CameraServiceProxy extends SystemService | |
private final boolean mNotifyNfc; | |
private final boolean mAllowMediaUid; | |
+ private long mClosedEvent; | |
+ private long mOpenEvent; | |
+ | |
/** | |
* Structure to track camera usage | |
*/ | |
@@ -195,6 +202,25 @@ public class CameraServiceProxy extends SystemService | |
state + " for client " + clientName + " API Level " + apiLevel); | |
updateActivityCount(cameraId, newCameraState, facing, clientName, apiLevel); | |
+ | |
+ if (facing == ICameraServiceProxy.CAMERA_FACING_FRONT) { | |
+ switch (newCameraState) { | |
+ case ICameraServiceProxy.CAMERA_STATE_OPEN : { | |
+ mOpenEvent = SystemClock.elapsedRealtime(); | |
+ if (SystemClock.elapsedRealtime() - mClosedEvent < CAMERA_EVENT_DELAY_TIME) { | |
+ mHandler.removeMessages(MSG_CAMERA_CLOSED); | |
+ } | |
+ mHandler.sendEmptyMessageDelayed(MSG_CAMERA_OPEN, CAMERA_EVENT_DELAY_TIME); | |
+ } break; | |
+ case ICameraServiceProxy.CAMERA_STATE_CLOSED : { | |
+ mClosedEvent = SystemClock.elapsedRealtime(); | |
+ if (SystemClock.elapsedRealtime() - mOpenEvent < CAMERA_EVENT_DELAY_TIME) { | |
+ mHandler.removeMessages(MSG_CAMERA_OPEN); | |
+ } | |
+ mHandler.sendEmptyMessageDelayed(MSG_CAMERA_CLOSED, CAMERA_EVENT_DELAY_TIME); | |
+ } break; | |
+ } | |
+ } | |
} | |
}; | |
@@ -217,7 +243,13 @@ public class CameraServiceProxy extends SystemService | |
case MSG_SWITCH_USER: { | |
notifySwitchWithRetries(msg.arg1); | |
} break; | |
- default: { | |
+ case MSG_CAMERA_CLOSED: { | |
+ sendCameraStateIntent("0"); | |
+ } break; | |
+ case MSG_CAMERA_OPEN: { | |
+ sendCameraStateIntent("1"); | |
+ } break; | |
+ default: { | |
Slog.e(TAG, "CameraServiceProxy error, invalid message: " + msg.what); | |
} break; | |
} | |
@@ -534,4 +566,9 @@ public class CameraServiceProxy extends SystemService | |
return "CAMERA_FACING_UNKNOWN"; | |
} | |
+ private void sendCameraStateIntent(String cameraState) { | |
+ Intent intent = new Intent(lineageos.content.Intent.ACTION_CAMERA_STATUS_CHANGED); | |
+ intent.putExtra(lineageos.content.Intent.EXTRA_CAMERA_STATE, cameraState); | |
+ mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM); | |
+ } | |
} | |
-- | |
2.17.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment