Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java

Issue 2784353002: Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.base; 5 package org.chromium.base;
6 6
7 import android.content.ContentValues; 7 import android.content.ContentValues;
8 import android.content.Context;
9 import android.database.Cursor; 8 import android.database.Cursor;
10 import android.net.Uri; 9 import android.net.Uri;
11 import android.provider.MediaStore; 10 import android.provider.MediaStore;
12 11
13 import org.chromium.base.annotations.CalledByNative; 12 import org.chromium.base.annotations.CalledByNative;
14 13
15 /** 14 /**
16 * Utilities for testing operations on content URI. 15 * Utilities for testing operations on content URI.
17 */ 16 */
18 public class ContentUriTestUtils { 17 public class ContentUriTestUtils {
19 /** 18 /**
20 * Insert an image into the MediaStore, and return the content URI. If the 19 * Insert an image into the MediaStore, and return the content URI. If the
21 * image already exists in the MediaStore, just retrieve the URI. 20 * image already exists in the MediaStore, just retrieve the URI.
22 * 21 *
23 * @param context Application context.
24 * @param path Path to the image file. 22 * @param path Path to the image file.
25 * @return Content URI of the image. 23 * @return Content URI of the image.
26 */ 24 */
27 @CalledByNative 25 @CalledByNative
28 private static String insertImageIntoMediaStore(Context context, String path ) { 26 private static String insertImageIntoMediaStore(String path) {
29 // Check whether the content URI exists. 27 // Check whether the content URI exists.
30 Cursor c = context.getContentResolver().query( 28 Cursor c = ContextUtils.getApplicationContext().getContentResolver().que ry(
31 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 29 MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
32 new String[] { MediaStore.Video.VideoColumns._ID }, 30 new String[] {MediaStore.Video.VideoColumns._ID},
33 MediaStore.Images.Media.DATA + " LIKE ?", 31 MediaStore.Images.Media.DATA + " LIKE ?", new String[] {path}, n ull);
34 new String[] { path },
35 null);
36 if (c != null && c.getCount() > 0) { 32 if (c != null && c.getCount() > 0) {
37 c.moveToFirst(); 33 c.moveToFirst();
38 int id = c.getInt(0); 34 int id = c.getInt(0);
39 return Uri.withAppendedPath( 35 return Uri.withAppendedPath(
40 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id).toStr ing(); 36 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id).toStr ing();
41 } 37 }
42 38
43 // Insert the content URI into MediaStore. 39 // Insert the content URI into MediaStore.
44 ContentValues values = new ContentValues(); 40 ContentValues values = new ContentValues();
45 values.put(MediaStore.MediaColumns.DATA, path); 41 values.put(MediaStore.MediaColumns.DATA, path);
46 Uri uri = context.getContentResolver().insert( 42 Uri uri = ContextUtils.getApplicationContext().getContentResolver().inse rt(
47 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 43 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
48 return uri.toString(); 44 return uri.toString();
49 } 45 }
50 } 46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698