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_INFO,
20         RestoreError.MISSING_WIDGET_PROVIDER,
21         RestoreError.INVALID_LOCATION,
22         RestoreError.SHORTCUT_NOT_FOUND,
23         RestoreError.APP_NOT_INSTALLED,
24         RestoreError.WIDGETS_DISABLED,
25         RestoreError.PROFILE_NOT_RESTORED,
26         RestoreError.WIDGET_REMOVED,
27         RestoreError.GRID_MIGRATION_FAILURE,
28         RestoreError.NO_SEARCH_WIDGET,
29         RestoreError.INVALID_WIDGET_ID
30     )
31     annotation class RestoreError {
32         companion object {
33             const val PROFILE_DELETED = "user_profile_deleted"
34             const val MISSING_INFO = "missing_information_when_loading"
35             const val MISSING_WIDGET_PROVIDER = "missing_widget_provider"
36             const val INVALID_LOCATION = "invalid_size_or_location"
37             const val SHORTCUT_NOT_FOUND = "shortcut_not_found"
38             const val APP_NOT_INSTALLED = "app_not_installed"
39             const val WIDGETS_DISABLED = "widgets_disabled"
40             const val PROFILE_NOT_RESTORED = "profile_not_restored"
41             const val WIDGET_REMOVED = "widget_not_found"
42             const val GRID_MIGRATION_FAILURE = "grid_migration_failed"
43             const val NO_SEARCH_WIDGET = "no_search_widget"
44             const val INVALID_WIDGET_ID = "invalid_widget_id"
45         }
46     }
47 
48     companion object {
49         const val TAG = "LauncherRestoreEventLogger"
50 
newInstancenull51         fun newInstance(context: Context?): LauncherRestoreEventLogger {
52             return ResourceBasedOverride.Overrides.getObject(
53                 LauncherRestoreEventLogger::class.java,
54                 context,
55                 R.string.launcher_restore_event_logger_class
56             )
57         }
58     }
59 
60     /**
61      * For logging when multiple items of a given data type failed to restore.
62      *
63      * @param dataType The data type that was not restored.
64      * @param count the number of data items that were not restored.
65      * @param error error type for why the data was not restored.
66      */
logLauncherItemsRestoreFailednull67     open fun logLauncherItemsRestoreFailed(dataType: String, count: Int, error: String?) {
68         // no-op
69     }
70 
71     /**
72      * For logging when multiple items of a given data type were successfully restored.
73      *
74      * @param dataType The data type that was restored.
75      * @param count the number of data items restored.
76      */
logLauncherItemsRestorednull77     open fun logLauncherItemsRestored(dataType: String, count: Int) {
78         // no-op
79     }
80 
81     /**
82      * Helper to log successfully restoring a single item from the Favorites table.
83      *
84      * @param favoritesId The id of the item type from [Favorites] that was restored.
85      */
logSingleFavoritesItemRestorednull86     open fun logSingleFavoritesItemRestored(favoritesId: Int) {
87         // no-op
88     }
89 
90     /**
91      * Helper to log successfully restoring multiple items from the Favorites table.
92      *
93      * @param favoritesId The id of the item type from [Favorites] that was restored.
94      * @param count number of items that restored.
95      */
logFavoritesItemsRestorednull96     open fun logFavoritesItemsRestored(favoritesId: Int, count: Int) {
97         // no-op
98     }
99 
100     /**
101      * Helper to log a failure to restore a single item from the Favorites table.
102      *
103      * @param favoritesId The id of the item type from [Favorites] that was not restored.
104      * @param error error type for why the data was not restored.
105      */
logSingleFavoritesItemRestoreFailednull106     open fun logSingleFavoritesItemRestoreFailed(favoritesId: Int, @RestoreError error: String?) {
107         // no-op
108     }
109 
110     /**
111      * Helper to log a failure to restore items from the Favorites table.
112      *
113      * @param favoritesId The id of the item type from [Favorites] that was not restored.
114      * @param count number of items that failed to restore.
115      * @param error error type for why the data was not restored.
116      */
logFavoritesItemsRestoreFailednull117     open fun logFavoritesItemsRestoreFailed(
118         favoritesId: Int,
119         count: Int,
120         @RestoreError error: String?
121     ) {
122         // no-op
123     }
124 
125     /**
126      * Uses the current [restoreEventLogger] to report its results to the [backupManager]. Use when
127      * done restoring items for Launcher.
128      */
reportLauncherRestoreResultsnull129     open fun reportLauncherRestoreResults() {
130         // no-op
131     }
132 }
133