userAgent support android 4.1

This commit is contained in:
wenshao
2013-08-13 23:06:28 +08:00
parent 12a2de6e7d
commit 0f3ad11822
5 changed files with 216 additions and 3 deletions
@@ -89,6 +89,7 @@ public class WebAppStat {
private final AtomicLong osAndroid31Count = new AtomicLong(0);
private final AtomicLong osAndroid32Count = new AtomicLong(0);
private final AtomicLong osAndroid40Count = new AtomicLong(0);
private final AtomicLong osAndroid41Count = new AtomicLong(0);
private final AtomicLong osLinuxUbuntuCount = new AtomicLong(0);
@@ -185,6 +186,7 @@ public class WebAppStat {
osAndroid31Count.set(0);
osAndroid32Count.set(0);
osAndroid40Count.set(0);
osAndroid41Count.set(0);
browserIE6Count.set(0);
browserIE7Count.set(0);
@@ -501,6 +503,7 @@ public class WebAppStat {
data.put("OSAndroid31Count", this.getOSAndroid31Count());
data.put("OSAndroid32Count", this.getOSAndroid32Count());
data.put("OSAndroid40Count", this.getOSAndroid40Count());
data.put("OSAndroid41Count", this.getOSAndroid41Count());
data.put("OSLinuxUbuntuCount", this.getOSLinuxUbuntuCount());
data.put("BrowserIECount", this.getBrowserIECount());
@@ -899,12 +902,16 @@ public class WebAppStat {
private boolean computeUserAgentAndroid(String userAgent) {
boolean isAndroid = userAgent.startsWith("Android", 23);
int toffset = 31;
if (!isAndroid) {
isAndroid = userAgent.startsWith("Android", 20);
toffset = 28;
}
if (isAndroid) {
osAndroidCount.incrementAndGet();
deviceAndroidCount.incrementAndGet();
int toffset = 31;
if (userAgent.startsWith("1.5", toffset)) {
osAndroid15Count.incrementAndGet();
} else if (userAgent.startsWith("1.6", toffset)) {
@@ -927,6 +934,8 @@ public class WebAppStat {
osAndroid32Count.incrementAndGet();
} else if (userAgent.startsWith("4.0", toffset)) {
osAndroid40Count.incrementAndGet();
} else if (userAgent.startsWith("4.1", toffset)) {
osAndroid41Count.incrementAndGet();
}
return true;
@@ -1026,6 +1035,10 @@ public class WebAppStat {
public long getOSAndroid40Count() {
return osAndroid40Count.get();
}
public long getOSAndroid41Count() {
return osAndroid41Count.get();
}
public long getOSLinuxUbuntuCount() {
return osLinuxUbuntuCount.get();
@@ -0,0 +1,50 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.support.http;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.support.http.stat.WebAppStat;
public class UserAgentAndroid_4_0_3_Test extends TestCase {
public void test_mac_firefox() throws Exception {
WebAppStat stat = new WebAppStat("");
stat.computeUserAgent("Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
Assert.assertEquals(0, stat.getBrowserChromeCount());
Assert.assertEquals(0, stat.getBrowserFirefoxCount());
Assert.assertEquals(0, stat.getBrowserOperaCount());
Assert.assertEquals(0, stat.getBrowserSafariCount());
Assert.assertEquals(0, stat.getBrowserIECount());
Assert.assertEquals(0, stat.getBrowserIE10Count());
Assert.assertEquals(1, stat.getDeviceAndroidCount());
Assert.assertEquals(0, stat.getDeviceIphoneCount());
Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
Assert.assertEquals(1, stat.getOSLinuxCount());
Assert.assertEquals(1, stat.getOSAndroidCount());
Assert.assertEquals(1, stat.getOSAndroid40Count());
Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
Assert.assertEquals(0, stat.getOSMacOSXCount());
Assert.assertEquals(0, stat.getOSWindowsCount());
Assert.assertEquals(0, stat.getOSWindows8Count());
Assert.assertEquals(0, stat.getOSSymbianCount());
Assert.assertEquals(0, stat.getOSFreeBSDCount());
Assert.assertEquals(0, stat.getOSOpenBSDCount());
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.support.http;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.support.http.stat.WebAppStat;
public class UserAgentAndroid_4_0_3_Test_2 extends TestCase {
public void test_mac_firefox() throws Exception {
WebAppStat stat = new WebAppStat("");
stat.computeUserAgent("Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
Assert.assertEquals(0, stat.getBrowserChromeCount());
Assert.assertEquals(0, stat.getBrowserFirefoxCount());
Assert.assertEquals(0, stat.getBrowserOperaCount());
Assert.assertEquals(0, stat.getBrowserSafariCount());
Assert.assertEquals(0, stat.getBrowserIECount());
Assert.assertEquals(0, stat.getBrowserIE10Count());
Assert.assertEquals(1, stat.getDeviceAndroidCount());
Assert.assertEquals(0, stat.getDeviceIphoneCount());
Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
Assert.assertEquals(1, stat.getOSLinuxCount());
Assert.assertEquals(1, stat.getOSAndroidCount());
Assert.assertEquals(1, stat.getOSAndroid40Count());
Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
Assert.assertEquals(0, stat.getOSMacOSXCount());
Assert.assertEquals(0, stat.getOSWindowsCount());
Assert.assertEquals(0, stat.getOSWindows8Count());
Assert.assertEquals(0, stat.getOSSymbianCount());
Assert.assertEquals(0, stat.getOSFreeBSDCount());
Assert.assertEquals(0, stat.getOSOpenBSDCount());
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.support.http;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.support.http.stat.WebAppStat;
public class UserAgentAndroid_4_0_4_Test extends TestCase {
public void test_mac_firefox() throws Exception {
WebAppStat stat = new WebAppStat("");
stat.computeUserAgent("Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19");
Assert.assertEquals(1, stat.getBrowserChromeCount());
Assert.assertEquals(0, stat.getBrowserFirefoxCount());
Assert.assertEquals(0, stat.getBrowserOperaCount());
Assert.assertEquals(0, stat.getBrowserSafariCount());
Assert.assertEquals(0, stat.getBrowserIECount());
Assert.assertEquals(0, stat.getBrowserIE10Count());
Assert.assertEquals(1, stat.getDeviceAndroidCount());
Assert.assertEquals(0, stat.getDeviceIphoneCount());
Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
Assert.assertEquals(1, stat.getOSLinuxCount());
Assert.assertEquals(1, stat.getOSAndroidCount());
Assert.assertEquals(1, stat.getOSAndroid40Count());
Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
Assert.assertEquals(0, stat.getOSMacOSXCount());
Assert.assertEquals(0, stat.getOSWindowsCount());
Assert.assertEquals(0, stat.getOSWindows8Count());
Assert.assertEquals(0, stat.getOSSymbianCount());
Assert.assertEquals(0, stat.getOSFreeBSDCount());
Assert.assertEquals(0, stat.getOSOpenBSDCount());
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.support.http;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.support.http.stat.WebAppStat;
public class UserAgentAndroid_4_1_Test extends TestCase {
public void test_mac_firefox() throws Exception {
WebAppStat stat = new WebAppStat("");
stat.computeUserAgent("Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19");
Assert.assertEquals(1, stat.getBrowserChromeCount());
Assert.assertEquals(0, stat.getBrowserFirefoxCount());
Assert.assertEquals(0, stat.getBrowserOperaCount());
Assert.assertEquals(0, stat.getBrowserSafariCount());
Assert.assertEquals(0, stat.getBrowserIECount());
Assert.assertEquals(0, stat.getBrowserIE10Count());
Assert.assertEquals(1, stat.getDeviceAndroidCount());
Assert.assertEquals(0, stat.getDeviceIphoneCount());
Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
Assert.assertEquals(1, stat.getOSLinuxCount());
Assert.assertEquals(1, stat.getOSAndroidCount());
Assert.assertEquals(1, stat.getOSAndroid41Count());
Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
Assert.assertEquals(0, stat.getOSMacOSXCount());
Assert.assertEquals(0, stat.getOSWindowsCount());
Assert.assertEquals(0, stat.getOSWindows8Count());
Assert.assertEquals(0, stat.getOSSymbianCount());
Assert.assertEquals(0, stat.getOSFreeBSDCount());
Assert.assertEquals(0, stat.getOSOpenBSDCount());
}
}