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

Commit c200f44c authored by Benjamin Franz's avatar Benjamin Franz
Browse files

Block assist when screenshots are disabled by policy

When a device or profile owner disables screen capture, we also want to
block context data being collected for the assist structure.

Bug: 21797707
Change-Id: Ib8716c6dd71d538a027c04e1e907c87e2afa0ac8
parent 107cb81f
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -2217,6 +2217,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case IS_SCREEN_CAPTURE_ALLOWED_ON_CURRENT_ACTIVITY_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            boolean res = isScreenCaptureAllowedOnCurrentActivity();
            reply.writeNoException();
            reply.writeInt(res ? 1 : 0);
            return true;
        }

        case KILL_UID_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            int uid = data.readInt();
@@ -5409,6 +5417,18 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }

    public boolean isScreenCaptureAllowedOnCurrentActivity() throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        mRemote.transact(IS_SCREEN_CAPTURE_ALLOWED_ON_CURRENT_ACTIVITY_TRANSACTION, data, reply, 0);
        reply.readException();
        boolean res = reply.readInt() != 0;
        data.recycle();
        reply.recycle();
        return res;
    }

    public void killUid(int uid, String reason) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
+4 −0
Original line number Diff line number Diff line
@@ -441,6 +441,8 @@ public interface IActivityManager extends IInterface {
    public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle,
            Bundle args) throws RemoteException;

    public boolean isScreenCaptureAllowedOnCurrentActivity() throws RemoteException;

    public void killUid(int uid, String reason) throws RemoteException;

    public void hang(IBinder who, boolean allowRestart) throws RemoteException;
@@ -852,4 +854,6 @@ public interface IActivityManager extends IInterface {
    int KEYGUARD_GOING_AWAY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+296;
    int REGISTER_UID_OBSERVER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+297;
    int UNREGISTER_UID_OBSERVER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+298;
    int IS_SCREEN_CAPTURE_ALLOWED_ON_CURRENT_ACTIVITY_TRANSACTION
            = IBinder.FIRST_CALL_TRANSACTION+299;
}
+3 −0
Original line number Diff line number Diff line
@@ -2402,6 +2402,9 @@ public class DevicePolicyManager {
     * <p>The calling device admin must be a device or profile owner. If it is not, a
     * security exception will be thrown.
     *
     * <p>From version {@link android.os.Build.VERSION_CODES#MNC} disabling screen capture also
     * blocks assist requests for all activities of the relevant user.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param disabled Whether screen capture is disabled or not.
     */
+16 −0
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.backup.IBackupManager;
import android.app.admin.DevicePolicyManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ClipData;
@@ -10687,6 +10688,21 @@ public final class ActivityManagerService extends ActivityManagerNative
        return pae.extras;
    }
    @Override
    public boolean isScreenCaptureAllowedOnCurrentActivity() {
        int userId = mCurrentUserId;
        synchronized (this) {
            ActivityRecord activity = getFocusedStack().topActivity();
            if (activity == null) {
                return false;
            }
            userId = activity.userId;
        }
        DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
                Context.DEVICE_POLICY_SERVICE);
        return (dpm == null) || (!dpm.getScreenCaptureDisabled(null, userId));
    }
    @Override
    public void requestAssistContextExtras(int requestType, IResultReceiver receiver) {
        enqueueAssistContext(requestType, null, null, receiver, UserHandle.getCallingUserId(),
+8 −2
Original line number Diff line number Diff line
@@ -193,8 +193,14 @@ final class VoiceInteractionSessionConnection implements ServiceConnection {
                        new UserHandle(mUser));
            }
            mShown = true;
            boolean allDataEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                    Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, mUser) != 0;
            boolean isScreenCaptureAllowed = true;
            try {
                isScreenCaptureAllowed = mAm.isScreenCaptureAllowedOnCurrentActivity();
            } catch (RemoteException e) {
            }
            boolean allDataEnabled = (Settings.Secure.getIntForUser(mContext.getContentResolver(),
                    Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, mUser) != 0)
                    && isScreenCaptureAllowed;
            mShowArgs = args;
            mShowFlags = flags;
            mHaveAssistData = false;