Skip to content

Commit

Permalink
Added screen recording detection
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Sep 13, 2024
1 parent 6bbc0d0 commit 3209e03
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.DETECT_SCREEN_RECORDING" />
<uses-permission android:name="android.permission.TURN_SCREEN_ON" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
Expand Down
1 change: 1 addition & 0 deletions app/src/fdroid/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.DETECT_SCREEN_RECORDING" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

Expand Down
1 change: 1 addition & 0 deletions app/src/github/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.DETECT_SCREEN_RECORDING" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/eu/faircode/email/ActivityView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_UNLOCKED;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -39,6 +40,7 @@
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Spanned;
import android.text.TextUtils;
Expand All @@ -49,6 +51,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -1165,18 +1168,49 @@ protected void onNewIntent(Intent intent) {
setIntent(intent);
}

private final java.util.function.Consumer<Integer> recordingCallback = new java.util.function.Consumer<Integer>() {
@Override
public void accept(Integer state) {
if (state == WindowManager.SCREEN_RECORDING_STATE_VISIBLE)
getMainHandler().post(new RunnableEx("screenrecording") {
@Override
public void delegate() {
ToastEx.makeText(ActivityView.this, R.string.title_screen_recording, Toast.LENGTH_LONG).show();
}
});
}
};

@Override
protected void onStart() {
super.onStart();
if (!Helper.isPlayStoreInstall())
infoTracker.addWindowLayoutInfoListener(this, Runnable::run, layoutStateChangeCallback);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM &&
hasPermission(Manifest.permission.DETECT_SCREEN_RECORDING))
try {
WindowManager wm = Helper.getSystemService(this, WindowManager.class);
wm.addScreenRecordingCallback(Helper.getUIExecutor(), recordingCallback);
} catch (Throwable ex) {
Log.e(ex);
}
}

@Override
protected void onStop() {
super.onStop();
if (!Helper.isPlayStoreInstall())
infoTracker.removeWindowLayoutInfoListener(layoutStateChangeCallback);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM &&
hasPermission(Manifest.permission.DETECT_SCREEN_RECORDING))
try {
WindowManager wm = Helper.getSystemService(this, WindowManager.class);
wm.removeScreenRecordingCallback(recordingCallback);
} catch (Throwable ex) {
Log.e(ex);
}
}

@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,7 @@
<string name="title_too_large">Message too large to completely reformat</string>
<string name="title_truncated">Message too large to display completely</string>
<string name="title_insufficient_memory">Message too large for the available memory (%1$d)</string>
<string name="title_screen_recording">The screen is being recorded!</string>
<string name="title_show_full">Show full message</string>
<string name="title_fullscreen">Show fullscreen</string>
<string name="title_fit_width">Fit width</string>
Expand Down

0 comments on commit 3209e03

Please sign in to comment.