Skip to content

Commit

Permalink
chore: expose getApplicationInfo (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Oct 11, 2024
1 parent 1f3d76b commit d770f8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions posthog-android/api/posthog-android.api
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public final class com/posthog/android/internal/MainHandler {
public final fun getMainLooper ()Landroid/os/Looper;
}

public final class com/posthog/android/internal/PostHogAndroidUtilsKt {
public static final fun getApplicationInfo (Landroid/content/Context;)Landroid/content/pm/ApplicationInfo;
}

public abstract interface class com/posthog/android/replay/PostHogDrawableConverter {
public abstract fun convert (Landroid/graphics/drawable/Drawable;)Landroid/graphics/Bitmap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager.GET_META_DATA
Expand All @@ -16,6 +17,7 @@ import android.os.Process
import android.telephony.TelephonyManager
import android.util.DisplayMetrics
import android.view.WindowManager
import com.posthog.PostHogInternal
import com.posthog.android.PostHogAndroidConfig

@Suppress("DEPRECATION")
Expand Down Expand Up @@ -186,3 +188,20 @@ internal fun String.tryParse(config: PostHogAndroidConfig): Uri? {
internal fun isMainThread(mainHandler: MainHandler): Boolean {
return Thread.currentThread().id == mainHandler.mainLooper.thread.id
}

@PostHogInternal
@Suppress("DEPRECATION")
@Throws(PackageManager.NameNotFoundException::class)
public fun getApplicationInfo(context: Context): ApplicationInfo =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context
.packageManager
.getApplicationInfo(
context.packageName,
PackageManager.ApplicationInfoFlags.of(GET_META_DATA.toLong()),
)
} else {
context
.packageManager
.getApplicationInfo(context.packageName, GET_META_DATA)
}

0 comments on commit d770f8b

Please sign in to comment.