14e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum/*
24e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * Copyright (C) 2017 The Android Open Source Project
34e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum *
44e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * Licensed under the Apache License, Version 2.0 (the "License");
54e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * you may not use this file except in compliance with the License.
64e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * You may obtain a copy of the License at
74e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum *
84e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum *      http://www.apache.org/licenses/LICENSE-2.0
94e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum *
104e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * Unless required by applicable law or agreed to in writing, software
114e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * distributed under the License is distributed on an "AS IS" BASIS,
124e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * See the License for the specific language governing permissions and
144e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * limitations under the License.
154e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum */
164e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
174e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumpackage android.net.lowpan;
184e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
194e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport android.annotation.NonNull;
204e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport android.annotation.Nullable;
21dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaumimport android.content.Context;
224e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport android.net.IpPrefix;
23dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaumimport android.net.LinkAddress;
24dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaumimport android.os.DeadObjectException;
254e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport android.os.Handler;
26dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaumimport android.os.Looper;
274e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport android.os.RemoteException;
284e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport android.os.ServiceSpecificException;
294e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport android.util.Log;
304e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumimport java.util.HashMap;
314e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
324e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum/**
334e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * Class for managing a specific Low-power Wireless Personal Area Network (LoWPAN) interface.
344e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum *
354e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum * @hide
364e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum */
37325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum// @SystemApi
384e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaumpublic class LowpanInterface {
394e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    private static final String TAG = LowpanInterface.class.getSimpleName();
404e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
414e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** Detached role. The interface is not currently attached to a network. */
426cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String ROLE_DETACHED = ILowpanInterface.ROLE_DETACHED;
434e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
444e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** End-device role. End devices do not route traffic for other nodes. */
456cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String ROLE_END_DEVICE = ILowpanInterface.ROLE_END_DEVICE;
464e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
474e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** Router role. Routers help route traffic around the mesh network. */
486cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String ROLE_ROUTER = ILowpanInterface.ROLE_ROUTER;
494e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
504e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
514e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Sleepy End-Device role.
524e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
534e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>End devices with this role are nominally asleep, waking up periodically to check in with
544e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * their parent to see if there are packets destined for them. Such devices are capable of
554e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * extraordinarilly low power consumption, but packet latency can be on the order of dozens of
564e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * seconds(depending on how the node is configured).
574e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
586cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String ROLE_SLEEPY_END_DEVICE = ILowpanInterface.ROLE_SLEEPY_END_DEVICE;
594e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
604e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
614e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Sleepy-router role.
624e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
634e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>Routers with this role are nominally asleep, waking up periodically to check in with other
644e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * routers and their children.
654e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
666cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String ROLE_SLEEPY_ROUTER = ILowpanInterface.ROLE_SLEEPY_ROUTER;
674e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
684e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** TODO: doc */
696cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String ROLE_LEADER = ILowpanInterface.ROLE_LEADER;
704e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
714e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** TODO: doc */
726cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String ROLE_COORDINATOR = ILowpanInterface.ROLE_COORDINATOR;
734e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
744e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
754e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Offline state.
764e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
774e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>This is the initial state of the LoWPAN interface when the underlying driver starts. In
784e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * this state the NCP is idle and not connected to any network.
794e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
804e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>This state can be explicitly entered by calling {@link #reset()}, {@link #leave()}, or
814e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <code>setUp(false)</code>, with the later two only working if we were not previously in the
824e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * {@link #STATE_FAULT} state.
834e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
844e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #getState()
854e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_FAULT
864e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
876cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String STATE_OFFLINE = ILowpanInterface.STATE_OFFLINE;
884e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
894e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
904e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Commissioning state.
914e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
924e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>The interface enters this state after a call to {@link #startCommissioningSession()}. This
934e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * state may only be entered directly from the {@link #STATE_OFFLINE} state.
944e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
954e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #startCommissioningSession()
964e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #getState()
974e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
984e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
996cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String STATE_COMMISSIONING = ILowpanInterface.STATE_COMMISSIONING;
1004e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1014e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
1024e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Attaching state.
1034e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1044e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>The interface enters this state when it starts the process of trying to find other nodes
1054e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * so that it can attach to any pre-existing network fragment, or when it is in the process of
1064e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * calculating the optimal values for unspecified parameters when forming a new network.
1074e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1084e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>The interface may stay in this state for a prolonged period of time (or may spontaneously
1094e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * enter this state from {@link #STATE_ATTACHED}) if the underlying network technology is
1104e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * heirarchical (like ZigBeeIP) or if the device role is that of an "end-device" ({@link
1114e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * #ROLE_END_DEVICE} or {@link #ROLE_SLEEPY_END_DEVICE}). This is because such roles cannot
1124e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * create their own network fragments.
1134e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1144e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_ATTACHED
1154e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #getState()
1164e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
1176cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String STATE_ATTACHING = ILowpanInterface.STATE_ATTACHING;
1184e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1194e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
1204e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Attached state.
1214e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1224e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>The interface enters this state from {@link #STATE_ATTACHING} once it is actively
1234e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * participating on a network fragment.
1244e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1254e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_ATTACHING
1264e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #getState()
1274e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
1286cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String STATE_ATTACHED = ILowpanInterface.STATE_ATTACHED;
1294e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1304e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
1314e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Fault state.
1324e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1334e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>The interface will enter this state when the driver has detected some sort of problem from
1344e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * which it was not immediately able to recover.
1354e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1364e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>This state can be entered spontaneously from any other state. Calling {@link #reset} will
1374e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * cause the device to return to the {@link #STATE_OFFLINE} state.
1384e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1394e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #getState
1404e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_OFFLINE
1414e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
1426cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String STATE_FAULT = ILowpanInterface.STATE_FAULT;
1434e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1444e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
1454e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Network type for Thread 1.x networks.
1464e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1474e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see android.net.lowpan.LowpanIdentity#getType
1484e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #getLowpanIdentity
1494e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
1504e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
1516cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String NETWORK_TYPE_THREAD_V1 = ILowpanInterface.NETWORK_TYPE_THREAD_V1;
1524e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1536cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public static final String EMPTY_PARTITION_ID = "";
1544e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1554e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
1564e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Callback base class for LowpanInterface
1574e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
1584e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
1594e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
160325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    // @SystemApi
1614e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public abstract static class Callback {
1624e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        public void onConnectedChanged(boolean value) {}
1634e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1644e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        public void onEnabledChanged(boolean value) {}
1654e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1664e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        public void onUpChanged(boolean value) {}
1674e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1684e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        public void onRoleChanged(@NonNull String value) {}
1694e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1704e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        public void onStateChanged(@NonNull String state) {}
1714e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1724e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        public void onLowpanIdentityChanged(@NonNull LowpanIdentity value) {}
1734e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1746cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        public void onLinkNetworkAdded(IpPrefix prefix) {}
1756cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
1766cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        public void onLinkNetworkRemoved(IpPrefix prefix) {}
1776cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
1786cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        public void onLinkAddressAdded(LinkAddress address) {}
1796cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
1806cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        public void onLinkAddressRemoved(LinkAddress address) {}
1814e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
1824e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
183dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    private final ILowpanInterface mBinder;
184dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    private final Looper mLooper;
1854e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    private final HashMap<Integer, ILowpanInterfaceListener> mListenerMap = new HashMap<>();
1864e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
1874e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
188dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * Create a new LowpanInterface instance. Applications will almost always want to use {@link
189dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * LowpanManager#getInterface LowpanManager.getInterface()} instead of this.
1904e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
191dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * @param context the application context
192dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * @param service the Binder interface
193dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * @param looper the Binder interface
1944e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
1954e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
196dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    public LowpanInterface(Context context, ILowpanInterface service, Looper looper) {
197dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        /* We aren't currently using the context, but if we need
198dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum         * it later on we can easily add it to the class.
199dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum         */
2004e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
201dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        mBinder = service;
202dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        mLooper = looper;
2034e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
2044e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
2054e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
206dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * Returns the ILowpanInterface object associated with this interface.
2074e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
2084e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
2094e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
210dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    public ILowpanInterface getService() {
211dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        return mBinder;
2124e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
2134e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
2144e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    // Public Actions
2154e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
2164e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
2174e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Form a new network with the given network information optional credential. Unspecified fields
2184e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * in the network information will be filled in with reasonable values. If the network
2194e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * credential is unspecified, one will be generated automatically.
2204e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
2214e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>This method will block until either the network was successfully formed or an error
2224e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * prevents the network form being formed.
2234e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
2244e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>Upon success, the interface will be up and attached to the newly formed network.
2254e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
2264e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #join(LowpanProvision)
2274e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
2284e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void form(@NonNull LowpanProvision provision) throws LowpanException {
2294e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
2306cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            mBinder.form(provision);
231dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
2324e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
233dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
234dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
2354e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
2366cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
2374e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
2384e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
2394e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
2404e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
2414e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Attempts to join a new network with the given network information. This method will block
2424e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * until either the network was successfully joined or an error prevented the network from being
2434e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * formed. Upon success, the interface will be up and attached to the newly joined network.
2444e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
2454e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>Note that “joining” is distinct from “attaching”: Joining requires at least one other peer
2464e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * device to be present in order for the operation to complete successfully.
2474e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
2484e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void join(@NonNull LowpanProvision provision) throws LowpanException {
2494e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
2506cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            mBinder.join(provision);
251dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
2524e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
253dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
254dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
2554e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
2566cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
2574e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
2584e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
2594e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
2604e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
2614e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Attaches to the network described by identity and credential. This is similar to {@link
2624e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * #join}, except that (assuming the identity and credential are valid) it will always succeed
2634e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * and provision the interface, even if there are no peers nearby.
2644e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
2654e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>This method will block execution until the operation has completed.
2664e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
2674e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void attach(@NonNull LowpanProvision provision) throws LowpanException {
2686cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        try {
2696cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            mBinder.attach(provision);
2706cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
2716cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
2726cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
2736cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
2746cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (ServiceSpecificException x) {
2756cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
2764e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
2774e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
2784e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
2794e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
2804e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Bring down the network interface and forget all non-volatile details about the current
2814e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * network.
2824e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
2834e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>This method will block execution until the operation has completed.
2844e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
2854e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void leave() throws LowpanException {
2864e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
2874e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mBinder.leave();
288dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
2894e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
290dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
291dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
2924e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
2936cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
2944e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
2954e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
2964e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
2974e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
2984e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Start a new commissioning session. Will fail if the interface is attached to a network or if
2994e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * the interface is disabled.
3004e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
3014e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public @NonNull LowpanCommissioningSession startCommissioningSession(
3024e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            @NonNull LowpanBeaconInfo beaconInfo) throws LowpanException {
3036cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        try {
3046cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            mBinder.startCommissioningSession(beaconInfo);
3056cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
3066cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return new LowpanCommissioningSession(mBinder, beaconInfo, mLooper);
3076cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
3086cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
3096cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
3104e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
3116cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (ServiceSpecificException x) {
3126cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
3136cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
3144e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
3154e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
3164e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
3174e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Reset this network interface as if it has been power cycled. Will bring the network interface
3184e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * down if it was previously up. Will not erase any non-volatile settings.
3194e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
3204e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>This method will block execution until the operation has completed.
3214e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
3224e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
3234e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
3244e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void reset() throws LowpanException {
3254e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
3264e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mBinder.reset();
327dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
3284e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
329dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
330dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
3314e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
3326cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
3334e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
3344e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
3354e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
3364e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    // Public Getters and Setters
3374e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
338dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    /** Returns the name of this network interface. */
3394e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    @NonNull
3404e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public String getName() {
3414e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
3424e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            return mBinder.getName();
343dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
3446cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
3456cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return "";
3466cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
3474e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
348dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
3494e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
3504e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
3514e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
352325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    /**
353325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * Indicates if the interface is enabled or disabled.
354325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     *
355325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * @see #setEnabled
356325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * @see android.net.lowpan.LowpanException#LOWPAN_DISABLED
357325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     */
358325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    public boolean isEnabled() {
3594e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
3606cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.isEnabled();
3616cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
3626cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
3634e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            return false;
3646cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
3656cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
3666cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
3674e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
3684e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
3694e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
370325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    /**
371325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * Enables or disables the LoWPAN interface. When disabled, the interface is put into a
372325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * low-power state and all commands that require the NCP to be queried will fail with {@link
373325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * android.net.lowpan.LowpanException#LOWPAN_DISABLED}.
374325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     *
375325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * @see #isEnabled
376325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * @see android.net.lowpan.LowpanException#LOWPAN_DISABLED
377325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * @hide
378325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     */
379325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    public void setEnabled(boolean enabled) throws LowpanException {
3806cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        try {
3816cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            mBinder.setEnabled(enabled);
3826cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
3836cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
3846cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
3856cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
3866cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (ServiceSpecificException x) {
3876cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
3886cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
3894e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
3904e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
3914e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
3924e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Indicates if the network interface is up or down.
3934e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
3944e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
3954e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
3964e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public boolean isUp() {
3974e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
3986cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.isUp();
3996cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4006cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
4014e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            return false;
4024e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4036cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
4046cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
4056cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
4064e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
4074e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4084e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
4094e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Indicates if there is at least one peer in range.
4104e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
4114e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @return <code>true</code> if we have at least one other peer in range, <code>false</code>
4124e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *     otherwise.
4134e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
4144e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public boolean isConnected() {
4154e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
4166cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.isConnected();
4176cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4186cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
4194e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            return false;
4206cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4216cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
4226cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
4234e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
4244e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
4254e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4264e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
4274e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Indicates if this interface is currently commissioned onto an existing network. If the
4284e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * interface is commissioned, the interface may be brought up using setUp().
4294e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
4304e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public boolean isCommissioned() {
4314e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
4326cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.isCommissioned();
4336cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4346cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
4354e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            return false;
4366cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4376cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
4386cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
4394e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
4404e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
4414e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4424e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
4434e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Get interface state
4444e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
4454e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <h3>State Diagram</h3>
4464e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
4474e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <img src="LowpanInterface-1.png" />
4484e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
4494e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @return The current state of the interface.
4504e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_OFFLINE
4514e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_COMMISSIONING
4524e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_ATTACHING
4534e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_ATTACHED
4544e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #STATE_FAULT
4554e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
4564e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public String getState() {
4574e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
4586cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getState();
4596cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4606cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
4614e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            return STATE_FAULT;
4626cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4636cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
4646cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
4656cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
4666cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    }
4676cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4686cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    /** Get network partition/fragment identifier. */
4696cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public String getPartitionId() {
4706cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        try {
4716cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getPartitionId();
4726cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4736cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
4746cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return EMPTY_PARTITION_ID;
4756cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
4766cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
4776cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
4784e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
4794e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
4804e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4814e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** TODO: doc */
4824e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public LowpanIdentity getLowpanIdentity() {
4834e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
4846cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getLowpanIdentity();
4854e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4866cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
4876cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return new LowpanIdentity();
4884e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4896cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
4906cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
4916cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
4924e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
4934e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
4944e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** TODO: doc */
4954e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    @NonNull
4964e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public String getRole() {
4974e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
4986cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getRole();
4994e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
5006cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (DeadObjectException x) {
5016cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return ROLE_DETACHED;
5024e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
5036cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
5046cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
5056cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
5064e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
5074e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
5084e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /** TODO: doc */
5094e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    @Nullable
5104e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public LowpanCredential getLowpanCredential() {
5114e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
5126cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getLowpanCredential();
5136cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
5146cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
5156cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
5164e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
5176cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    }
5186cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
5196cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public @NonNull String[] getSupportedNetworkTypes() throws LowpanException {
5206cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        try {
5216cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getSupportedNetworkTypes();
5224e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
5236cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
5246cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
5256cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
5266cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (ServiceSpecificException x) {
5276cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
5286cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
5294e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
5304e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
5316cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public @NonNull LowpanChannelInfo[] getSupportedChannels() throws LowpanException {
5326cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        try {
5336cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getSupportedChannels();
5346cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
5356cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (RemoteException x) {
5366cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw x.rethrowAsRuntimeException();
5376cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
5386cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        } catch (ServiceSpecificException x) {
5396cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
5406cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum        }
5414e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
5424e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
5434e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    // Listener Support
5444e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
5454e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
5464e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Registers a subclass of {@link LowpanInterface.Callback} to receive events.
5474e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
5484e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @param cb Subclass of {@link LowpanInterface.Callback} which will receive events.
5494e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @param handler If not <code>null</code>, events will be dispatched via the given handler
5504e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *     object. If <code>null</code>, the thread upon which events will be dispatched is
5514e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *     unspecified.
5524e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #registerCallback(Callback)
5534e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #unregisterCallback(Callback)
5544e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
5554e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void registerCallback(@NonNull Callback cb, @Nullable Handler handler) {
5564e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        ILowpanInterfaceListener.Stub listenerBinder =
5574e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum                new ILowpanInterfaceListener.Stub() {
558dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    private Handler mHandler;
559dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
560dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    {
561dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                        if (handler != null) {
562dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                            mHandler = handler;
563dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                        } else if (mLooper != null) {
564dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                            mHandler = new Handler(mLooper);
565dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                        } else {
566dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                            mHandler = new Handler();
567dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                        }
568dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    }
569dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
5706cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
5716cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onEnabledChanged(boolean value) {
5726cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onEnabledChanged(value));
5736cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    }
5746cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
5756cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
5766cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onConnectedChanged(boolean value) {
5776cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onConnectedChanged(value));
5786cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    }
5796cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
5806cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
5816cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onUpChanged(boolean value) {
5826cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onUpChanged(value));
583dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    }
584dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
5856cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
5866cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onRoleChanged(String value) {
5876cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onRoleChanged(value));
588dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    }
589dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
5906cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
5916cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onStateChanged(String value) {
5926cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onStateChanged(value));
593dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    }
594dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
5956cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
5966cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onLowpanIdentityChanged(LowpanIdentity value) {
5976cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onLowpanIdentityChanged(value));
5986cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    }
5996cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
6006cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
6016cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onLinkNetworkAdded(IpPrefix value) {
6026cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onLinkNetworkAdded(value));
6036cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    }
6046cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
6056cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
6066cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onLinkNetworkRemoved(IpPrefix value) {
6076cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onLinkNetworkRemoved(value));
6086cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    }
6096cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
6106cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
6116cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onLinkAddressAdded(String value) {
6126cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        LinkAddress la;
6136cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        try {
6146cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                            la = new LinkAddress(value);
6156cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        } catch (IllegalArgumentException x) {
6166cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                            Log.e(
6176cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                                    TAG,
6186cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                                    "onLinkAddressAdded: Bad LinkAddress \"" + value + "\", " + x);
6196cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                            return;
6206cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        }
6216cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onLinkAddressAdded(la));
6226cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    }
6236cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum
6246cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
6256cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onLinkAddressRemoved(String value) {
6266cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        LinkAddress la;
6276cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        try {
6286cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                            la = new LinkAddress(value);
6296cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        } catch (IllegalArgumentException x) {
6306cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                            Log.e(
6316cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                                    TAG,
6326cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                                    "onLinkAddressRemoved: Bad LinkAddress \""
6336cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                                            + value
6346cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                                            + "\", "
6356cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                                            + x);
6366cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                            return;
6376cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        }
6386cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        mHandler.post(() -> cb.onLinkAddressRemoved(la));
639dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    }
640dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
6416cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    @Override
6426cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                    public void onReceiveFromCommissioner(byte[] packet) {
6436cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum                        // This is only used by the LowpanCommissioningSession.
6444e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum                    }
6454e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum                };
6464e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
6474e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mBinder.addListener(listenerBinder);
6484e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
649dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
6504e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
651dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
6524e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        synchronized (mListenerMap) {
6534e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mListenerMap.put(System.identityHashCode(cb), listenerBinder);
6544e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
6554e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
6564e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
6574e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
6584e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Registers a subclass of {@link LowpanInterface.Callback} to receive events.
6594e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
6604e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * <p>The thread upon which events will be dispatched is unspecified.
6614e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
6624e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @param cb Subclass of {@link LowpanInterface.Callback} which will receive events.
6634e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #registerCallback(Callback, Handler)
6644e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #unregisterCallback(Callback)
6654e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
6664e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void registerCallback(Callback cb) {
6674e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        registerCallback(cb, null);
6684e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
6694e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
6704e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
6714e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Unregisters a previously registered callback class.
6724e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
6734e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @param cb Subclass of {@link LowpanInterface.Callback} which was previously registered to
6744e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *     receive events.
6754e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #registerCallback(Callback, Handler)
6764e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @see #registerCallback(Callback)
6774e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
6784e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void unregisterCallback(Callback cb) {
6794e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        int hashCode = System.identityHashCode(cb);
680325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum        synchronized (mListenerMap) {
681325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum            ILowpanInterfaceListener listenerBinder = mListenerMap.get(hashCode);
6824e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
683325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum            if (listenerBinder != null) {
6844e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum                mListenerMap.remove(hashCode);
685325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum
686325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum                try {
687325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum                    mBinder.removeListener(listenerBinder);
688dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                } catch (DeadObjectException x) {
689dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    // We ignore a dead object exception because that
690dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    // pretty clearly means our callback isn't registered.
691325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum                } catch (RemoteException x) {
692dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                    throw x.rethrowAsRuntimeException();
693325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum                }
6944e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            }
6954e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
6964e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
6974e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
698325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    // Active and Passive Scanning
6994e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
700325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    /**
701325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * Creates a new {@link android.net.lowpan.LowpanScanner} object for this interface.
702325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     *
703325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * <p>This method allocates a new unique object for each call.
704325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     *
705325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     * @see android.net.lowpan.LowpanScanner
706325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum     */
707325b7f5a066bc69c2ad32e1290274d18f40e423bRobert Quattlebaum    public @NonNull LowpanScanner createScanner() {
7084e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        return new LowpanScanner(mBinder);
7094e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
7104e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
7114e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    // Route Management
7124e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
7134e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
714dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * Makes a copy of the internal list of LinkAddresses.
715dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     *
716dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * @hide
717dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     */
7186cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public LinkAddress[] getLinkAddresses() throws LowpanException {
719dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        try {
7206cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            String[] linkAddressStrings = mBinder.getLinkAddresses();
721dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            LinkAddress[] ret = new LinkAddress[linkAddressStrings.length];
722dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            int i = 0;
723dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            for (String str : linkAddressStrings) {
724dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum                ret[i++] = new LinkAddress(str);
725dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            }
726dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            return ret;
727dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
728dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        } catch (RemoteException x) {
729dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
730dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
731dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        } catch (ServiceSpecificException x) {
7326cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
733dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        }
734dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    }
735dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
736dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    /**
737dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * Makes a copy of the internal list of networks reachable on via this link.
738dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     *
739dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     * @hide
740dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum     */
7416cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum    public IpPrefix[] getLinkNetworks() throws LowpanException {
742dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        try {
7436cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            return mBinder.getLinkNetworks();
744dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
745dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        } catch (RemoteException x) {
746dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
747dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
748dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        } catch (ServiceSpecificException x) {
7496cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
750dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum        }
751dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    }
752dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
753dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum    /**
7544e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Advertise the given IP prefix as an on-mesh prefix.
7554e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
7564e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
7574e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
7584e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void addOnMeshPrefix(IpPrefix prefix, int flags) throws LowpanException {
7594e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
7604e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mBinder.addOnMeshPrefix(prefix, flags);
761dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
7624e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
763dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
764dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
7654e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
7666cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
7674e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
7684e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
7694e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
7704e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
7714e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Remove an IP prefix previously advertised by this device from the list of advertised on-mesh
7724e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * prefixes.
7734e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
7744e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
7754e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
7764e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void removeOnMeshPrefix(IpPrefix prefix) {
7774e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
7784e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mBinder.removeOnMeshPrefix(prefix);
779dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
7804e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
781dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
782dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
7834e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
7844e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            // Catch and ignore all service exceptions
7854e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            Log.e(TAG, x.toString());
7864e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
7874e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
7884e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
7894e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
7904e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Advertise this device to other devices on the mesh network as having a specific route to the
7914e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * given network. This device will then receive forwarded traffic for that network.
7924e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
7934e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
7944e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
7954e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void addExternalRoute(IpPrefix prefix, int flags) throws LowpanException {
7964e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
7974e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mBinder.addExternalRoute(prefix, flags);
798dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
7994e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
800dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
801dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
8024e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
8036cfc490ccd8ea0d9ef4d52482ff65471f7631969Robert Quattlebaum            throw LowpanException.rethrowFromServiceSpecificException(x);
8044e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
8054e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
8064e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum
8074e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    /**
8084e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * Revoke a previously advertised specific route to the given network.
8094e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     *
8104e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     * @hide
8114e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum     */
8124e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    public void removeExternalRoute(IpPrefix prefix) {
8134e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        try {
8144e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            mBinder.removeExternalRoute(prefix);
815dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
8164e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (RemoteException x) {
817dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum            throw x.rethrowAsRuntimeException();
818dfd6889a842b61eb0b02d9630dc7f9785a5da7ecRobert Quattlebaum
8194e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        } catch (ServiceSpecificException x) {
8204e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            // Catch and ignore all service exceptions
8214e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum            Log.e(TAG, x.toString());
8224e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum        }
8234e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum    }
8244e0c2195dd999859f4e79cec1884326fb52a5916Robert Quattlebaum}
825