WiFiDirectPrinterListUtils.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package com.epson.mobilephone.common.wifidirect;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.os.Build;
  5. import java.util.AbstractList;
  6. import java.util.ArrayList;
  7. import java.util.Iterator;
  8. import epson.print.MyPrinter;
  9. public class WiFiDirectPrinterListUtils {
  10. private static final String TAG = "WiFiDirectPrinterListUtils";
  11. private String curConnectInfo;
  12. private ArrayList<PrinterInfo> innerPrinterList = null;
  13. private ListController listController = null;
  14. private Context mAppContext = null;
  15. private String p2pPrinterMacAddr;
  16. private AbstractList<Object> uiPrinterList = null;
  17. private WiFiControl wiFiControl = null;
  18. public interface ListController {
  19. void addPrinter(Object obj, int i);
  20. void replacePrinter(int i, Object obj, int i2);
  21. }
  22. enum PRINTER_TYPE {
  23. USB,
  24. LOCAL,
  25. WIFIDIRECT
  26. }
  27. private class PrinterInfo {
  28. /* renamed from: ip */
  29. String f157ip;
  30. String macAddr;
  31. Object printer;
  32. String ssid;
  33. PRINTER_TYPE type;
  34. public PrinterInfo(PRINTER_TYPE printer_type, String str, String str2, String str3, Object obj) {
  35. type = printer_type;
  36. macAddr = str;
  37. f157ip = str2;
  38. ssid = str3;
  39. printer = obj;
  40. }
  41. }
  42. public WiFiDirectPrinterListUtils(Context context, AbstractList<Object> abstractList, ListController listController2, String str) {
  43. mAppContext = context.getApplicationContext();
  44. wiFiControl = WiFiControl.getInstance(mAppContext);
  45. innerPrinterList = new ArrayList<>();
  46. uiPrinterList = abstractList;
  47. listController = listController2;
  48. curConnectInfo = str;
  49. clearPrinterInfoList();
  50. }
  51. public void clearPrinterInfoList() {
  52. EPLog.d(TAG, "clearPrinterInfoList()");
  53. innerPrinterList.clear();
  54. updateP2pPrinterMacAddr();
  55. }
  56. public void updateP2pPrinterMacAddr() {
  57. EPLog.d(TAG, "updateP2pPrinterMacAddr()");
  58. WifiP2pUtils.ConnectionInfo connectionInfo = WifiP2pUtils.getInstance(mAppContext).getConnectionInfo();
  59. if (connectionInfo == null) {
  60. p2pPrinterMacAddr = null;
  61. return;
  62. }
  63. if (connectionInfo.isGroupOwnerThisDevice) {
  64. p2pPrinterMacAddr = WiFiControl.p2pAddr2PtrAddr(connectionInfo.p2PMacAdder, connectionInfo.printerName);
  65. } else {
  66. p2pPrinterMacAddr = WiFiControl.p2pAddr2PtrAddrP2P(connectionInfo.p2PMacAdder, connectionInfo.printerName);
  67. }
  68. if (MacAddrFilter.getInstance(mAppContext).isExcludedMacAddress(WiFiControl.p2pAddr2PtrAddr(connectionInfo.p2PMacAdder, connectionInfo.printerName))) {
  69. p2pPrinterMacAddr = null;
  70. }
  71. }
  72. public static String getCurPrinterString(Activity activity, String str, String str2) {
  73. if (str2 == null) {
  74. return str;
  75. }
  76. return (!WiFiControl.ConnectType.SimpleAP.equals(WiFiControl.getSSIDType(str2)) || Build.VERSION.SDK_INT < 26 || !WiFiControl.isSimpleAP(WiFiUtils.getInstance(activity).getCurSSID()) || activity.checkSelfPermission("android.permission.ACCESS_COARSE_LOCATION") == 0) ? str2 : str;
  77. }
  78. public void addPrinter(Object obj, int i, String str, String str2) {
  79. boolean z = true;
  80. boolean z2 = false;
  81. switch (getType(str)) {
  82. case LOCAL:
  83. if (str2 == null || str2.isEmpty()) {
  84. EPLog.w(TAG, "Invalid MacAddress");
  85. return;
  86. } else if (str2.equals(p2pPrinterMacAddr)) {
  87. EPLog.d(TAG, "Ignore Printer. This printer communicates via P2P:" + str);
  88. return;
  89. } else {
  90. Iterator<PrinterInfo> it = innerPrinterList.iterator();
  91. while (true) {
  92. if (it.hasNext()) {
  93. PrinterInfo next = it.next();
  94. if (!PRINTER_TYPE.LOCAL.equals(next.type)) {
  95. String str3 = next.macAddr;
  96. if (str2 != null && str2.equals(str3)) {
  97. EPLog.d(TAG, "Replace Duplicate Printer:" + next.ssid + "->" + str);
  98. int indexOf = uiPrinterList.indexOf(next.printer);
  99. if (-1 != indexOf) {
  100. listController.replacePrinter(indexOf, obj, i);
  101. z = false;
  102. } else {
  103. EPLog.e(TAG, "Illegal curPrinterList1 (Maybe replaced):" + str);
  104. }
  105. }
  106. }
  107. }
  108. }
  109. if (z) {
  110. listController.addPrinter(obj, i);
  111. }
  112. innerPrinterList.add(new PrinterInfo(PRINTER_TYPE.LOCAL, str2, str, (String) null, obj));
  113. return;
  114. }
  115. case WIFIDIRECT:
  116. Iterator<PrinterInfo> it2 = innerPrinterList.iterator();
  117. while (true) {
  118. if (it2.hasNext()) {
  119. PrinterInfo next2 = it2.next();
  120. String str4 = next2.macAddr;
  121. if (str4 == null || str4.isEmpty()) {
  122. EPLog.w(TAG, "Invalid MacAddress");
  123. } else if (PRINTER_TYPE.WIFIDIRECT.equals(next2.type)) {
  124. if (str4 != null && str4.equals(str2)) {
  125. switch (WiFiControl.getSSIDType(str)) {
  126. case WiFiP2P:
  127. if (next2.ssid.equals(curConnectInfo)) {
  128. break;
  129. } else {
  130. EPLog.d(TAG, "Replace Duplicate Printer:" + next2.ssid + "->" + str);
  131. int indexOf2 = uiPrinterList.indexOf(next2.printer);
  132. if (-1 == indexOf2) {
  133. EPLog.e(TAG, "Illegal curPrinterList2 (Maybe replaced):" + str);
  134. break;
  135. } else {
  136. listController.replacePrinter(indexOf2, obj, i);
  137. z = false;
  138. break;
  139. }
  140. }
  141. case SimpleAP:
  142. if (str.equals(curConnectInfo)) {
  143. break;
  144. } else {
  145. EPLog.d(TAG, "Found Duplicate Printer:" + next2.ssid + "(" + str + ")");
  146. z = false;
  147. break;
  148. }
  149. default:
  150. EPLog.w(TAG, "Invalid Type");
  151. break;
  152. }
  153. }
  154. } else {
  155. String p2pPtrAddr2PtrAddr = WiFiControl.p2pPtrAddr2PtrAddr(str4);
  156. if ((str4 != null && str4.equals(str2)) || (p2pPtrAddr2PtrAddr != null && p2pPtrAddr2PtrAddr.equals(str2))) {
  157. String curConnectInfo2 = wiFiControl.getCurConnectInfo(str4);
  158. if (curConnectInfo2 != null) {
  159. int[] iArr = C11211.f155x793e0ec3;
  160. WiFiControl wiFiControl2 = wiFiControl;
  161. if (iArr[WiFiControl.getSSIDType(str).ordinal()] != 2) {
  162. z2 = z;
  163. } else if (curConnectInfo2.equals(curConnectInfo)) {
  164. EPLog.d(TAG, "Replace Duplicate Printer:" + next2.f157ip + "->" + str);
  165. int indexOf3 = uiPrinterList.indexOf(next2.printer);
  166. if (-1 != indexOf3) {
  167. listController.replacePrinter(indexOf3, obj, i);
  168. } else {
  169. EPLog.e(TAG, "Illegal curPrinterList3 (Maybe replaced):" + str);
  170. }
  171. } else {
  172. EPLog.d(TAG, "Found Duplicate Printer:" + next2.f157ip + "(" + str + ")");
  173. }
  174. } else {
  175. EPLog.d(TAG, "Found Duplicate Printer:" + next2.f157ip + "(" + str + ")");
  176. }
  177. }
  178. }
  179. } else {
  180. z2 = z;
  181. }
  182. }
  183. if (z2) {
  184. listController.addPrinter(obj, i);
  185. }
  186. innerPrinterList.add(new PrinterInfo(PRINTER_TYPE.WIFIDIRECT, str2, (String) null, str, obj));
  187. return;
  188. case USB:
  189. listController.addPrinter(obj, i);
  190. return;
  191. default:
  192. EPLog.w(TAG, "Un known Type");
  193. return;
  194. }
  195. }
  196. private PRINTER_TYPE getType(String str) {
  197. WiFiControl.ConnectType connectType = WiFiControl.ConnectType.NONE;
  198. WiFiControl wiFiControl2 = wiFiControl;
  199. if (!connectType.equals(WiFiControl.getSSIDType(str))) {
  200. return PRINTER_TYPE.WIFIDIRECT;
  201. }
  202. if (MyPrinter.PRINTER_USB.equals(str)) {
  203. return PRINTER_TYPE.USB;
  204. }
  205. return PRINTER_TYPE.LOCAL;
  206. }
  207. }