Android config properties - java

I've been looking into how to manage my config properties in an android project. I need a place to store urls, usernames and passwords of the web services my app connects to. In a normal java project i would have a config.properties file and would use spring to inject the properties into wherever they were needed. I thought about using the strings.xml file, is this a bad place to store them? Are there any issues with storing sensitive data like passwords in there? Any other ideas of what i could do?
Any advice would be greatly appreciated!
David

It is Better to store them in /assets directory or in /res/raw directory see http://myossdevblog.blogspot.in/2010/02/reading-properties-files-on-android.html

I always just put stuff like this in strings.xml but I don't really deal with passwords. Preferences are also an option. You will probably want to encrypt the passwords.
Rember that you have control of a web app servier, you don't have control of a user's device. It may be rooted, it may not, they may have easy access to pull your apk and look at it, or check out the preferences. So if you are really worried about security of these things you may want to not store them on the device.
One easy option would be to run a proxy server that had the necessary access, and run all your web service calls through the proxy.

One good place is to put these in a properties file, the advantage is if for some reason your URL changes then you can easily overwrite the key/value in the file with a new URL from server (provided you have code that supports that and runs on app launch). Taken further, this mechanism can be used to enable/disable features of an app, enable debug logs to help troubleshoot customer service issues etc.

The Android Shared Preferences seems like the proper storage for any application config data to be preserved over app restarts (providing the data is not too large in which case you may need a database).
Hope this helps,
Robert

Related

Is there a way of changing custom values for each client without building a whole new apk?

I don't really know how to explain this, but let's say I had a web app, and I wanted to change things like some settings of some sort after a deploy the web app to the client, normally I would have to go to a .settings file or a .config file and change it from there after I deploy it. Is there any way I can do that on Android as well?
like for example, let's say each client has a custom url, and I have to access it from the android app, how can I change that url, without building a whole new apk, but only changing a .settings file or a .config file?
Does anyone know if that's possible? Thanks!
Edit: Also keep in mind that this is not an app that should go public on the play store, but it's instead meant to be a business to business application.

How to deploy embedded database contained within .jar file?

I'm currently developing a java application where users shall be able to create profiles, sign in with their login data, store some information connected to their user profile, etc. within a database. As the application should come lightweight and the normal user who isn't as technophile as developers might not want to manually set up a database on his system prior to being able to use the application or even might not be able to do so.
Hence what I am going for obviously will be an embedded database. As I've already read through several posts dealing with embedded databases and how to access them I'm already aware that I won't be able to simply pack an initialized - yet empty - database within my .jar file and let users store new data in it as it will be static and read-only when packed within the .jar file.
But as obviously there has to be some way to set a database up without even bothering the user with its creation or configuration I'm now asking myself What are the usual ways to do so? How is this typically done? Because obviously there are a lot of applications that use non-static embedded databases.
An idea I've come up with is creating such an empty, initialized database which then will be packed within the .jar file and upon each launch of the application, the application looks for a appropriate database file within its current location and if it doesn't find one it simply copies the empty database packed in its .jar file to the folder. But I'm not sure if this would actually be enough to make this work or if this is actually properly achievable or if there's no better way to do so.
I'm really curious for what a typical solution of this scenario looks like and thanks in advance for your input and ideas on this.

How to save application data for use across users in OS X

I have a Mac Java application that needs to persist data across reboots. The data needs to be saved so that any user has access to it. E.g. an SQLite database file that can be used for all users.
It looks like the /Library/Application Support/ folder is supposed to be used for this, but I'm not able to write to it without making my app run as root or changing the permissions of the file to rwxrwxrwx.
What is the proper way to save application-level data on Mac?
The developer documentation covering this is a bit of a large topic:
https://developer.apple.com/library/Mac/referencelibrary/GettingStarted/GS_DataManagement_MacOSX/_index.html#//apple_ref/doc/uid/TP40009046
https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010672
According to the File System Programming guide you should make a specific subdirectory inside /Library/Application\ Support for your app to store app data common to all users on the system. I'd use reverse domain name notation such as com.yourcompany.yourapp or something else unlikely to collide with another app's use of the common directory for this.
You might also look into using an existing app bundler for OS X such as https://bitbucket.org/infinitekind/appbundler rather than hard code paths to file locations.

Is an Android app which uses local JSON files to store data vulnerable?

