Disabling the activate button when paused

This revises the previous attempt to drop taps when another window is
obscuring the device admin details. Any system alert windows or toasts
are disabled when the activity is in focus, otherwise the button is
disabled so no floating activities can obscure it and delegate taps back
to the security sensitive "Activate" button.

Test: CtsVerifier -> Device Administration -> Device Admin Tapjacking Test

Bug: 35056974
Change-Id: I292a44e713ea4a4b0305ca3b3b21f1c82fd73c2b
This commit is contained in:
Suprabh Shukla
2017-05-22 15:20:06 -07:00
parent 532a88dcd0
commit 05c8eb5fd0

View File

@@ -40,6 +40,7 @@ import android.net.Uri;
import android.os.Binder; import android.os.Binder;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteCallback; import android.os.RemoteCallback;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle; import android.os.UserHandle;
@@ -90,6 +91,7 @@ public class DeviceAdminAdd extends Activity {
public static final String EXTRA_CALLED_FROM_SUPPORT_DIALOG = public static final String EXTRA_CALLED_FROM_SUPPORT_DIALOG =
"android.app.extra.CALLED_FROM_SUPPORT_DIALOG"; "android.app.extra.CALLED_FROM_SUPPORT_DIALOG";
private final IBinder mToken = new Binder();
Handler mHandler; Handler mHandler;
DevicePolicyManager mDPM; DevicePolicyManager mDPM;
@@ -118,8 +120,6 @@ public class DeviceAdminAdd extends Activity {
boolean mWaitingForRemoveMsg; boolean mWaitingForRemoveMsg;
boolean mAddingProfileOwner; boolean mAddingProfileOwner;
boolean mAdminPoliciesInitialized; boolean mAdminPoliciesInitialized;
int mCurSysAppOpMode;
int mCurToastAppOpMode;
boolean mIsCalledFromSupportDialog = false; boolean mIsCalledFromSupportDialog = false;
@@ -352,6 +352,9 @@ public class DeviceAdminAdd extends Activity {
restrictedAction.setFilterTouchesWhenObscured(true); restrictedAction.setFilterTouchesWhenObscured(true);
restrictedAction.setOnClickListener(new View.OnClickListener() { restrictedAction.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
if (!mActionButton.isEnabled()) {
return;
}
if (mAdding) { if (mAdding) {
addAndFinish(); addAndFinish();
} else if (isManagedProfile(mDeviceAdmin) } else if (isManagedProfile(mDeviceAdmin)
@@ -473,24 +476,21 @@ public class DeviceAdminAdd extends Activity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
mActionButton.setEnabled(true);
updateInterface(); updateInterface();
// As long as we are running, don't let this admin overlay stuff on top of the screen. // As long as we are running, don't let anyone overlay stuff on top of the screen.
final int uid = mDeviceAdmin.getActivityInfo().applicationInfo.uid; mAppOps.setUserRestriction(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, true, mToken);
final String pkg = mDeviceAdmin.getActivityInfo().applicationInfo.packageName; mAppOps.setUserRestriction(AppOpsManager.OP_TOAST_WINDOW, true, mToken);
mCurSysAppOpMode = mAppOps.checkOp(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, uid, pkg);
mCurToastAppOpMode = mAppOps.checkOp(AppOpsManager.OP_TOAST_WINDOW, uid, pkg);
mAppOps.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, uid, pkg, AppOpsManager.MODE_IGNORED);
mAppOps.setMode(AppOpsManager.OP_TOAST_WINDOW, uid, pkg, AppOpsManager.MODE_IGNORED);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
// As long as we are running, don't let this admin overlay stuff on top of the screen. // This just greys out the button. The actual listener is attached to R.id.restricted_action
final int uid = mDeviceAdmin.getActivityInfo().applicationInfo.uid; mActionButton.setEnabled(false);
final String pkg = mDeviceAdmin.getActivityInfo().applicationInfo.packageName; mAppOps.setUserRestriction(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, false, mToken);
mAppOps.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, uid, pkg, mCurSysAppOpMode); mAppOps.setUserRestriction(AppOpsManager.OP_TOAST_WINDOW, false, mToken);
mAppOps.setMode(AppOpsManager.OP_TOAST_WINDOW, uid, pkg, mCurToastAppOpMode);
try { try {
ActivityManager.getService().resumeAppSwitches(); ActivityManager.getService().resumeAppSwitches();
} catch (RemoteException e) { } catch (RemoteException e) {