• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.backuprestore
2 
3 import android.content.Context
4 import androidx.annotation.StringDef
5 import com.android.launcher3.LauncherSettings.Favorites
6 import com.android.launcher3.R
7 import com.android.launcher3.util.ResourceBasedOverride
8 
9 /**
10  * Wrapper for logging Restore event metrics for both success and failure to restore the Launcher
11  * workspace from a backup.
12  */
13 open class LauncherRestoreEventLogger : ResourceBasedOverride {
14 
15     /** Enumeration of potential errors returned to calls of pause/resume app updates. */
16     @Retention(AnnotationRetention.SOURCE)
17     @StringDef(
18         RestoreError.PROFILE_DELETED,
19         RestoreError.MISSING_WIDGET_PROVIDER,
20         RestoreError.OVERLAPPING_ITEM,
21         RestoreError.INVALID_WIDGET_SIZE,
22         RestoreError.INVALID_WIDGET_CONTAINER,
23         RestoreError.SHORTCUT_NOT_FOUND,
24         RestoreError.APP_NO_TARGET_PACKAGE,
25         RestoreError.APP_NO_DB_INTENT,
26         RestoreError.APP_NO_LAUNCH_INTENT,
27         RestoreError.APP_NOT_RESTORED_OR_INSTALLING,
28         RestoreError.APP_NOT_INSTALLED_EXTERNAL_MEDIA,
29         RestoreError.WIDGETS_DISABLED,
30         RestoreError.PROFILE_NOT_RESTORED,
31         RestoreError.WIDGET_REMOVED,
32         RestoreError.DATABASE_FILE_NOT_RESTORED,
33         RestoreError.GRID_MIGRATION_FAILURE,
34         RestoreError.NO_SEARCH_WIDGET,
35         RestoreError.INVALID_WIDGET_ID,
36         RestoreError.OTHER_WIDGET_INFLATION_FAIL,
37         RestoreError.UNSPECIFIED_WIDGET_INFLATION_RESULT,
38         RestoreError.UNRESTORED_PENDING_WIDGET,
39         RestoreError.INVALID_CUSTOM_WIDGET_ID,
40     )
41     annotation class RestoreError {
42         companion object {
43             const val PROFILE_DELETED = "user_profile_deleted"
44             const val MISSING_WIDGET_PROVIDER = "missing_widget_provider"
45             const val OVERLAPPING_ITEM = "overlapping_item"
46             const val INVALID_WIDGET_SIZE = "invalid_widget_size"
47             const val INVALID_WIDGET_CONTAINER = "invalid_widget_container"
48             const val SHORTCUT_NOT_FOUND = "shortcut_not_found"
49             const val APP_NO_TARGET_PACKAGE = "app_no_target_package"
50             const val APP_NO_DB_INTENT = "app_no_db_intent"
51             const val APP_NO_LAUNCH_INTENT = "app_no_launch_intent"
52             const val APP_NOT_RESTORED_OR_INSTALLING = "app_not_restored_or_installed"
53             const val APP_NOT_INSTALLED_EXTERNAL_MEDIA = "app_not_installed_external_media"
54             const val WIDGETS_DISABLED = "widgets_disabled"
55             const val PROFILE_NOT_RESTORED = "profile_not_restored"
56             const val DATABASE_FILE_NOT_RESTORED = "db_file_not_restored"
57             const val WIDGET_REMOVED = "widget_not_found"
58             const val GRID_MIGRATION_FAILURE = "grid_migration_failed"
59             const val NO_SEARCH_WIDGET = "no_search_widget"
60             const val INVALID_WIDGET_ID = "invalid_widget_id"
61             const val OTHER_WIDGET_INFLATION_FAIL = "other_widget_fail"
62             const val UNSPECIFIED_WIDGET_INFLATION_RESULT = "unspecified_widget_inflation_result"
63             const val UNRESTORED_PENDING_WIDGET = "unrestored_pending_widget"
64             const val INVALID_CUSTOM_WIDGET_ID = "invalid_custom_widget_id"
65         }
66     }
67 
68     companion object {
69         const val TAG = "LauncherRestoreEventLogger"
70 
newInstancenull71         fun newInstance(context: Context?): LauncherRestoreEventLogger {
72             return ResourceBasedOverride.Overrides.getObject(
73                 LauncherRestoreEventLogger::class.java,
74                 context,
75                 R.string.launcher_restore_event_logger_class,
76             )
77         }
78     }
79 
80     /**
81      * For logging when multiple items of a given data type failed to restore.
82      *
83      * @param dataType The data type that was not restored.
84      * @param count the number of data items that were not restored.
85      * @param error error type for why the data was not restored.
86      */
logLauncherItemsRestoreFailednull87     open fun logLauncherItemsRestoreFailed(dataType: String, count: Int, error: String?) {
88         // no-op
89     }
90 
91     /**
92      * For logging when multiple items of a given data type were successfully restored.
93      *
94      * @param dataType The data type that was restored.
95      * @param count the number of data items restored.
96      */
logLauncherItemsRestorednull97     open fun logLauncherItemsRestored(dataType: String, count: Int) {
98         // no-op
99     }
100 
101     /**
102      * Helper to log successfully restoring a single item from the Favorites table.
103      *
104      * @param favoritesId The id of the item type from [Favorites] that was restored.
105      */
logSingleFavoritesItemRestorednull106     open fun logSingleFavoritesItemRestored(favoritesId: Int) {
107         // no-op
108     }
109 
110     /**
111      * Helper to log successfully restoring multiple items from the Favorites table.
112      *
113      * @param favoritesId The id of the item type from [Favorites] that was restored.
114      * @param count number of items that restored.
115      */
logFavoritesItemsRestorednull116     open fun logFavoritesItemsRestored(favoritesId: Int, count: Int) {
117         // no-op
118     }
119 
120     /**
121      * Helper to log a failure to restore a single item from the Favorites table.
122      *
123      * @param favoritesId The id of the item type from [Favorites] that was not restored.
124      * @param error error type for why the data was not restored.
125      */
logSingleFavoritesItemRestoreFailednull126     open fun logSingleFavoritesItemRestoreFailed(favoritesId: Int, @RestoreError error: String?) {
127         // no-op
128     }
129 
130     /**
131      * Helper to log a failure to restore items from the Favorites table.
132      *
133      * @param favoritesId The id of the item type from [Favorites] that was not restored.
134      * @param count number of items that failed to restore.
135      * @param error error type for why the data was not restored.
136      */
logFavoritesItemsRestoreFailednull137     open fun logFavoritesItemsRestoreFailed(
138         favoritesId: Int,
139         count: Int,
140         @RestoreError error: String?,
141     ) {
142         // no-op
143     }
144 
145     /**
146      * Uses the current [restoreEventLogger] to report its results to the [backupManager]. Use when
147      * done restoring items for Launcher.
148      */
reportLauncherRestoreResultsnull149     open fun reportLauncherRestoreResults() {
150         // no-op
151     }
152 }
153