I haven't tried on Android, but here is how it works in plain Java.
You're using your keystore as a truststore here, so (hopefully) it doesn't contain any private key or secret material. In this case, the purpose of the password is to verify the integrity of the store.
From the Keystore.load(InputStream, char[])
documentation:
A password may be given to unlock the keystore (e.g. the keystore
resides on a hardware token device), or to check the integrity of the
keystore data. If a password is not given for integrity checking, then
integrity checking is not performed.
Either you use null
as the password (in which case you'll always be able to load the certificates) or you use a non-null char
array with the actual password (in which case an incorrect password will fail with something like "java.io.IOException: Keystore was tampered with, or password was incorrect").
Using a password here is meant to increase the security (to prevent the truststore to be tampered with). This being said, if you're bundling both this truststore and this application together, it's likely that an attacker able to replace the truststore would also gain access to the password (by decompiling) anyway. (I'm not too familiar with Android app distribution, but if apps are signed, it's possible that tampering with raw resources such as your truststore would invalidate the signature too, so that might be a more realistic way of having this protection. Otherwise, I guess you can ask the user to input the truststore's password every time, but that seems unrealistic.)
It's not really part of your question, but to secure the SSL/TLS connection, you also need to verify that the certificate sent by the server is valid for the host name you were trying to reach, after SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("192.168.1.16", 9999);
.
This was discussed recently in this question in Java. (Unfortunately, you won't be able to use the new Java 7 API to do this automatically for you on Android, so you'll have to check the certificate a bit more manually. You might also be interested in this recent question.)
EDIT (following your comment):
I'm concerned about someone recompiling the application, retrieving
the passcode and the truststore and using it to connect to my server.
If it is possible then it kind of defeats the purpose of the TLS in
the first place.
It's not clear from this comment you understand the purpose of the truststore (see this question, for example).
The purpose of the truststore in your client app isn't to authenticate your app to the server, it is to make sure your client can verify the identity of the server it connects to, so that it can't be tricked into connecting to a MITM attacker. It's not about how your server trusts your app/client/user, but it's about how your app trusts your server.
Authenticating the app user to the server would be the purpose of a keystore. This is fine for authenticating the user (but it would make more sense if each user had a different certificate). Making sure connections can only come from your app is another, much more difficult problem (a lost cause, if you don't have complete control of the client hardware at all times). Using a common client certificate in your app could buy you a bit of time, but anyone who has got hold of the client code could certainly reverse engineer it eventually. I wouldn't spend too much time on it. You might be interested in these questions: