Search in sources :

Example 71 with ContentResolver

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

the class FilesActivity method writeStackToRecentsBlocking.

// Turns out only DocumentsActivity was ever calling saveStackBlocking.
// There may be a  case where we want to contribute entries from
// Behavior here in FilesActivity, but it isn't yet obvious.
// TODO: Contribute to recents, or remove this.
void writeStackToRecentsBlocking() {
    final ContentResolver resolver = getContentResolver();
    final ContentValues values = new ContentValues();
    final byte[] rawStack = DurableUtils.writeToArrayOrNull(mState.stack);
    // Remember location for next app launch
    final String packageName = getCallingPackageMaybeExtra();
    values.clear();
    values.put(ResumeColumns.STACK, rawStack);
    values.put(ResumeColumns.EXTERNAL, 0);
    resolver.insert(RecentsProvider.buildResume(packageName), values);
}
Also used : ContentValues(android.content.ContentValues) ContentResolver(android.content.ContentResolver)

Example 72 with ContentResolver

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

the class SettingsProviderTest method setSettingAndAssertSuccessfulChange.

private void setSettingAndAssertSuccessfulChange(Runnable setCommand, final int type, final String name, final String value, final int userId) throws Exception {
    ContentResolver contentResolver = getContext().getContentResolver();
    final Uri settingUri = getBaseUriForType(type);
    final AtomicBoolean success = new AtomicBoolean();
    ContentObserver contentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {

        public void onChange(boolean selfChange, Uri changeUri, int changeId) {
            Log.i(LOG_TAG, "onChange(" + selfChange + ", " + changeUri + ", " + changeId + ")");
            assertEquals("Wrong change Uri", changeUri, settingUri);
            assertEquals("Wrong user id", userId, changeId);
            String changeValue = getStringViaFrontEndApiSetting(type, name, userId);
            assertEquals("Wrong setting value", value, changeValue);
            success.set(true);
            synchronized (mLock) {
                mLock.notifyAll();
            }
        }
    };
    contentResolver.registerContentObserver(settingUri, false, contentObserver, userId);
    try {
        setCommand.run();
        final long startTimeMillis = SystemClock.uptimeMillis();
        synchronized (mLock) {
            if (success.get()) {
                return;
            }
            final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
            if (elapsedTimeMillis > WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS) {
                fail("Could not change setting for " + WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS + " ms");
            }
            final long remainingTimeMillis = WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS - elapsedTimeMillis;
            try {
                mLock.wait(remainingTimeMillis);
            } catch (InterruptedException ie) {
            /* ignore */
            }
        }
    } finally {
        contentResolver.unregisterContentObserver(contentObserver);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Handler(android.os.Handler) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) ContentObserver(android.database.ContentObserver)

Example 73 with ContentResolver

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

the class LocationControllerImpl method setLocationEnabled.

/**
     * Enable or disable location in settings.
     *
     * <p>This will attempt to enable/disable every type of location setting
     * (e.g. high and balanced power).
     *
     * <p>If enabling, a user consent dialog will pop up prompting the user to accept.
     * If the user doesn't accept, network location won't be enabled.
     *
     * @return true if attempt to change setting was successful.
     */
public boolean setLocationEnabled(boolean enabled) {
    int currentUserId = ActivityManager.getCurrentUser();
    if (isUserLocationRestricted(currentUserId)) {
        return false;
    }
    final ContentResolver cr = mContext.getContentResolver();
    // When enabling location, a user consent dialog will pop up, and the
    // setting won't be fully enabled until the user accepts the agreement.
    int mode = enabled ? Settings.Secure.LOCATION_MODE_PREVIOUS : Settings.Secure.LOCATION_MODE_OFF;
    // for the current foreground user.
    return Settings.Secure.putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, currentUserId);
}
Also used : ContentResolver(android.content.ContentResolver)

Example 74 with ContentResolver

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

the class BackupManagerService method writeBackupEnableState.

private static void writeBackupEnableState(boolean enable, int userId) {
    File base = new File(Environment.getDataDirectory(), "backup");
    File enableFile = new File(base, BACKUP_ENABLE_FILE);
    File stage = new File(base, BACKUP_ENABLE_FILE + "-stage");
    FileOutputStream fout = null;
    try {
        fout = new FileOutputStream(stage);
        fout.write(enable ? 1 : 0);
        fout.close();
        stage.renameTo(enableFile);
    // will be synced immediately by the try-with-resources call to close()
    } catch (IOException | RuntimeException e) {
        // Whoops; looks like we're doomed.  Roll everything out, disabled,
        // including the legacy state.
        Slog.e(TAG, "Unable to record backup enable state; reverting to disabled: " + e.getMessage());
        final ContentResolver r = sInstance.mContext.getContentResolver();
        Settings.Secure.putStringForUser(r, Settings.Secure.BACKUP_ENABLED, null, userId);
        enableFile.delete();
        stage.delete();
    } finally {
        IoUtils.closeQuietly(fout);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) AtomicFile(android.util.AtomicFile) ContentResolver(android.content.ContentResolver)

Example 75 with ContentResolver

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

the class DisplayAdjustmentUtils method applyDaltonizerSetting.

public static void applyDaltonizerSetting(Context context, int userId) {
    final ContentResolver cr = context.getContentResolver();
    final DisplayTransformManager dtm = LocalServices.getService(DisplayTransformManager.class);
    int daltonizerMode = AccessibilityManager.DALTONIZER_DISABLED;
    if (Secure.getIntForUser(cr, Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) != 0) {
        daltonizerMode = Secure.getIntForUser(cr, Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, DEFAULT_DISPLAY_DALTONIZER, userId);
    }
    float[] grayscaleMatrix = null;
    if (daltonizerMode == AccessibilityManager.DALTONIZER_SIMULATE_MONOCHROMACY) {
        // Monochromacy isn't supported by the native Daltonizer.
        grayscaleMatrix = MATRIX_GRAYSCALE;
        daltonizerMode = AccessibilityManager.DALTONIZER_DISABLED;
    }
    dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_GRAYSCALE, grayscaleMatrix);
    dtm.setDaltonizerMode(daltonizerMode);
}
Also used : DisplayTransformManager(com.android.server.display.DisplayTransformManager) 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