private static ContentResolver getContentResolver() { return RuntimeEnvironment.application.getContentResolver(); }
/** * Sets the value of the {@link Settings.System#TIME_12_24} setting. * * @param use24HourTimeFormat new status for the time setting */ public static void set24HourTimeFormat(boolean use24HourTimeFormat) { Settings.System.putString(RuntimeEnvironment.application.getContentResolver(), Settings.System.TIME_12_24, use24HourTimeFormat ? "24" : "12"); }
/** * Non-Android accessor that allows the value of the WIFI_ON setting to be set. * * @param isOn new status for wifi mode */ public static void setWifiOn(boolean isOn) { Settings.Global.putInt( RuntimeEnvironment.application.getContentResolver(), Settings.Global.WIFI_ON, isOn ? 1 : 0); Settings.System.putInt( RuntimeEnvironment.application.getContentResolver(), Settings.System.WIFI_ON, isOn ? 1 : 0); }
@Before public void setUp() throws Exception { context = ApplicationProvider.getApplicationContext(); contentResolver = context.getContentResolver(); }
@Test public void decodeStream_shouldSetDescriptionAndCreatedFrom() throws Exception { InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse("content:/path")); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); ShadowBitmap shadowBitmap = shadowOf(bitmap); assertEquals("Bitmap for content:/path", shadowBitmap.getDescription()); assertEquals(inputStream, shadowBitmap.getCreatedFromStream()); assertEquals(100, bitmap.getWidth()); assertEquals(100, bitmap.getHeight()); bitmap.getPixels(new int[bitmap.getHeight() * bitmap.getWidth()], 0, 0, 0, 0, bitmap.getWidth(), bitmap.getHeight()); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void testSetAdbEnabled_sinceJBMR1_settingsGlobal_false() { ShadowSettings.setAdbEnabled(false); assertThat(Global.getInt(context.getContentResolver(), Global.ADB_ENABLED, 1)).isEqualTo(0); }
@Test public void decodeStream_shouldGetWidthAndHeightFromHints() throws Exception { ShadowBitmapFactory.provideWidthAndHeightHints(Uri.parse("content:/path"), 123, 456); InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse("content:/path")); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); assertEquals("Bitmap for content:/path", shadowOf(bitmap).getDescription()); assertEquals(123, bitmap.getWidth()); assertEquals(456, bitmap.getHeight()); }
@Test public void decodeStream_shouldSetDescriptionWithNullOptions() throws Exception { InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse("content:/path")); Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, null); assertEquals("Bitmap for content:/path", shadowOf(bitmap).getDescription()); assertEquals(100, bitmap.getWidth()); assertEquals(100, bitmap.getHeight()); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void testSetAdbEnabled_sinceJBMR1_settingsGlobal_true() { ShadowSettings.setAdbEnabled(true); assertThat(Global.getInt(context.getContentResolver(), Global.ADB_ENABLED, 0)).isEqualTo(1); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void testSetInstallNonMarketApps_sinceJBMR1_settingsGlobal_true() { ShadowSettings.setInstallNonMarketApps(true); assertThat(Global.getInt(context.getContentResolver(), Global.INSTALL_NON_MARKET_APPS, 0)) .isEqualTo(1); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void testSetInstallNonMarketApps_sinceJBMR1_settingsGlobal_false() { ShadowSettings.setInstallNonMarketApps(false); assertThat(Global.getInt(context.getContentResolver(), Global.INSTALL_NON_MARKET_APPS, 1)) .isEqualTo(0); } }
@Test public void decodeResourceStream_canTakeOptions() throws Exception { BitmapFactory.Options options = new BitmapFactory.Options(); InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse("content:/path")); options.inSampleSize = 100; Bitmap bitmap = BitmapFactory.decodeResourceStream( context.getResources(), null, inputStream, null, options); assertEquals(true, shadowOf(bitmap).getDescription().contains("inSampleSize=100")); }
@Test public void testSetAdbEnabled_settingsSecure_true() { ShadowSettings.setAdbEnabled(true); assertThat(Secure.getInt(context.getContentResolver(), Secure.ADB_ENABLED, 0)).isEqualTo(1); }
@Test public void testSetInstallNonMarketApps_settingsSecure_true() { ShadowSettings.setInstallNonMarketApps(true); assertThat(Secure.getInt(context.getContentResolver(), Secure.INSTALL_NON_MARKET_APPS, 0)) .isEqualTo(1); }
@Test public void testSetInstallNonMarketApps_settingsSecure_false() { ShadowSettings.setInstallNonMarketApps(false); assertThat(Secure.getInt(context.getContentResolver(), Secure.INSTALL_NON_MARKET_APPS, 1)) .isEqualTo(0); }
@Test public void testSetAdbEnabled_settingsSecure_false() { ShadowSettings.setAdbEnabled(false); assertThat(Secure.getInt(context.getContentResolver(), Secure.ADB_ENABLED, 1)).isEqualTo(0); }
@Test public void testReturnsOpenedInputStreamWhenFileFound() throws FileNotFoundException { InputStream expected = new ByteArrayInputStream(new byte[0]); Shadows.shadowOf(RuntimeEnvironment.application.getContentResolver()) .registerInputStream(harness.uri, expected); assertEquals(expected, harness.get().open(harness.uri)); }
@Test public void decodeUri_shouldGetWidthAndHeightFromHints() throws Exception { ShadowBitmapFactory.provideWidthAndHeightHints(Uri.parse("content:/path"), 123, 456); Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), Uri.parse("content:/path")); assertEquals("Bitmap for content:/path", shadowOf(bitmap).getDescription()); assertEquals(123, bitmap.getWidth()); assertEquals(456, bitmap.getHeight()); }
@Test public void testVideoQueryReturnsVideoCursor() { Uri queryUri = MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI; ThumbFetcher.VideoThumbnailQuery query = new ThumbFetcher.VideoThumbnailQuery(getContentResolver()); RoboCursor testCursor = new RoboCursor(); Shadows.shadowOf(RuntimeEnvironment.application.getContentResolver()) .setCursor(queryUri, testCursor); assertEquals(testCursor, query.query(harness.uri)); }
@Test public void testImageQueryReturnsImageCursor() { Uri queryUri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI; ThumbFetcher.ImageThumbnailQuery query = new ThumbFetcher.ImageThumbnailQuery(getContentResolver()); RoboCursor testCursor = new RoboCursor(); Shadows.shadowOf(RuntimeEnvironment.application.getContentResolver()) .setCursor(queryUri, testCursor); assertEquals(testCursor, query.query(harness.uri)); }