Hi,
This could be done with two different ways: 1. framework layer, 2 kernel event system.
For such remapping on aosp framework, you may need to modify synthesizeButtonKeys function in https://android.googlesource.com/platform/frameworks/base/+/a45746e/services/input/InputReader.cpp, filter the mouse MOUSE_SECONDARY event , mapping it to KEYCODE_BACK.
For kernel event system, you need write a service to map BTN_RIGHT to KEY_BACK, then the aosp can always get KEY_BACK event while you click mouse BTN_RIGHT.
Best Regards,
Zhiming