[SettingsProvider] force close MemoryIntArray before garbage collection

BUG: 277448672
BUG: 274971295
Test: builds
Change-Id: I2f8c9e65721dcfc41a382e7bf9e0c2ad7e1c66aa
This commit is contained in:
Songchun Fan
2023-04-17 15:43:47 -07:00
parent 48e1f12c18
commit f3af9c52e7

View File

@@ -3037,14 +3037,23 @@ public final class Settings {
public void destroy() {
try {
// If this process is the system server process, mArray is the same object as
// the memory int array kept inside SetingsProvider, so skipping the close()
if (!Settings.isInSystemServer()) {
// the memory int array kept inside SettingsProvider, so skipping the close()
if (!Settings.isInSystemServer() && !mArray.isClosed()) {
mArray.close();
}
} catch (IOException e) {
Log.e(TAG, "Error closing backing array", e);
}
}
@Override
protected void finalize() throws Throwable {
try {
destroy();
} finally {
super.finalize();
}
}
}
private static final class ContentProviderHolder {