Closing a window within an activity using adb shell commands
When it comes to closing a dialog or a window, a user uses the Back key of their device. Through command-line you can emulate the functionality of Back key using a particular key event. The key event for Back key is KEYCODE_BACK. It has the constant value 4. Use it with input command in this manner:

adb shell input keyevent KEYCODE_BACK
adb shell input keyevent 4    # alternative


I recommend you read this answer by Rene Barbosa. It lists many useful key events. I also recommend you execute adb shell input to find out how useful that command can be.