Skip to content

Commit 9731afd

Browse files
authored
android: use PackageManager to determine install AppSourceChecker (#517)
We were using MaybeGoogle to determine whether the app was installed from the Play Store, but this has not worked since the refactor. Fixes tailscale/tailscale#13442 Updates tailscale/corp#23283 Signed-off-by: kari-ts <[email protected]>
1 parent 9654bb5 commit 9731afd

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
lines changed

android/src/main/java/com/tailscale/ipn/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner {
7777

7878
override fun getPlatformDNSConfig(): String = dns.dnsConfigAsString
7979

80-
override fun isPlayVersion(): Boolean = MaybeGoogle.isGoogle()
80+
override fun getInstallSource(): String = AppSourceChecker.getInstallSource(this)
8181

8282
override fun shouldUseGoogleDNSFallback(): Boolean = BuildConfig.USE_GOOGLE_DNS_FALLBACK
8383

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Tailscale Inc & AUTHORS
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
package com.tailscale.ipn
4+
5+
import android.content.Context
6+
import android.os.Build
7+
import android.util.Log
8+
9+
object AppSourceChecker {
10+
11+
const val TAG = "AppSourceChecker"
12+
13+
fun getInstallSource(context: Context): String {
14+
val packageManager = context.packageManager
15+
val packageName = context.packageName
16+
Log.d(TAG, "Package name: $packageName")
17+
18+
val installerPackageName = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
19+
packageManager.getInstallSourceInfo(packageName).installingPackageName
20+
} else {
21+
packageManager.getInstallerPackageName(packageName)
22+
}
23+
24+
Log.d(TAG, "Installer package name: $installerPackageName")
25+
26+
return when (installerPackageName) {
27+
"com.android.vending" -> "googleplay"
28+
"org.fdroid.fdroid" -> "fdroid"
29+
"com.amazon.venezia" -> "amazon"
30+
null -> "unknown"
31+
else -> "unknown($installerPackageName)"
32+
}
33+
}
34+
}

android/src/main/java/com/tailscale/ipn/MaybeGoogle.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

libtailscale/backend.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ type settingsFunc func(*router.Config, *dns.OSConfig) error
105105
func (a *App) runBackend(ctx context.Context) error {
106106
paths.AppSharedDir.Store(a.dataDir)
107107
hostinfo.SetOSVersion(a.osVersion())
108-
if !a.appCtx.IsPlayVersion() {
109-
hostinfo.SetPackage("nogoogle")
110-
}
108+
hostinfo.SetPackage(a.appCtx.GetInstallSource())
111109
deviceModel := a.modelName()
112110
if a.isChromeOS() {
113111
deviceModel = "ChromeOS: " + deviceModel

libtailscale/interfaces.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ type AppContext interface {
3333
// GetModelName gets the Android device's model name.
3434
GetModelName() (string, error)
3535

36-
// IsPlayVersion reports whether this is the Google Play version of the app
37-
// (as opposed to F-droid/sideloaded).
38-
IsPlayVersion() bool
36+
// GetInstallSource gets information about how the app was installed or updated.
37+
GetInstallSource() string
3938

4039
// ShouldUseGoogleDNSFallback reports whether or not to use Google for DNS fallback.
4140
ShouldUseGoogleDNSFallback() bool

0 commit comments

Comments
 (0)