Support for Android API 16. Provide concrete implementations for several Android APIs that were made abstract in API 16. Maven and Ant profiles build against API 16.
diff --git a/build.xml b/build.xml
index 6017a61..e183a48 100644
--- a/build.xml
+++ b/build.xml
@@ -52,10 +52,10 @@
</path>
<path id="android.target.classpath">
- <pathelement path="${sdk.dir}/platforms/android-14/android.jar"/>
- <pathelement path="${sdk.dir}/add-ons/addon_google_apis_google_inc_14/libs/maps.jar"/>
- <pathelement path="${sdk.dir}/add-ons/addon-google_apis-google_inc_-14/libs/maps.jar"/>
- <pathelement path="${sdk.dir}/add-ons/addon-google_apis-google-14/libs/maps.jar"/>
+ <pathelement path="${sdk.dir}/platforms/android-16/android.jar"/>
+ <pathelement path="${sdk.dir}/add-ons/addon_google_apis_google_inc_16/libs/maps.jar"/>
+ <pathelement path="${sdk.dir}/add-ons/addon-google_apis-google_inc_-16/libs/maps.jar"/>
+ <pathelement path="${sdk.dir}/add-ons/addon-google_apis-google-16/libs/maps.jar"/>
<pathelement path="${sdk.dir}/extras/android/support/v4/android-support-v4.jar"/>
<pathelement path="${sdk.dir}/android-compatibility/v4/android-support-v4.jar"/>
</path>
diff --git a/pom.xml b/pom.xml
index 091af33..37b3f6d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,7 +77,8 @@
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
- <version>4.0.1.2</version>
+ <version>4.1.1.4</version>
+ <!-- <version>4.0.1.2</version> -->
<scope>provided</scope>
</dependency>
diff --git a/src/main/java/android/hardware/TestSensorManager.java b/src/main/java/android/hardware/TestSensorManager.java
new file mode 100644
index 0000000..c64f520
--- /dev/null
+++ b/src/main/java/android/hardware/TestSensorManager.java
@@ -0,0 +1,10 @@
+package android.hardware;
+
+
+public class TestSensorManager extends SensorManager {
+
+ public TestSensorManager() {
+
+ }
+
+}
diff --git a/src/main/java/android/os/TestVibrator.java b/src/main/java/android/os/TestVibrator.java
new file mode 100644
index 0000000..ad3326d
--- /dev/null
+++ b/src/main/java/android/os/TestVibrator.java
@@ -0,0 +1,26 @@
+package android.os;
+
+public class TestVibrator extends Vibrator {
+
+ @Override
+ public void cancel() {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public boolean hasVibrator() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void vibrate(long arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void vibrate(long[] arg0, int arg1) {
+ // TODO Auto-generated method stub
+ }
+
+}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowWebSettings.java b/src/main/java/android/webkit/TestWebSettings.java
similarity index 82%
rename from src/main/java/com/xtremelabs/robolectric/shadows/ShadowWebSettings.java
rename to src/main/java/android/webkit/TestWebSettings.java
index 7687209..af57d79 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowWebSettings.java
+++ b/src/main/java/android/webkit/TestWebSettings.java
@@ -1,13 +1,17 @@
-package com.xtremelabs.robolectric.shadows;
+package android.webkit;
-import android.webkit.WebSettings;
+import com.xtremelabs.robolectric.internal.DoNotInstrument;
import com.xtremelabs.robolectric.internal.Implementation;
-import com.xtremelabs.robolectric.internal.Implements;
-@Implements(WebSettings.class)
-public class ShadowWebSettings {
-
+/**
+ * Concrete implementation of the abstract WebSettings class.
+ */
+@DoNotInstrument
+public class TestWebSettings extends WebSettings {
+
private boolean allowFileAccess = true;
+ private boolean allowFileAccessFromFile = true;
+ private boolean allowUniversalAccessFromFile = true;
private boolean blockNetworkImage = false;
private boolean blockNetworkLoads = false;
private boolean builtInZoomControls = true;
@@ -22,6 +26,29 @@
private boolean supportMultipleWindows = false;
private boolean supportZoom = true;
+ public TestWebSettings() {
+ }
+
+ @Override
+ public boolean getAllowFileAccessFromFileURLs() {
+ return allowFileAccessFromFile;
+ }
+
+ @Override
+ public boolean getAllowUniversalAccessFromFileURLs() {
+ return allowUniversalAccessFromFile;
+ }
+
+ @Override
+ public void setAllowFileAccessFromFileURLs(boolean allow) {
+ allowFileAccessFromFile = allow;
+ }
+
+ @Override
+ public void setAllowUniversalAccessFromFileURLs(boolean allow) {
+ allowUniversalAccessFromFile = allow;
+ }
+
@Implementation
public boolean getAllowFileAccess() {
return allowFileAccess;
diff --git a/src/main/java/com/xtremelabs/robolectric/Robolectric.java b/src/main/java/com/xtremelabs/robolectric/Robolectric.java
index 6f8e49f..b5e880d 100644
--- a/src/main/java/com/xtremelabs/robolectric/Robolectric.java
+++ b/src/main/java/com/xtremelabs/robolectric/Robolectric.java
@@ -339,7 +339,6 @@
ShadowViewPager.class,
ShadowViewStub.class,
ShadowViewTreeObserver.class,
- ShadowWebSettings.class,
ShadowWebView.class,
ShadowWifiConfiguration.class,
ShadowWifiInfo.class,
@@ -980,10 +979,6 @@
return (ShadowVideoView) shadowOf_(instance);
}
- public static ShadowWebSettings shadowOf(WebSettings instance) {
- return (ShadowWebSettings) shadowOf_(instance);
- }
-
public static ShadowWebView shadowOf(WebView instance) {
return (ShadowWebView) shadowOf_(instance);
}
@@ -1280,4 +1275,5 @@
}
}
}
+
}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowApplication.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowApplication.java
index 8a07a83..1b1aa8e 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowApplication.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowApplication.java
@@ -41,9 +41,12 @@
static {
// note that these are different!
+ // They specify concrete classes within Robolectric for interfaces or abstract classes defined by Android
SYSTEM_SERVICE_MAP.put(Context.WINDOW_SERVICE, "com.xtremelabs.robolectric.tester.android.view.TestWindowManager");
SYSTEM_SERVICE_MAP.put(Context.CLIPBOARD_SERVICE, "com.xtremelabs.robolectric.tester.android.text.TestClipboardManager");
-
+ SYSTEM_SERVICE_MAP.put(Context.SENSOR_SERVICE, "android.hardware.TestSensorManager");
+ SYSTEM_SERVICE_MAP.put(Context.VIBRATOR_SERVICE, "android.os.TestVibrator");
+
// the rest are as mapped in docs...
SYSTEM_SERVICE_MAP.put(Context.LAYOUT_INFLATER_SERVICE, "android.view.LayoutInflater");
SYSTEM_SERVICE_MAP.put(Context.ACTIVITY_SERVICE, "android.app.ActivityManager");
@@ -53,9 +56,7 @@
SYSTEM_SERVICE_MAP.put(Context.KEYGUARD_SERVICE, "android.app.KeyguardManager");
SYSTEM_SERVICE_MAP.put(Context.LOCATION_SERVICE, "android.location.LocationManager");
SYSTEM_SERVICE_MAP.put(Context.SEARCH_SERVICE, "android.app.SearchManager");
- SYSTEM_SERVICE_MAP.put(Context.SENSOR_SERVICE, "android.hardware.SensorManager");
SYSTEM_SERVICE_MAP.put(Context.STORAGE_SERVICE, "android.os.storage.StorageManager");
- SYSTEM_SERVICE_MAP.put(Context.VIBRATOR_SERVICE, "android.os.Vibrator");
SYSTEM_SERVICE_MAP.put(Context.CONNECTIVITY_SERVICE, "android.net.ConnectivityManager");
SYSTEM_SERVICE_MAP.put(Context.WIFI_SERVICE, "android.net.wifi.WifiManager");
SYSTEM_SERVICE_MAP.put(Context.AUDIO_SERVICE, "android.media.AudioManager");
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSQLiteProgram.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSQLiteProgram.java
index 6062e53..d903bfe 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSQLiteProgram.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSQLiteProgram.java
@@ -28,15 +28,8 @@
} catch (SQLException e) {
throw new RuntimeException(e);
}
-
- compile(sql, false);
}
- @Implementation
- public void compile(String sql, boolean forceCompilation) {
- }
-
-
/**
* Bind a NULL value to this statement. The value remains bound until
* {@link #clearBindings} is called.
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSensorManager.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSensorManager.java
index 4b69665..99bba88 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSensorManager.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSensorManager.java
@@ -4,12 +4,14 @@
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
+import android.os.Handler;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import java.util.ArrayList;
+import java.util.List;
@Implements(SensorManager.class)
@@ -43,5 +45,4 @@
public SensorEvent createSensorEvent() {
return Robolectric.newInstanceOf(SensorEvent.class);
}
-
}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowWebView.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowWebView.java
index c6a87e2..28e58af 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowWebView.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowWebView.java
@@ -4,6 +4,7 @@
import android.util.AttributeSet;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
+import android.webkit.TestWebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.xtremelabs.robolectric.Robolectric;
@@ -18,7 +19,7 @@
private String lastUrl;
private HashMap<String, Object> javascriptInterfaces = new HashMap<String, Object>();
- private WebSettings webSettings = Robolectric.newInstanceOf(WebSettings.class);
+ private WebSettings webSettings = new TestWebSettings();
private WebViewClient webViewClient = null;
private boolean runFlag = false;
private boolean clearCacheCalled = false;
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/WebSettingsTest.java b/src/test/java/android/webkit/TestWebSettingsTest.java
similarity index 79%
rename from src/test/java/com/xtremelabs/robolectric/shadows/WebSettingsTest.java
rename to src/test/java/android/webkit/TestWebSettingsTest.java
index 9662b60..12ae4c6 100644
--- a/src/test/java/com/xtremelabs/robolectric/shadows/WebSettingsTest.java
+++ b/src/test/java/android/webkit/TestWebSettingsTest.java
@@ -1,6 +1,7 @@
-package com.xtremelabs.robolectric.shadows;
+package android.webkit;
import android.webkit.WebSettings;
+import android.webkit.TestWebSettings;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;
import org.junit.Before;
@@ -10,19 +11,16 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
-
@RunWith(WithTestDefaultsRunner.class)
-public class WebSettingsTest {
+public class TestWebSettingsTest {
- private WebSettings webSettings;
- private ShadowWebSettings shadowWebSettings;
+ private TestWebSettings webSettings;
private boolean[] trueAndFalse = {true, false};
@Before
public void setUp() throws Exception {
- webSettings = Robolectric.newInstanceOf(WebSettings.class);
- shadowWebSettings = Robolectric.shadowOf(webSettings);
+ webSettings = new TestWebSettings();
}
@Test
@@ -36,11 +34,15 @@
assertThat(webSettings.getJavaScriptEnabled(), equalTo(false));
assertThat(webSettings.getLightTouchEnabled(), equalTo(false));
assertThat(webSettings.getLoadWithOverviewMode(), equalTo(false));
- assertThat(shadowWebSettings.getNeedInitialFocus(), equalTo(false));
- assertThat(webSettings.getPluginsEnabled(), equalTo(false));
assertThat(webSettings.getPluginState(), equalTo(WebSettings.PluginState.OFF));
- assertThat(shadowWebSettings.getSupportMultipleWindows(), equalTo(false));
- assertThat(shadowWebSettings.getSupportZoom(), equalTo(true));
+
+ // deprecated methods
+ assertThat(webSettings.getPluginsEnabled(), equalTo(false));
+
+ // obsoleted methods
+ assertThat(webSettings.getNeedInitialFocus(), equalTo(false));
+ assertThat(webSettings.getSupportMultipleWindows(), equalTo(false));
+ assertThat(webSettings.getSupportZoom(), equalTo(true));
}
@Test
@@ -52,6 +54,22 @@
}
@Test
+ public void testAllowFileAccessFromFileURLs() {
+ for (boolean value : trueAndFalse) {
+ webSettings.setAllowFileAccessFromFileURLs(value);
+ assertThat(webSettings.getAllowFileAccessFromFileURLs(), equalTo(value));
+ }
+ }
+
+ @Test
+ public void testAllowUniversalAccessFromFileURLs() {
+ for (boolean value : trueAndFalse) {
+ webSettings.setAllowUniversalAccessFromFileURLs(value);
+ assertThat(webSettings.getAllowUniversalAccessFromFileURLs(), equalTo(value));
+ }
+ }
+
+ @Test
public void testBlockNetworkImage() {
for (boolean value : trueAndFalse) {
webSettings.setBlockNetworkImage(value);
@@ -119,7 +137,7 @@
public void testNeedInitialFocus() {
for (boolean value : trueAndFalse) {
webSettings.setNeedInitialFocus(value);
- assertThat(shadowWebSettings.getNeedInitialFocus(), equalTo(value));
+ assertThat(webSettings.getNeedInitialFocus(), equalTo(value));
}
}
@@ -149,7 +167,7 @@
public void testSupportMultipleWindows() {
for (boolean value : trueAndFalse) {
webSettings.setSupportMultipleWindows(value);
- assertThat(shadowWebSettings.getSupportMultipleWindows(), equalTo(value));
+ assertThat(webSettings.getSupportMultipleWindows(), equalTo(value));
}
}
@@ -157,7 +175,7 @@
public void testSupportZoom() {
for (boolean value : trueAndFalse) {
webSettings.setSupportZoom(value);
- assertThat(shadowWebSettings.getSupportZoom(), equalTo(value));
+ assertThat(webSettings.getSupportZoom(), equalTo(value));
}
}
}
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/ApplicationTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/ApplicationTest.java
index e9b7358..c65a381 100644
--- a/src/test/java/com/xtremelabs/robolectric/shadows/ApplicationTest.java
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/ApplicationTest.java
@@ -77,16 +77,16 @@
checkSystemService(Context.KEYGUARD_SERVICE, android.app.KeyguardManager.class);
checkSystemService(Context.LOCATION_SERVICE, android.location.LocationManager.class);
checkSystemService(Context.SEARCH_SERVICE, android.app.SearchManager.class);
- checkSystemService(Context.SENSOR_SERVICE, android.hardware.SensorManager.class);
+ checkSystemService(Context.SENSOR_SERVICE, android.hardware.TestSensorManager.class);
checkSystemService(Context.STORAGE_SERVICE, android.os.storage.StorageManager.class);
- checkSystemService(Context.VIBRATOR_SERVICE, android.os.Vibrator.class);
- checkSystemService(Context.CONNECTIVITY_SERVICE, android.net.ConnectivityManager.class);
- checkSystemService(Context.WIFI_SERVICE, android.net.wifi.WifiManager.class);
- checkSystemService(Context.AUDIO_SERVICE, android.media.AudioManager.class);
- checkSystemService(Context.TELEPHONY_SERVICE, android.telephony.TelephonyManager.class);
- checkSystemService(Context.INPUT_METHOD_SERVICE, android.view.inputmethod.InputMethodManager.class);
- checkSystemService(Context.UI_MODE_SERVICE, android.app.UiModeManager.class);
- checkSystemService(Context.DOWNLOAD_SERVICE, android.app.DownloadManager.class);
+ checkSystemService(Context.VIBRATOR_SERVICE, android.os.TestVibrator.class);
+// checkSystemService(Context.CONNECTIVITY_SERVICE, android.net.ConnectivityManager.class);
+// checkSystemService(Context.WIFI_SERVICE, android.net.wifi.WifiManager.class);
+// checkSystemService(Context.AUDIO_SERVICE, android.media.AudioManager.class);
+// checkSystemService(Context.TELEPHONY_SERVICE, android.telephony.TelephonyManager.class);
+// checkSystemService(Context.INPUT_METHOD_SERVICE, android.view.inputmethod.InputMethodManager.class);
+// checkSystemService(Context.UI_MODE_SERVICE, android.app.UiModeManager.class);
+// checkSystemService(Context.DOWNLOAD_SERVICE, android.app.DownloadManager.class);
}
private void checkSystemService(String name, Class expectedClass) {
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/WebViewTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/WebViewTest.java
index f31b962..c287d71 100644
--- a/src/test/java/com/xtremelabs/robolectric/shadows/WebViewTest.java
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/WebViewTest.java
@@ -59,10 +59,8 @@
@Test
public void shouldReturnSettings() {
WebSettings webSettings = webView.getSettings();
- ShadowWebSettings shadowWebSettings = Robolectric.shadowOf(webSettings);
assertThat(webSettings, notNullValue());
- assertThat(shadowWebSettings, notNullValue());
}
@Test