My Android app uses plain text JSON files to store some data. Such files are saved into the private folder of the app, e.g. Android/data/com.example.app/. I would like to know if my app is vulnerable with such kind of files around. Data in those files are not sensible or secret, and they are not processed by JavaScript (they are parsed with JSON Java methods); I am concerned about some malicious JSON code to be injected and mess with my app or the user's device. Is it possible?
Even if the injected code was not malicious it can cause you problems because:
Others can see and alter the file. (At least with rooted devices)
if the content is altered then you are prone have unexpected results while parsing the file.
You would not want your app related data to be altered by others by any means unless you want it to be (but by using Content Providers.)
I hope it makes sense.
By default, data that you store into the private folder is neither accessible by the user nor by other applications. See the documentation on the Android developers website about this: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
However, as mentioned by SMR, if a device has been rooted this data is available to the user and might be compromised by any apps that the user has given root permission to.
However it's a minority of users that are actually rooted and those that are should more or less know what they've gotten themselves into and what they're actions can do. It's up to you to decide if it's worth some effort to look out for these special cases.
But by default your data should be safe and sound.
If the data is not that much private then you can put those data in the assets folder and you can access the same. If it is not like that then you can keep it inside the applications data folder

Saving properties for Java application during setup

I've created a Java application that is basically an interface to a MySQL database. It helps organize and keep track of data. We are using it in my workplace with no problem - I have exported it from Eclipse as a jar file and given everyone a copy of this jar file.
Now we want to make this software available to other workplaces. The problem is that the URL, username, and password for the database are hardcoded in the application. I want to create a setup process for it so that when someone downloads it, they go through a wizard that downloads MySQL and sets up the database wherever they choose. The person can then distribute the jar file to everyone in their workplace without them having to do the setup, because everyone will be accessing the same database.
This process must save the database URL, username, and password somehow so that the people in the workplace can run the jar from whatever computer. This makes me think that they should be saved inside the jar... is a Properties file that I need? Can I put a Properties file inside the jar and allow it to be edited during the setup process?
Any guidance is greatly appreciated, I'm very new to this!
==================================================================================
EDIT: I think what I'm going to do now is let the user install MySQL and set up their database themself. As the answers below suggested, having this automatic might be more trouble than it's worth, as I would have to deal with everyone's different platforms, preferences for setting up the database, security concerns, etc. Once they do this, they will just download my jar file.
I've added a properties file to my jar file to store the database URL, username, and password. This file is initially empty, so when the user runs the jar for the first time, the program will attempt to access the properties file, see that it's empty, and prompt the user to enter this information. It will then extract the properties file from the jar, edit in their information, and stick the properties file back into the jar. Then, the person should be able to distribute the updated jar to their coworkers and they should all be able to open it without having to supply that information. I've got this part almost working. I'm also going to add the ability to "reconfigure" the program - in case the user moves their database - by calling the same method (they would again have to distribute the new version of the program).
Next I want to try securing the properties file somehow by encrypting it or obfuscating the code (although I think that only works for class files and not text files...?). My concern is that anyone in the workplace can unjar it and open the properties file, then use the URL, username, and password to access the database on their own and cause damage. Ideally, no one would be able to unjar it at all except for the program itself.
If anyone has other concerns about my method, please let me know!
First, it would not be trivial to set up a database in a central location in a workplace so that it is accessible by different users. Also, there is the problem of the first user setting it up and then re-distributing the application to others.
Answering the technical questions - the easiest way would be to unjar to a known location, edit the properties file at that location, and then re-jar to a new file, perhaps with a suffix specific to that workplace.
You could save the property file in a subdirectory of the user home directory, obtained by System.getProperty("user.home). Also, have a look at the Apache Commons Configuration library.
How do you deploy your Application?
If you're using Webstart, you could define your properties in your jnlp-File and access them with System.getProperties(...);
Take a look at HSQLDB. It is a lighter weight db that is rely easy to setup. You can configure it to me the db if it doesn't exist and us it if it does. However, if you need something like MySQL and want to have many users connecting to it from different workstations, I would not recommend downloading and configuring it through an install process. There will be a lot of network and security concerns. As a side note a properties file is a good idea.
This is a link that explains some of the security concerns to think about. Also, thinking about this a little more, users might not have the necessary permissions to setup/configure a db server. It is probably safer/easier for you in the long run to allow them to set up the db server and have them put a properties file in your applications classpath.
As a side note, have you considered making this a web application? That could make things even simpler for you, people wouldnt have to download anything, and there would be no setup for most users.

Categories