Skip to content

Commit 358f021

Browse files
committed
Logs: Use profile verifier compilation status to debug baseline profiles
For more info see: https://developer.android.com/topic/performance/ baselineprofiles/debug-baseline-profiles#installation_issues
1 parent 177697b commit 358f021

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/main/MainActivity.kt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.woocommerce.android.ui.main
44

55
import NotificationsPermissionCard
6+
import android.annotation.SuppressLint
67
import android.app.Activity
78
import android.app.ProgressDialog
89
import android.content.Intent
@@ -32,11 +33,15 @@ import androidx.fragment.app.DialogFragment
3233
import androidx.fragment.app.Fragment
3334
import androidx.fragment.app.FragmentManager
3435
import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
36+
import androidx.lifecycle.lifecycleScope
3537
import androidx.navigation.NavController
3638
import androidx.navigation.NavDestination
3739
import androidx.navigation.NavOptions
3840
import androidx.navigation.fragment.FragmentNavigatorExtras
3941
import androidx.navigation.fragment.NavHostFragment
42+
import androidx.profileinstaller.ProfileVerifier
43+
import androidx.profileinstaller.ProfileVerifier.CompilationStatus
44+
import androidx.work.await
4045
import com.automattic.android.tracks.crashlogging.CrashLogging
4146
import com.google.android.material.appbar.AppBarLayout
4247
import com.woocommerce.android.AppPrefs
@@ -109,11 +114,15 @@ import com.woocommerce.android.util.ChromeCustomTabUtils
109114
import com.woocommerce.android.util.PackageUtils
110115
import com.woocommerce.android.util.WooAnimUtils.Duration
111116
import com.woocommerce.android.util.WooAnimUtils.animateBottomBar
117+
import com.woocommerce.android.util.WooLog
112118
import com.woocommerce.android.util.WooPermissionUtils
113119
import com.woocommerce.android.viewmodel.MultiLiveEvent
114120
import com.woocommerce.android.widgets.AppRatingDialog
115121
import com.woocommerce.android.widgets.DisabledAppBarLayoutBehavior
116122
import dagger.hilt.android.AndroidEntryPoint
123+
import kotlinx.coroutines.Dispatchers
124+
import kotlinx.coroutines.launch
125+
import kotlinx.coroutines.withContext
117126
import org.wordpress.android.login.LoginAnalyticsListener
118127
import org.wordpress.android.login.LoginMode
119128
import org.wordpress.android.util.NetworkUtils
@@ -389,6 +398,7 @@ class MainActivity :
389398

390399
override fun onResume() {
391400
super.onResume()
401+
lifecycleScope.launch { logCompilationStatus() }
392402
AnalyticsTracker.trackViewShown(this)
393403

394404
// Track if App was opened from a widget
@@ -404,6 +414,49 @@ class MainActivity :
404414
viewModel.showFeatureAnnouncementIfNeeded()
405415
}
406416

417+
/**
418+
* This method is used for debugging baseline profile purpose based on profile verifier compilation status.
419+
*
420+
* @see <a href="https://developer.android.com/topic/performance/baselineprofiles/debug-baseline-profiles#installation_issues</a> for more details.
421+
*/
422+
@Suppress("MaxLineLength")
423+
@SuppressLint("RestrictedApi")
424+
private suspend fun logCompilationStatus() {
425+
withContext(Dispatchers.IO) {
426+
val status = ProfileVerifier.getCompilationStatusAsync().await()
427+
when (status.profileInstallResultCode) {
428+
CompilationStatus.RESULT_CODE_NO_PROFILE_INSTALLED ->
429+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: Baseline Profile not found")
430+
431+
CompilationStatus.RESULT_CODE_COMPILED_WITH_PROFILE ->
432+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: Compiled with profile")
433+
434+
CompilationStatus.RESULT_CODE_PROFILE_ENQUEUED_FOR_COMPILATION ->
435+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: Enqueued for compilation")
436+
437+
CompilationStatus.RESULT_CODE_COMPILED_WITH_PROFILE_NON_MATCHING ->
438+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: App was installed through Play store")
439+
440+
CompilationStatus.RESULT_CODE_ERROR_PACKAGE_NAME_DOES_NOT_EXIST ->
441+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: PackageName not found")
442+
443+
CompilationStatus.RESULT_CODE_ERROR_CACHE_FILE_EXISTS_BUT_CANNOT_BE_READ ->
444+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: Cache file exists but cannot be read")
445+
446+
CompilationStatus.RESULT_CODE_ERROR_CANT_WRITE_PROFILE_VERIFICATION_RESULT_CACHE_FILE ->
447+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: Can't write cache file")
448+
449+
CompilationStatus.RESULT_CODE_ERROR_UNSUPPORTED_API_VERSION ->
450+
WooLog.d(WooLog.T.BASELINE_PROFILES, "ProfileInstaller: Enqueued for compilation")
451+
452+
else -> WooLog.d(
453+
WooLog.T.BASELINE_PROFILES,
454+
"ProfileInstaller: Profile not compiled or enqueued [Result Code: ${status.profileInstallResultCode}]"
455+
)
456+
}
457+
}
458+
}
459+
407460
override fun onPause() {
408461
binding.appBarLayout.removeOnOffsetChangedListener(appBarOffsetListener)
409462
super.onPause()

WooCommerce/src/main/kotlin/com/woocommerce/android/util/WooLog.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ object WooLog {
4444
GOOGLE_ADS,
4545
POS,
4646
CUSTOM_FIELDS,
47-
SHIPPING_LABELS
47+
SHIPPING_LABELS,
48+
BASELINE_PROFILES,
4849
}
4950

5051
// Breaking convention to be consistent with org.wordpress.android.util.AppLog

0 commit comments

Comments
 (0)