summaryrefslogtreecommitdiff
path: root/core/java/android/util/AtomicFile.java
Commit message (Collapse)AuthorAgeFilesLines
* Implemented AtomicFile.toString()Felipe Leme2021-10-221-0/+5
| | | | | | | | | It shows the path of the base filename. Test: atest FrameworksUtilTests:android.util.AtomicFileTest Fixes: 203131233 Change-Id: Ib8d36610a4c34d210cc465ec8006d4df33ef638d
* Merge "Properly keep compatibility with openRead() during a write." into ↵TreeHugger Robot2020-05-211-2/+12
|\ | | | | | | | | | | rvc-dev am: beac47b12e am: 2e7334ebd3 am: ca13677e7d am: 2fe9669565 Change-Id: Ic3d81c597c5403d0eaf7b97034bbca8f0a9aa3aa
| * Properly keep compatibility with openRead() during a write.Hai Zhang2020-05-201-2/+12
| | | | | | | | | | | | Bug: 157092639 Test: atest AppIdleHistoryTests#testFilesCreation Change-Id: I7d6808139aa41b25715293207b8ad42f9f42ef65
* | Merge "Maintain compatibility by deleting target directory before renaming ↵TreeHugger Robot2020-05-201-11/+20
|\ \ | | | | | | | | | into it."
| * | Maintain compatibility by deleting target directory before renaming into it.Hai Zhang2020-05-201-11/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The target shouldn't be a directory, but if it is, it would be deleted (as long as it's empty). This became some kind of API and we need to remain compatible with it. Bug: 151959443 Test: Reboot and ensure ShortcutService can persist its state Change-Id: I11a80cd4252128b025912b7aab86b113935e549a
* | | Merge "Don't delete the new file in openRead()." into rvc-dev am: c74a76863b ↵TreeHugger Robot2020-05-201-5/+2
|\ \ \ | |/ / |/| / | |/ | | | | am: 990a07462b am: 441824370e am: f4ac6d5669 Change-Id: I1bc66212d98449dc5c2301c22fe79c80304cb88e
| * Don't delete the new file in openRead().Hai Zhang2020-05-191-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although it may seems a left-over from a previous interrupted write, actually there are callers who call startWrite(), openRead() and then finishWrite(), and this was okay in the previous implementation, so we have to keep supporting it. The new file is virtually ignored in the new implementation, and we have no good way to know if it's actually a left-over or one that's being written, so simply leaving it there is also okay. Fixes: 157092639 Test: atest AppIdleHistoryTests#testFilesCreation Change-Id: I4dc7fde99d2b8e04356f082a6e6ad61c2835022e
| * Change AtomicFile to use rename-into-place.Hai Zhang2020-05-191-79/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation of backing up beforehand doesn't handle the case where the file is created for the first time, and might leave a corrupted file in case of failure. This new implementation creates a new file for writing data into, and renames it into the place of the original file after writing finished. Fixes: 151959443 Test: atest android.util.AtomicFileTest Change-Id: I5c4c438526a2aecdd2af18f71e16b41a05817c61 Merged-In: I5c4c438526a2aecdd2af18f71e16b41a05817c61
* | Change AtomicFile to use rename-into-place.Hai Zhang2020-05-181-78/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation of backing up beforehand doesn't handle the case where the file is created for the first time, and might leave a corrupted file in case of failure. This new implementation creates a new file for writing data into, and renames it into the place of the original file after writing finished. Fixes: 151959443 Test: atest android.util.AtomicFileTest Change-Id: I5c4c438526a2aecdd2af18f71e16b41a05817c61
* | Add SystemApi(MODULE_LIBRARIES) to AtomicFile APIDmitri Plotnikov2020-05-141-10/+36
|/ | | | | | | | | Cleaning up the API in the process Test: atest android.jobscheduler.cts Bug: 142281756 Change-Id: Ia52dc6fda867f3015ecbf068a0a69cc0f17cd92a
* Reduce pss collection amount, improve logging.Dianne Hackborn2018-01-261-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Tuned rates that we collect PSS, to reduce how much we do that heavy operation. Added a new way to determine whether a process has changed to a state for the "first" time -- now this is when it has gone to that state for the first time since it was in a lower state. This will reduce the amount of time we consider a process to be first to only when it has previously gone into a higher state than it had before. Keep track of more fine-grained information about why we collect a PSS sample (not just internal, but for a single process, all processes because of a mem state change, all processes because of a poll). Started collecting RSS in various places, so we can start looking at that w.r.t. PSS and see about transitioning to it is a new primary metric. Added logging for many of the places where the system writes its configuration files, so we can more easily see any bad behavior going on in those areas. Added some currently disabled code to read smaps directly instead of using fgets(). Probably won't help, but want tot test. Bug: 70859548 Test: atest CtsAppTestCases Change-Id: I400dba0f3ae9c024df51c946cfa592561028b598
* Persisted jobs versus incorrect boot-time RTCChristopher Tate2017-07-311-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Devices routinely boot in a state where the RTC is wildly incorrect in the past (2009, 1999, or even at Unix epoch zero). When we have persistent jobs to be scheduled at boot, this presents a problem: when should those jobs run, given that our idea of "now" is incorrect? The previous implementation fell back to rescheduling these jobs "from scratch" in this situation, as though they were newly-introduced, but this turns out to have some emergent pathologies when the jobs were intended to become runnable after long initial delays: the rescheduling behavior could wind up starving jobs out entirely, never running them regardless of how much real uptime the device had, given the "wrong" pattern of reboots. We now preserve the original nominal schedule, but recognize when we have booted in a pathological situation, and correct the schedule for these jobs when the system clock becomes sensible. Bug 63817592 Test: JobScheduler test suite plus manual bogus-boot-time repro Change-Id: Ia36fc5298b68db74e4e07e973b68e68e66206b43
* Handle an edge case that can reset settings provider dataAmith Yamasani2017-07-201-0/+9
| | | | | | | | | If the AtomicFile does the rename and fails when writing the original, make sure we can at least use the backup on reboot. Bug: 63753300 Test: Stop shell, move settings_global.xml to backup, start shell. Change-Id: I2049b48af05161bb2c68717a71c1700a95150a6c
* Record app<->device association to xml fileEugene Susla2017-03-061-1/+18
| | | | | | | | Bug: 30932767 Test: Ensure file not exists -> query associations -> ensure result is empty list Associate device -> cat xml file -> ensure record appears as extected Disassociate device -> cat xml file -> ensure record is no longer present Change-Id: Ibe456a6d9292e05e2391f5138e43fdaa37f87e1b
* Rewrite of the settings provider.Svetoslav2015-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change modifies how global, secure, and system settings are managed. In particular, we are moving away from the database to an in-memory model where the settings are persisted asynchronously to XML. This simplifies evolution and improves performance, for example, changing a setting is down from around 400 ms to 10 ms as we do not hit the disk. The trade off is that we may lose data if the system dies before persisting the change. In practice this is not a problem because 1) this is very rare; 2) apps changing a setting use the setting itself to know if it changed, so next time the app runs (after a reboot that lost data) the app will be oblivious that data was lost. When persisting the settings we delay the write a bit to batch multiple changes. If a change occurs we reschedule the write but when a maximal delay occurs after the first non-persisted change we write to disk no matter what. This prevents a malicious app poking the settings all the time to prevent them being persisted. The settings are persisted in separate XML files for each type of setting per user. Specifically, they are in the user's system directory and the files are named: settings_type_of_settings.xml. Data migration is performed after the data base is upgraded to its last version after which the global, system, and secure tables are dropped. The global, secure, and system settings now have the same version and are upgraded as a whole per user to allow migration of settings between these them. The upgrade steps should be added to the SettingsProvider.UpgradeController and not in the DatabaseHelper. Setting states are mapped to an integer key derived from the user id and the setting type. Therefore, all setting states are in a lookup table which makes all opertions very fast. The code is a complete rewrite aiming for improved clarity and increased maintainability as opposed to using minor optimizations. Now setting and getting the changed setting takes around 10 ms. We can optimize later if needed. Now the code path through the call API and the one through the content provider APIs end up being the same which fixes bugs where some enterprise cases were not implemented in the content provider code path. Note that we are keeping the call code path as it is a bit faster than the provider APIs with about 2 ms for setting and getting a setting. The front-end settings APIs use the call method. Further, we are restricting apps writing to the system settings. If the app is targeting API higher than Lollipop MR1 we do not let them have their settings in the system ones. Otherwise, we warn that this will become an error. System apps like GMS core can change anything like the system or shell or root. Since old apps can add their settings, this can increase the system memory footprint with no limit. Therefore, we limit the amount of settings data an app can write to the system settings before starting to reject new data. Another problem with the system settings was that an app with a permission to write there can put invalid values for the settings. We now have validators for these settings that ensure only valid values are accepted. Since apps can put their settings in the system table, when the app is uninstalled this data is stale in the sytem table without ever being used. Now we keep the package that last changed the setting and when the package is removed all settings it touched that are not in the ones defined in the APIs are dropped. Keeping in memory settings means that we cannot handle arbitrary SQL operations, rather the supported operations are on a single setting by name and all settings (querying). This should not be a problem in practice but we have to verify it. For that reason, we log unsupported SQL operations to the event log to do some crunching and see what if any cases we should additionally support. There are also tests for the settings provider in this change. Change-Id: I941dc6e567588d9812905b147dbe1a3191c8dd68
* First iteration of a public UsageStats APIAdam Lesinski2014-07-181-0/+14
| | | | | | | | | | UsageStats API that allows apps to get a list of packages that have been recently used, along with basic stats like how long they have been in the foreground and the most recent time they were running. Bug: 15165667 Change-Id: I2a2d1ff69bd0b5703ac3d9de1780df42ad90d439
* Make AtomicFile a public API. It's about time!Dianne Hackborn2012-07-311-0/+233
Change-Id: Ib34e294747405b7ab709cb0bbb2d9a0cc80ce86a