summaryrefslogtreecommitdiff
path: root/core/java/android/app/SharedPreferencesImpl.java
Commit message (Collapse)AuthorAgeFilesLines
* Merge "Migrate CALLBACK_ON_CLEAR_CHANGE"Treehugger Robot2020-11-181-2/+2
|\
| * Migrate CALLBACK_ON_CLEAR_CHANGEAndrei Onea2020-11-091-2/+2
| | | | | | | | | | | | | | | | Use @EnabledSince instead of @EnabledAfter for CALLBACK_ON_CLEAR_CHANGE. Test: m Bug: 172238506 Change-Id: I74d558cbf5c572fad11329269266fab017afde8e
* | Add maxTargetSdk restriction to unused APIs.Mathew Inwood2020-11-041-1/+1
|/ | | | | | | | | | | These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. Bug: 170729553 Test: Treehugger Merged-In: I626caf7c1fe46c5ab1f39c2895b42a34319f771a Change-Id: I54e5ecd11e76ca1de3c5893e3a98b0108e735413
* Fix @link tags in @ChangeId docs.Mathew Inwood2020-01-171-2/+3
| | | | | | | | | We now have javadoc based docs generated from these comments now. Ensure the links can be resolved. Bug: 144927670 Test: See follow-up CLs Change-Id: I7c3121e062ec82b64a81f3ec00cddb1bf932ffd9
* Use new UnsupportedAppUsage annotation.Artur Satayev2019-12-181-1/+1
| | | | | | | | Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I8789f8499d4dca08580672e9e45ed9a7026dd686
* Updated onSharedPreferenceChanged listener behavior.Varun Shah2019-08-261-69/+29
| | | | | | | | | | | | | The onSharedPreferenceChanged listener will now also be called on Editor#clear with a null key. This change is gated behind a flag using the new app compat framework. Removed the OnSharedPreferencesClear listener interface. Bug: 119147584 Bug: 138293946 Test: atest android.content.cts.SharedPreferencesTest Change-Id: Ieea168eb40afb8f1b5830f1541be20d93d6f94b5
* Add OnSharedPreferencesClearListener for Editor#clear.Varun Shah2019-06-131-1/+65
| | | | | | | | | A new interface has been added that provides a way to receive callbacks when shared preferences are cleared. Bug: 119147584 Test: android.content.cts.SharedPreferencesTest Change-Id: Ie74a6db49711bc5228cf75689872ae188af7979c
* Add @UnsupportedAppUsage annotationsMathew Inwood2018-08-141-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | For packages: android.app.usage android.app.trust android.app.timezonedetector android.app.timezone android.app.timedetector android.app.job android.app.backup android.app.assist android.app.admin android.app This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: I618c5dc4462ae990d9df45c3e9ed3f092cc5138c
* Frameworks: Move SharedPreferencesImpl to tristateAndreas Gampe2018-01-051-9/+34
| | | | | | | | | | | | | The code loading shared preferences from disk may throw in other ways then a missing file, for example during an out-of-memory situation. Ensure that waiters will be woken up, and propagate the exception to the getters. Bug: 67986472 Test: m Test: Device boots Test: m cts && cts-tradefed run commandAndExit cts-dev --module CtsContentTestCases -c android.content.cts.SharedPreferencesTest Change-Id: I56e47342111f1cb53c5817c0429af4a6787475a9
* Revert "Frameworks: Move SharedPreferencesImpl to Future"Andreas Gampe2018-01-031-74/+54
| | | | | | | | | | | | | | This reverts commit 70b600d45683b574104d10198da9bce49aa6be23. In preparation for a different fix. There are too many loopholes with updates vs commits. Bug: 67986472 Bug: 71533447 Test: m Test: Device boots Test: m cts && cts-tradefed run commandAndExit cts-dev --module CtsContentTestCases -c android.content.cts.SharedPreferencesTest Change-Id: I872a81ae1a26e1f77aad2a52daf88e093a686ec6
* Revert "Frameworks: Silently ignore InterruptedException"Andreas Gampe2018-01-031-9/+4
| | | | | | | | | | | | | | This reverts commit c8d5fc857208b08b984a802277807e9195b2f9a7. In preparation for different fix. Bug: 67986472 Bug: 70122540 Bug: 71533447 Test: m Test: Device boots Test: m cts && cts-tradefed run commandAndExit cts-dev --module CtsContentTestCases -c android.content.cts.SharedPreferencesTest Change-Id: I0b9e72d271725e15c20b68de981303c96ac1bd2a
* Merge "Frameworks: Silently ignore InterruptedException"Andreas Gampe2017-12-051-4/+9
|\ | | | | | | | | | | am: 7e717e09cd Change-Id: I75da071918e7fc2e547df4e4d75121806c730ca2
| * Frameworks: Silently ignore InterruptedExceptionAndreas Gampe2017-12-041-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Apps seem to rely on this undocumented behavior so that the threaded sync adapter doesn't crash an app. That's really bad on the app side, but we will have to live with it. Bug: 67986472 Bug: 70122540 Test: m Test: Device boots Test: m cts && cts-tradefed run commandAndExit cts-dev --module CtsContentTestCases -c android.content.cts.SharedPreferencesTest Change-Id: I1ee4dfba4ad29c4f66fa60d3c8f8a99900b3447a
* | Merge "Frameworks: Move SharedPreferencesImpl to Future"Andreas Gampe2017-12-021-54/+74
|\| | | | | | | | | | | am: aa3e9d351e Change-Id: I2a47400d1e584aef1a16e05840ab964ca5735110
| * Frameworks: Move SharedPreferencesImpl to FutureAndreas Gampe2017-11-211-54/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | The asynchronous loading code is not safe wrt/ exceptions. Instead of adding a tri-state for loading, move the code to use a Future for the map. This encapsulates the required wait & synchronization, as well as propagating any exceptions. Bug: 67986472 Test: m Test: Device boots Test: m cts && cts-tradefed run commandAndExit cts-dev --module CtsContentTestCases -c android.content.cts.SharedPreferencesTest Change-Id: I6616e8a05e64eb1cfe024cc3239a05847dfe1fab
* | Merge "Frameworks: Clean up SharedPreferencesImpl"Andreas Gampe2017-11-291-30/+48
|\| | | | | | | | | | | am: 572f46a3ef Change-Id: I7b922f795283cefabf661e999e5a9897889fa287
| * Frameworks: Clean up SharedPreferencesImplAndreas Gampe2017-11-211-30/+48
| | | | | | | | | | | | | | | | | | | | Clean up in preparation for an implementation change. Add missing annotations. Rename inner lock to be uniquely named. Use the local map instead of mMap in the commit logic. Test: m Test: m cts && cts-tradefed run commandAndExit cts-dev --module CtsContentTestCases -c android.content.cts.SharedPreferencesTest Change-Id: Id3a798732c83a4aa6487225e2375ade4985852e2
| * Make SharedPreferences check with higher precisionPhilip P. Moltmann2017-11-201-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When two processes modify shared preferences we use the timestamp to figure out if the file was changes underneath. Do this with the highest precision available (instead of sec) as before. It would be possible to make the check more reliable by writing a unique id to the shared pref file, but this would make this check much more expensive in the common case that nothing changed. Considering that this has not been a problem and we don't officially give any guarantee for this sounds like a good middle-ground. (cherry picked from commit ffe74357aec5330098795000e131e8d581b8b274) Merged-In: I04c96b6a946618d5599c26410c88d7cd654d31fb Change-Id: I04c96b6a946618d5599c26410c88d7cd654d31fb Test: SharedPreferencesTest Fixes: 62949739
* | Make SharedPreferences check with higher precisionPhilip P. Moltmann2017-07-191-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When two processes modify shared preferences we use the timestamp to figure out if the file was changes underneath. Do this with the highest precision available (instead of sec) as before. It would be possible to make the check more reliable by writing a unique id to the shared pref file, but this would make this check much more expensive in the common case that nothing changed. Considering that this has not been a problem and we don't officially give any guarantee for this sounds like a good middle-ground. Change-Id: I04c96b6a946618d5599c26410c88d7cd654d31fb Test: SharedPreferencesTest Fixes: 62949739
* | SharedPreferencesImpl: Avoid pointless allocation during apply.Narayan Kamath2017-07-101-1/+1
|/ | | | | Test: make Change-Id: I5ae03b5561b38e23af50764e17ac5ccfccc1b476
* Merge "Issue a warning if SharedPreferences are corrupted"Philip P. Moltmann2017-03-081-2/+2
|\
| * Issue a warning if SharedPreferences are corruptedPhilip P. Moltmann2017-03-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | We already only issue a warning if the xml cannot be parsed. So if the xml could be parsed by the result could not be cast to a map, we should also only issue a warning. Also log the corrupted file as this is called on an async thread and it is not clear what file is affected. Bug: 29006064 Test: Just logging changes. Change-Id: I503fd4ee9b905f72668136b4d98c819cd7f9021b
* | Log histogram of fsync times of sharedPreferencesPhilip P. Moltmann2017-03-061-15/+30
|/ | | | | | | | | | | | | Example log: Time required to fsync /data/user/0/com.google.android.gms/shared_prefs/gms_sync_prefs_sync:ContactMetadata.xml: [<1: 0, <2: 0, <4: 0, <8: 0, <16: 0, <32: 0, <64: 0, <128: 0, <256: 0, <512: 0, <1024: 1, <2048: 0, <4096: 0, <8192: 0, <16384: 0, >=16384: 0] Fixes: 30662828 Test: Looked at log Change-Id: I6d585b107ae14e05ff1c77b0a0017de684226cba
* Process queuedWork on main thread and add loggingPhilip P. Moltmann2017-02-151-17/+96
| | | | | | | | | | | | | | - The queued work processing thread might be sleeping while the main thread is waiting for it to do work. Hence process the work in the main thread. - Carefully add logging so that slowness can be tracked. - Fix usage of the wrong lock (sWork instead of sLock). - Increase the time of the delay between apply and write to make possible side-effects more visible Test: SharedPrefencesTest, looked at logging Bug: 30662828 Change-Id: Ie8a5d531e180dacec29c947ba0b59b170facf782
* Revert accidential merge 492a058d58e991445996cb8cc8dcb24494ac20c5Philip P. Moltmann2017-02-141-4/+4
| | | | | Test: Clean revert Change-Id: I61d339bb85936e1d50742be1e4c6dab781f3a4e7
* resolve merge conflicts of d043a840f7f12ce2c54e7d4564a6ac9cfa24dd17 to ↵Philip P. Moltmann2017-02-141-4/+4
|\ | | | | | | | | | | | | | | nyc-mr2-dev-plus-aosp am: b02f8eb241 Change-Id: I1307ea308423c0fd34564d788ab64c023a5be2c5
| * [DO NOT MERGE] Revert "[DO NOT MERGE] Delay SharedPreferences.apply() by 50 ms"Philip P. Moltmann2017-02-131-4/+4
| | | | | | | | | | | | | | This reverts commit 2fc44947dd4f45a23c56985d4c12f01332027a9f. Bug: 30662828 Change-Id: Ia22343c19e155555dff3b0cb58f7b58df0ce6301
| * [DO NOT MERGE] Delay SharedPreferences.apply() by 50 msPhilip P. Moltmann2017-01-311-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... so that multiple applies can be combined into a single write. Do do this I replaces the executor in the QueuedWork by a more Android-y handler. Test: Ran shared preferences CTS tests. Looked at log and saw a lot of skipped writes Bug: 33385963 Bug: 30662828 Change-Id: I8f33df717be7091532930ccf6ca8c48940e4edd4 (cherry picked from commit 3349644872d9b769f4e2d0ec1b91d368a552ff8d)
| * Do not write if apply() did not change the file.Philip P. Moltmann2016-12-141-10/+10
| | | | | | | | | | | | Bug: 33385963 Test: SharedPreferences CTS tests Change-Id: I39955f8fbcdaa54faa539a3c503e12cb00808136
| * Only persist last Shared Preferences statePhilip P. Moltmann2016-12-141-12/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If multiple async shared preferences writes are queued, all but the last one can be ignored as they will be overwritten by the last one anyway. For commit() we need to make sure that we have at least persisted the state of the commit. Generation counts are 64 bit, hence they never overflow. Test: Produced a lot of SharedPreferences.Editor.apply and did not see excessive writes anymore, ran SharedPreferences CTS tests Bug: 33385963 Change-Id: I3968ed4b71befee6eeb90bea1666a0bb646544f6
* | Use local locks in SharedPreferencesImpl.Philip P. Moltmann2016-12-151-59/+90
| | | | | | | | | | | | Fixes: 33430093 Test: SharedPreferences CTS tests Change-Id: Ia2ac48a0273608d5be6a227dc6669cea9d44bc1d
* | Delay SharedPreferences.apply() by 50 msPhilip P. Moltmann2016-12-141-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | ... so that multiple applies can be combined into a single write. Do do this I replaces the executor in the QueuedWork by a more Android-y handler. Test: Ran shared preferences CTS tests. Looked at log and saw a lot of skipped writes Bug: 33385963 Change-Id: I8f33df717be7091532930ccf6ca8c48940e4edd4
* | Do not write if apply() did not change the file.Philip P. Moltmann2016-12-121-10/+10
| | | | | | | | | | | | Bug: 33385963 Test: SharedPreferences CTS tests Change-Id: I39955f8fbcdaa54faa539a3c503e12cb00808136
* | Only persist last Shared Preferences statePhilip P. Moltmann2016-12-071-12/+60
|/ | | | | | | | | | | | | | | | If multiple async shared preferences writes are queued, all but the last one can be ignored as they will be overwritten by the last one anyway. For commit() we need to make sure that we have at least persisted the state of the commit. Generation counts are 64 bit, hence they never overflow. Test: Produced a lot of SharedPreferences.Editor.apply and did not see excessive writes anymore, ran SharedPreferences CTS tests Bug: 33385963 Change-Id: I3968ed4b71befee6eeb90bea1666a0bb646544f6
* Don't hold a lock while reading shared preferences from disk.Svet Ganov2016-02-191-23/+23
| | | | | | | | | | | | | Shared prefrences loads thir content from disk on a separate thread to improve performance, however it holds the lock the whole time while reading from disk which as a result blocks operations that don't rely on reading data from being performed intil load completes, e.g. reguistering a prefernces change listener does not depend on having the data loaded. bug:5254577 Change-Id: I5ad67b285631c34d5aadac7138ba8bfaa728cf94
* Offer to migrate databases and SharedPreferences.Jeff Sharkey2016-01-301-1/+1
| | | | | | | | | | | | | | Databases and SharedPreferences often involve multiple files under the hood, so developers wanting to migrate them between different storage contexts should ask us to make sure all relevant files are migrated correctly. This makes a best-effort attempt to recover from battery pulls during migration, while still trying to alert developers to conflicting files. Bug: 26668510, 25860525 Change-Id: I9ffa3e8cb6191dfd4237b9466a081d6d77df3ba0
* Add some @Nullable annotations to SharedPreferencesScott Kennedy2015-01-301-4/+7
| | | | Change-Id: I26e7a02a18d802902fca6892bed77b4f98ccf3ee
* resolved conflicts for merge of 3ce4f3d0 to masterElliott Hughes2014-04-281-6/+6
|\ | | | | | | Change-Id: Id5c5997ad8f801b32e1dbd97413ea42e38c27210
| * Track libcore.os' move to android.system.Elliott Hughes2014-04-281-6/+6
| | | | | | | | | | | | | | (This is partial, but should cover everything in AOSP master except for the zygote.) Change-Id: I1042c99245765746a744c44e714095cb2c6cb75d
* | am 909427d0: am f588d2df: am d0ec6d8c: am bc2a449a: am cb4d3ec1: Merge "Fix ↵Narayan Kamath2014-01-131-2/+4
|\| | | | | | | | | | | | | preference puts with "null" values." * commit '909427d093c30d2d4f4ffe5da19f1db6c3e9a3b3': Fix preference puts with "null" values.
| * Fix preference puts with "null" values.Narayan Kamath2014-01-081-2/+4
| | | | | | | | | | | | | | | | | | | | Null values were being written out as <null /> elements in the XML prefs file (as expected). This allowed the getFoo() functions to work correctly because they treated null values as missing mappings but containsKey would fail. bug: https://code.google.com/p/android/issues/detail?id=64563 Change-Id: I1f466d01db96bf26e208d4fed3a6f257228bea5d
* | Remove unused imports from frameworks/base.John Spurlock2013-11-201-1/+0
|/ | | | Change-Id: Ia1f99bd2c1105b0b0f70aa614f1f4a67b2840906
* Document immutable requirement of SharedPreferences return objectsChristopher Tate2012-10-191-1/+2
| | | | | | | | | | | | | | | In particular, make it quite clear that the set returned by getStringSet() must not be modfied by the app, period; and add a similar caution about the map returned via getAll(). Also, fix a bug that could lead to unexpected data being committed if the set instance passed to putStringSet() was mutated by the app after that call (including mutations after commit() was invoked). Bug 7312641 Change-Id: If9a1be1b0669ac879ff7a7dc67a8805548ea10cc
* Use Libcore's stat instead of FileUtils#getFileStatusKenny Root2012-08-161-23/+44
| | | | | | | | Remove the last user of FileUtils#getFileStatus and move it to Libcore.os.stat instead. Then we can remove the JNI code that does the equivalent of a stat. Change-Id: Ieb566a2a8a17c2dd0150724b4eb3ac1cc41c823d
* Fix issue #5435470: SharedPreferencesImpl should read from file...Dianne Hackborn2011-10-101-1/+3
| | | | | | ...via BufferedInputStream Change-Id: Ic14eff1e53b6f4a0de5f59bd97cd390eb908e3c6
* Make getSharedPreference() async, blocking on first access.Brad Fitzpatrick2010-12-071-26/+106
| | | | | Bug: 3177046 Change-Id: Ibc36a1e196afd39c4f9da513a2bf4ba9e2c72177
* Don't re-read SharedPreferences unnecessarily.Brad Fitzpatrick2010-11-191-1/+5
| | | | | | | | | | | | | | | Previously reads were only cached once a write occurred because loading didn't set the stat metadata, thus the sp.hasFileChangedUnexpectedly() check always fired on reading. Now the initial read populates the stat info, so getSharedPreference() repeatedly bypasses reading from disk, even wtihout writes. This was probably a regression from apply() being added in Gingerbread. Bug: 3211034 Change-Id: Ifa0bbb27c53a4099544950a4f822fab1fc23a47d
* Move SharedPreferencesImpl out of ContextImpl.javaBrad Fitzpatrick2010-11-101-0/+518
Change-Id: I3a58ec4c9501e906c133e841b5c5ec6bced04a02