Search in sources :

Example 81 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class SettingsProviderTest method testParseProviderList.

@MediumTest
public void testParseProviderList() {
    ContentResolver r = getContext().getContentResolver();
    // We only accept "+value" and "-value"
    // Test adding a value
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test1");
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test1"));
    // Test adding a second value
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test2");
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test1"));
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test2"));
    // Test adding a third value
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test3");
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test1"));
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test2"));
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test3"));
    // Test deleting the first value in a 3 item list
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test1");
    assertFalse(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test1"));
    // Test deleting the middle value in a 3 item list
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test4");
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test2"));
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test3"));
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test4"));
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test3");
    assertFalse(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test3"));
    // Test deleting the last value in a 3 item list
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test5");
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test2"));
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test4"));
    assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test5"));
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test5");
    assertFalse(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("test5"));
}
Also used : ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 82 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class SettingsProviderTest method testNameValueCache.

@MediumTest
public void testNameValueCache() {
    ContentResolver r = getContext().getContentResolver();
    Settings.Secure.putString(r, "test_service", "Value");
    assertEquals("Value", Settings.Secure.getString(r, "test_service"));
    // Make sure the value can be overwritten.
    Settings.Secure.putString(r, "test_service", "New");
    assertEquals("New", Settings.Secure.getString(r, "test_service"));
    // Also that delete works.
    assertEquals(1, r.delete(Settings.Secure.getUriFor("test_service"), null, null));
    assertEquals(null, Settings.Secure.getString(r, "test_service"));
    // Apps should not be able to use System settings.
    try {
        Settings.System.putString(r, "test_setting", "Value");
        fail("IllegalArgumentException expected");
    } catch (java.lang.IllegalArgumentException e) {
    // expected
    }
}
Also used : ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 83 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class SettingsProviderTest method testRowNumberContentUri.

@MediumTest
// Settings.Bookmarks uses a query format that's not supported now.
@Suppress
public void testRowNumberContentUri() {
    ContentResolver r = getContext().getContentResolver();
    // The bookmarks table (and everything else) uses standard row number content URIs.
    Uri uri = Settings.Bookmarks.add(r, new Intent("TEST"), "Test Title", "Test Folder", '*', 123);
    assertTrue(ContentUris.parseId(uri) > 0);
    assertEquals("TEST", Settings.Bookmarks.getIntentForShortcut(r, '*').getAction());
    ContentValues v = new ContentValues();
    v.put(Settings.Bookmarks.INTENT, "#Intent;action=TOAST;end");
    assertEquals(1, r.update(uri, v, null, null));
    assertEquals("TOAST", Settings.Bookmarks.getIntentForShortcut(r, '*').getAction());
    assertEquals(1, r.delete(uri, null, null));
    assertEquals(null, Settings.Bookmarks.getIntentForShortcut(r, '*'));
}
Also used : ContentValues(android.content.ContentValues) Intent(android.content.Intent) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 84 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class SettingsProviderTest method testSettingsChangeForOtherUser.

@MediumTest
public void testSettingsChangeForOtherUser() {
    UserManager um = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
    ContentResolver r = getContext().getContentResolver();
    // Make sure there's an owner
    assertTrue(findUser(um, UserHandle.USER_SYSTEM));
    // create a new user to use for testing
    UserInfo otherUser = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
    assertTrue(otherUser != null);
    try {
        assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
        final String testKey = "testSettingsChangeForOtherUser";
        final String testValue1 = "value1";
        final String testValue2 = "value2";
        Settings.Secure.putString(r, testKey, testValue1);
        Settings.Secure.putStringForUser(r, testKey, testValue2, otherUser.id);
        assertEquals(testValue1, Settings.Secure.getString(r, testKey));
        assertEquals(testValue2, Settings.Secure.getStringForUser(r, testKey, otherUser.id));
        assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
    } finally {
        // Tidy up
        um.removeUser(otherUser.id);
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 85 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class SmsProviderTest method testProvider.

@LargeTest
public void testProvider() throws Exception {
    // This test does the following
    //  1. Insert 10 messages from the same number at different times.
    //
    //  . Delete the messages and make sure that they were deleted.
    long now = System.currentTimeMillis();
    Uri[] urls = new Uri[10];
    String[] dates = new String[] { Long.toString(new GregorianCalendar(1970, 1, 1, 0, 0, 0).getTimeInMillis()), Long.toString(new GregorianCalendar(1971, 2, 13, 16, 35, 3).getTimeInMillis()), Long.toString(new GregorianCalendar(1978, 10, 22, 0, 1, 0).getTimeInMillis()), Long.toString(new GregorianCalendar(1980, 1, 11, 10, 22, 30).getTimeInMillis()), Long.toString(now - (5 * 24 * 60 * 60 * 1000)), Long.toString(now - (2 * 24 * 60 * 60 * 1000)), Long.toString(now - (5 * 60 * 60 * 1000)), Long.toString(now - (30 * 60 * 1000)), Long.toString(now - (5 * 60 * 1000)), Long.toString(now) };
    ContentValues map = new ContentValues();
    map.put("address", "+15045551337");
    map.put("read", 0);
    ContentResolver contentResolver = mContext.getContentResolver();
    for (int i = 0; i < urls.length; i++) {
        map.put("body", "Test " + i + " !");
        map.put("date", dates[i]);
        urls[i] = contentResolver.insert(Sms.Inbox.CONTENT_URI, map);
        assertNotNull(urls[i]);
    }
    Cursor c = contentResolver.query(Sms.Inbox.CONTENT_URI, null, null, null, "date");
    for (Uri url : urls) {
        int count = contentResolver.delete(url, null, null);
        assertEquals(1, count);
    }
}
Also used : ContentValues(android.content.ContentValues) GregorianCalendar(java.util.GregorianCalendar) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) LargeTest(android.test.suitebuilder.annotation.LargeTest)

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