Merge "Prevent screenshot when admin disable screenshots for all users" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4b568d3470
@@ -213,6 +213,8 @@
|
|||||||
<!-- Notification text displayed when we fail to take a screenshot. [CHAR LIMIT=100] -->
|
<!-- 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
|
<string name="screenshot_failed_to_capture_text">Taking screenshots isn\'t allowed by the app or
|
||||||
your organization</string>
|
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] -->
|
<!-- Label for UI element which allows editing the screenshot [CHAR LIMIT=30] -->
|
||||||
<string name="screenshot_edit_label">Edit</string>
|
<string name="screenshot_edit_label">Edit</string>
|
||||||
<!-- Content description indicating that tapping the element will allow editing the screenshot [CHAR LIMIT=NONE] -->
|
<!-- Content description indicating that tapping the element will allow editing the screenshot [CHAR LIMIT=NONE] -->
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import static com.android.systemui.screenshot.LogConfig.logTag;
|
|||||||
|
|
||||||
import android.annotation.MainThread;
|
import android.annotation.MainThread;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -42,9 +43,11 @@ import android.os.Looper;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
@@ -62,9 +65,11 @@ public class TakeScreenshotService extends Service {
|
|||||||
private ScreenshotController mScreenshot;
|
private ScreenshotController mScreenshot;
|
||||||
|
|
||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
|
private final DevicePolicyManager mDevicePolicyManager;
|
||||||
private final UiEventLogger mUiEventLogger;
|
private final UiEventLogger mUiEventLogger;
|
||||||
private final ScreenshotNotificationsController mNotificationsController;
|
private final ScreenshotNotificationsController mNotificationsController;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
private final BroadcastReceiver mCloseSystemDialogs = new BroadcastReceiver() {
|
private final BroadcastReceiver mCloseSystemDialogs = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -91,16 +96,18 @@ public class TakeScreenshotService extends Service {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TakeScreenshotService(ScreenshotController screenshotController, UserManager userManager,
|
public TakeScreenshotService(ScreenshotController screenshotController, UserManager userManager,
|
||||||
UiEventLogger uiEventLogger,
|
DevicePolicyManager devicePolicyManager, UiEventLogger uiEventLogger,
|
||||||
ScreenshotNotificationsController notificationsController) {
|
ScreenshotNotificationsController notificationsController, Context context) {
|
||||||
if (DEBUG_SERVICE) {
|
if (DEBUG_SERVICE) {
|
||||||
Log.d(TAG, "new " + this);
|
Log.d(TAG, "new " + this);
|
||||||
}
|
}
|
||||||
mHandler = new Handler(Looper.getMainLooper(), this::handleMessage);
|
mHandler = new Handler(Looper.getMainLooper(), this::handleMessage);
|
||||||
mScreenshot = screenshotController;
|
mScreenshot = screenshotController;
|
||||||
mUserManager = userManager;
|
mUserManager = userManager;
|
||||||
|
mDevicePolicyManager = devicePolicyManager;
|
||||||
mUiEventLogger = uiEventLogger;
|
mUiEventLogger = uiEventLogger;
|
||||||
mNotificationsController = notificationsController;
|
mNotificationsController = notificationsController;
|
||||||
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -182,6 +189,14 @@ public class TakeScreenshotService extends Service {
|
|||||||
requestCallback.reportError();
|
requestCallback.reportError();
|
||||||
return true;
|
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 screenshotRequest =
|
||||||
(ScreenshotHelper.ScreenshotRequest) msg.obj;
|
(ScreenshotHelper.ScreenshotRequest) msg.obj;
|
||||||
|
|||||||
Reference in New Issue
Block a user