[Arakhnę-Dev] [324] * Add support for Android operating system.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 324
Author:   galland
Date:     2012-02-01 22:18:08 +0100 (Wed, 01 Feb 2012)
Log Message:
-----------
* Add support for Android operating system.

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java	2012-01-30 19:17:54 UTC (rev 323)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java	2012-02-01 21:18:08 UTC (rev 324)
@@ -37,6 +37,18 @@
  */
 public class Android {
 
+	/** Name of the home directory.
+	 */
+	public static final String HOME_DIRECTORY = "sdcard"; //$NON-NLS-1$
+	
+	/** Name of the system-wide configuration directory.
+	 */
+	public static final String CONFIGURATION_DIRECTORY = "config"; //$NON-NLS-1$
+
+	/** Name of the system-wide data directory.
+	 */
+	public static final String DATA_DIRECTORY = "data"; //$NON-NLS-1$
+
 	private static SoftReference<Object> context = null;
 	private static WeakReference<Object> contextResolver = null;
 	private static WeakReference<ClassLoader> contextClassLoader = null;
@@ -47,6 +59,24 @@
 		//
 	}
 	
+	/** Make a valid android application name from the given application name.
+	 * A valid android application name is a package name followed by the name
+	 * of the application.
+	 * 
+	 * @param applicationName is the simple application name.
+	 * @return the android application name.
+	 */
+	public static String makeAndroidApplicationName(String applicationName) {
+		String fullName;
+		if (applicationName.indexOf('.')>=0) {
+			fullName = applicationName;
+		}
+		else {
+			fullName = "org.arakhne.partnership."+applicationName; //$NON-NLS-1$
+		}
+		return fullName;
+	}
+	
 	/** Replies the class {@code Context} from Android.
 	 * 
 	 * @return the class {@code Context} from Android.

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2012-01-30 19:17:54 UTC (rev 323)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2012-02-01 21:18:08 UTC (rev 324)
@@ -1342,10 +1342,13 @@
 	 */
 	public static File getUserHomeDirectory() throws FileNotFoundException {
 		String userHome = System.getProperty("user.home"); //$NON-NLS-1$
-		if (userHome!=null) {
+		if (userHome!=null && !userHome.isEmpty()) {
 			File file = new File(userHome);
 			if (file.isDirectory()) return file;
 		}
+		if (OperatingSystem.ANDROID.isCurrentOS()) {
+			return join(File.listRoots()[0], Android.HOME_DIRECTORY);
+		}
 		throw new FileNotFoundException();
 	}
 
@@ -1354,7 +1357,11 @@
 	 * @return the home directory of the current user.
 	 */
 	public static String getUserHomeDirectoryName() {
-		return System.getProperty("user.home"); //$NON-NLS-1$
+		String userHome = System.getProperty("user.home"); //$NON-NLS-1$
+		if ((userHome==null || userHome.isEmpty()) && (OperatingSystem.ANDROID.isCurrentOS())) {
+			return join(File.listRoots()[0], Android.HOME_DIRECTORY).toString();
+		}
+		return userHome;
 	}
 
 	/** Replies the user configuration directory for the specified software.
@@ -1376,7 +1383,11 @@
 		try {
 			File userHome = getUserHomeDirectory();
 			OperatingSystem os = OperatingSystem.getCurrentOS();
-			if (os.isUnixCompliant()) {
+			if (os==OperatingSystem.ANDROID) {
+				return join(userHome, "Android", Android.DATA_DIRECTORY,  //$NON-NLS-1$
+						Android.makeAndroidApplicationName(software));
+			}
+			else if (os.isUnixCompliant()) {
 				return new File(new File(userHome, ".config"), software); //$NON-NLS-1$
 			}
 			else if (os==OperatingSystem.WIN) {
@@ -1433,7 +1444,11 @@
 		if (software==null || "".equals(software)) //$NON-NLS-1$
 			throw new IllegalArgumentException();
 		OperatingSystem os = OperatingSystem.getCurrentOS();
-		if (os.isUnixCompliant()) {
+		if (os==OperatingSystem.ANDROID) {
+			return join(File.listRoots()[0], Android.CONFIGURATION_DIRECTORY,
+					Android.makeAndroidApplicationName(software));
+		}
+		else if (os.isUnixCompliant()) {
 			File[] roots = File.listRoots();
 			return join(roots[0],"etc", software); //$NON-NLS-1$
 		}
@@ -1483,7 +1498,11 @@
 		if (software==null || "".equals(software)) //$NON-NLS-1$
 			throw new IllegalArgumentException();
 		OperatingSystem os = OperatingSystem.getCurrentOS();
-		if (os.isUnixCompliant()) {
+		if (os==OperatingSystem.ANDROID) {
+			return join(File.listRoots()[0], Android.DATA_DIRECTORY,
+					Android.makeAndroidApplicationName(software));
+		}
+		else if (os.isUnixCompliant()) {
 			File[] roots = File.listRoots();
 			return join(roots[0],"usr","lib", software); //$NON-NLS-1$ //$NON-NLS-2$
 		}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/