Skip to content

Commit

Permalink
Fix #973 Make sure all resources are closed in RegistrationIntentServ…
Browse files Browse the repository at this point in the history
…ice (#998)

* Fix #973 Make sure all resources are closed

Make sure all FileStream and FileLock are closed using AutoClose pattern.
  • Loading branch information
chkuang-g authored Jun 17, 2022
1 parent 5f23f71 commit a2279e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,19 @@ public static void writeTokenToInternalStorage(Context context, String token) {
// Write out the buffer length into the first four bytes.
sizeBuffer.order(ByteOrder.LITTLE_ENDIAN);
sizeBuffer.putInt(buffer.length);
FileLock lock = null;
try {
// Acquire lock. This prevents the C++ code from consuming and clearing the file while we
// append to it.
FileOutputStream lockFileStream = context.openFileOutput(MessageWriter.LOCK_FILE, 0);
lock = lockFileStream.getChannel().lock();

FileOutputStream outputStream =
context.openFileOutput(MessageWriter.STORAGE_FILE, Context.MODE_APPEND);
// We send both the buffer length and the buffer itself so that we can potentially process
// more than one event in the case where they get queued up.
try (FileOutputStream lockFileStream = context.openFileOutput(MessageWriter.LOCK_FILE, 0);
// Acquire lock. This prevents the C++ code from consuming and clearing the file while we
// append to it.
FileLock lock = lockFileStream.getChannel().lock();
FileOutputStream outputStream =
context.openFileOutput(MessageWriter.STORAGE_FILE, Context.MODE_APPEND)) {
// We send both the buffer length and the buffer itself so that we can potentially
// process more than one event in the case where they get queued up.
outputStream.write(sizeBuffer.array());
outputStream.write(buffer);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
// Release the lock.
try {
if (lock != null) {
lock.release();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Expand Down
22 changes: 12 additions & 10 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ All Firebase SDKs | platform(com.google.firebase:firebase-bom:30.1.0)
| | (Android Bill of Materials)
Firebase AdMob | libfirebase_admob.a
| | libfirebase_app.a
| | com.google.firebase:firebase-analytics
| | com.google.firebase:firebase-analytics
| | (Maven package)
| | com.google.firebase:firebase-ads:19.8.0
| | com.google.firebase:firebase-ads:19.8.0
| | (Maven package)
Firebase Analytics | libfirebase_analytics.a
| | libfirebase_app.a
| | com.google.firebase:firebase-analytics
| | com.google.firebase:firebase-analytics
| | (Maven package)
Firebase Authentication | libfirebase_auth.a
| | libfirebase_app.a
| | com.google.firebase:firebase-analytics
| | com.google.firebase:firebase-analytics
| | (Maven package)
| | com.google.firebase:firebase-auth
| | com.google.firebase:firebase-auth
| | (Maven package)
Firebase Dynamic Links | libfirebase_dynamic_links.a
| | libfirebase_app.a
| | com.google.firebase:firebase-analytics
| | com.google.firebase:firebase-analytics
| | (Maven package)
| | com.google.firebase:firebase-dynamic-links
| | (Maven package)
Expand Down Expand Up @@ -156,7 +156,7 @@ Firebase Storage | libfirebase_storage.a
| | (Maven package)
| | com.google.firebase:firebase-auth
| | (Maven package)
Google Play services module| com.google.android.gms:play-services-base:18.0.1
Google Play services module| com.google.android.gms:play-services-base:18.0.1
| | (Maven package)

The Firebase C++ SDK uses an Android BoM (Bill of Materials) to specify a single
Expand Down Expand Up @@ -615,6 +615,8 @@ code.
- Changes
- General (Android): Switched over to Android BoM (Bill of Materials)
for dependency versions. This requires Gradle 5.
- Messaging (Android): Fixed #973. Make sure all the resources are closed in
`RegistrationIntentService`.

### 9.1.0
- Changes
Expand Down Expand Up @@ -710,16 +712,16 @@ code.
and include support for ARM-based Mac systems.
- General (iOS): iOS SDKs are now built using Xcode 12.2.
- Messaging (Android): Fixes an issue to receive token when
initialize the app.
initialize the app.
([#667](https://github.com/firebase/firebase-cpp-sdk/pull/667)).
- Auth (Desktop): Fix a crash that would occur if parsing the JSON
response from the server failed
([#692](https://github.com/firebase/firebase-cpp-sdk/pull/692)).

### 8.5.0
- Changes
- General: Updating Android and iOS dependencies to the latest.
- General: Fixes an issue with generating Proguard files.
- General: Fixes an issue with generating Proguard files.
([#664](https://github.com/firebase/firebase-cpp-sdk/pull/664)).

### 8.4.0
Expand Down

0 comments on commit a2279e9

Please sign in to comment.