There is an important difference between MMI and USSD codes.
USSD are executed as soon as the final "#" is entered while MMI codes require a click on the "Call" button.
IMPORTANT : In all cases, "#" must be changed to its "%23" ASCII value.
1- MMI codes work with the android.intent.action.DIAL action.
Here is a Command line example for MMI code *#43# :
adb shell am start -a android.intent.action.CALL -d tel:*%2343%23
Will trigger interaction between device and network to report Call waiting status and display the toast "Call Waiting / The service is activated" (or .. is not ..).
In your code; something like this will work :
DeviceManipulations.call(phoneNumber.replace("#", "%23"));
2- USSD fail when used with CALL action. Use android.intent.action.DIAL. Plus, it takes a few tricks :
With command line, you must put the code between double quotes.
Example for MMI code *#06# :
adb shell am start -a android.intent.action.DIAL -d tel:"*%2306%23"
This displays the Device Information popup.
With my DeviceManipulations code, using DIAL with "*%2306%23" leaves the dialer opened with the code but the execution does not start. Workaround is to do it in two parts : DIAL without the last "#" :
int intlong = codeUSSD.length();
codeUSSD = codeUSSD.substring(0, (intlong-1));
DeviceManipulations.dial(codeUSSD.replace("#", "%23"));
.. followed with "input keyevent" for the last "#" :
DeviceManipulations.customExec("adb shell input keyevent 18");
I suppose that sending every single caracter with "intput keyevent" method would work best but the above is a shortcut.
Note : The "input keyevent 18" does not trigger action with Samsung devices. Those have a different dialer than Google's. I have to use an Appium interaction with those.