In order to run our application on runtime on devices exclusively meant for it, I want to disable device hardware buttons such as Home, Task & Back buttons.
My Android version is 13, device is Samsung Galaxy Tab Active 3 2020 although I want it to work on other devices.
I already know I have to edit /system/usr/keylayout/Generic.kl and the app has root privileges. So I run this in runtime which was correctly working on Android 10:
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("mount -o remount,rw /\n");
os.writeBytes("sed -i 's/^[^#]*BACK/# &/' /system/usr/keylayout/Generic.kl\n");
os.writeBytes("sed -i 's/^[^#]*HOME/# &/' /system/usr/keylayout/Generic.kl\n");
os.writeBytes("sed -i 's/^[^#]*APP_SWITCH/# &/' /system/usr/keylayout/Generic.kl\n");
os.writeBytes("reboot\n");
os.writeBytes("exit\n");
os.flush();
But The problem is, as soon as the first edit on Generic.kl is performed, meaning this line:
sed -i 's/^[^#]*BACK/# &/' /system/usr/keylayout/Generic.kl\n
The tablet gets rebooted automatically and the file Generic.kl is restored to its initial state. So, no success with editing it programmatically.
I'm not sure about the context of your requirement however, in newer Android versions (including Android 13), the system partition is mounted as read-only by default to improve security.
You can try a custom launcher application that runs as the default home screen. This launcher can hide the hardware buttons or handle their actions according to your application's requirements.