Search in sources :

Example 6 with ContentResolver

use of android.content.ContentResolver in project android_frameworks_base by ParanoidAndroid.

the class NtpTrustedTime method getInstance.

public static synchronized NtpTrustedTime getInstance(Context context) {
    if (sSingleton == null) {
        final Resources res = context.getResources();
        final ContentResolver resolver = context.getContentResolver();
        final String defaultServer = res.getString(com.android.internal.R.string.config_ntpServer);
        final long defaultTimeout = res.getInteger(com.android.internal.R.integer.config_ntpTimeout);
        final String secureServer = Settings.Global.getString(resolver, Settings.Global.NTP_SERVER);
        final long timeout = Settings.Global.getLong(resolver, Settings.Global.NTP_TIMEOUT, defaultTimeout);
        final String server = secureServer != null ? secureServer : defaultServer;
        sSingleton = new NtpTrustedTime(server, timeout);
    }
    return sSingleton;
}
Also used : Resources(android.content.res.Resources) ContentResolver(android.content.ContentResolver)

Example 7 with ContentResolver

use of android.content.ContentResolver in project android_frameworks_base by ParanoidAndroid.

the class TextClock method registerObserver.

private void registerObserver() {
    final ContentResolver resolver = getContext().getContentResolver();
    resolver.registerContentObserver(Settings.System.CONTENT_URI, true, mFormatChangeObserver);
}
Also used : ContentResolver(android.content.ContentResolver)

Example 8 with ContentResolver

use of android.content.ContentResolver in project android_frameworks_base by ParanoidAndroid.

the class SettingsProviderTest method testParseProviderList.

