Back to project page twawm2.
The source code is released under:
Copyright (c) 2014, afnf All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistr...
If you think the Android project twawm2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.appspot.afnf4199ga.twawm.router; // www. jav a 2 s . com import net.afnf.and.twawm2.R; import com.appspot.afnf4199ga.twawm.BluetoothHelper; import com.appspot.afnf4199ga.twawm.Const; import com.appspot.afnf4199ga.twawm.OnlineChecker; import com.appspot.afnf4199ga.twawm.app.BackgroundService; import com.appspot.afnf4199ga.twawm.app.MainActivity; import com.appspot.afnf4199ga.twawm.app.MainActivity.ACTIVITY_FLAG; import com.appspot.afnf4199ga.twawm.app.UIAct; import com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.CTRL; import com.appspot.afnf4199ga.utils.AndroidUtils; import com.appspot.afnf4199ga.utils.Logger; import com.appspot.afnf4199ga.utils.MyStringUtlis; public class RouterControl { public static void execStandby() { Logger.i("RouterControl execStandby"); Thread thread = new Thread() { public void run() { BackgroundService service = BackgroundService.getInstance(); if (service == null) { Logger.e("service is null on RouterControl.execStandby"); return; } // ???????? RouterInfo routerInfo = new RouterInfo(); int ret = RouterControlByHttp.exec(service, CTRL.STANDBY, routerInfo); // ????????????? if (ret == RouterControlByHttp.CTRL_FAILED) { Logger.i("router STANDBY failed, ret=" + ret + ", retring..."); RouterControlByHttp.resetPrevious(); ret = RouterControlByHttp.exec(service, CTRL.STANDBY, routerInfo); } Logger.i("RouterControl execStandby, ret=" + ret); service.onStandbyComplete(ret == RouterControlByHttp.CTRL_OK); } }; thread.start(); } public static void execFetchInfo(OnlineChecker checker) { // ?????????? new FetchThread(checker).start(); } static class FetchThread extends Thread { OnlineChecker callbackTarget; public FetchThread(OnlineChecker checker) { this.callbackTarget = checker; } public void run() { BackgroundService service = BackgroundService.getInstance(); if (service == null) { Logger.e("service is null on RouterControl.FetchThread"); return; } RouterInfo routerInfo = new RouterInfo(); int ret = RouterControlByHttp.exec(service, CTRL.GET_INFO, routerInfo); // ?? switch (ret) { case RouterControlByHttp.CTRL_OK: Logger.i("router GET_INFO, ret=" + ret + ", " + routerInfo); // ?????????????????????????????????? if (BluetoothHelper.isValidBluetoothAddress(routerInfo.bluetoothAddress) && MyStringUtlis.eqauls(routerInfo.bluetoothAddress, Const.getPrefBluetoothAddress(service)) == false) { // BT?????? Logger.v("updatePrefBluetoothAddress called"); Const.updatePrefBluetoothAddress(service, routerInfo.bluetoothAddress); // toast UIAct.toast(service.getString(R.string.bt_addr_saved)); } break; // ???????????????????????? case RouterControlByHttp.CTRL_PASS_NOT_INITIALIZED: case RouterControlByHttp.CTRL_UNAUTHORIZED: // ??????? if (Const.getPrefStartWizardAutomatically(service)) { MainActivity.startActivity(service, ACTIVITY_FLAG.INIT_WIZARD); // callback????????? return; } // ??????????????????????????break????????????????????callback // ?? default: Logger.w("router GET_INFO failed, ret=" + ret); } // callback????? callbackTarget.onRouterInfoFetched(ret, routerInfo); } } public static void execWimaxReconnection() { Logger.i("RouterControl execWimaxReconnection"); Thread thread = new Thread() { public void run() { try { BackgroundService service = BackgroundService.getInstance(); if (service == null) { Logger.e("service is null on RouterControl.execWimaxReconnection"); return; } boolean nad11 = RouterControlByHttp.isNad(); int ret; RouterInfo routerInfo = new RouterInfo(); // ???? UIAct.toast(service.getString(R.string.wimax_disconnecting)); // ???? ret = RouterControlByHttp.exec(service, nad11 ? CTRL.NAD_WIMAX_RECONN : CTRL.WIMAX_DISCN, routerInfo); if (ret != RouterControlByHttp.CTRL_OK) { UIAct.toast(service.getString(R.string.failed)); } // ?????????????????? service.getStateMachine().setOfflineTemporarily(); // ???? AndroidUtils.sleep(2000); // ?? UIAct.toast(service.getString(R.string.wimax_connecting)); // WM3800R??????????????????? if (nad11 == false) { // ?INFOBTN??????????????????????????????????????????resetPrevious?????? RouterControlByHttp.resetPrevious(); // ???? ret = RouterControlByHttp.exec(service, CTRL.WIMAX_CONN, routerInfo); if (ret != RouterControlByHttp.CTRL_OK) { UIAct.toast(service.getString(R.string.failed)); } RouterControlByHttp.resetPrevious(); } // ????????????????? service.startOnlineCheck(Const.ONLINE_CHECK_DELAY_AFTER_CTRL); } catch (Throwable e) { Logger.w("RouterControl execWimaxReconnection failed", e); } } }; thread.start(); } public static void execRouterCtrl(final CTRL ctrl) { Logger.i("RouterControl execRouterCtrl"); Thread thread = new Thread() { public void run() { try { BackgroundService service = BackgroundService.getInstance(); if (service == null) { Logger.e("service is null on RouterControl.execRouterCtrl"); return; } // toast if (ctrl == CTRL.REBOOT_WM) { UIAct.toast(service.getString(R.string.reboot_wmrouter)); } // ?? RouterInfo routerInfo = new RouterInfo(); int ret = RouterControlByHttp.exec(service, ctrl, routerInfo); if (ret != RouterControlByHttp.CTRL_OK) { UIAct.toast(service.getString(R.string.failed)); } // ?????????????????? service.getStateMachine().setOfflineTemporarily(); // ??????????????????AP???????????????????????????? service.startOnlineCheck(Const.ONLINE_CHECK_DELAY_AFTER_CTRL); } catch (Throwable e) { Logger.w("RouterControl execRouterReboot failed", e); } } }; thread.start(); } }