DO NOT MERGE: Prevent non-system IME from becoming device admin
Currently selected IME can inject KeyEvent on DeviceAdminAdd screen to
activate itself as device admin and cause various DoS attacks.
This CL ensures KeyEvent on "Activate" button can only come from system
apps.
Bug: 280793427
Test: atest DeviceAdminActivationTest
Change-Id: I6470d1684d707f4b1e86f8b456be0b4e0af5f188
(cherry picked from commit 70a501d02e
)
This commit is contained in:
@@ -66,6 +66,7 @@ import android.text.TextUtils.TruncateAt;
|
|||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -156,9 +157,9 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {
|
|||||||
|
|
||||||
mHandler = new Handler(getMainLooper());
|
mHandler = new Handler(getMainLooper());
|
||||||
|
|
||||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = getSystemService(DevicePolicyManager.class);
|
||||||
mAppOps = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
|
mAppOps = getSystemService(AppOpsManager.class);
|
||||||
mLayoutInflaternflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mLayoutInflaternflater = getSystemService(LayoutInflater.class);
|
||||||
PackageManager packageManager = getPackageManager();
|
PackageManager packageManager = getPackageManager();
|
||||||
|
|
||||||
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
|
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
|
||||||
@@ -421,8 +422,8 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {
|
|||||||
|
|
||||||
final View restrictedAction = findViewById(R.id.restricted_action);
|
final View restrictedAction = findViewById(R.id.restricted_action);
|
||||||
restrictedAction.setFilterTouchesWhenObscured(true);
|
restrictedAction.setFilterTouchesWhenObscured(true);
|
||||||
restrictedAction.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
final View.OnClickListener restrictedActionClickListener = v -> {
|
||||||
if (!mActionButton.isEnabled()) {
|
if (!mActionButton.isEnabled()) {
|
||||||
showPolicyTransparencyDialogIfRequired();
|
showPolicyTransparencyDialogIfRequired();
|
||||||
return;
|
return;
|
||||||
@@ -465,14 +466,20 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {
|
|||||||
}
|
}
|
||||||
}, mHandler));
|
}, mHandler));
|
||||||
// Don't want to wait too long.
|
// Don't want to wait too long.
|
||||||
getWindow().getDecorView().getHandler().postDelayed(new Runnable() {
|
getWindow().getDecorView().getHandler().postDelayed(
|
||||||
@Override public void run() {
|
() -> continueRemoveAction(null), 2 * 1000);
|
||||||
continueRemoveAction(null);
|
|
||||||
}
|
|
||||||
}, 2*1000);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
restrictedAction.setOnKeyListener((view, keyCode, keyEvent) -> {
|
||||||
|
if ((keyEvent.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == 0) {
|
||||||
|
Log.e(TAG, "Can not activate device-admin with KeyEvent from non-system app.");
|
||||||
|
// Consume event to suppress click.
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
// Fallback to view click handler.
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
restrictedAction.setOnClickListener(restrictedActionClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user