@MediumTest
public void testParseProviderList() {
    ContentResolver r = getContext().getContentResolver();
    // Make sure we get out what we put in.
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "test1,test2,test3");
    assertEquals(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED), "test1,test2,test3");
    // Test adding a value
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "");
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test1");
    assertEquals("test1", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
    // Test adding a second value
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test2");
    assertEquals("test1,test2", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
    // Test adding a third value
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test3");
    assertEquals("test1,test2,test3", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
    // Test deleting the first value in a 3 item list
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test1");
    assertEquals("test2,test3", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
    // Test deleting the middle value in a 3 item list
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "test1,test2,test3");
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test2");
    assertEquals("test1,test3", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
    // Test deleting the last value in a 3 item list
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "test1,test2,test3");
    Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test3");
    assertEquals("test1,test2", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
}
Also used : ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 9 with ContentResolver

use of android.content.ContentResolver in project android_frameworks_base by ParanoidAndroid.

the class AudioService method readPersistedSettings.

private void readPersistedSettings() {
    final ContentResolver cr = mContentResolver;
    int ringerModeFromSettings = Settings.Global.getInt(cr, Settings.Global.MODE_RINGER, AudioManager.RINGER_MODE_NORMAL);
    int ringerMode = ringerModeFromSettings;
    // ringer modes
    if (!AudioManager.isValidRingerMode(ringerMode)) {
        ringerMode = AudioManager.RINGER_MODE_NORMAL;
    }
    if ((ringerMode == AudioManager.RINGER_MODE_VIBRATE) && !mHasVibrator) {
        ringerMode = AudioManager.RINGER_MODE_SILENT;
    }
    if (ringerMode != ringerModeFromSettings) {
        Settings.Global.putInt(cr, Settings.Global.MODE_RINGER, ringerMode);
    }
    if (mUseFixedVolume) {
        ringerMode = AudioManager.RINGER_MODE_NORMAL;
    }
    synchronized (mSettingsLock) {
        mRingerMode = ringerMode;
        // System.VIBRATE_ON is not used any more but defaults for mVibrateSetting
        // are still needed while setVibrateSetting() and getVibrateSetting() are being
        // deprecated.
        mVibrateSetting = getValueForVibrateSetting(0, AudioManager.VIBRATE_TYPE_NOTIFICATION, mHasVibrator ? AudioManager.VIBRATE_SETTING_ONLY_SILENT : AudioManager.VIBRATE_SETTING_OFF);
        mVibrateSetting = getValueForVibrateSetting(mVibrateSetting, AudioManager.VIBRATE_TYPE_RINGER, mHasVibrator ? AudioManager.VIBRATE_SETTING_ONLY_SILENT : AudioManager.VIBRATE_SETTING_OFF);
        // make sure settings for ringer mode are consistent with device type: non voice capable
        // devices (tablets) include media stream in silent mode whereas phones don't.
        mRingerModeAffectedStreams = Settings.System.getIntForUser(cr, Settings.System.MODE_RINGER_STREAMS_AFFECTED, ((1 << AudioSystem.STREAM_RING) | (1 << AudioSystem.STREAM_NOTIFICATION) | (1 << AudioSystem.STREAM_SYSTEM) | (1 << AudioSystem.STREAM_SYSTEM_ENFORCED)), UserHandle.USER_CURRENT);
        // ringtone, notification and system streams are always affected by ringer mode
        mRingerModeAffectedStreams |= (1 << AudioSystem.STREAM_RING) | (1 << AudioSystem.STREAM_NOTIFICATION) | (1 << AudioSystem.STREAM_SYSTEM);
        if (mVoiceCapable) {
            mRingerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_MUSIC);
        } else {
            mRingerModeAffectedStreams |= (1 << AudioSystem.STREAM_MUSIC);
        }
        synchronized (mCameraSoundForced) {
            if (mCameraSoundForced) {
                mRingerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_SYSTEM_ENFORCED);
            } else {
                mRingerModeAffectedStreams |= (1 << AudioSystem.STREAM_SYSTEM_ENFORCED);
            }
        }
        Settings.System.putIntForUser(cr, Settings.System.MODE_RINGER_STREAMS_AFFECTED, mRingerModeAffectedStreams, UserHandle.USER_CURRENT);
        readDockAudioSettings(cr);
    }
    //******************************************************************
    //TODO: should this be a user specific setting or device (see below)
    mLinkNotificationWithVolume = Settings.System.getInt(cr, Settings.System.VOLUME_LINK_NOTIFICATION, 1) == 1;
    //******************************************************************
    mMuteAffectedStreams = System.getIntForUser(cr, System.MUTE_STREAMS_AFFECTED, ((1 << AudioSystem.STREAM_MUSIC) | (1 << AudioSystem.STREAM_RING) | (1 << AudioSystem.STREAM_SYSTEM)), UserHandle.USER_CURRENT);
    boolean masterMute = System.getIntForUser(cr, System.VOLUME_MASTER_MUTE, 0, UserHandle.USER_CURRENT) == 1;
    if (mUseFixedVolume) {
        masterMute = false;
        AudioSystem.setMasterVolume(1.0f);
    }
    AudioSystem.setMasterMute(masterMute);
    broadcastMasterMuteStatus(masterMute);
    // Each stream will read its own persisted settings
    // Broadcast the sticky intent
    broadcastRingerMode(ringerMode);
    // Broadcast vibrate settings
    broadcastVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
    broadcastVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
    // Restore the default media button receiver from the system settings
    restoreMediaButtonReceiver();
}
Also used : ContentResolver(android.content.ContentResolver)

Example 10 with ContentResolver

use of android.content.ContentResolver in project android_frameworks_base by ParanoidAndroid.

the class Ringtone method getTitle.

private static String getTitle(Context context, Uri uri, boolean followSettingsUri) {
    Cursor cursor = null;
    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);
                title = context.getString(com.android.internal.R.string.ringtone_default_with_actual, actualTitle);
            }
        } else if (RingtoneManager.THEME_AUTHORITY.equals(authority)) {
            Uri themes = Uri.parse("content://com.tmobile.thememanager.themes/themes");
            title = stringForQuery(res.query(themes, new String[] { "ringtone_name" }, "ringtone_uri = ?", new String[] { uri.toString() }, null));
            if (title == null) {
                title = stringForQuery(res.query(themes, new String[] { "notif_ringtone_name" }, "notif_ringtone_uri = ?", new String[] { uri.toString() }, null));
            }
        } else {
            try {
                if (DrmStore.AUTHORITY.equals(authority)) {
                    cursor = res.query(uri, DRM_COLUMNS, null, null, null);
                } else if (MediaStore.AUTHORITY.equals(authority)) {
                    cursor = res.query(uri, MEDIA_COLUMNS, null, null, null);
                }
            } catch (SecurityException e) {
            // missing cursor is handled below
            }
            try {
                if (cursor != null && cursor.getCount() == 1) {
                    cursor.moveToFirst();
                    return cursor.getString(2);
                } else {
                    title = uri.getLastPathSegment();
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
    }
    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) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Aggregations

ContentResolver (android.content.ContentResolver)1121 Uri (android.net.Uri)236 Cursor (android.database.Cursor)190 ContentValues (android.content.ContentValues)112 Intent (android.content.Intent)90 RemoteException (android.os.RemoteException)67 IOException (java.io.IOException)59 Context (android.content.Context)52 File (java.io.File)46 ArrayList (java.util.ArrayList)46 Resources (android.content.res.Resources)45 ComponentName (android.content.ComponentName)44 MediumTest (android.test.suitebuilder.annotation.MediumTest)37 PreferenceScreen (android.support.v7.preference.PreferenceScreen)33 Bitmap (android.graphics.Bitmap)31 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