Search in sources :

Example 61 with ContentResolver

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();
    }
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) Handler(android.os.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Subscription(rx.Subscription) ContentObserver(android.database.ContentObserver) Test(org.junit.Test)

Example 62 with ContentResolver

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();
}
Also used : StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Example 63 with ContentResolver

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);
        }
    }
}
Also used : Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 64 with ContentResolver

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();
        }
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) IOException(java.io.IOException) ContentResolver(android.content.ContentResolver)

Example 65 with ContentResolver

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;
}
Also used : Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Aggregations

ContentResolver (android.content.ContentResolver)1198 Uri (android.net.Uri)243 Cursor (android.database.Cursor)196 ContentValues (android.content.ContentValues)116 Intent (android.content.Intent)94 RemoteException (android.os.RemoteException)67 IOException (java.io.IOException)62 Context (android.content.Context)58 ArrayList (java.util.ArrayList)50 File (java.io.File)48 Resources (android.content.res.Resources)46 ComponentName (android.content.ComponentName)44 MediumTest (android.test.suitebuilder.annotation.MediumTest)37 PreferenceScreen (android.support.v7.preference.PreferenceScreen)35 Bitmap (android.graphics.Bitmap)33 ContentObserver (android.database.ContentObserver)28 FileNotFoundException (java.io.FileNotFoundException)28 PendingIntent (android.app.PendingIntent)25 MockContentResolver (android.test.mock.MockContentResolver)25 AssetFileDescriptor (android.content.res.AssetFileDescriptor)24