Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: expose getApplicationInfo #187

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading