Merge "Renaming SharedPreferences$Editor.startCommit to apply" into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
bb660d7e1b
@@ -45080,7 +45080,7 @@
|
|||||||
<parameter name="key" type="java.lang.String">
|
<parameter name="key" type="java.lang.String">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="startCommit"
|
<method name="apply"
|
||||||
return="void"
|
return="void"
|
||||||
abstract="true"
|
abstract="true"
|
||||||
native="false"
|
native="false"
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ import java.util.Set;
|
|||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
class ReceiverRestrictedContext extends ContextWrapper {
|
class ReceiverRestrictedContext extends ContextWrapper {
|
||||||
ReceiverRestrictedContext(Context base) {
|
ReceiverRestrictedContext(Context base) {
|
||||||
@@ -2821,8 +2820,6 @@ class ContextImpl extends Context {
|
|||||||
private final Map<String, Object> mModified = Maps.newHashMap();
|
private final Map<String, Object> mModified = Maps.newHashMap();
|
||||||
private boolean mClear = false;
|
private boolean mClear = false;
|
||||||
|
|
||||||
private AtomicBoolean mCommitInFlight = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
public Editor putString(String key, String value) {
|
public Editor putString(String key, String value) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
mModified.put(key, value);
|
mModified.put(key, value);
|
||||||
@@ -2868,11 +2865,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startCommit() {
|
public void apply() {
|
||||||
if (!mCommitInFlight.compareAndSet(false, true)) {
|
|
||||||
throw new IllegalStateException("can't call startCommit() twice");
|
|
||||||
}
|
|
||||||
|
|
||||||
final MemoryCommitResult mcr = commitToMemory();
|
final MemoryCommitResult mcr = commitToMemory();
|
||||||
final Runnable awaitCommit = new Runnable() {
|
final Runnable awaitCommit = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -2888,7 +2881,6 @@ class ContextImpl extends Context {
|
|||||||
Runnable postWriteRunnable = new Runnable() {
|
Runnable postWriteRunnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
awaitCommit.run();
|
awaitCommit.run();
|
||||||
mCommitInFlight.set(false);
|
|
||||||
QueuedWork.remove(awaitCommit);
|
QueuedWork.remove(awaitCommit);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -3012,13 +3004,13 @@ class ContextImpl extends Context {
|
|||||||
* that they're enqueued.
|
* that they're enqueued.
|
||||||
*
|
*
|
||||||
* @param postWriteRunnable if non-null, we're being called
|
* @param postWriteRunnable if non-null, we're being called
|
||||||
* from startCommit() and this is the runnable to run after
|
* from apply() and this is the runnable to run after
|
||||||
* the write proceeds. if null (from a regular commit()),
|
* the write proceeds. if null (from a regular commit()),
|
||||||
* then we're allowed to do this disk write on the main
|
* then we're allowed to do this disk write on the main
|
||||||
* thread (which in addition to reducing allocations and
|
* thread (which in addition to reducing allocations and
|
||||||
* creating a background thread, this has the advantage that
|
* creating a background thread, this has the advantage that
|
||||||
* we catch them in userdebug StrictMode reports to convert
|
* we catch them in userdebug StrictMode reports to convert
|
||||||
* them where possible to startCommit...)
|
* them where possible to apply() ...)
|
||||||
*/
|
*/
|
||||||
private void enqueueDiskWrite(final MemoryCommitResult mcr,
|
private void enqueueDiskWrite(final MemoryCommitResult mcr,
|
||||||
final Runnable postWriteRunnable) {
|
final Runnable postWriteRunnable) {
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ public interface SharedPreferences {
|
|||||||
/**
|
/**
|
||||||
* Interface used for modifying values in a {@link SharedPreferences}
|
* Interface used for modifying values in a {@link SharedPreferences}
|
||||||
* object. All changes you make in an editor are batched, and not copied
|
* object. All changes you make in an editor are batched, and not copied
|
||||||
* back to the original {@link SharedPreferences} or persistent storage
|
* back to the original {@link SharedPreferences} until you call {@link #commit}
|
||||||
* until you call {@link #commit}.
|
* or {@link #apply}
|
||||||
*/
|
*/
|
||||||
public interface Editor {
|
public interface Editor {
|
||||||
/**
|
/**
|
||||||
* Set a String value in the preferences editor, to be written back once
|
* Set a String value in the preferences editor, to be written back once
|
||||||
* {@link #commit} is called.
|
* {@link #commit} or {@link #apply} are called.
|
||||||
*
|
*
|
||||||
* @param key The name of the preference to modify.
|
* @param key The name of the preference to modify.
|
||||||
* @param value The new value for the preference.
|
* @param value The new value for the preference.
|
||||||
@@ -72,7 +72,7 @@ public interface SharedPreferences {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an int value in the preferences editor, to be written back once
|
* Set an int value in the preferences editor, to be written back once
|
||||||
* {@link #commit} is called.
|
* {@link #commit} or {@link #apply} are called.
|
||||||
*
|
*
|
||||||
* @param key The name of the preference to modify.
|
* @param key The name of the preference to modify.
|
||||||
* @param value The new value for the preference.
|
* @param value The new value for the preference.
|
||||||
@@ -84,7 +84,7 @@ public interface SharedPreferences {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a long value in the preferences editor, to be written back once
|
* Set a long value in the preferences editor, to be written back once
|
||||||
* {@link #commit} is called.
|
* {@link #commit} or {@link #apply} are called.
|
||||||
*
|
*
|
||||||
* @param key The name of the preference to modify.
|
* @param key The name of the preference to modify.
|
||||||
* @param value The new value for the preference.
|
* @param value The new value for the preference.
|
||||||
@@ -96,7 +96,7 @@ public interface SharedPreferences {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a float value in the preferences editor, to be written back once
|
* Set a float value in the preferences editor, to be written back once
|
||||||
* {@link #commit} is called.
|
* {@link #commit} or {@link #apply} are called.
|
||||||
*
|
*
|
||||||
* @param key The name of the preference to modify.
|
* @param key The name of the preference to modify.
|
||||||
* @param value The new value for the preference.
|
* @param value The new value for the preference.
|
||||||
@@ -108,7 +108,7 @@ public interface SharedPreferences {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a boolean value in the preferences editor, to be written back
|
* Set a boolean value in the preferences editor, to be written back
|
||||||
* once {@link #commit} is called.
|
* once {@link #commit} or {@link #apply} are called.
|
||||||
*
|
*
|
||||||
* @param key The name of the preference to modify.
|
* @param key The name of the preference to modify.
|
||||||
* @param value The new value for the preference.
|
* @param value The new value for the preference.
|
||||||
@@ -159,7 +159,7 @@ public interface SharedPreferences {
|
|||||||
*
|
*
|
||||||
* <p>If you don't care about the return value and you're
|
* <p>If you don't care about the return value and you're
|
||||||
* using this from your application's main thread, consider
|
* using this from your application's main thread, consider
|
||||||
* using {@link #startCommit} instead.
|
* using {@link #apply} instead.
|
||||||
*
|
*
|
||||||
* @return Returns true if the new values were successfully written
|
* @return Returns true if the new values were successfully written
|
||||||
* to persistent storage.
|
* to persistent storage.
|
||||||
@@ -173,16 +173,16 @@ public interface SharedPreferences {
|
|||||||
* in the SharedPreferences.
|
* in the SharedPreferences.
|
||||||
*
|
*
|
||||||
* <p>Note that when two editors are modifying preferences at the same
|
* <p>Note that when two editors are modifying preferences at the same
|
||||||
* time, the last one to call commit wins.
|
* time, the last one to call apply wins.
|
||||||
*
|
*
|
||||||
* <p>Unlike {@link #commit}, which writes its preferences out
|
* <p>Unlike {@link #commit}, which writes its preferences out
|
||||||
* to persistent storage synchronously, {@link #startCommit}
|
* to persistent storage synchronously, {@link #apply}
|
||||||
* commits its changes to the in-memory
|
* commits its changes to the in-memory
|
||||||
* {@link SharedPreferences} immediately but starts an
|
* {@link SharedPreferences} immediately but starts an
|
||||||
* asynchronous commit to disk and you won't be notified of
|
* asynchronous commit to disk and you won't be notified of
|
||||||
* any failures. If another editor on this
|
* any failures. If another editor on this
|
||||||
* {@link SharedPreferences} does a regular {@link #commit}
|
* {@link SharedPreferences} does a regular {@link #commit}
|
||||||
* while a {@link #startCommit} is still outstanding, the
|
* while a {@link #apply} is still outstanding, the
|
||||||
* {@link #commit} will block until all async commits are
|
* {@link #commit} will block until all async commits are
|
||||||
* completed as well as the commit itself.
|
* completed as well as the commit itself.
|
||||||
*
|
*
|
||||||
@@ -190,7 +190,7 @@ public interface SharedPreferences {
|
|||||||
* the base class will wait for any async commits to finish in
|
* the base class will wait for any async commits to finish in
|
||||||
* its {@link android.app.Activity#onPause}.</p>
|
* its {@link android.app.Activity#onPause}.</p>
|
||||||
*/
|
*/
|
||||||
void startCommit();
|
void apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1195,7 +1195,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
|
|||||||
|
|
||||||
private void tryCommit(SharedPreferences.Editor editor) {
|
private void tryCommit(SharedPreferences.Editor editor) {
|
||||||
if (mPreferenceManager.shouldCommit()) {
|
if (mPreferenceManager.shouldCommit()) {
|
||||||
editor.startCommit();
|
editor.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1737,7 +1737,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
|||||||
mContext.getSharedPreferences(SHARED_PREFERENCES_NAME,
|
mContext.getSharedPreferences(SHARED_PREFERENCES_NAME,
|
||||||
mContext.MODE_PRIVATE).edit();
|
mContext.MODE_PRIVATE).edit();
|
||||||
editor.putBoolean(SHARED_PREFERENCE_DOCK_ADDRESS + mDockAddress, true);
|
editor.putBoolean(SHARED_PREFERENCE_DOCK_ADDRESS + mDockAddress, true);
|
||||||
editor.startCommit();
|
editor.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ public class BootReceiver extends BroadcastReceiver {
|
|||||||
if (lastTime == fileTime) return; // Already logged this particular file
|
if (lastTime == fileTime) return; // Already logged this particular file
|
||||||
// TODO: move all these SharedPreferences Editor commits
|
// TODO: move all these SharedPreferences Editor commits
|
||||||
// outside this function to the end of logBootEvents
|
// outside this function to the end of logBootEvents
|
||||||
prefs.edit().putLong(filename, fileTime).startCommit();
|
prefs.edit().putLong(filename, fileTime).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
Slog.i(TAG, "Copying " + filename + " to DropBox (" + tag + ")");
|
Slog.i(TAG, "Copying " + filename + " to DropBox (" + tag + ")");
|
||||||
|
|||||||
Reference in New Issue
Block a user