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);
}
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);
}
}
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);
}
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);
}
}
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);
}
Aggregations