DeviceInformationActivity.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. package epson.support;
  2. import android.app.Service;
  3. import android.bluetooth.BluetoothAdapter;
  4. import android.content.Context;
  5. import android.net.wifi.WifiManager;
  6. import android.os.AsyncTask;
  7. import android.os.Build;
  8. import android.os.Bundle;
  9. import android.os.Handler;
  10. import android.os.Message;
  11. import android.view.View;
  12. import android.widget.ProgressBar;
  13. import android.widget.TextView;
  14. import androidx.annotation.NonNull;
  15. import androidx.annotation.Nullable;
  16. import com.epson.memcardacc.DirectorySelecterActivity;
  17. import com.epson.mobilephone.common.maintain2.MaintainPrinter2;
  18. import com.epson.mobilephone.common.wifidirect.ManageDefaultNetwork;
  19. import com.epson.mobilephone.common.wifidirect.WiFiControl;
  20. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  21. import com.epson.mobilephone.common.wifidirect.WifiP2pUtils;
  22. import java.lang.ref.WeakReference;
  23. import java.math.BigInteger;
  24. import java.net.InetAddress;
  25. import java.net.NetworkInterface;
  26. import java.net.UnknownHostException;
  27. import java.nio.ByteOrder;
  28. import java.util.Collections;
  29. import epson.common.Constants;
  30. import epson.common.IPAddressUtils;
  31. import epson.common.Utils;
  32. import epson.print.ActivityIACommon;
  33. import epson.print.MyPrinter;
  34. import epson.print.R;
  35. import epson.print.Util.EPLog;
  36. public class DeviceInformationActivity extends ActivityIACommon {
  37. private static final int EPS_COMM_BID = 2;
  38. private static final int EPS_ERR_PRINTER_NOT_FOUND = -1300;
  39. private static final int EPS_PRNERR_COMM = 102;
  40. private static final int PROBE_ERROR = 1;
  41. private static final int STATUS_ERROR = 2;
  42. private static final int UPDATE_PRINTER_STATUS = 0;
  43. TextView PrinterIPInfo;
  44. ProgressBar PrinterProbeProgress;
  45. TextView PrinterStatusInfo;
  46. private String TAG = "Device Information";
  47. TextView TextBluetoothStatus;
  48. TextView TextIPAddress;
  49. TextView TextOSVersion;
  50. TextView TextPrinterIP;
  51. TextView TextPrinterName;
  52. TextView TextPrinterStatus;
  53. TextView TextWiFiName;
  54. TextView TextWiFiState;
  55. Handler mHandler = new Handler(new Handler.Callback() {
  56. public boolean handleMessage(Message message) {
  57. String str;
  58. String str2;
  59. EPLog.m313i("IprintHome", "HandlerCallback");
  60. int i = message.getData().getInt(Constants.PRINTER_LOCATION);
  61. EpLog.m69d("printerLocation " + i);
  62. boolean z = false;
  63. switch (message.what) {
  64. case 0:
  65. EPLog.m313i(TAG, "UPDATE_PRINTER_STATUS");
  66. int[] mStatus = mPrinter.getMPrinterInfor().getMStatus();
  67. EpLog.m69d("status " + mStatus[0]);
  68. if (i == 1 && WiFiDirectManager.getConnectInfo(getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_PRINTER) != null) {
  69. str = getString(R.string.wifi_direct_status);
  70. z = true;
  71. } else if (i == 1 || (i == 3 && Utils.isConnectedWifi(getApplicationContext()))) {
  72. str = getString(R.string.printer_ready);
  73. z = true;
  74. } else if (i != 2 && (i != 3 || Utils.isConnectedWifi(getApplicationContext()))) {
  75. str = getString(R.string.not_select_status);
  76. } else if (!Utils.isOnline(getApplicationContext())) {
  77. str = getString(R.string.cannot_connect);
  78. } else {
  79. str = getString(R.string.remote_can_connect);
  80. }
  81. setPrinterInfo(str, z);
  82. String access$000 = TAG;
  83. EPLog.m313i(access$000, "Stt title: " + str);
  84. break;
  85. case 1:
  86. EPLog.m313i(TAG, "PROBE_ERROR");
  87. if (i != 1 || WiFiDirectManager.getConnectInfo(getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_PRINTER) == null) {
  88. str2 = getString(R.string.comm_error);
  89. } else {
  90. str2 = getString(R.string.wifi_direct_status);
  91. }
  92. setPrinterInfo(str2, false);
  93. String access$0002 = TAG;
  94. EPLog.m313i(access$0002, "Stt title: " + str2);
  95. break;
  96. case 2:
  97. EPLog.m313i(TAG, "STATUS_ERROR");
  98. int[] intArray = message.getData().getIntArray("STATUS_ERROR");
  99. if (i != 1 || WiFiDirectManager.getConnectInfo(getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_PRINTER) == null) {
  100. if (intArray == null) {
  101. DeviceInformationActivity deviceInformationActivity = this;
  102. setPrinterInfo(getString(R.string.upon_error), true);
  103. String access$0003 = TAG;
  104. EPLog.m313i(access$0003, "Stt titlef: " + getString(R.string.upon_error));
  105. break;
  106. } else {
  107. String access$0004 = TAG;
  108. EPLog.m313i(access$0004, "statusError[0] : " + intArray[0]);
  109. String access$0005 = TAG;
  110. EPLog.m313i(access$0005, "statusError[1] : " + intArray[1]);
  111. if (intArray[0] != 2 && intArray[0] != 1 && intArray[0] != 3) {
  112. if (intArray[0] != 4 || (intArray[1] != 102 && intArray[1] != -1300)) {
  113. DeviceInformationActivity deviceInformationActivity2 = DeviceInformationActivity.this;
  114. deviceInformationActivity2.setPrinterInfo(deviceInformationActivity2.getString(R.string.upon_error), true);
  115. String access$0006 = TAG;
  116. EPLog.m313i(access$0006, "Stt title: " + getString(R.string.upon_error));
  117. break;
  118. } else {
  119. DeviceInformationActivity deviceInformationActivity3 = DeviceInformationActivity.this;
  120. deviceInformationActivity3.setPrinterInfo(deviceInformationActivity3.getString(R.string.comm_error), false);
  121. String access$0007 = TAG;
  122. EPLog.m313i(access$0007, "Stt title: " + getString(R.string.comm_error));
  123. break;
  124. }
  125. } else {
  126. DeviceInformationActivity deviceInformationActivity4 = DeviceInformationActivity.this;
  127. deviceInformationActivity4.setPrinterInfo(deviceInformationActivity4.getString(R.string.printer_ready), true);
  128. String access$0008 = TAG;
  129. EPLog.m313i(access$0008, "Stt title: " + getString(R.string.printer_ready));
  130. break;
  131. }
  132. }
  133. } else {
  134. DeviceInformationActivity deviceInformationActivity5 = DeviceInformationActivity.this;
  135. deviceInformationActivity5.setPrinterInfo(deviceInformationActivity5.getString(R.string.wifi_direct_status), true);
  136. String access$0009 = TAG;
  137. EPLog.m313i(access$0009, "Stt title: " + getString(R.string.printer_ready));
  138. break;
  139. }
  140. break;
  141. default:
  142. EPLog.m313i("IprintHome", DirectorySelecterActivity.PARAM_DEFAULT_DIR);
  143. DeviceInformationActivity deviceInformationActivity6 = DeviceInformationActivity.this;
  144. deviceInformationActivity6.setPrinterInfo(deviceInformationActivity6.getString(R.string.printer_not_select), false);
  145. break;
  146. }
  147. hideLoadProgressBar();
  148. return true;
  149. }
  150. });
  151. private MaintainPrinter2 mPrinter = MaintainPrinter2.getInstance();
  152. private ProbePrinter task;
  153. protected void onCreate(Bundle bundle) {
  154. super.onCreate(bundle);
  155. setContentView(R.layout.device_information);
  156. setActionBar(R.string.str_deviceInformation_Info, true);
  157. checkSmartPhoneInfo();
  158. checkPrinterInfo();
  159. checkWiFiInfo();
  160. }
  161. public void onBackPressed() {
  162. super.onBackPressed();
  163. stopProbePrinter();
  164. }
  165. public void onDestroy() {
  166. stopProbePrinter();
  167. super.onDestroy();
  168. }
  169. private void stopProbePrinter() {
  170. if (this.task != null) {
  171. EPLog.m313i(this.TAG, "stopProbePrinter");
  172. mPrinter.doCancelFindPrinter();
  173. task.cancel(true);
  174. task = null;
  175. }
  176. }
  177. private void checkPrinterInfo() {
  178. TextPrinterName = (TextView) findViewById(R.id.tv_devicePrinterName);
  179. MyPrinter curPrinter = MyPrinter.getCurPrinter(getApplicationContext());
  180. int location = curPrinter.getLocation();
  181. if (curPrinter.getName() != null) {
  182. TextPrinterName.setText(curPrinter.getName());
  183. showLoadProgressBar();
  184. if (location == 1 || (location == 3 && Utils.isConnectedWifi(getApplicationContext()))) {
  185. ManageDefaultNetwork.getInstance(this).setDefaultNetworkSimpleAp();
  186. EpLog.m70d("IprintHome", "Update printer status after execute Probing");
  187. task = new ProbePrinter(curPrinter, mPrinter, mHandler);
  188. task.execute(new Context[]{this});
  189. return;
  190. }
  191. EpLog.m70d("IprintHome", "Update printer status without execute Probing ");
  192. sendUpdatePrinterStatus(mHandler, location);
  193. }
  194. }
  195. private void setPrinterInfo(String str, boolean z) {
  196. TextPrinterStatus = (TextView) findViewById(R.id.tv_devicePrinterStatus);
  197. TextPrinterIP = (TextView) findViewById(R.id.tv_devicePrinterIPAddress);
  198. TextPrinterStatus.setText(str);
  199. if (z) {
  200. TextPrinterIP.setText(MyPrinter.getCurPrinter(getApplicationContext()).getIp());
  201. }
  202. }
  203. private void checkSmartPhoneInfo() {
  204. StringBuilder sb = new StringBuilder();
  205. TextBluetoothStatus = (TextView) findViewById(R.id.tv_deviceBluetoothStatus);
  206. TextOSVersion = (TextView) findViewById(R.id.tv_deviceOSVersion);
  207. sb.append("Android ");
  208. sb.append(Build.VERSION.RELEASE);
  209. TextOSVersion.setText(sb.toString());
  210. BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
  211. if (defaultAdapter == null) {
  212. TextBluetoothStatus.setText(R.string.str_deviceInformation_BluetoothOFF);
  213. } else if (!defaultAdapter.isEnabled()) {
  214. TextBluetoothStatus.setText(R.string.str_deviceInformation_BluetoothOFF);
  215. } else {
  216. TextBluetoothStatus.setText(R.string.str_deviceInformation_BluetoothON);
  217. }
  218. }
  219. private void checkWiFiInfo() {
  220. throw new UnsupportedOperationException("Method not decompiled: epson.support.checkWiFiInfo():void");
  221. }
  222. /* renamed from: epson.support.DeviceInformationActivity$2 */
  223. static /* synthetic */ class C24682 {
  224. /* renamed from: $SwitchMap$com$epson$mobilephone$common$wifidirect$WiFiControl$ConnectType */
  225. static final /* synthetic */ int[] f415x793e0ec3 = new int[WiFiControl.ConnectType.values().length];
  226. static {
  227. }
  228. }
  229. private String getIpAddressFromWiFi() {
  230. int ipAddress = ((WifiManager) getApplicationContext().getSystemService(Service.WIFI_SERVICE)).getConnectionInfo().getIpAddress();
  231. if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
  232. ipAddress = Integer.reverseBytes(ipAddress);
  233. }
  234. try {
  235. return InetAddress.getByAddress(BigInteger.valueOf((long) ipAddress).toByteArray()).getHostAddress();
  236. } catch (UnknownHostException unused) {
  237. EpLog.m72e(this.TAG, "Unable to get host address.");
  238. return null;
  239. }
  240. }
  241. public static String getIpAddressFromP2P(Context context) {
  242. try {
  243. NetworkInterface p2PInterfaceInfo = WifiP2pUtils.getInstance(context).getP2PInterfaceInfo();
  244. if (p2PInterfaceInfo == null) {
  245. return null;
  246. }
  247. for (T t : Collections.list(p2PInterfaceInfo.getInetAddresses())) {
  248. if (!t.isLoopbackAddress()) {
  249. String upperCase = t.getHostAddress().toUpperCase();
  250. if (IPAddressUtils.isIPv4Address(upperCase)) {
  251. return upperCase;
  252. }
  253. }
  254. }
  255. return null;
  256. } catch (Exception unused) {
  257. }
  258. }
  259. private static void sendUpdatePrinterStatus(@Nullable Handler handler, int i) {
  260. if (handler != null) {
  261. Message obtainMessage = handler.obtainMessage();
  262. obtainMessage.what = 0;
  263. Bundle bundle = new Bundle();
  264. bundle.putInt(Constants.PRINTER_LOCATION, i);
  265. obtainMessage.setData(bundle);
  266. handler.sendMessage(obtainMessage);
  267. }
  268. }
  269. private static class ProbePrinter extends AsyncTask<Context, Void, Boolean> {
  270. private final WeakReference<Handler> mHandlerReference;
  271. private final MyPrinter mMyPrinter;
  272. private MaintainPrinter2 mPrinter;
  273. private int mPrinterLocation;
  274. protected void onPreExecute() {
  275. }
  276. public ProbePrinter(@NonNull MyPrinter myPrinter, @NonNull MaintainPrinter2 maintainPrinter2, @Nullable Handler handler) {
  277. mHandlerReference = new WeakReference<>(handler);
  278. mPrinter = maintainPrinter2;
  279. mMyPrinter = myPrinter;
  280. }
  281. protected Boolean doInBackground(Context... contextArr) {
  282. EpLog.m77i("ProbePrinter doInBackground");
  283. mPrinter.doInitDriver(contextArr[0], 2);
  284. mPrinterLocation = mMyPrinter.getLocation();
  285. int i = mPrinterLocation;
  286. if (i == 1 || i == 3) {
  287. if (mMyPrinter.getPrinterId() == null) {
  288. mPrinterLocation = 0;
  289. } else if (mPrinter.doProbePrinter(60, mMyPrinter.getPrinterId(), mMyPrinter.getIp(), mPrinterLocation) != 0) {
  290. localSendMessage(1);
  291. return false;
  292. } else {
  293. int doSetPrinter = mPrinter.doSetPrinter();
  294. EpLog.m77i("Set Printer result: " + doSetPrinter);
  295. if (doSetPrinter != 0) {
  296. localSendMessage(1);
  297. return false;
  298. }
  299. int doGetStatus = mPrinter.doGetStatus();
  300. EpLog.m77i("Printer Status result: " + doGetStatus);
  301. if (doGetStatus != 0) {
  302. localSendMessage(1);
  303. return false;
  304. }
  305. int[] mStatus = mPrinter.getMPrinterInfor().getMStatus();
  306. if (mStatus[0] != 0) {
  307. sendStatusError(mStatus);
  308. return false;
  309. }
  310. }
  311. }
  312. return true;
  313. }
  314. private void sendStatusError(int[] iArr) {
  315. Handler handler = (Handler) mHandlerReference.get();
  316. if (handler != null) {
  317. Message obtainMessage = handler.obtainMessage();
  318. obtainMessage.what = 2;
  319. Bundle bundle = new Bundle();
  320. bundle.putIntArray("STATUS_ERROR", iArr);
  321. bundle.putInt(Constants.PRINTER_LOCATION, mPrinterLocation);
  322. obtainMessage.setData(bundle);
  323. handler.sendMessage(obtainMessage);
  324. }
  325. }
  326. private void localSendMessage(int i) {
  327. Handler handler = (Handler) mHandlerReference.get();
  328. if (handler != null) {
  329. Message obtainMessage = handler.obtainMessage();
  330. obtainMessage.what = i;
  331. Bundle bundle = new Bundle();
  332. bundle.putInt(Constants.PRINTER_LOCATION, mPrinterLocation);
  333. obtainMessage.setData(bundle);
  334. handler.sendMessage(obtainMessage);
  335. }
  336. }
  337. protected void onCancelled() {
  338. EpLog.m77i("ProbePrinter onCancelled");
  339. super.onCancelled();
  340. }
  341. protected void onPostExecute(Boolean bool) {
  342. EpLog.m77i("ProbePrinter onPostExecute");
  343. if (bool.booleanValue()) {
  344. sendUpdatePrinterStatus((Handler) mHandlerReference.get(), mPrinterLocation);
  345. }
  346. }
  347. }
  348. private void showLoadProgressBar() {
  349. PrinterProbeProgress = (ProgressBar) findViewById(R.id.progress_status);
  350. PrinterStatusInfo = (TextView) findViewById(R.id.tv_devicePrinterStatusInfo);
  351. PrinterIPInfo = (TextView) findViewById(R.id.tv_devicePrinterIPAddressInfo);
  352. PrinterProbeProgress.setVisibility(View.VISIBLE);
  353. PrinterStatusInfo.setTextColor(getApplicationContext().getResources().getColor(R.color.light_gray));
  354. PrinterIPInfo.setTextColor(getApplicationContext().getResources().getColor(R.color.light_gray));
  355. }
  356. private void hideLoadProgressBar() {
  357. PrinterProbeProgress.setVisibility(View.GONE);
  358. PrinterStatusInfo.setTextColor(getApplicationContext().getResources().getColor(R.color.black));
  359. PrinterIPInfo.setTextColor(getApplicationContext().getResources().getColor(R.color.black));
  360. }
  361. }