How FadCam Supports Background Video Recording With the Screen Off: A Technical Deep Dive
FadCam achieves background video recording with the screen off by combining a foreground service with a partial wake-lock and a specialized "privacy black mode" activity that overlays a solid-black screen while the camera continues capturing frames.
FadCam (anonfaded/FadCam) is an open-source Android application that enables discrete video recording even when the device appears inactive. The implementation of background video recording with the screen off relies on a sophisticated interplay between Android's foreground service APIs, power management wake-locks, and custom UI components that simulate a powered-down display while maintaining full camera operation.
The Architecture Behind Screen-Off Recording
Foreground Service Implementation in RecordingService
At the core of FadCam's persistence is RecordingService, located at app/src/main/java/com/fadcam/services/RecordingService.java. The service calls startForeground(NOTIFICATION_ID, ...) within its onStartCommand method, promoting itself to a foreground service that Android's system monitors will not terminate during background operation. This status is prerequisite for maintaining camera access when the user switches applications or locks the device.
Partial Wake-Lock for CPU Continuity
To prevent the CPU from sleeping when the display turns off, the service acquires a PARTIAL_WAKE_LOCK in its onCreate() method:
recordingWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "FadCam:RecordingService");
This wake-lock ensures that the Camera2 pipeline and MediaRecorder continue processing frames even when the system would otherwise enter a low-power state, effectively enabling true background video recording with the screen off.
Privacy Black Mode: Simulating a Powered-Down Screen
The PrivacyBlackActivity Overlay
When users enable privacy mode, FadCam launches PrivacyBlackActivity (app/src/main/java/com/fadcam/ui/PrivacyBlackActivity.java). This activity creates a full-screen View with a solid black background:
blackView.setBackgroundColor(0xFF000000);
The activity enters immersive sticky mode using flags such as SYSTEM_UI_FLAG_IMMERSIVE_STICKY and SYSTEM_UI_FLAG_FULLSCREEN, hiding both navigation and status bars. While this activity remains in the foreground, the underlying RecordingService continues operating, giving users the visual impression that the device is off while recording proceeds uninterrupted.
Gesture-Based Exit Mechanisms
FadCam implements multiple touch gestures to exit the black screen without visible UI elements. The activity detects onLongPress, onFling, and triple-tap events to trigger finish(), returning the user to the standard interface. For example, the swipe-up detection checks:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float vx, float vy) {
if (prefs.isPrivacyBlackSwipeUpEnabled() && e1.getY() - e2.getY() > 50 && Math.abs(vy) > 100) {
finish();
}
return true;
}
These hidden controls ensure that the privacy black mode remains secure against accidental discovery while allowing authorized users to regain control.
Configuration and User Preferences
Enabling the Feature via SecuritySettingsFragment
The toggle for this functionality resides in SecuritySettingsFragment (app/src/main/java/com/fadcam/ui/SecuritySettingsFragment.java). Users activate the "Black background" option, which stores the preference using the key PREF_PRIVACY_BLACK_MODE_ENABLED in SharedPreferencesManager.
Persistent Storage in SharedPreferencesManager
Located at app/src/main/java/com/fadcam/SharedPreferencesManager.java, this utility class persists the user's privacy settings. When recording initiates, the service checks this preference to determine whether to launch PrivacyBlackActivity automatically.
Practical Implementation Examples
To initiate background video recording with the screen off programmatically, developers can combine the service intent with the privacy activity.
Starting the foreground service:
Intent startIntent = new Intent(context, RecordingService.class);
startIntent.setAction(Constants.INTENT_ACTION_START_RECORDING);
ContextCompat.startForegroundService(context, startIntent);
Enabling and launching privacy black mode:
SharedPreferencesManager prefs = SharedPreferencesManager.getInstance(context);
prefs.edit().putBoolean(SharedPreferencesManager.PREF_PRIVACY_BLACK_MODE_ENABLED, true).apply();
Intent blackIntent = new Intent(context, PrivacyBlackActivity.class);
blackIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(blackIntent);
These snippets demonstrate how RecordingStartActivity serves as a shortcut entry point, allowing users to begin recording immediately without displaying the main application UI.
Summary
- Foreground Service Persistence:
RecordingService.javautilizesstartForeground()to maintain process priority during screen-off operation. - Wake-Lock Management: A
PARTIAL_WAKE_LOCKprevents CPU suspension, ensuring the Camera2 pipeline remains active. - Visual Concealment:
PrivacyBlackActivityrenders a full-screen black overlay with immersive flags to simulate a powered-down device. - User Control: Gesture detection (swipe, long-press, triple-tap) provides hidden exit mechanisms from the black screen.
- Configuration Layer:
SecuritySettingsFragmentandSharedPreferencesManagerhandle persistence of thePREF_PRIVACY_BLACK_MODE_ENABLEDtoggle.
Frequently Asked Questions
Does FadCam require root access to record with the screen off?
No, FadCam leverages standard Android APIs including foreground services and wake-locks available since API level 1 and 5 respectively. The implementation in RecordingService.java uses PowerManager and Context.startForegroundService() without requiring elevated privileges.
How does the privacy black mode differ from simply locking the screen?
When the device is locked normally, Android typically pauses camera access for background applications. FadCam's privacy black mode keeps PrivacyBlackActivity in the foreground with a visible window while displaying only black pixels, maintaining the camera session that would otherwise terminate during standard screen lock.
Can the recording continue if the user switches to another app?
Yes, because RecordingService runs as a foreground service with an active notification, it persists across application switches. The partial wake-lock ensures recording continues even if the user navigates away or the OLED screen turns off completely.
Where is the wake-lock released when recording stops?
The wake-lock is managed within RecordingService.java, specifically acquired in onCreate() and released when the service handles the stop recording action or is destroyed, ensuring battery drain is minimized once background video recording with the screen off concludes.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →