Analytics.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. package com.epson.iprint.prtlogger;
  2. import android.content.Context;
  3. import androidx.annotation.NonNull;
  4. import androidx.annotation.Nullable;
  5. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  6. import epson.print.IprintApplication;
  7. import epson.print.MyPrinter;
  8. import epson.print.Util.EPLog;
  9. import epson.print.copy.Component.ecopycomponent.CopyParams;
  10. import epson.print.rpcopy.Component.ecopycomponent.RepeatCopyAnalyticsParams;
  11. import epson.print.screen.PrintProgress;
  12. import epson.print.screen.PrintSetting;
  13. import epson.scan.lib.I1ScanParams;
  14. public class Analytics {
  15. public static final String ACTION_ID_HOME_BUY_INK = "Home-BuyInk";
  16. public static final String ACTION_ID_HOME_CAMERACOPY = "Home-CameraCopy";
  17. public static final String ACTION_ID_HOME_COPY = "Home-Copy";
  18. public static final String ACTION_ID_HOME_DOCUMENT = "Home-Document";
  19. public static final String ACTION_ID_HOME_INFO = "Home-Info";
  20. public static final String ACTION_ID_HOME_MAINTAIN = "Home-Maintain";
  21. public static final String ACTION_ID_HOME_MEMORYCARD_ACCESS = "Home-MemoryCardAccess";
  22. public static final String ACTION_ID_HOME_ONLINE_STORAGE = "Home-OnlineStorage";
  23. public static final String ACTION_ID_HOME_PHOTO = "Home-Photo";
  24. public static final String ACTION_ID_HOME_PHOTO_TRANSFER = "Home-PhotoTransfer";
  25. public static final String ACTION_ID_HOME_READY_INK = "Home-ReadyInk";
  26. public static final String ACTION_ID_HOME_SCAN = "Home-Scan";
  27. public static final String ACTION_ID_HOME_WEB = "Home-Web";
  28. public static final String ACTION_ID_MAINTENANCE_BUY_INK = "Maintenance-BuyInk";
  29. public static final String ACTION_ID_MAINTENANCE_FIRMWARE_UPDATE = "Firmware Update";
  30. public static final String ACTION_ID_MAINTENANCE_HEAD_CLEANING = "HeadCleaning";
  31. public static final String ACTION_ID_MAINTENANCE_NOZZLE_CHECK = "NozzlleCheck";
  32. public static final String ACTION_ID_MAINTENANCE_READY_INK = "Maintenance-ReadyInk";
  33. public static final String ACTION_ID_SETUP_BLE = "PrinterSetup-BLE";
  34. public static final int CONNECTION_TYPE_NO_CONNECTION_TYPE = -1;
  35. public static final int CONNECTION_TYPE_OTG = 11;
  36. public static final int CONNECTION_TYPE_REMOTE = 10;
  37. private static final int CUSTOM_DIMENSION_BLE_PATH = 1;
  38. private static final int CUSTOM_DIMENSION_BLE_RESULT = 2;
  39. private static final int CUSTOM_DIMENSION_DEBUG = 28;
  40. private static final String CUSTOM_DIMENSION_DEBUG_VALUE = "develop";
  41. public static final String EXTENSION_STRING_WEB = "http";
  42. public static final String SCREEN_ID_HOME = "Home";
  43. private static final String TAG = "Analytics";
  44. public static final int WIFI_DIRECT_TYPE_NORMAL_WIFI_DIRECT = 1;
  45. public static final int WIFI_DIRECT_TYPE_NOT_WIFI_DIRECT = 0;
  46. public static final int WIFI_DIRECT_TYPE_SIMPLE_AP = 2;
  47. private static String getActionString(int i) {
  48. if (i == 4100) {
  49. return "Intent-Web";
  50. }
  51. if (i == 4353) {
  52. return "Intent-Scan";
  53. }
  54. switch (i) {
  55. case 1:
  56. return "Photos";
  57. case 2:
  58. return "Saved Documents";
  59. case 3:
  60. return "Web";
  61. case 4:
  62. return "Scan-Print";
  63. case 5:
  64. return "Document Capture";
  65. default:
  66. switch (i) {
  67. case 256:
  68. return "Evernote";
  69. case 257:
  70. return "Google Drive";
  71. case PrintLog.PRINT_SOURCE_DROPBOX /*258*/:
  72. return "Dropbox";
  73. case PrintLog.PRINT_SOURCE_BOX /*259*/:
  74. return "Box";
  75. case PrintLog.PRINT_SOURCE_ONEDRIVE /*260*/:
  76. return "OneDrive";
  77. case PrintLog.PRINT_SOURCE_MYPOCKET /*261*/:
  78. return "MyPocket";
  79. default:
  80. switch (i) {
  81. case 4097:
  82. return "Intent-Photos";
  83. case 4098:
  84. return "Intent-Documents";
  85. default:
  86. switch (i) {
  87. case PrintLog.ACTION_ID_MEMORY_CARD_COPY_TO_PRINTER:
  88. case PrintLog.ACTION_ID_MEMORY_CARD_COPY_TO_MOBILE_DEVICE:
  89. return "Memory Access";
  90. case PrintLog.ACTION_PHOTO_TRANSFER:
  91. return "Send Photo";
  92. case PrintLog.ACTION_COPY:
  93. return "Copy";
  94. case PrintLog.ACTION_SCAN:
  95. return "Scan";
  96. case PrintLog.ACTION_REPEAT_COPY:
  97. return "RepeatCopy";
  98. default:
  99. return "";
  100. }
  101. }
  102. }
  103. }
  104. }
  105. @NonNull
  106. private static String getConnectionTypeString(int i) {
  107. switch (i) {
  108. case 0:
  109. return "Infra";
  110. case 1:
  111. return "Wi-Fi Direct";
  112. case 2:
  113. return "SimpleAP";
  114. default:
  115. switch (i) {
  116. case 10:
  117. return "Remote";
  118. case 11:
  119. return "OTG";
  120. default:
  121. return "";
  122. }
  123. }
  124. }
  125. private static String getDateString(int i) {
  126. return i == 0 ? "OFF" : "ON";
  127. }
  128. private static String getOnOff(boolean z) {
  129. return z ? "ON" : "OFF";
  130. }
  131. private static String getScanColorTypeString(int i) {
  132. switch (i) {
  133. case 1:
  134. return "Color";
  135. case 2:
  136. return "Grayscale";
  137. case 3:
  138. return "Monochrome";
  139. default:
  140. return "";
  141. }
  142. }
  143. private static String getScanDeviceString(int i) {
  144. switch (i) {
  145. case 0:
  146. return "DocumentTable";
  147. case 1:
  148. return "ADF";
  149. default:
  150. return "";
  151. }
  152. }
  153. private static String getScanGammaString(int i) {
  154. return i != 0 ? "1" : BoxConstants.ROOT_FOLDER_ID;
  155. }
  156. public enum SetUpResult {
  157. Success("Success"),
  158. Fail("Fail"),
  159. Error("Error"),
  160. Error106("Error-106"),
  161. Error119("Error-119");
  162. private final String name;
  163. private SetUpResult(String str) {
  164. name = str;
  165. }
  166. public String toString() {
  167. return name;
  168. }
  169. }
  170. public enum SetUpPath {
  171. Home("HomePopup"),
  172. Button("SetUpButton");
  173. private final String name;
  174. private SetUpPath(String str) {
  175. name = str;
  176. }
  177. public String toString() {
  178. return name;
  179. }
  180. }
  181. public static void sendPrintLog(@NonNull Context context, @NonNull PrintProgress.ProgressParams progressParams) {
  182. if (NewLoggerController.isLoggerEnabled(context)) {
  183. PrintLog printLog = progressParams.getPrintLog();
  184. if (printLog == null) {
  185. printLog = new PrintLog();
  186. }
  187. int printNumber = AnalyticsPreferences.getPrintNumber(context);
  188. EPLog.i(" ************** " + printNumber);
  189. if (printNumber > 0) {
  190. PrintSetting printSetting = progressParams.getPrintSetting(context);
  191. printSetting.loadSettings();
  192. HitBuilders.EventBuilder value = createEventBuilder().setCategory("function").setAction(getActionString(printLog)).setValue((long) (printNumber * printSetting.copiesValue));
  193. String defaultPrinterName = getDefaultPrinterName(context);
  194. if (defaultPrinterName != null) {
  195. value.setLabel(defaultPrinterName);
  196. }
  197. ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) value.setCustomDimension(2, getConnectionString(context))).setCustomDimension(3, Integer.toString(printSetting.paperSizeValue))).setCustomDimension(4, Integer.toString(printSetting.paperTypeValue))).setCustomDimension(5, Integer.toString(printSetting.qualityValue))).setCustomDimension(6, Integer.toString(getLayoutValue(printSetting)))).setCustomDimension(7, Integer.toString(printSetting.paperSourceValue))).setCustomDimension(8, Integer.toString(printSetting.colorValue))).setCustomDimension(9, Integer.toString(printSetting.duplexValue));
  198. if (printLog.previewType == 1) {
  199. ((HitBuilders.EventBuilder) value.setCustomDimension(11, progressParams.getApfMode() ? "ON" : "OFF")).setCustomDimension(10, getDateString(printSetting.printdate));
  200. }
  201. String sizeLimitString = getSizeLimitString(printLog.originalFileExtension, 150);
  202. if (!sizeLimitString.isEmpty()) {
  203. value.setCustomDimension(1, sizeLimitString);
  204. }
  205. String sizeLimitString2 = getSizeLimitString(printLog.callerPackage, 150);
  206. if (!sizeLimitString2.isEmpty()) {
  207. value.setCustomDimension(12, sizeLimitString2);
  208. }
  209. IprintApplication.getInstance().getDefaultTracker().send(value.build());
  210. }
  211. }
  212. }
  213. private static int getLayoutValue(PrintSetting printSetting) {
  214. int i = printSetting.layoutMultiPageValue;
  215. if (i == 0) {
  216. return printSetting.layoutValue;
  217. }
  218. if (i == 65536) {
  219. return 256;
  220. }
  221. if (i != 131072) {
  222. return i != 262144 ? 2 : 1024;
  223. }
  224. return 512;
  225. }
  226. @NonNull
  227. static String getSizeLimitString(String str, int i) {
  228. if (str == null) {
  229. return "";
  230. }
  231. int length = str.length();
  232. if (i > length) {
  233. i = length;
  234. }
  235. return str.substring(0, i);
  236. }
  237. public static String getDefaultPrinterName(@NonNull Context context) {
  238. return MyPrinter.getCurPrinter(context).getName();
  239. }
  240. @NonNull
  241. private static String getConnectionString(@NonNull Context context) {
  242. return getConnectionTypeString(AnalyticsPreferences.getConnectionPath(context));
  243. }
  244. private static String getActionString(PrintLog printLog) {
  245. return printLog == null ? "" : getActionString(printLog.uiRoute);
  246. }
  247. public static void sendScanI1Log(Context context, I1ScanParams i1ScanParams, CommonLog commonLog, boolean z) {
  248. if (commonLog != null && context != null && i1ScanParams != null && NewLoggerController.isLoggerEnabled(context)) {
  249. HitBuilders.EventBuilder createEventBuilder = createEventBuilder();
  250. setCommonData(commonLog, createEventBuilder);
  251. setScanDataFromI1(i1ScanParams, createEventBuilder, z);
  252. sendData(createEventBuilder);
  253. }
  254. }
  255. private static void setScanDataFromI1(@NonNull I1ScanParams i1ScanParams, @NonNull HitBuilders.EventBuilder eventBuilder, boolean z) {
  256. ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) eventBuilder.setCustomDimension(13, getScanDeviceString(i1ScanParams.inputDevice))).setCustomDimension(15, getScanColorTypeString(i1ScanParams.colorType))).setCustomDimension(16, Integer.toString(i1ScanParams.resolution))).setCustomDimension(17, getOnOff(i1ScanParams.twoSide != 0))).setCustomDimension(18, getScanGammaString(i1ScanParams.gamma))).setCustomDimension(19, Integer.toString(i1ScanParams.brightness))).setCustomDimension(41, getOnOff(z));
  257. }
  258. public static void sendCopyLog(@NonNull Context context, CopyParams copyParams, CommonLog commonLog) {
  259. if (copyParams != null && NewLoggerController.isLoggerEnabled(context)) {
  260. HitBuilders.EventBuilder createEventBuilder = createEventBuilder();
  261. setCommonData(commonLog, createEventBuilder);
  262. setCopyData(copyParams, createEventBuilder);
  263. sendData(createEventBuilder);
  264. }
  265. }
  266. private static void setCopyData(@NonNull CopyParams copyParams, @NonNull HitBuilders.EventBuilder eventBuilder) {
  267. ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) eventBuilder.setCustomDimension(20, copyParams.colorMode)).setCustomDimension(21, copyParams.density)).setCustomDimension(22, copyParams.magnification)).setCustomDimension(23, copyParams.paperSize)).setCustomDimension(24, copyParams.paperType)).setCustomDimension(25, copyParams.printDevice)).setCustomDimension(26, copyParams.copyType)).setCustomDimension(27, copyParams.copyQuality);
  268. }
  269. public static void sendRepeatCopyLog(@NonNull Context context, RepeatCopyAnalyticsParams repeatCopyAnalyticsParams, @NonNull CommonLog commonLog) {
  270. if (repeatCopyAnalyticsParams != null && NewLoggerController.isLoggerEnabled(context)) {
  271. HitBuilders.EventBuilder createEventBuilder = createEventBuilder();
  272. setCommonData(commonLog, createEventBuilder);
  273. setRepeatCopyData(repeatCopyAnalyticsParams, createEventBuilder);
  274. sendData(createEventBuilder);
  275. }
  276. }
  277. private static void setRepeatCopyData(@NonNull RepeatCopyAnalyticsParams repeatCopyAnalyticsParams, @NonNull HitBuilders.EventBuilder eventBuilder) {
  278. ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) ((HitBuilders.EventBuilder) eventBuilder.setCustomDimension(30, repeatCopyAnalyticsParams.colorMode)).setCustomDimension(31, repeatCopyAnalyticsParams.density)).setCustomDimension(32, repeatCopyAnalyticsParams.repeatLayout)).setCustomDimension(33, repeatCopyAnalyticsParams.paperSize)).setCustomDimension(34, repeatCopyAnalyticsParams.paperType)).setCustomDimension(35, repeatCopyAnalyticsParams.printDevice)).setCustomDimension(36, repeatCopyAnalyticsParams.copyQuality)).setCustomDimension(37, repeatCopyAnalyticsParams.removeBackground);
  279. sendDataIfNonNull(eventBuilder, 38, repeatCopyAnalyticsParams.XCutLine);
  280. sendDataIfNonNull(eventBuilder, 39, repeatCopyAnalyticsParams.XCutLineStyle);
  281. sendDataIfNonNull(eventBuilder, 40, repeatCopyAnalyticsParams.XCutLineWeight);
  282. }
  283. private static void sendDataIfNonNull(@NonNull HitBuilders.EventBuilder eventBuilder, int i, @Nullable String str) {
  284. if (str != null) {
  285. eventBuilder.setCustomDimension(i, str);
  286. }
  287. }
  288. public static void sendCommonLog(Context context, CommonLog commonLog) {
  289. if (NewLoggerController.isLoggerEnabled(context) && commonLog != null && context != null) {
  290. HitBuilders.EventBuilder createEventBuilder = createEventBuilder();
  291. setCommonData(commonLog, createEventBuilder);
  292. sendData(createEventBuilder);
  293. }
  294. }
  295. private static void setCommonData(@NonNull CommonLog commonLog, @NonNull HitBuilders.EventBuilder eventBuilder) {
  296. eventBuilder.setCategory("function").setAction(getActionString(commonLog.action)).setValue((long) commonLog.numberOfSheet);
  297. int i = commonLog.connectionType;
  298. if (i >= 0) {
  299. eventBuilder.setCustomDimension(2, getConnectionTypeString(i));
  300. }
  301. if (commonLog.printerName != null) {
  302. eventBuilder.setLabel(commonLog.printerName);
  303. }
  304. if (commonLog.callerPackage != null) {
  305. eventBuilder.setCustomDimension(12, getSizeLimitString(commonLog.callerPackage, 150));
  306. }
  307. setDirectionData(commonLog, eventBuilder);
  308. }
  309. private static void sendData(@NonNull HitBuilders.EventBuilder eventBuilder) {
  310. IprintApplication.getInstance().getDefaultTracker().send(eventBuilder.build());
  311. }
  312. private static void setDirectionData(CommonLog commonLog, HitBuilders.EventBuilder eventBuilder) {
  313. String str;
  314. switch (commonLog.action) {
  315. case PrintLog.ACTION_ID_MEMORY_CARD_COPY_TO_PRINTER /*8193*/:
  316. str = "toPrinter";
  317. break;
  318. case 8194:
  319. str = "toSmartPhone";
  320. break;
  321. default:
  322. return;
  323. }
  324. eventBuilder.setCustomDimension(1, str);
  325. }
  326. public static void savePrintInfo(@NonNull Context context, int i) {
  327. EPLog.i(" @@@@@@@@@@@@@ printSheet = " + i);
  328. AnalyticsPreferences.savePrintNumber(context, i);
  329. AnalyticsPreferences.saveConnectionPath(context, getConnectionType(context));
  330. }
  331. public static void cleanPrintNumber(@NonNull Context context) {
  332. AnalyticsPreferences.savePrintNumber(context, 0);
  333. }
  334. public static int getConnectionType(@NonNull Context context) {
  335. if (MyPrinter.isRemotePrinter(context)) {
  336. return 10;
  337. }
  338. if (MyPrinter.isPrinterRouteOtg(context)) {
  339. return 11;
  340. }
  341. return getWifiDirectTypeIprintV4(context);
  342. }
  343. public static void countScreen(@NonNull Context context, String str) {
  344. if (NewLoggerController.isLoggerEnabled(context)) {
  345. if (str == null) {
  346. EPLog.w(TAG, "ERROR: countScreen() screenId == null");
  347. return;
  348. }
  349. Tracker defaultTracker = IprintApplication.getInstance().getDefaultTracker();
  350. defaultTracker.setScreenName(str);
  351. defaultTracker.send(createScreenViewBuilder().build());
  352. }
  353. }
  354. public static void sendAction(@NonNull Context context, String str) {
  355. if (NewLoggerController.isLoggerEnabled(context)) {
  356. if (str == null) {
  357. EPLog.w(TAG, "ERROR: sendAction() actionId == null");
  358. } else {
  359. IprintApplication.getInstance().getDefaultTracker().send(createEventBuilder().setCategory("tap").setAction(str).build());
  360. }
  361. }
  362. }
  363. public static void sendSetup(String str, SetUpPath setUpPath, SetUpResult setUpResult) {
  364. HitBuilders.EventBuilder label = createEventBuilder().setCategory("setup").setAction(ACTION_ID_SETUP_BLE).setLabel(str);
  365. label.setCustomDimension(1, setUpPath.toString());
  366. label.setCustomDimension(2, setUpResult.toString());
  367. IprintApplication.getInstance().getDefaultTracker().send(label.build());
  368. }
  369. private static HitBuilders.EventBuilder createEventBuilder() {
  370. HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder();
  371. if (isAnalyticsDebug()) {
  372. eventBuilder.setCustomDimension(28, CUSTOM_DIMENSION_DEBUG_VALUE);
  373. }
  374. return eventBuilder;
  375. }
  376. private static HitBuilders.ScreenViewBuilder createScreenViewBuilder() {
  377. HitBuilders.ScreenViewBuilder screenViewBuilder = new HitBuilders.ScreenViewBuilder();
  378. if (isAnalyticsDebug()) {
  379. screenViewBuilder.setCustomDimension(28, CUSTOM_DIMENSION_DEBUG_VALUE);
  380. }
  381. return screenViewBuilder;
  382. }
  383. private static boolean isAnalyticsDebug() {
  384. return IprintApplication.isConnectStaging();
  385. }
  386. public static int getWifiDirectTypeIprintV4(Context context) {
  387. if (!WiFiDirectManager.isWifiDirectFY13(context) && !WiFiDirectManager.isWifiDirectP2P(context)) {
  388. return WiFiDirectManager.isSimpleAP(context) ? 2 : 0;
  389. }
  390. return 1;
  391. }
  392. }