DeviceInformationActivity.java 17 KB

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