Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7839b9d authored by Alex Johnston's avatar Alex Johnston
Browse files

Prevent screenshot when admin disable screenshots for all users

* An IT admin has the ability to disable screenshots
  for all users when the device has a DO or COPE PO
* When screenshots are disabled for all users, prevent
  a screenshot from being taken instead of taking a
  black screenshot

Bug: 217558483
Test: Manual testing with TestDPC
Change-Id: I167996bb337cc906b5475089f674fd9c37dff808
parent 809036e6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -213,6 +213,8 @@
    <!-- Notification text displayed when we fail to take a screenshot. [CHAR LIMIT=100] -->
    <string name="screenshot_failed_to_capture_text">Taking screenshots isn\'t allowed by the app or
        your organization</string>
    <!-- Notification text displayed when screenshots are blocked by an IT admin. [CHAR LIMIT=100] -->
    <string name="screenshot_blocked_by_admin">Taking screenshots is blocked by your IT admin</string>
    <!-- Label for UI element which allows editing the screenshot [CHAR LIMIT=30] -->
    <string name="screenshot_edit_label">Edit</string>
    <!-- Content description indicating that tapping the element will allow editing the screenshot [CHAR LIMIT=NONE] -->
+17 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static com.android.systemui.screenshot.LogConfig.logTag;

import android.annotation.MainThread;
import android.app.Service;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -42,9 +43,11 @@ import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.NonNull;

@@ -62,9 +65,11 @@ public class TakeScreenshotService extends Service {
    private ScreenshotController mScreenshot;

    private final UserManager mUserManager;
    private final DevicePolicyManager mDevicePolicyManager;
    private final UiEventLogger mUiEventLogger;
    private final ScreenshotNotificationsController mNotificationsController;
    private final Handler mHandler;
    private final Context mContext;

    private final BroadcastReceiver mCloseSystemDialogs = new BroadcastReceiver() {
        @Override
@@ -91,16 +96,18 @@ public class TakeScreenshotService extends Service {

    @Inject
    public TakeScreenshotService(ScreenshotController screenshotController, UserManager userManager,
            UiEventLogger uiEventLogger,
            ScreenshotNotificationsController notificationsController) {
            DevicePolicyManager devicePolicyManager, UiEventLogger uiEventLogger,
            ScreenshotNotificationsController notificationsController, Context context) {
        if (DEBUG_SERVICE) {
            Log.d(TAG, "new " + this);
        }
        mHandler = new Handler(Looper.getMainLooper(), this::handleMessage);
        mScreenshot = screenshotController;
        mUserManager = userManager;
        mDevicePolicyManager = devicePolicyManager;
        mUiEventLogger = uiEventLogger;
        mNotificationsController = notificationsController;
        mContext = context;
    }

    @Override
@@ -182,6 +189,14 @@ public class TakeScreenshotService extends Service {
            requestCallback.reportError();
            return true;
        }
        if(mDevicePolicyManager.getScreenCaptureDisabled(null, UserHandle.USER_ALL)) {
            Log.w(TAG, "Skipping screenshot because an IT admin has disabled "
                    + "screenshots on the device");
            Toast.makeText(mContext, R.string.screenshot_blocked_by_admin,
                    Toast.LENGTH_SHORT).show();
            requestCallback.reportError();
            return true;
        }

        ScreenshotHelper.ScreenshotRequest screenshotRequest =
                (ScreenshotHelper.ScreenshotRequest) msg.obj;