-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1937 from OneSignal/player-model/handle-DeadSyste…
…mException [Player model] Handle DeadSystemException
- Loading branch information
Showing
10 changed files
with
293 additions
and
131 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
OneSignalSDK/onesignal/src/main/java/com/onesignal/ApplicationInfoHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.onesignal | ||
|
||
import android.annotation.TargetApi | ||
import android.content.Context | ||
import android.content.pm.ApplicationInfo | ||
import android.content.pm.PackageManager | ||
import android.os.DeadSystemException | ||
import android.util.AndroidException | ||
|
||
class ApplicationInfoHelper { | ||
companion object { | ||
// Safe to cache as nothing can change the app while it is running. | ||
private var cachedInfo: ApplicationInfo? = null | ||
|
||
@TargetApi(24) | ||
fun getInfo(context: Context): ApplicationInfo? { | ||
if (cachedInfo != null) { | ||
return cachedInfo | ||
} | ||
|
||
val packageManager = context.packageManager | ||
return try { | ||
// Using this instead of context.applicationInfo as it's metaData is always null | ||
cachedInfo = packageManager.getApplicationInfo( | ||
context.packageName, | ||
PackageManager.GET_META_DATA, | ||
) | ||
cachedInfo | ||
} catch (e: AndroidException) { | ||
// Suppressing DeadSystemException as the app is already dying for | ||
// another reason and allowing this exception to bubble up would | ||
// create a red herring for app developers. We still re-throw | ||
// others, as we don't want to silently hide other issues. | ||
if (e !is DeadSystemException) { | ||
throw e | ||
} | ||
null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.