use of android.content.ContentResolver in project storio by pushtorefresh.
the class RxChangesObserverTest method contentObserverShouldReturnFalseOnDeliverSelfNotificationsOnAllSdkVersions.
@Test
public void contentObserverShouldReturnFalseOnDeliverSelfNotificationsOnAllSdkVersions() {
for (int sdkVersion = MIN_SDK_VERSION; sdkVersion < MAX_SDK_VERSION; sdkVersion++) {
ContentResolver contentResolver = mock(ContentResolver.class);
Uri uri = mock(Uri.class);
final AtomicReference<ContentObserver> contentObserver = new AtomicReference<ContentObserver>();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
contentObserver.set((ContentObserver) invocation.getArguments()[2]);
return null;
}
}).when(contentResolver).registerContentObserver(same(uri), eq(true), any(ContentObserver.class));
Handler handler = mock(Handler.class);
Observable<Changes> observable = RxChangesObserver.observeChanges(contentResolver, singleton(uri), handler, sdkVersion);
Subscription subscription = observable.subscribe();
assertThat(contentObserver.get().deliverSelfNotifications()).isFalse();
subscription.unsubscribe();
}
}
use of android.content.ContentResolver in project storio by pushtorefresh.
the class DefaultStorIOContentResolverTest method defaultSchedulerReturnsNullIfSpecifiedSchedulerNull.
@Test
public void defaultSchedulerReturnsNullIfSpecifiedSchedulerNull() {
StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(mock(ContentResolver.class)).defaultScheduler(null).build();
assertThat(storIOContentResolver.defaultScheduler()).isNull();
}
use of android.content.ContentResolver in project platform_frameworks_base by android.
the class MediaPlayer method setDataSource.
/**
* Sets the data source as a content Uri.
*
* @param context the Context to use when resolving the Uri
* @param uri the Content URI of the data you want to play
* @param headers the headers to be sent together with the request for the data
* Note that the cross domain redirection is allowed by default, but that can be
* changed with key/value pairs through the headers parameter with
* "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value
* to disallow or allow cross domain redirection.
* @throws IllegalStateException if it is called in an invalid state
*/
public void setDataSource(@NonNull Context context, @NonNull Uri uri, @Nullable Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
final ContentResolver resolver = context.getContentResolver();
final String scheme = uri.getScheme();
if (ContentResolver.SCHEME_FILE.equals(scheme)) {
setDataSource(uri.getPath());
return;
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme) && Settings.AUTHORITY.equals(uri.getAuthority())) {
// Try cached ringtone first since the actual provider may not be
// encryption aware, or it may be stored on CE media storage
final int type = RingtoneManager.getDefaultType(uri);
final Uri cacheUri = RingtoneManager.getCacheForType(type);
final Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context, type);
if (attemptDataSource(resolver, cacheUri)) {
return;
} else if (attemptDataSource(resolver, actualUri)) {
return;
} else {
setDataSource(uri.toString(), headers);
}
} else {
// Try requested Uri locally first, or fallback to media server
if (attemptDataSource(resolver, uri)) {
return;
} else {
setDataSource(uri.toString(), headers);
}
}
}
use of android.content.ContentResolver in project platform_frameworks_base by android.
the class MediaPlayer method addTimedTextSource.
/**
* Adds an external timed text source file (Uri).
*
* Currently supported format is SubRip with the file extension .srt, case insensitive.
* Note that a single external timed text source may contain multiple tracks in it.
* One can find the total number of available tracks using {@link #getTrackInfo()} to see what
* additional tracks become available after this method call.
*
* @param context the Context to use when resolving the Uri
* @param uri the Content URI of the data you want to play
* @param mimeType The mime type of the file. Must be one of the mime types listed above.
* @throws IOException if the file cannot be accessed or is corrupted.
* @throws IllegalArgumentException if the mimeType is not supported.
* @throws IllegalStateException if called in an invalid state.
*/
public void addTimedTextSource(Context context, Uri uri, String mimeType) throws IOException, IllegalArgumentException, IllegalStateException {
String scheme = uri.getScheme();
if (scheme == null || scheme.equals("file")) {
addTimedTextSource(uri.getPath(), mimeType);
return;
}
AssetFileDescriptor fd = null;
try {
ContentResolver resolver = context.getContentResolver();
fd = resolver.openAssetFileDescriptor(uri, "r");
if (fd == null) {
return;
}
addTimedTextSource(fd.getFileDescriptor(), mimeType);
return;
} catch (SecurityException ex) {
} catch (IOException ex) {
} finally {
if (fd != null) {
fd.close();
}
}
}
use of android.content.ContentResolver in project platform_frameworks_base by android.
the class Ringtone method getTitle.
/**
* @hide
*/
public static String getTitle(Context context, Uri uri, boolean followSettingsUri, boolean allowRemote) {
ContentResolver res = context.getContentResolver();
String title = null;
if (uri != null) {
String authority = uri.getAuthority();
if (Settings.AUTHORITY.equals(authority)) {
if (followSettingsUri) {
Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.getDefaultType(uri));
String actualTitle = getTitle(context, actualUri, false, /*followSettingsUri*/
allowRemote);
title = context.getString(com.android.internal.R.string.ringtone_default_with_actual, actualTitle);
}
} else {
Cursor cursor = null;
try {
if (MediaStore.AUTHORITY.equals(authority)) {
final String mediaSelection = allowRemote ? null : MEDIA_SELECTION;
cursor = res.query(uri, MEDIA_COLUMNS, mediaSelection, null, null);
if (cursor != null && cursor.getCount() == 1) {
cursor.moveToFirst();
return cursor.getString(2);
}
// missing cursor is handled below
}
} catch (SecurityException e) {
IRingtonePlayer mRemotePlayer = null;
if (allowRemote) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mRemotePlayer = audioManager.getRingtonePlayer();
}
if (mRemotePlayer != null) {
try {
title = mRemotePlayer.getTitle(uri);
} catch (RemoteException re) {
}
}
} finally {
if (cursor != null) {
cursor.close();
}
cursor = null;
}
if (title == null) {
title = uri.getLastPathSegment();
}
}
}
if (title == null) {
title = context.getString(com.android.internal.R.string.ringtone_unknown);
if (title == null) {
title = "";
}
}
return title;
}
Aggregations