Analytics.java 20 KB

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