Merge "DO NOT MERGE: Prevent non-system IME from becoming device admin" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fbe97f1ee4
@@ -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,8 +157,8 @@ 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 = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
PackageManager packageManager = getPackageManager();
|
PackageManager packageManager = getPackageManager();
|
||||||
|
|
||||||
@@ -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