Android Open Source - twawm2 Router Control






From Project

Back to project page twawm2.

License

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.

Java Source Code

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();
    }
}




Java Source Code List

com.appspot.afnf4199ga.twawm.BluetoothHelper.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.HostnameListTest.java
com.appspot.afnf4199ga.twawm.HostnameList.java
com.appspot.afnf4199ga.twawm.IconSelectorTest.java
com.appspot.afnf4199ga.twawm.IconSelector.java
com.appspot.afnf4199ga.twawm.OnlineChecker.java
com.appspot.afnf4199ga.twawm.StateMachineTest.java
com.appspot.afnf4199ga.twawm.StateMachine.java
com.appspot.afnf4199ga.twawm.TwawmUtils.java
com.appspot.afnf4199ga.twawm.app.BackgroundServiceTest.java
com.appspot.afnf4199ga.twawm.app.BackgroundService.java
com.appspot.afnf4199ga.twawm.app.DefaultWidgetProvider.java
com.appspot.afnf4199ga.twawm.app.InfoActivity.java
com.appspot.afnf4199ga.twawm.app.InitialConfigurationWizardActivity.java
com.appspot.afnf4199ga.twawm.app.LogSendActivity.java
com.appspot.afnf4199ga.twawm.app.MainActivity.java
com.appspot.afnf4199ga.twawm.app.MainApp.java
com.appspot.afnf4199ga.twawm.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.twawm.app.NetworkSwitcher.java
com.appspot.afnf4199ga.twawm.app.StaticIntentListener.java
com.appspot.afnf4199ga.twawm.app.UIAct.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivityTest.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivity.java
com.appspot.afnf4199ga.twawm.ctl.CwacTouchListView.java
com.appspot.afnf4199ga.twawm.ctl.ListItem.java
com.appspot.afnf4199ga.twawm.router.EcoModeControlTest.java
com.appspot.afnf4199ga.twawm.router.EcoModeControl.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.MyHttpClientTest.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttpTest.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.utils.AndroidUtilsTest.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.MyStringUtlisTest.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyTestUtils.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.wmgraph.app.FetchThread.java
com.appspot.afnf4199ga.wmgraph.app.InetLookupThread.java
com.appspot.afnf4199ga.wmgraph.app.InfoActivity.java
com.appspot.afnf4199ga.wmgraph.app.MainActivity.java
com.appspot.afnf4199ga.wmgraph.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.wmgraph.app.UIAct.java
net.afnf.and.twawm2.DexmakerInstrumentationTestCase.java
net.afnf.and.twawm2.MyInstrumentationTestRunner.java