diff options
author | Brett Chabot <brettchabot@google.com> | 2024-04-25 15:08:43 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-04-25 15:09:21 -0700 |
commit | b551e5049d6c88c79fa5e51150aa546dd49d78aa (patch) | |
tree | cfc0ecfdb74db93dac2ea335cc27c2b0c9793e5b | |
parent | c577257599dc30cf283f8961c286d4ef65e799cb (diff) | |
download | robolectric-b551e5049d6c88c79fa5e51150aa546dd49d78aa.tar.gz |
More unsupported SDK code cleanup.
Perform more cleanup related to the move to a minimum supported SDK of lollipop (21)
missed in last commit (c577257599dc30cf283f8961c286d4ef65e799cb):
- Remove methods with a maxSdk of JELLY_BEAN*
- Remove RuntimeEnvironment.castNativePtr and associated Number to long conversions
- Set default manifest minSdkVersion and targetSdkVersion to 21
- Remove if checks for apiLevel that are now redundant
- Remove redundant Config(minSdk = LOLLIPOP) statements
PiperOrigin-RevId: 628203572
60 files changed, 110 insertions, 329 deletions
@@ -5,7 +5,7 @@ Robolectric is the industry-standard unit testing framework for Android. With Robolectric, your tests run in a simulated Android environment inside a JVM, without the overhead and flakiness of an emulator. Robolectric tests routinely run 10x faster than those on cold-started emulators. -Robolectric supports running unit tests for *15* different versions of Android, ranging from KitKat (API level 19) to U (API level 34). +Robolectric supports running unit tests for *14* different versions of Android, ranging from Lollipop (API level 21) to U (API level 34). ## Usage diff --git a/integration_tests/ctesque/src/sharedTest/java/android/util/RationalTest.java b/integration_tests/ctesque/src/sharedTest/java/android/util/RationalTest.java index 69a088b31..46565be13 100644 --- a/integration_tests/ctesque/src/sharedTest/java/android/util/RationalTest.java +++ b/integration_tests/ctesque/src/sharedTest/java/android/util/RationalTest.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import android.os.Build; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -41,11 +40,9 @@ import java.io.Serializable; import java.lang.reflect.Field; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.annotation.Config; import org.robolectric.annotation.internal.DoNotInstrument; @DoNotInstrument -@Config(minSdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(AndroidJUnit4.class) public class RationalTest { diff --git a/resources/src/main/java/org/robolectric/manifest/AndroidManifest.java b/resources/src/main/java/org/robolectric/manifest/AndroidManifest.java index 60f805d72..aab424ed1 100644 --- a/resources/src/main/java/org/robolectric/manifest/AndroidManifest.java +++ b/resources/src/main/java/org/robolectric/manifest/AndroidManifest.java @@ -614,12 +614,12 @@ public class AndroidManifest implements UsesSdk { * <p>Note that if {@link #targetSdkVersion} isn't set, this value changes the behavior of some * Android code (notably {@link android.content.SharedPreferences}) to emulate old bugs. * - * @return the minimum SDK version, or KitKat (19) by default + * @return the minimum SDK version, or Lollipop (21) by default */ @Override public int getMinSdkVersion() { parseAndroidManifest(); - return minSdkVersion == null ? 19 : minSdkVersion; + return minSdkVersion == null ? 21 : minSdkVersion; } /** @@ -629,7 +629,7 @@ public class AndroidManifest implements UsesSdk { * <p>Note that this value changes the behavior of some Android code (notably {@link * android.content.SharedPreferences}) to emulate old bugs. * - * @return the target SDK version, or KitKat (19) by default + * @return the target SDK version, or Lollipop (21) by default */ @Override public int getTargetSdkVersion() { diff --git a/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java b/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java index 9ea315982..9b90d7603 100755 --- a/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java +++ b/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java @@ -16,7 +16,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.PackageParser.Package; import android.content.res.AssetManager; @@ -362,18 +361,8 @@ public class AndroidTestEnvironment implements TestEnvironment { activityThread.getPackageInfo(applicationInfo, null, Context.CONTEXT_INCLUDE_CODE); final _LoadedApk_ _loadedApk_ = reflector(_LoadedApk_.class, loadedApk); - Context contextImpl; - if (apiLevel >= VERSION_CODES.LOLLIPOP) { - contextImpl = reflector(_ContextImpl_.class).createAppContext(activityThread, loadedApk); - } else { - try { - contextImpl = - systemContextImpl.createPackageContext( - applicationInfo.packageName, Context.CONTEXT_INCLUDE_CODE); - } catch (PackageManager.NameNotFoundException e) { - throw new RuntimeException(e); - } - } + Context contextImpl = + reflector(_ContextImpl_.class).createAppContext(activityThread, loadedApk); ShadowPackageManager shadowPackageManager = Shadow.extract(contextImpl.getPackageManager()); shadowPackageManager.addPackageInternal(parsedPackage); activityThreadReflector.setInitialApplication(application); diff --git a/robolectric/src/test/java/org/robolectric/QualifiersTest.java b/robolectric/src/test/java/org/robolectric/QualifiersTest.java index de99cdba4..bf2959d24 100644 --- a/robolectric/src/test/java/org/robolectric/QualifiersTest.java +++ b/robolectric/src/test/java/org/robolectric/QualifiersTest.java @@ -8,7 +8,6 @@ import static org.junit.Assert.fail; import android.app.Activity; import android.content.res.Configuration; import android.content.res.Resources; -import android.os.Build.VERSION_CODES; import android.view.View; import android.widget.TextView; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -97,7 +96,8 @@ public class QualifiersTest { assertThat(resources.getConfiguration().smallestScreenWidthDp).isEqualTo(720); } - @Test @Config(qualifiers = "b+sr+Latn", minSdk = VERSION_CODES.LOLLIPOP) + @Test + @Config(qualifiers = "b+sr+Latn") public void supportsBcp47() throws Exception { assertThat(resources.getString(R.string.hello)).isEqualTo("Zdravo"); } diff --git a/robolectric/src/test/java/org/robolectric/RobolectricTestRunnerMultiApiTest.java b/robolectric/src/test/java/org/robolectric/RobolectricTestRunnerMultiApiTest.java index 4fd1ba199..38ab0da4d 100644 --- a/robolectric/src/test/java/org/robolectric/RobolectricTestRunnerMultiApiTest.java +++ b/robolectric/src/test/java/org/robolectric/RobolectricTestRunnerMultiApiTest.java @@ -189,8 +189,8 @@ public class RobolectricTestRunnerMultiApiTest { assertThat(runListener.ignored).isEmpty(); // Since test method should only be run once - int sdksInclusivelyBetweenJellyBeanMr2AndLollipop = 3; - assertThat(runListener.finished).hasSize(sdksInclusivelyBetweenJellyBeanMr2AndLollipop); + int sdksInclusivelyInRange = 3; + assertThat(runListener.finished).hasSize(sdksInclusivelyInRange); } @Test @@ -225,8 +225,8 @@ public class RobolectricTestRunnerMultiApiTest { runner.run(runNotifier); assertThat(runListener.ignored).isEmpty(); - int sdksInclusivelyBetweenJellyBeanMr2AndLollipop = 3; - assertThat(runListener.finished).hasSize(sdksInclusivelyBetweenJellyBeanMr2AndLollipop); + int sdksInclusivelyInRange = 3; + assertThat(runListener.finished).hasSize(sdksInclusivelyInRange); } /////////////////////////// diff --git a/robolectric/src/test/java/org/robolectric/android/ResourceTableFactoryIntegrationTest.java b/robolectric/src/test/java/org/robolectric/android/ResourceTableFactoryIntegrationTest.java index d4395c5a7..f513b2f93 100644 --- a/robolectric/src/test/java/org/robolectric/android/ResourceTableFactoryIntegrationTest.java +++ b/robolectric/src/test/java/org/robolectric/android/ResourceTableFactoryIntegrationTest.java @@ -4,16 +4,13 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.TruthJUnit.assume; import static org.robolectric.shadows.ShadowAssetManager.useLegacy; -import android.os.Build; import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; import org.robolectric.res.ResName; @RunWith(AndroidJUnit4.class) -@Config(minSdk = Build.VERSION_CODES.LOLLIPOP) public class ResourceTableFactoryIntegrationTest { @Test public void shouldIncludeStyleableAttributesThatDoNotHaveACorrespondingEntryInAttrClass() throws Exception { diff --git a/robolectric/src/test/java/org/robolectric/manifest/AndroidManifestTest.java b/robolectric/src/test/java/org/robolectric/manifest/AndroidManifestTest.java index e64cacd04..9c65dcf33 100644 --- a/robolectric/src/test/java/org/robolectric/manifest/AndroidManifestTest.java +++ b/robolectric/src/test/java/org/robolectric/manifest/AndroidManifestTest.java @@ -231,15 +231,15 @@ public class AndroidManifestTest { assertThat(newConfigWith("minsdk7.xml", "android:minSdkVersion=\"7\"").getTargetSdkVersion()) .isEqualTo(7); assertThat(newConfigWith("noattributes.xml", "").getTargetSdkVersion()) - .isEqualTo(VERSION_CODES.KITKAT); + .isEqualTo(VERSION_CODES.LOLLIPOP); } @Test - public void shouldReadMinSdkVersionFromAndroidManifestOrDefaultToKitKat() throws Exception { + public void shouldReadMinSdkVersionFromAndroidManifestOrDefaultToLollipop() throws Exception { assertThat(newConfigWith("minsdk17.xml", "android:minSdkVersion=\"17\"").getMinSdkVersion()) .isEqualTo(17); assertThat(newConfigWith("noattributes.xml", "").getMinSdkVersion()) - .isEqualTo(VERSION_CODES.KITKAT); + .isEqualTo(VERSION_CODES.LOLLIPOP); } @Test diff --git a/robolectric/src/test/java/org/robolectric/res/StyleResourceLoaderTest.java b/robolectric/src/test/java/org/robolectric/res/StyleResourceLoaderTest.java index dc2026601..dc940d272 100644 --- a/robolectric/src/test/java/org/robolectric/res/StyleResourceLoaderTest.java +++ b/robolectric/src/test/java/org/robolectric/res/StyleResourceLoaderTest.java @@ -1,6 +1,6 @@ package org.robolectric.res; -import static android.os.Build.VERSION_CODES.JELLY_BEAN; +import static android.os.Build.VERSION_CODES.LOLLIPOP; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.TruthJUnit.assume; import static org.robolectric.util.TestUtil.sdkResources; @@ -19,7 +19,7 @@ public class StyleResourceLoaderTest { @Before public void setUp() throws Exception { assume().that(RuntimeEnvironment.useLegacyResources()).isTrue(); - ResourcePath resourcePath = sdkResources(JELLY_BEAN); + ResourcePath resourcePath = sdkResources(LOLLIPOP); resourceTable = new ResourceTableFactory().newResourceTable("android", resourcePath); } diff --git a/robolectric/src/test/java/org/robolectric/shadows/PlaybackInfoBuilderTest.java b/robolectric/src/test/java/org/robolectric/shadows/PlaybackInfoBuilderTest.java index d59dc0b7e..ce2ccae95 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/PlaybackInfoBuilderTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/PlaybackInfoBuilderTest.java @@ -4,15 +4,12 @@ import static com.google.common.truth.Truth.assertThat; import android.media.AudioAttributes; import android.media.session.MediaController.PlaybackInfo; -import android.os.Build.VERSION_CODES; import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.annotation.Config; /** Test for {@link PlaybackInfoBuilder} */ @RunWith(AndroidJUnit4.class) -@Config(minSdk = VERSION_CODES.LOLLIPOP) public class PlaybackInfoBuilderTest { @Test public void build_playbackInfo() { diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowAlarmManagerTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowAlarmManagerTest.java index a2ae9222b..d1da6964c 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowAlarmManagerTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowAlarmManagerTest.java @@ -257,7 +257,6 @@ public class ShadowAlarmManagerTest { verify(onFire).onAlarm(); } - @Config(minSdk = VERSION_CODES.LOLLIPOP) @Test public void setAlarmClock_pendingIntent() { AlarmClockInfo alarmClockInfo = @@ -534,7 +533,6 @@ public class ShadowAlarmManagerTest { } @Test - @Config(minSdk = VERSION_CODES.LOLLIPOP) public void getNextAlarmClockInfo() { AlarmClockInfo alarmClockInfo1 = new AlarmClockInfo( diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowAppOpsManagerTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowAppOpsManagerTest.java index 168e03fa1..74e52f562 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowAppOpsManagerTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowAppOpsManagerTest.java @@ -467,7 +467,6 @@ public class ShadowAppOpsManagerTest { } @Test - @Config(minSdk = VERSION_CODES.LOLLIPOP) public void setRestrictions() { appOps.setRestriction( OP_VIBRATE, AudioAttributes.USAGE_NOTIFICATION, MODE_ERRORED, new String[] {PACKAGE_NAME1}); diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowApplicationTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowApplicationTest.java index 91be98663..359cbad6c 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowApplicationTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowApplicationTest.java @@ -125,27 +125,19 @@ public class ShadowApplicationTest { } @Test - public void shouldProvideServicesIntroducedInJellyBeanMr1() throws Exception { + public void shouldProvideServicesAvailableInAllSdKs() throws Exception { assertThat(context.getSystemService(Context.DISPLAY_SERVICE)) .isInstanceOf(android.hardware.display.DisplayManager.class); assertThat(context.getSystemService(Context.USER_SERVICE)).isInstanceOf(UserManager.class); - } - - @Test - public void shouldProvideServicesIntroducedInKitKat() throws Exception { - assertThat(context.getSystemService(Context.PRINT_SERVICE)).isInstanceOf(PrintManager.class); - assertThat(context.getSystemService(Context.CAPTIONING_SERVICE)) - .isInstanceOf(CaptioningManager.class); - } - - @Test - public void shouldProvideServicesIntroducedInLollipop() throws Exception { assertThat(context.getSystemService(Context.MEDIA_SESSION_SERVICE)) .isInstanceOf(MediaSessionManager.class); assertThat(context.getSystemService(Context.BATTERY_SERVICE)) .isInstanceOf(BatteryManager.class); assertThat(context.getSystemService(Context.RESTRICTIONS_SERVICE)) .isInstanceOf(RestrictionsManager.class); + assertThat(context.getSystemService(Context.PRINT_SERVICE)).isInstanceOf(PrintManager.class); + assertThat(context.getSystemService(Context.CAPTIONING_SERVICE)) + .isInstanceOf(CaptioningManager.class); } @Test diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataInputTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataInputTest.java index 4b0359800..894476d5c 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataInputTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataInputTest.java @@ -6,19 +6,16 @@ import static org.robolectric.util.reflector.Reflector.reflector; import android.app.backup.BackupDataInput; import android.app.backup.BackupDataInputStream; -import android.os.Build.VERSION_CODES; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.annotation.Config; import org.robolectric.util.reflector.Constructor; import org.robolectric.util.reflector.ForType; @RunWith(AndroidJUnit4.class) -@Config(minSdk = VERSION_CODES.LOLLIPOP) public final class ShadowBackupDataInputTest { private static final String TEST_KEY_1 = "key_1"; diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataOutputTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataOutputTest.java index ac222a899..2fe9db27b 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataOutputTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowBackupDataOutputTest.java @@ -6,17 +6,14 @@ import static org.robolectric.Shadows.shadowOf; import static org.robolectric.util.reflector.Reflector.reflector; import android.app.backup.BackupDataOutput; -import android.os.Build.VERSION_CODES; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.IOException; import java.util.Arrays; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.annotation.Config; import org.robolectric.util.reflector.ForType; @RunWith(AndroidJUnit4.class) -@Config(minSdk = VERSION_CODES.LOLLIPOP) public final class ShadowBackupDataOutputTest { private static final String TEST_PREFIX = "prefix"; diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowCallTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowCallTest.java index 0d7c05114..e8e9dfdf4 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowCallTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowCallTest.java @@ -14,7 +14,6 @@ import org.robolectric.util.ReflectionHelpers; /** Test of ShadowCall. */ @RunWith(AndroidJUnit4.class) -@Config(minSdk = VERSION_CODES.LOLLIPOP) public final class ShadowCallTest { Call call; ShadowCall shadowCall; diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowDisplayTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowDisplayTest.java index d13dc511e..099c9105e 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowDisplayTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowDisplayTest.java @@ -90,7 +90,7 @@ public class ShadowDisplayTest { } @Test - public void stateChangeShouldApplyToOtherInstancesOfSameDisplay_postKitKatFields() { + public void stateChangeShouldApplyToOtherInstancesOfSameDisplay() { shadow.setState(Display.STATE_DOZE_SUSPEND); display = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY); diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowPausedMessageQueueTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowPausedMessageQueueTest.java index 9098c6b50..c0a86f05f 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowPausedMessageQueueTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowPausedMessageQueueTest.java @@ -36,7 +36,7 @@ public class ShadowPausedMessageQueueTest { @After public void tearDown() { - if (shadowQueue != null) { + if (queue != null) { shadowQueue.quit(); } } diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowSQLiteConnectionTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowSQLiteConnectionTest.java index 9a46cfde8..9c2eab273 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowSQLiteConnectionTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowSQLiteConnectionTest.java @@ -238,8 +238,7 @@ public class ShadowSQLiteConnectionTest { private SQLiteConnection getSQLiteConnection() { ptr = ShadowLegacySQLiteConnection.nativeOpen( - databasePath.getPath(), 0, "test connection", false, false) - .longValue(); + databasePath.getPath(), 0, "test connection", false, false); connections = ReflectionHelpers.getStaticField(ShadowLegacySQLiteConnection.class, "CONNECTIONS"); return connections.getConnection(ptr); diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowSettingsTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowSettingsTest.java index 09ab05a55..6c037a073 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowSettingsTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowSettingsTest.java @@ -2,7 +2,6 @@ package org.robolectric.shadows; import static android.location.LocationManager.GPS_PROVIDER; import static android.location.LocationManager.NETWORK_PROVIDER; -import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; import static android.os.Build.VERSION_CODES.O; import static android.provider.Settings.Secure.LOCATION_MODE; import static android.provider.Settings.Secure.LOCATION_MODE_BATTERY_SAVING; @@ -236,29 +235,6 @@ public class ShadowSettingsTest { assertThat(Secure.isLocationProviderEnabled(contentResolver, NETWORK_PROVIDER)).isTrue(); } - @Config(maxSdk = JELLY_BEAN_MR2) - @Test - public void setLocationProviderEnabled() { - // Verify default values - assertThat(Secure.isLocationProviderEnabled(contentResolver, GPS_PROVIDER)).isTrue(); - assertThat(Secure.isLocationProviderEnabled(contentResolver, NETWORK_PROVIDER)).isFalse(); - - Secure.setLocationProviderEnabled(contentResolver, NETWORK_PROVIDER, true); - - assertThat(Secure.isLocationProviderEnabled(contentResolver, GPS_PROVIDER)).isTrue(); - assertThat(Secure.isLocationProviderEnabled(contentResolver, NETWORK_PROVIDER)).isTrue(); - - Secure.setLocationProviderEnabled(contentResolver, GPS_PROVIDER, false); - - assertThat(Secure.isLocationProviderEnabled(contentResolver, GPS_PROVIDER)).isFalse(); - assertThat(Secure.isLocationProviderEnabled(contentResolver, NETWORK_PROVIDER)).isTrue(); - - Secure.setLocationProviderEnabled(contentResolver, NETWORK_PROVIDER, false); - - assertThat(Secure.isLocationProviderEnabled(contentResolver, GPS_PROVIDER)).isFalse(); - assertThat(Secure.isLocationProviderEnabled(contentResolver, NETWORK_PROVIDER)).isFalse(); - } - @Test public void testGlobalGetFloat() { float durationScale = diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowWindowManagerGlobalTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowWindowManagerGlobalTest.java index 28185849a..6092630c1 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowWindowManagerGlobalTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowWindowManagerGlobalTest.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -9,7 +8,6 @@ import android.content.ClipData; import android.graphics.Rect; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.os.Looper; import android.view.Display; import android.view.MotionEvent; import android.view.View; @@ -49,13 +47,6 @@ public class ShadowWindowManagerGlobalTest { } @Test - @Config(minSdk = JELLY_BEAN_MR1) - public void getWindowSession_withLooper_shouldReturnSession() { - // method not available in JELLY BEAN, sorry :( - assertThat(ShadowWindowManagerGlobal.getWindowSession(Looper.getMainLooper())).isNotNull(); - } - - @Test public void getLastDragClipData() { MotionEvent downEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 12f, 34f, 0); Robolectric.buildActivity(DragActivity.class) diff --git a/scripts/README.md b/scripts/README.md index 884a36f74..2a9476a31 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -52,16 +52,20 @@ Now use repo to sync the android source, and then build. The currently supported Android versions are: -* `4.1.2_r1` - Jelly Bean API 16 -* `4.2.2_r1.2` - Jelly Bean MR1 API 17 -* `4.3_r2` - Jelly Bean MR2 API 18 -* `4.4_r1` - Kit Kat API 19 * `5.0.2_r3` - Lollipop API 21 * `5.1.1_r9` - Lollipop MR1 API 22 * `6.0.1_r3` - Marshmallow API 23 * `7.0.0_r1` - Nougat API 24 * `7.1.0_r7` - Nougat MR1 API 25 * `8.0.0_r4` - Oreo API 26 +* `8.1.0` - Oreo MR1 API 27 +* `9` - P API 28 +* `10` - Q API 29 +* `11` - R API 30 +* `12` - S API 31 +* `12.1` - S V2 API 32 +* `13` - T API 33 +* `14` - U API 34 Beware it can take upwards of 100 GB of space to sync and build. diff --git a/shadows/framework/src/main/java/org/robolectric/RuntimeEnvironment.java b/shadows/framework/src/main/java/org/robolectric/RuntimeEnvironment.java index a728c859b..c262e889b 100644 --- a/shadows/framework/src/main/java/org/robolectric/RuntimeEnvironment.java +++ b/shadows/framework/src/main/java/org/robolectric/RuntimeEnvironment.java @@ -1,6 +1,5 @@ package org.robolectric; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static org.robolectric.annotation.LooperMode.Mode.LEGACY; import static org.robolectric.shadows.ShadowLooper.assertLooperMode; @@ -250,16 +249,6 @@ public class RuntimeEnvironment { return apiLevel; } - public static Number castNativePtr(long ptr) { - // Weird, using a ternary here doesn't work, there's some auto promotion of boxed types - // happening. - if (getApiLevel() >= LOLLIPOP) { - return ptr; - } else { - return (int) ptr; - } - } - /** * Retrieves the current master scheduler. This scheduler is always used by the main {@link * android.os.Looper Looper}, and if the global scheduler option is set it is also used for the diff --git a/shadows/framework/src/main/java/org/robolectric/android/internal/DisplayConfig.java b/shadows/framework/src/main/java/org/robolectric/android/internal/DisplayConfig.java index 22368c241..bb3c57eaa 100644 --- a/shadows/framework/src/main/java/org/robolectric/android/internal/DisplayConfig.java +++ b/shadows/framework/src/main/java/org/robolectric/android/internal/DisplayConfig.java @@ -1,6 +1,5 @@ package org.robolectric.android.internal; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1; import static android.os.Build.VERSION_CODES.M; import static android.os.Build.VERSION_CODES.N; @@ -232,11 +231,9 @@ public final class DisplayConfig { logicalDensityDpi = other.logicalDensityDpi; physicalXDpi = other.physicalXDpi; physicalYDpi = other.physicalYDpi; - if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) { - appVsyncOffsetNanos = other.appVsyncOffsetNanos; - presentationDeadlineNanos = other.presentationDeadlineNanos; - state = other.state; - } + appVsyncOffsetNanos = other.appVsyncOffsetNanos; + presentationDeadlineNanos = other.presentationDeadlineNanos; + state = other.state; ownerUid = other.ownerUid; ownerPackageName = other.ownerPackageName; if (RuntimeEnvironment.getApiLevel() >= O) { @@ -364,11 +361,9 @@ public final class DisplayConfig { other.logicalDensityDpi = logicalDensityDpi; other.physicalXDpi = physicalXDpi; other.physicalYDpi = physicalYDpi; - if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) { - other.appVsyncOffsetNanos = appVsyncOffsetNanos; - other.presentationDeadlineNanos = presentationDeadlineNanos; - other.state = state; - } + other.appVsyncOffsetNanos = appVsyncOffsetNanos; + other.presentationDeadlineNanos = presentationDeadlineNanos; + other.state = state; other.ownerUid = ownerUid; other.ownerPackageName = ownerPackageName; if (RuntimeEnvironment.getApiLevel() >= O) { diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/LegacyManifestParser.java b/shadows/framework/src/main/java/org/robolectric/shadows/LegacyManifestParser.java index 760c7b7fc..d651a9177 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/LegacyManifestParser.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/LegacyManifestParser.java @@ -15,7 +15,6 @@ import static android.content.pm.ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; import static android.content.pm.ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; import static android.content.pm.ApplicationInfo.FLAG_TEST_ONLY; import static android.content.pm.ApplicationInfo.FLAG_VM_SAFE_MODE; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.PatternMatcher.PATTERN_LITERAL; import static android.os.PatternMatcher.PATTERN_PREFIX; import static android.os.PatternMatcher.PATTERN_SIMPLE_GLOB; @@ -272,12 +271,7 @@ public class LegacyManifestParser { .createIfNotExists(pkg.packageName + "-codePath") .toAbsolutePath() .toString(); - if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) { - pkg.codePath = codePath; - } else { - ReflectionHelpers.setField(Package.class, pkg, "mPath", codePath); - } - + pkg.codePath = codePath; return pkg; } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/MediaCodecInfoBuilder.java b/shadows/framework/src/main/java/org/robolectric/shadows/MediaCodecInfoBuilder.java index 95c079190..9d3afb373 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/MediaCodecInfoBuilder.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/MediaCodecInfoBuilder.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.Q; import static java.util.Arrays.asList; @@ -119,14 +118,12 @@ public class MediaCodecInfoBuilder { ClassParameter.from(String.class, name), // canonicalName ClassParameter.from(int.class, flags), ClassParameter.from(CodecCapabilities[].class, capabilities)); - } else if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) { + } else { return ReflectionHelpers.callConstructor( MediaCodecInfo.class, ClassParameter.from(String.class, name), ClassParameter.from(boolean.class, isEncoder), ClassParameter.from(CodecCapabilities[].class, capabilities)); - } else { - throw new UnsupportedOperationException("Unable to create MediaCodecInfo"); } } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java index 6fcde1f7b..76fc86ee8 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1; import static android.os.Build.VERSION_CODES.N; import static android.os.Build.VERSION_CODES.O; @@ -574,13 +573,8 @@ public class ShadowAccessibilityNodeInfo { newShadow.labeledBy = (labeledBy == null) ? null : obtain(labeledBy); newShadow.view = view; newShadow.actionListener = actionListener; - if (getApiLevel() >= LOLLIPOP) { - newShadow.accessibilityNodeInfoReflector.setActionsList( - new ArrayList<>(realAccessibilityNodeInfo.getActionList())); - } else { - newShadow.accessibilityNodeInfoReflector.setActionsMask( - realAccessibilityNodeInfo.getActions()); - } + newShadow.accessibilityNodeInfoReflector.setActionsList( + new ArrayList<>(realAccessibilityNodeInfo.getActionList())); if (children != null) { newShadow.children = new ArrayList<>(); @@ -602,15 +596,14 @@ public class ShadowAccessibilityNodeInfo { newInfo.setLiveRegion(realAccessibilityNodeInfo.getLiveRegion()); newInfo.setRangeInfo(realAccessibilityNodeInfo.getRangeInfo()); newShadow.realAccessibilityNodeInfo.getExtras().putAll(realAccessibilityNodeInfo.getExtras()); - if (getApiLevel() >= LOLLIPOP) { - newInfo.setMaxTextLength(realAccessibilityNodeInfo.getMaxTextLength()); - newInfo.setError(realAccessibilityNodeInfo.getError()); - } + newInfo.setMaxTextLength(realAccessibilityNodeInfo.getMaxTextLength()); + newInfo.setError(realAccessibilityNodeInfo.getError()); + if (getApiLevel() >= LOLLIPOP_MR1) { newShadow.traversalAfter = (traversalAfter == null) ? null : obtain(traversalAfter); newShadow.traversalBefore = (traversalBefore == null) ? null : obtain(traversalBefore); } - if ((getApiLevel() >= LOLLIPOP) && (accessibilityWindowInfo != null)) { + if (accessibilityWindowInfo != null) { newShadow.accessibilityWindowInfo = ShadowAccessibilityWindowInfo.obtain(accessibilityWindowInfo); } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityWindowInfo.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityWindowInfo.java index c20012ed6..cf51b33ba 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityWindowInfo.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAccessibilityWindowInfo.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.N; import static android.os.Build.VERSION_CODES.O; import static android.os.Build.VERSION_CODES.Q; @@ -25,7 +24,7 @@ import org.robolectric.util.reflector.ForType; * Shadow of {@link android.view.accessibility.AccessibilityWindowInfo} that allows a test to set * properties that are locked in the original class. */ -@Implements(value = AccessibilityWindowInfo.class, minSdk = LOLLIPOP) +@Implements(value = AccessibilityWindowInfo.class) public class ShadowAccessibilityWindowInfo { private static final Map<StrictEqualityWindowWrapper, StackTraceElement[]> obtainedInstances = diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlarmManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlarmManager.java index cec406166..cc666e81e 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlarmManager.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlarmManager.java @@ -4,7 +4,6 @@ import static android.app.AlarmManager.RTC_WAKEUP; import static org.robolectric.util.reflector.Reflector.reflector; import android.annotation.Nullable; -import android.annotation.RequiresApi; import android.app.AlarmManager; import android.app.AlarmManager.AlarmClockInfo; import android.app.AlarmManager.OnAlarmListener; @@ -203,7 +202,6 @@ public class ShadowAlarmManager { false); } - @RequiresApi(VERSION_CODES.LOLLIPOP) @Implementation protected void setAlarmClock(AlarmClockInfo info, PendingIntent operation) { setImpl(RTC_WAKEUP, info.getTriggerTime(), WINDOW_EXACT, 0L, operation, null, info, true); @@ -355,7 +353,6 @@ public class ShadowAlarmManager { return canScheduleExactAlarms; } - @RequiresApi(VERSION_CODES.LOLLIPOP) @Implementation @Nullable protected AlarmClockInfo getNextAlarmClock() { @@ -533,9 +530,7 @@ public class ShadowAlarmManager { WINDOW_HEURISTIC, operation, null, - VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && showIntent != null - ? new AlarmClockInfo(triggerAtMs, showIntent) - : null, + showIntent != null ? new AlarmClockInfo(triggerAtMs, showIntent) : null, allowWhileIdle); } @@ -561,7 +556,7 @@ public class ShadowAlarmManager { this.allowWhileIdle = allowWhileIdle; this.handler = null; - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && alarmClockInfo != null) { + if (alarmClockInfo != null) { this.showIntent = ((AlarmClockInfo) alarmClockInfo).getShowIntent(); } else { this.showIntent = null; @@ -596,7 +591,7 @@ public class ShadowAlarmManager { } else { this.handler = null; } - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && alarmClockInfo != null) { + if (alarmClockInfo != null) { this.showIntent = ((AlarmClockInfo) alarmClockInfo).getShowIntent(); } else { this.showIntent = null; @@ -646,7 +641,6 @@ public class ShadowAlarmManager { return workSource; } - @RequiresApi(VERSION_CODES.LOLLIPOP) @Nullable public AlarmClockInfo getAlarmClockInfo() { return (AlarmClockInfo) alarmClockInfo; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlwaysOnHotwordDetector.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlwaysOnHotwordDetector.java index 3f5b90db0..285ab265b 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlwaysOnHotwordDetector.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAlwaysOnHotwordDetector.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.Q; import static android.os.Build.VERSION_CODES.R; import static android.os.Build.VERSION_CODES.S; @@ -40,7 +39,7 @@ import org.robolectric.util.reflector.Constructor; import org.robolectric.util.reflector.ForType; /** Shadow implementation of {@link android.service.voice.AlwaysOnHotwordDetector}. */ -@Implements(value = AlwaysOnHotwordDetector.class, minSdk = LOLLIPOP, isInAndroidSdk = false) +@Implements(value = AlwaysOnHotwordDetector.class, isInAndroidSdk = false) public class ShadowAlwaysOnHotwordDetector { @RealObject private AlwaysOnHotwordDetector realObject; @@ -165,7 +164,6 @@ public class ShadowAlwaysOnHotwordDetector { /** Shadow for AsyncTask kicked off in the constructor of AlwaysOnHotwordDetector. */ @Implements( className = "android.service.voice.AlwaysOnHotwordDetector$RefreshAvailabiltyTask", - minSdk = LOLLIPOP, maxSdk = TIRAMISU, isInAndroidSdk = false) public static class ShadowRefreshAvailabilityTask<Params, Progress, Result> diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppTask.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppTask.java index 505c75fc3..0efd3b2e8 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppTask.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppTask.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import android.app.ActivityManager.AppTask; import android.app.ActivityManager.RecentTaskInfo; @@ -12,7 +11,7 @@ import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.util.ReflectionHelpers; -@Implements(value = AppTask.class, minSdk = LOLLIPOP) +@Implements(value = AppTask.class) public class ShadowAppTask { private boolean isFinished; private RecentTaskInfo recentTaskInfo; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowApplicationPackageManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowApplicationPackageManager.java index f749507b9..ffe019520 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowApplicationPackageManager.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowApplicationPackageManager.java @@ -21,7 +21,6 @@ import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY; import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS; import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES; import static android.content.pm.PackageManager.SIGNATURE_UNKNOWN_PACKAGE; -import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1; import static android.os.Build.VERSION_CODES.M; import static android.os.Build.VERSION_CODES.N; @@ -1196,21 +1195,6 @@ public class ShadowApplicationPackageManager extends ShadowPackageManager { return null; } - @Implementation(maxSdk = JELLY_BEAN) - protected void getPackageSizeInfo(Object pkgName, Object observer) { - final PackageStats packageStats = packageStatsMap.get((String) pkgName); - new Handler(Looper.getMainLooper()) - .post( - () -> { - try { - ((IPackageStatsObserver) observer) - .onGetStatsCompleted(packageStats, packageStats != null); - } catch (RemoteException remoteException) { - remoteException.rethrowFromSystemServer(); - } - }); - } - @Implementation(maxSdk = M) protected void getPackageSizeInfo(Object pkgName, Object uid, final Object observer) { final PackageStats packageStats = packageStatsMap.get((String) pkgName); diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetInputStream.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetInputStream.java index 9b91a22c1..82292453d 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetInputStream.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetInputStream.java @@ -1,11 +1,9 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static org.robolectric.util.reflector.Reflector.reflector; import android.content.res.AssetManager.AssetInputStream; import java.io.InputStream; -import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Implements; import org.robolectric.annotation.RealObject; import org.robolectric.res.android.Asset; @@ -26,13 +24,7 @@ public class ShadowArscAssetInputStream extends ShadowAssetInputStream { } private Asset getAsset() { - int apiLevel = RuntimeEnvironment.getApiLevel(); - long assetPtr; - if (apiLevel >= LOLLIPOP) { - assetPtr = reflector(_AssetInputStream_.class, realObject).getNativeAsset(); - } else { - assetPtr = reflector(_AssetInputStream_.class, realObject).getAssetInt(); - } + long assetPtr = reflector(_AssetInputStream_.class, realObject).getNativeAsset(); return Registries.NATIVE_ASSET_REGISTRY.getNativeObject(assetPtr); } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetManager.java index 31fa0480f..d482bba1c 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetManager.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowArscAssetManager.java @@ -272,12 +272,6 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { // @HiddenApi - @Implementation(maxSdk = VERSION_CODES.JELLY_BEAN_MR1) - public int addAssetPath(String path) { - return addAssetPathNative(path); - } - - @HiddenApi @Implementation(maxSdk = M) final protected int addAssetPathNative(String path) { return addAssetPathNative(path, false); @@ -315,7 +309,7 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { @HiddenApi @Implementation - protected Number openAsset(String fileName, int mode) throws FileNotFoundException { + protected long openAsset(String fileName, int mode) throws FileNotFoundException { CppAssetManager am = assetManagerForJavaObject(); ALOGV("openAsset in %s", am); @@ -336,9 +330,9 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { throw new FileNotFoundException(fileName8); } - //printf("Created Asset Stream: %p\n", a); + // printf("Created Asset Stream: %p\n", a); - return RuntimeEnvironment.castNativePtr(Registries.NATIVE_ASSET_REGISTRY.register(a)); + return Registries.NATIVE_ASSET_REGISTRY.register(a); } @HiddenApi @Implementation @@ -363,16 +357,16 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { @HiddenApi @Implementation - protected Number openNonAssetNative(int cookie, String fileName, int accessMode) + protected long openNonAssetNative(int cookie, String fileName, int accessMode) throws FileNotFoundException { CppAssetManager am = assetManagerForJavaObject(); if (am == null) { - return RuntimeEnvironment.castNativePtr(0); + return 0; } ALOGV("openNonAssetNative in %s (Java object %s)\n", am, AssetManager.class); String fileName8 = fileName; if (fileName8 == null) { - return RuntimeEnvironment.castNativePtr(-1); + return -1; } AccessMode mode = AccessMode.fromInt(accessMode); if (mode != Asset.AccessMode.ACCESS_UNKNOWN && mode != Asset.AccessMode.ACCESS_RANDOM @@ -388,8 +382,8 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { long assetId = Registries.NATIVE_ASSET_REGISTRY.register(a); // todo: something better than this [xw] a.onClose = () -> destroyAsset(assetId); - //printf("Created Asset Stream: %p\n", a); - return RuntimeEnvironment.castNativePtr(assetId); + // printf("Created Asset Stream: %p\n", a); + return assetId; } @HiddenApi @Implementation @@ -921,15 +915,15 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { } - @HiddenApi @Implementation - protected Number getNativeStringBlock(int block) { + @HiddenApi + @Implementation + protected long getNativeStringBlock(int block) { CppAssetManager am = assetManagerForJavaObject(); if (am == null) { - return RuntimeEnvironment.castNativePtr(0); + return 0; } - return RuntimeEnvironment.castNativePtr( - am.getResources().getTableStringBlock(block).getNativePtr()); + return am.getResources().getTableStringBlock(block).getNativePtr(); } @Implementation @@ -948,13 +942,13 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { @HiddenApi @Implementation - protected Number newTheme() { + protected long newTheme() { CppAssetManager am = assetManagerForJavaObject(); if (am == null) { - return RuntimeEnvironment.castNativePtr(0); + return 0; } ResTableTheme theme = new ResTableTheme(am.getResources()); - return RuntimeEnvironment.castNativePtr(Registries.NATIVE_THEME_REGISTRY.register(theme)); + return Registries.NATIVE_THEME_REGISTRY.register(theme); } @HiddenApi @@ -1005,17 +999,17 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { @HiddenApi @Implementation - protected Number openXmlAssetNative(int cookie, String fileName) throws FileNotFoundException { + protected long openXmlAssetNative(int cookie, String fileName) throws FileNotFoundException { CppAssetManager am = assetManagerForJavaObject(); if (am == null) { - return RuntimeEnvironment.castNativePtr(0); + return 0; } ALOGV("openXmlAsset in %s (Java object %s)\n", am, ShadowArscAssetManager.class); String fileName8 = fileName; if (fileName8 == null) { - return RuntimeEnvironment.castNativePtr(0); + return 0; } int assetCookie = cookie; @@ -1043,8 +1037,7 @@ public class ShadowArscAssetManager extends ShadowAssetManager.ArscBase { throw new FileNotFoundException("Corrupt XML binary file"); } - return RuntimeEnvironment.castNativePtr( - Registries.NATIVE_RES_XML_TREES.register(block)); + return Registries.NATIVE_RES_XML_TREES.register(block); } @HiddenApi diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAudioRecord.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAudioRecord.java index 63fab17ac..36a123bde 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAudioRecord.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAudioRecord.java @@ -1,7 +1,6 @@ package org.robolectric.shadows; import static android.media.AudioRecord.ERROR_BAD_VALUE; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1; import static android.os.Build.VERSION_CODES.M; @@ -23,7 +22,7 @@ import org.robolectric.annotation.Resetter; * <p>It is also possible to provide the underlying data by implementing {@link AudioRecordSource} * and setting this via {@link #setSourceProvider(AudioRecordSourceProvider)}. */ -@Implements(value = AudioRecord.class, minSdk = LOLLIPOP) +@Implements(value = AudioRecord.class) public final class ShadowAudioRecord { @RealObject AudioRecord audioRecord; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataInput.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataInput.java index eb9445101..01a574ee1 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataInput.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataInput.java @@ -4,7 +4,6 @@ import static java.lang.Math.min; import static org.robolectric.util.reflector.Reflector.reflector; import android.app.backup.BackupDataInput; -import android.os.Build.VERSION_CODES; import com.google.common.collect.ImmutableList; import java.io.FileDescriptor; import java.util.ArrayList; @@ -15,7 +14,7 @@ import org.robolectric.util.reflector.Accessor; import org.robolectric.util.reflector.ForType; /** Shadow for BackupDataInput. */ -@Implements(value = BackupDataInput.class, minSdk = VERSION_CODES.LOLLIPOP, looseSignatures = true) +@Implements(value = BackupDataInput.class, looseSignatures = true) public class ShadowBackupDataInput { private List<BackupDataEntity> entities = new ArrayList<>(); diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataOutput.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataOutput.java index b82f7c32c..c2460d213 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataOutput.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBackupDataOutput.java @@ -2,7 +2,6 @@ package org.robolectric.shadows; import android.annotation.Nullable; import android.app.backup.BackupDataOutput; -import android.os.Build.VERSION_CODES; import com.google.common.collect.ImmutableList; import java.io.FileDescriptor; import java.util.ArrayList; @@ -15,7 +14,7 @@ import org.robolectric.util.reflector.Accessor; import org.robolectric.util.reflector.ForType; /** Shadow for BackupDataOutput. */ -@Implements(value = BackupDataOutput.class, minSdk = VERSION_CODES.LOLLIPOP) +@Implements(value = BackupDataOutput.class) public class ShadowBackupDataOutput { protected static final String KEY_PREFIX_JOINER = ":"; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmapRegionDecoder.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmapRegionDecoder.java index 82f6c79b1..acef7316d 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmapRegionDecoder.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmapRegionDecoder.java @@ -1,7 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; -import static org.robolectric.RuntimeEnvironment.getApiLevel; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -74,12 +72,7 @@ public class ShadowBitmapRegionDecoder { } private static BitmapRegionDecoder newInstance() { - if (getApiLevel() >= LOLLIPOP) { - return ReflectionHelpers.callConstructor(BitmapRegionDecoder.class, - new ReflectionHelpers.ClassParameter<>(long.class, 0L)); - } else { - return ReflectionHelpers.callConstructor(BitmapRegionDecoder.class, - new ReflectionHelpers.ClassParameter<>(int.class, 0)); - } + return ReflectionHelpers.callConstructor( + BitmapRegionDecoder.class, new ReflectionHelpers.ClassParameter<>(long.class, 0L)); } } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java index 49d43d475..84bf1ca8c 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java @@ -116,7 +116,7 @@ public class ShadowBluetoothAdapter { setIsBluetoothSupported(true); BluetoothAdapterReflector bluetoothReflector = reflector(BluetoothAdapterReflector.class); int apiLevel = RuntimeEnvironment.getApiLevel(); - if (apiLevel >= VERSION_CODES.LOLLIPOP && apiLevel <= VERSION_CODES.R) { + if (apiLevel <= VERSION_CODES.R) { bluetoothReflector.setSBluetoothLeAdvertiser(null); bluetoothReflector.setSBluetoothLeScanner(null); } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothGatt.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothGatt.java index 3935c8ff7..fc8b17a04 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothGatt.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothGatt.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.O; import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.R; @@ -95,7 +94,7 @@ public class ShadowBluetoothGatt { iBluetoothGattClass, BluetoothDevice.class, Integer.TYPE, Integer.TYPE }, new Object[] {null, device, 0, 0}); - } else if (apiLevel >= LOLLIPOP) { + } else { bluetoothGatt = Shadow.newInstance( BluetoothGatt.class, @@ -103,12 +102,6 @@ public class ShadowBluetoothGatt { Context.class, iBluetoothGattClass, BluetoothDevice.class, Integer.TYPE }, new Object[] {RuntimeEnvironment.getApplication(), null, device, 0}); - } else { - bluetoothGatt = - Shadow.newInstance( - BluetoothGatt.class, - new Class<?>[] {Context.class, iBluetoothGattClass, BluetoothDevice.class}, - new Object[] {RuntimeEnvironment.getApplication(), null, device}); } PerfStatsCollector.getInstance().incrementCount("constructShadowBluetoothGatt"); diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothLeScanner.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothLeScanner.java index a27e1096a..e57379a0d 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothLeScanner.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothLeScanner.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.O; import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.unmodifiableList; @@ -26,7 +25,7 @@ import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; /** Adds Robolectric support for BLE scanning. */ -@Implements(value = BluetoothLeScanner.class, minSdk = LOLLIPOP) +@Implements(value = BluetoothLeScanner.class) public class ShadowBluetoothLeScanner { private List<ScanParams> activeScanParams = new ArrayList<>(); diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCall.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCall.java index e68223e2f..8b0239cc5 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCall.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCall.java @@ -23,7 +23,7 @@ import org.robolectric.util.reflector.Direct; import org.robolectric.util.reflector.ForType; /** Robolectric test for {@link android.telecom.Call}. */ -@Implements(value = Call.class, minSdk = VERSION_CODES.LOLLIPOP) +@Implements(value = Call.class) public class ShadowCall { @RealObject Call realObject; private boolean hasSentRttRequest; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCaptureSessionImpl.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCaptureSessionImpl.java index cadab2291..fce200556 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCaptureSessionImpl.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCaptureSessionImpl.java @@ -16,7 +16,6 @@ import org.robolectric.util.ReflectionHelpers; /** Shadow class for {@link CameraCaptureSessionImpl} */ @Implements( value = CameraCaptureSessionImpl.class, - minSdk = VERSION_CODES.LOLLIPOP, isInAndroidSdk = false) public class ShadowCameraCaptureSessionImpl { @RealObject private CameraCaptureSessionImpl realObject; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCharacteristics.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCharacteristics.java index e023a810f..66012f389 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCharacteristics.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCameraCharacteristics.java @@ -3,7 +3,6 @@ package org.robolectric.shadows; import android.annotation.Nullable; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraCharacteristics.Key; -import android.os.Build.VERSION_CODES; import com.google.common.base.Preconditions; import java.util.HashMap; import java.util.Map; @@ -11,7 +10,7 @@ import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.util.ReflectionHelpers; -@Implements(value = CameraCharacteristics.class, minSdk = VERSION_CODES.LOLLIPOP) +@Implements(value = CameraCharacteristics.class) public class ShadowCameraCharacteristics { private final Map<Key<?>, Object> charactersKeyToValue = new HashMap<>(); diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEnvironment.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEnvironment.java index bd3bbb47b..f11322b69 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEnvironment.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowEnvironment.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; import static android.os.Build.VERSION_CODES.M; import static android.os.Build.VERSION_CODES.Q; import static android.os.Build.VERSION_CODES.R; @@ -136,11 +135,6 @@ public class ShadowEnvironment { return new File[] {path.toFile()}; } - @Implementation(maxSdk = JELLY_BEAN_MR2) - protected static File getExternalStorageAppCacheDirectory(String packageName) { - return buildExternalStorageAppCacheDirs(packageName)[0]; - } - /** * Sets the return value of {@link #getExternalStoragePublicDirectory}. Note that the default * value provides a directory that is usable in the test environment. If the test app uses this diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowInstrumentation.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowInstrumentation.java index d33cf20d9..6ad76286c 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowInstrumentation.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowInstrumentation.java @@ -1061,7 +1061,6 @@ public class ShadowInstrumentation { /** Reflector interface for {@link Instrumentation}'s internals. */ @ForType(Instrumentation.class) public interface _Instrumentation_ { - // > JELLY_BEAN_MR1: void init( ActivityThread thread, Context instrContext, diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyAssetManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyAssetManager.java index 5bf6a6c97..d3557a403 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyAssetManager.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyAssetManager.java @@ -7,7 +7,6 @@ import static android.os.Build.VERSION_CODES.O; import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.TIRAMISU; -import static org.robolectric.RuntimeEnvironment.castNativePtr; import static org.robolectric.shadow.api.Shadow.invokeConstructor; import static org.robolectric.util.ReflectionHelpers.ClassParameter.from; import static org.robolectric.util.reflector.Reflector.reflector; @@ -874,12 +873,13 @@ public class ShadowLegacyAssetManager extends ShadowAssetManager { return type; } - @HiddenApi @Implementation - public Number createTheme() { + @HiddenApi + @Implementation + public long createTheme() { synchronized (nativeThemes) { long nativePtr = nextInternalThemeId++; nativeThemes.put(nativePtr, new NativeTheme(new ThemeStyleSet())); - return castNativePtr(nativePtr); + return nativePtr; } } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyCursorWindow.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyCursorWindow.java index ec31ac526..38c91b832 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyCursorWindow.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacyCursorWindow.java @@ -1,7 +1,6 @@ package org.robolectric.shadows; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.robolectric.RuntimeEnvironment.castNativePtr; import android.database.Cursor; import android.database.CursorWindow; @@ -24,8 +23,8 @@ public class ShadowLegacyCursorWindow extends ShadowCursorWindow { private static final WindowData WINDOW_DATA = new WindowData(); @Implementation - protected static Number nativeCreate(String name, int cursorWindowSize) { - return castNativePtr(WINDOW_DATA.create(name, cursorWindowSize)); + protected static long nativeCreate(String name, int cursorWindowSize) { + return WINDOW_DATA.create(name, cursorWindowSize); } @Implementation diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacySQLiteConnection.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacySQLiteConnection.java index 7a2b439cc..727929e70 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacySQLiteConnection.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLegacySQLiteConnection.java @@ -5,7 +5,6 @@ import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.Q; import static android.os.Build.VERSION_CODES.S_V2; import static android.os.Build.VERSION_CODES.TIRAMISU; -import static org.robolectric.RuntimeEnvironment.castNativePtr; import android.database.sqlite.SQLiteAbortException; import android.database.sqlite.SQLiteAccessPermException; @@ -67,10 +66,10 @@ public class ShadowLegacySQLiteConnection extends ShadowSQLiteConnection { private static final int IGNORED_REINDEX_STMT = -2; @Implementation(maxSdk = O) - protected static Number nativeOpen( + protected static long nativeOpen( String path, int openFlags, String label, boolean enableTrace, boolean enableProfile) { SQLiteLibraryLoader.load(); - return castNativePtr(CONNECTIONS.open(path)); + return CONNECTIONS.open(path); } @Implementation(minSdk = O_MR1) @@ -82,7 +81,7 @@ public class ShadowLegacySQLiteConnection extends ShadowSQLiteConnection { boolean enableProfile, int lookasideSlotSize, int lookasideSlotCount) { - return nativeOpen(path, openFlags, label, enableTrace, enableProfile).longValue(); + return nativeOpen(path, openFlags, label, enableTrace, enableProfile); } @Implementation diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocaleData.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocaleData.java index ee3748664..668ca53d2 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocaleData.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocaleData.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1; import static android.os.Build.VERSION_CODES.M; import static android.os.Build.VERSION_CODES.R; @@ -127,14 +126,7 @@ public class ShadowLocaleData { } localDataReflector.setMonetarySeparator('.'); - - if (getApiLevel() >= LOLLIPOP) { - // Lollipop uses a String - localDataReflector.setMinusSign("-"); - } else { - // Upto KitKat was a char - localDataReflector.setMinusSign('-'); - } + localDataReflector.setMinusSign("-"); localDataReflector.setExponentSeparator("E"); localDataReflector.setInfinity("\u221E"); diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocationManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocationManager.java index 02d6b1776..b27bd96d7 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocationManager.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowLocationManager.java @@ -905,7 +905,7 @@ public class ShadowLocationManager { /** * Returns the list of {@link LocationRequest} currently registered under the given provider. * Clients compiled against the public Android SDK should only use this method on S+, clients - * compiled against the system Android SDK may only use this method on Kitkat+. + * compiled against the system Android SDK can use this method on any supported SDK. * * <p>Prior to Android S {@link LocationRequest} equality is not well defined, so prefer using * {@link #getLegacyLocationRequests(String)} instead if equality is required for testing. @@ -1785,8 +1785,8 @@ public class ShadowLocationManager { } /** - * LocationRequest doesn't exist prior to Kitkat, and is not public prior to S, so a new class is - * required to represent it prior to those platforms. + * LocationRequest is not public prior to S, so a new class is required to represent it prior to + * those platforms. */ public static final class RoboLocationRequest { @Nullable private final Object locationRequest; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowNativePluralRules.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowNativePluralRules.java index 454843ee5..6e50ec5b1 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowNativePluralRules.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowNativePluralRules.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; import static android.os.Build.VERSION_CODES.M; import org.robolectric.annotation.Implementation; @@ -15,10 +14,4 @@ public class ShadowNativePluralRules { if (quantity == 1) return 1; else return 5 /* other */; } - - @Implementation(maxSdk = JELLY_BEAN_MR2) - protected static int quantityForIntImpl(int address, int quantity) { - return quantityForIntImpl((long)address, quantity); - - } } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowParcel.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowParcel.java index 79ef89737..817761991 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowParcel.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowParcel.java @@ -9,7 +9,6 @@ import static android.os.Build.VERSION_CODES.Q; import static android.os.Build.VERSION_CODES.R; import static android.os.Build.VERSION_CODES.S; import static android.os.Build.VERSION_CODES.TIRAMISU; -import static org.robolectric.RuntimeEnvironment.castNativePtr; import android.os.BadParcelableException; import android.os.IBinder; @@ -422,8 +421,8 @@ public class ShadowParcel { @Implementation @HiddenApi - public static Number nativeCreate() { - return castNativePtr(NATIVE_BYTE_BUFFER_REGISTRY.register(new ByteBuffer())); + public static long nativeCreate() { + return NATIVE_BYTE_BUFFER_REGISTRY.register(new ByteBuffer()); } @Implementation diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowPausedMessageQueue.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowPausedMessageQueue.java index 3dd0587c3..230313531 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowPausedMessageQueue.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowPausedMessageQueue.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1; import static android.os.Build.VERSION_CODES.M; import static com.google.common.base.Preconditions.checkState; @@ -221,9 +220,8 @@ public class ShadowPausedMessageQueue extends ShadowMessageQueue { } } - @Implementation(maxSdk = JELLY_BEAN_MR1) - protected void quit() { - reflector(MessageQueueReflector.class, realQueue).quit(false); + void quit() { + quit(true); } @Implementation diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowRegion.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowRegion.java index 753e32264..8f9a7eee9 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowRegion.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowRegion.java @@ -3,7 +3,6 @@ package org.robolectric.shadows; import static org.robolectric.util.reflector.Reflector.reflector; import android.graphics.Region; -import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.HiddenApi; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; @@ -36,8 +35,8 @@ public class ShadowRegion { @HiddenApi @Implementation - protected static Number nativeConstructor() { - return RuntimeEnvironment.castNativePtr(nextId++); + protected static long nativeConstructor() { + return nextId++; } @ForType(Region.class) diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowSettings.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowSettings.java index d4ebacb98..e5a7f5676 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowSettings.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowSettings.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static android.os.Build.VERSION_CODES.M; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.Q; @@ -164,12 +163,6 @@ public class ShadowSettings { return updateEnabledProviders(cr, provider, enabled); } - @Implementation(maxSdk = JELLY_BEAN) - protected static void setLocationProviderEnabled( - ContentResolver cr, String provider, boolean enabled) { - updateEnabledProviders(cr, provider, enabled); - } - // only for use locally and by ShadowLocationManager, which requires a tight integration with // ShadowSettings due to historical weirdness between LocationManager and Settings. static boolean updateEnabledProviders(ContentResolver cr, String provider, boolean enabled) { diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java index 41299cb5c..fe582460b 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java @@ -10,12 +10,10 @@ import android.content.res.Configuration; import android.graphics.Rect; import android.os.Build; import android.os.Build.VERSION_CODES; -import android.os.Looper; import android.os.RemoteException; import android.util.MergedConfiguration; import android.view.Display; import android.view.HandlerActionQueue; -import android.view.IWindowSession; import android.view.InsetsState; import android.view.Surface; import android.view.SurfaceControl; @@ -94,13 +92,6 @@ public class ShadowViewRootImpl { ShadowViewRootImpl.isNavigationBarVisible = Optional.empty(); } - @Implementation(maxSdk = VERSION_CODES.JELLY_BEAN) - protected static IWindowSession getWindowSession(Looper mainLooper) { - IWindowSession windowSession = ShadowWindowManagerGlobal.getWindowSession(); - ReflectionHelpers.setStaticField(ViewRootImpl.class, "sWindowSession", windowSession); - return windowSession; - } - @Implementation public void playSoundEffect(int effectId) {} diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerGlobal.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerGlobal.java index 456609dea..b749a962a 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerGlobal.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerGlobal.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE; import static com.google.common.base.Preconditions.checkArgument; @@ -18,7 +17,6 @@ import android.content.Context; import android.graphics.Rect; import android.os.Binder; import android.os.IBinder; -import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; @@ -322,11 +320,6 @@ public class ShadowWindowManagerGlobal { return windowSession; } - @Implementation(maxSdk = JELLY_BEAN_MR1) - protected static Object getWindowSession(Looper looper) { - return getWindowSession(); - } - @Implementation protected static synchronized IWindowSession peekWindowSession() { return windowSession; diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerImpl.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerImpl.java index 9fd17e952..bf54a5c14 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerImpl.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowWindowManagerImpl.java @@ -1,6 +1,5 @@ package org.robolectric.shadows; -import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static android.os.Build.VERSION_CODES.R; import static android.os.Build.VERSION_CODES.S_V2; import static android.view.View.SYSTEM_UI_FLAG_VISIBLE; @@ -66,11 +65,6 @@ public class ShadowWindowManagerImpl extends ShadowWindowManager { return ImmutableList.copyOf(views.get(realObject.getDefaultDisplay().getDisplayId())); } - @Implementation(maxSdk = JELLY_BEAN) - public Display getDefaultDisplay() { - return reflector(ReflectorWindowManagerImpl.class, realObject).getDefaultDisplay(); - } - /** Re implement to avoid server call */ @Implementation(minSdk = R, maxSdk = S_V2) protected WindowInsets getWindowInsetsFromServer(WindowManager.LayoutParams attrs, Rect bounds) { diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowXmlBlock.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowXmlBlock.java index ac02b5779..578549a5c 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowXmlBlock.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowXmlBlock.java @@ -3,7 +3,6 @@ package org.robolectric.shadows; import static org.robolectric.res.android.Errors.NO_ERROR; import android.os.Build.VERSION_CODES; -import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.res.android.Ref; @@ -17,7 +16,7 @@ import org.xmlpull.v1.XmlPullParserException; public class ShadowXmlBlock { @Implementation - protected static Number nativeCreate(byte[] bArray, int off, int len) { + protected static long nativeCreate(byte[] bArray, int off, int len) { if (bArray == null) { throw new NullPointerException(); } @@ -39,18 +38,18 @@ public class ShadowXmlBlock { throw new IllegalArgumentException(); } - return RuntimeEnvironment.castNativePtr(Registries.NATIVE_RES_XML_TREES.register(osb)); + return Registries.NATIVE_RES_XML_TREES.register(osb); } @Implementation - protected static Number nativeGetStringBlock(long obj) { + protected static long nativeGetStringBlock(long obj) { ResXMLTree osb = Registries.NATIVE_RES_XML_TREES.getNativeObject(obj); -// if (osb == NULL) { -// jniThrowNullPointerException(env, NULL); -// return 0; -// } + // if (osb == NULL) { + // jniThrowNullPointerException(env, NULL); + // return 0; + // } - return RuntimeEnvironment.castNativePtr(osb.getStrings().getNativePtr()); + return osb.getStrings().getNativePtr(); } @Implementation(maxSdk = VERSION_CODES.P) |