devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wk...@apache.org
Subject svn commit: r1648789 - /devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
Date Thu, 01 Jan 2015 00:22:38 GMT
Author: wkeil
Date: Thu Jan  1 00:22:38 2015
New Revision: 1648789

URL: http://svn.apache.org/r1648789
Log:
DMAP-111: Improve Web Examples 

Task-Url: https://issues.apache.org/jira/browse/DMAP-111

Modified:
    devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java

Modified: devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java?rev=1648789&r1=1648788&r2=1648789&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
(original)
+++ devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
Thu Jan  1 00:22:38 2015
@@ -61,7 +61,7 @@ public class AndroidDeviceBuilder extend
             if (d != null) {
             	System.out.println("Token: " + token);
                 if (d.getConfidence() > confidenceTreshold) {
-                    return d;
+                    return fixFromUserAgent(d, userAgent);
                 } else {
                     if (d.getConfidence() > 0) {
                         foundDevices.add(d);
@@ -71,7 +71,7 @@ public class AndroidDeviceBuilder extend
         }
         if (foundDevices.size() > 0) {
             Collections.sort(foundDevices, Collections.reverseOrder());
-            return foundDevices.get(0);
+            return fixFromUserAgent(foundDevices.get(0), userAgent);
         } else {
         	it = orderedRules.keySet().iterator(); // need it again for "Fuzzy" patterns
         	while (it.hasNext()) {
@@ -79,7 +79,7 @@ public class AndroidDeviceBuilder extend
         		Device d = fuzzyAndroidDeviceWithToken(userAgent, token);
         		if (d != null) {
         			System.out.println("Got: " + token);
-        			return d;
+        			return fixFromUserAgent(d, userAgent);
         		}
         	}
         }
@@ -223,6 +223,22 @@ public class AndroidDeviceBuilder extend
         }
     	return null;
     }
+    
+    private Device fixFromUserAgent(final Device device, final UserAgent userAgent) {
+//    	if (device.containsProperty("device_os_version")) {
+    		String pattern = userAgent.getPatternElementsInside();
+    		String[] parts = pattern.split(";");
+    		for (String part : parts) {
+    			if (part.trim().startsWith("Android")) {
+    				String versionPart = part.trim().substring("Android".length());
+    				if (!versionPart.equals(device.get("device_os_version"))) {
+    					device.putProperty("device_os_version", versionPart);
+    				}
+    			}
+    		}
+//    	}
+    	return device;
+    }
 
     @Override
     protected void afterOderingCompleteInit(Map<String, Device> devices) {



Mime
View raw message