Merge "Remove lowpan internal API"
This commit is contained in:
@@ -72,7 +72,6 @@ filegroup {
|
|||||||
":framework-keystore-sources",
|
":framework-keystore-sources",
|
||||||
":framework-identity-sources",
|
":framework-identity-sources",
|
||||||
":framework-location-sources",
|
":framework-location-sources",
|
||||||
":framework-lowpan-sources",
|
|
||||||
":framework-mca-effect-sources",
|
":framework-mca-effect-sources",
|
||||||
":framework-mca-filterfw-sources",
|
":framework-mca-filterfw-sources",
|
||||||
":framework-mca-filterpacks-sources",
|
":framework-mca-filterpacks-sources",
|
||||||
@@ -167,7 +166,6 @@ java_defaults {
|
|||||||
"identity/java",
|
"identity/java",
|
||||||
"keystore/java",
|
"keystore/java",
|
||||||
"location/java",
|
"location/java",
|
||||||
"lowpan/java",
|
|
||||||
"media/java",
|
"media/java",
|
||||||
"media/mca/effect/java",
|
"media/mca/effect/java",
|
||||||
"media/mca/filterfw/java",
|
"media/mca/filterfw/java",
|
||||||
|
|||||||
@@ -147,8 +147,6 @@ import android.net.NetworkWatchlistManager;
|
|||||||
import android.net.PacProxyManager;
|
import android.net.PacProxyManager;
|
||||||
import android.net.TetheringManager;
|
import android.net.TetheringManager;
|
||||||
import android.net.VpnManager;
|
import android.net.VpnManager;
|
||||||
import android.net.lowpan.ILowpanManager;
|
|
||||||
import android.net.lowpan.LowpanManager;
|
|
||||||
import android.net.vcn.IVcnManagementService;
|
import android.net.vcn.IVcnManagementService;
|
||||||
import android.net.vcn.VcnManager;
|
import android.net.vcn.VcnManager;
|
||||||
import android.net.wifi.WifiFrameworkInitializer;
|
import android.net.wifi.WifiFrameworkInitializer;
|
||||||
@@ -768,15 +766,6 @@ public final class SystemServiceRegistry {
|
|||||||
ctx.mMainThread.getHandler());
|
ctx.mMainThread.getHandler());
|
||||||
}});
|
}});
|
||||||
|
|
||||||
registerService(Context.LOWPAN_SERVICE, LowpanManager.class,
|
|
||||||
new CachedServiceFetcher<LowpanManager>() {
|
|
||||||
@Override
|
|
||||||
public LowpanManager createService(ContextImpl ctx) throws ServiceNotFoundException {
|
|
||||||
IBinder b = ServiceManager.getServiceOrThrow(Context.LOWPAN_SERVICE);
|
|
||||||
ILowpanManager service = ILowpanManager.Stub.asInterface(b);
|
|
||||||
return new LowpanManager(ctx.getOuterContext(), service);
|
|
||||||
}});
|
|
||||||
|
|
||||||
registerService(Context.WIFI_NL80211_SERVICE, WifiNl80211Manager.class,
|
registerService(Context.WIFI_NL80211_SERVICE, WifiNl80211Manager.class,
|
||||||
new CachedServiceFetcher<WifiNl80211Manager>() {
|
new CachedServiceFetcher<WifiNl80211Manager>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package {
|
|
||||||
// See: http://go/android-license-faq
|
|
||||||
// A large-scale-change added 'default_applicable_licenses' to import
|
|
||||||
// all of the 'license_kinds' from "frameworks_base_license"
|
|
||||||
// to get the below license kinds:
|
|
||||||
// SPDX-license-identifier-Apache-2.0
|
|
||||||
default_applicable_licenses: ["frameworks_base_license"],
|
|
||||||
}
|
|
||||||
|
|
||||||
filegroup {
|
|
||||||
name: "framework-lowpan-sources",
|
|
||||||
srcs: [
|
|
||||||
"**/*.java",
|
|
||||||
"**/*.aidl",
|
|
||||||
],
|
|
||||||
visibility: ["//frameworks/base"],
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
interface ILowpanEnergyScanCallback {
|
|
||||||
oneway void onEnergyScanResult(int channel, int rssi);
|
|
||||||
oneway void onEnergyScanFinished();
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.net.IpPrefix;
|
|
||||||
import android.net.lowpan.ILowpanEnergyScanCallback;
|
|
||||||
import android.net.lowpan.ILowpanInterfaceListener;
|
|
||||||
import android.net.lowpan.ILowpanNetScanCallback;
|
|
||||||
import android.net.lowpan.LowpanBeaconInfo;
|
|
||||||
import android.net.lowpan.LowpanChannelInfo;
|
|
||||||
import android.net.lowpan.LowpanCredential;
|
|
||||||
import android.net.lowpan.LowpanIdentity;
|
|
||||||
import android.net.lowpan.LowpanProvision;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
interface ILowpanInterface {
|
|
||||||
|
|
||||||
// These are here for the sake of C++ interface implementations.
|
|
||||||
|
|
||||||
const String PERM_ACCESS_LOWPAN_STATE = "android.permission.ACCESS_LOWPAN_STATE";
|
|
||||||
const String PERM_CHANGE_LOWPAN_STATE = "android.permission.CHANGE_LOWPAN_STATE";
|
|
||||||
const String PERM_READ_LOWPAN_CREDENTIAL = "android.permission.READ_LOWPAN_CREDENTIAL";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Channel mask key.
|
|
||||||
* Used for setting a channel mask when starting a scan.
|
|
||||||
* Type: int[]
|
|
||||||
* */
|
|
||||||
const String KEY_CHANNEL_MASK = "android.net.lowpan.property.CHANNEL_MASK";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Max Transmit Power Key.
|
|
||||||
* Used for setting the maximum transmit power when starting a network scan.
|
|
||||||
* Type: Integer
|
|
||||||
* */
|
|
||||||
const String KEY_MAX_TX_POWER = "android.net.lowpan.property.MAX_TX_POWER";
|
|
||||||
|
|
||||||
// Interface States
|
|
||||||
|
|
||||||
const String STATE_OFFLINE = "offline";
|
|
||||||
const String STATE_COMMISSIONING = "commissioning";
|
|
||||||
const String STATE_ATTACHING = "attaching";
|
|
||||||
const String STATE_ATTACHED = "attached";
|
|
||||||
const String STATE_FAULT = "fault";
|
|
||||||
|
|
||||||
// Device Roles
|
|
||||||
|
|
||||||
const String ROLE_END_DEVICE = "end-device";
|
|
||||||
const String ROLE_ROUTER = "router";
|
|
||||||
const String ROLE_SLEEPY_END_DEVICE = "sleepy-end-device";
|
|
||||||
const String ROLE_SLEEPY_ROUTER = "sleepy-router";
|
|
||||||
const String ROLE_LEADER = "leader";
|
|
||||||
const String ROLE_COORDINATOR = "coordinator";
|
|
||||||
const String ROLE_DETACHED = "detached";
|
|
||||||
|
|
||||||
const String NETWORK_TYPE_UNKNOWN = "unknown";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Network type for Thread 1.x networks.
|
|
||||||
*
|
|
||||||
* @see android.net.lowpan.LowpanIdentity#getType
|
|
||||||
* @see #getLowpanIdentity
|
|
||||||
*/
|
|
||||||
const String NETWORK_TYPE_THREAD_V1 = "org.threadgroup.thread.v1";
|
|
||||||
|
|
||||||
// Service-Specific Error Code Constants
|
|
||||||
|
|
||||||
const int ERROR_UNSPECIFIED = 1;
|
|
||||||
const int ERROR_INVALID_ARGUMENT = 2;
|
|
||||||
const int ERROR_DISABLED = 3;
|
|
||||||
const int ERROR_WRONG_STATE = 4;
|
|
||||||
const int ERROR_TIMEOUT = 5;
|
|
||||||
const int ERROR_IO_FAILURE = 6;
|
|
||||||
const int ERROR_NCP_PROBLEM = 7;
|
|
||||||
const int ERROR_BUSY = 8;
|
|
||||||
const int ERROR_ALREADY = 9;
|
|
||||||
const int ERROR_CANCELED = 10;
|
|
||||||
const int ERROR_FEATURE_NOT_SUPPORTED = 11;
|
|
||||||
const int ERROR_JOIN_FAILED_UNKNOWN = 12;
|
|
||||||
const int ERROR_JOIN_FAILED_AT_SCAN = 13;
|
|
||||||
const int ERROR_JOIN_FAILED_AT_AUTH = 14;
|
|
||||||
const int ERROR_FORM_FAILED_AT_SCAN = 15;
|
|
||||||
|
|
||||||
// Methods
|
|
||||||
|
|
||||||
@utf8InCpp String getName();
|
|
||||||
|
|
||||||
@utf8InCpp String getNcpVersion();
|
|
||||||
@utf8InCpp String getDriverVersion();
|
|
||||||
LowpanChannelInfo[] getSupportedChannels();
|
|
||||||
@utf8InCpp String[] getSupportedNetworkTypes();
|
|
||||||
byte[] getMacAddress();
|
|
||||||
|
|
||||||
boolean isEnabled();
|
|
||||||
void setEnabled(boolean enabled);
|
|
||||||
|
|
||||||
boolean isUp();
|
|
||||||
boolean isCommissioned();
|
|
||||||
boolean isConnected();
|
|
||||||
@utf8InCpp String getState();
|
|
||||||
|
|
||||||
@utf8InCpp String getRole();
|
|
||||||
@utf8InCpp String getPartitionId();
|
|
||||||
byte[] getExtendedAddress();
|
|
||||||
|
|
||||||
LowpanIdentity getLowpanIdentity();
|
|
||||||
LowpanCredential getLowpanCredential();
|
|
||||||
|
|
||||||
@utf8InCpp String[] getLinkAddresses();
|
|
||||||
IpPrefix[] getLinkNetworks();
|
|
||||||
|
|
||||||
void join(in LowpanProvision provision);
|
|
||||||
void form(in LowpanProvision provision);
|
|
||||||
void attach(in LowpanProvision provision);
|
|
||||||
void leave();
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
void startCommissioningSession(in LowpanBeaconInfo beaconInfo);
|
|
||||||
void closeCommissioningSession();
|
|
||||||
oneway void sendToCommissioner(in byte[] packet);
|
|
||||||
|
|
||||||
void beginLowPower();
|
|
||||||
oneway void pollForData();
|
|
||||||
|
|
||||||
oneway void onHostWake();
|
|
||||||
|
|
||||||
void addListener(ILowpanInterfaceListener listener);
|
|
||||||
oneway void removeListener(ILowpanInterfaceListener listener);
|
|
||||||
|
|
||||||
void startNetScan(in Map properties, ILowpanNetScanCallback listener);
|
|
||||||
oneway void stopNetScan();
|
|
||||||
|
|
||||||
void startEnergyScan(in Map properties, ILowpanEnergyScanCallback listener);
|
|
||||||
oneway void stopEnergyScan();
|
|
||||||
|
|
||||||
void addOnMeshPrefix(in IpPrefix prefix, int flags);
|
|
||||||
oneway void removeOnMeshPrefix(in IpPrefix prefix);
|
|
||||||
|
|
||||||
void addExternalRoute(in IpPrefix prefix, int flags);
|
|
||||||
oneway void removeExternalRoute(in IpPrefix prefix);
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.net.IpPrefix;
|
|
||||||
import android.net.lowpan.LowpanIdentity;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
interface ILowpanInterfaceListener {
|
|
||||||
oneway void onEnabledChanged(boolean value);
|
|
||||||
|
|
||||||
oneway void onConnectedChanged(boolean value);
|
|
||||||
|
|
||||||
oneway void onUpChanged(boolean value);
|
|
||||||
|
|
||||||
oneway void onRoleChanged(@utf8InCpp String value);
|
|
||||||
|
|
||||||
oneway void onStateChanged(@utf8InCpp String value);
|
|
||||||
|
|
||||||
oneway void onLowpanIdentityChanged(in LowpanIdentity value);
|
|
||||||
|
|
||||||
oneway void onLinkNetworkAdded(in IpPrefix value);
|
|
||||||
|
|
||||||
oneway void onLinkNetworkRemoved(in IpPrefix value);
|
|
||||||
|
|
||||||
oneway void onLinkAddressAdded(@utf8InCpp String value);
|
|
||||||
|
|
||||||
oneway void onLinkAddressRemoved(@utf8InCpp String value);
|
|
||||||
|
|
||||||
oneway void onReceiveFromCommissioner(in byte[] packet);
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
import android.net.lowpan.ILowpanInterface;
|
|
||||||
import android.net.lowpan.ILowpanManagerListener;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
interface ILowpanManager {
|
|
||||||
|
|
||||||
/* Keep this in sync with Context.LOWPAN_SERVICE */
|
|
||||||
const String LOWPAN_SERVICE_NAME = "lowpan";
|
|
||||||
|
|
||||||
ILowpanInterface getInterface(@utf8InCpp String name);
|
|
||||||
|
|
||||||
@utf8InCpp String[] getInterfaceList();
|
|
||||||
|
|
||||||
void addListener(ILowpanManagerListener listener);
|
|
||||||
void removeListener(ILowpanManagerListener listener);
|
|
||||||
|
|
||||||
void addInterface(ILowpanInterface lowpan_interface);
|
|
||||||
void removeInterface(ILowpanInterface lowpan_interface);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.net.lowpan.ILowpanInterface;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
interface ILowpanManagerListener {
|
|
||||||
oneway void onInterfaceAdded(ILowpanInterface lowpanInterface);
|
|
||||||
oneway void onInterfaceRemoved(ILowpanInterface lowpanInterface);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.net.lowpan.LowpanBeaconInfo;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
interface ILowpanNetScanCallback {
|
|
||||||
oneway void onNetScanBeacon(in LowpanBeaconInfo beacon);
|
|
||||||
oneway void onNetScanFinished();
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception indicating this operation requires the interface to be enabled.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class InterfaceDisabledException extends LowpanException {
|
|
||||||
|
|
||||||
public InterfaceDisabledException() {}
|
|
||||||
|
|
||||||
public InterfaceDisabledException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InterfaceDisabledException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InterfaceDisabledException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception indicating the join operation was unable to find the given network.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class JoinFailedAtAuthException extends JoinFailedException {
|
|
||||||
|
|
||||||
public JoinFailedAtAuthException() {}
|
|
||||||
|
|
||||||
public JoinFailedAtAuthException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JoinFailedAtAuthException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JoinFailedAtAuthException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception indicating the join operation was unable to find the given network.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class JoinFailedAtScanException extends JoinFailedException {
|
|
||||||
|
|
||||||
public JoinFailedAtScanException() {}
|
|
||||||
|
|
||||||
public JoinFailedAtScanException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JoinFailedAtScanException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JoinFailedAtScanException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception indicating the join operation has failed.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class JoinFailedException extends LowpanException {
|
|
||||||
|
|
||||||
public JoinFailedException() {}
|
|
||||||
|
|
||||||
public JoinFailedException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JoinFailedException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JoinFailedException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
parcelable LowpanBeaconInfo cpp_header "android/net/lowpan/LowpanBeaconInfo.h";
|
|
||||||
@@ -1,234 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import com.android.internal.util.HexDump;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes a LoWPAN Beacon
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanBeaconInfo implements Parcelable {
|
|
||||||
public static final int UNKNOWN_RSSI = Integer.MAX_VALUE;
|
|
||||||
public static final int UNKNOWN_LQI = 0;
|
|
||||||
|
|
||||||
private LowpanIdentity mIdentity;
|
|
||||||
private int mRssi = UNKNOWN_RSSI;
|
|
||||||
private int mLqi = UNKNOWN_LQI;
|
|
||||||
private byte[] mBeaconAddress = null;
|
|
||||||
private final TreeSet<Integer> mFlags = new TreeSet<>();
|
|
||||||
|
|
||||||
public static final int FLAG_CAN_ASSIST = 1;
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
public static class Builder {
|
|
||||||
final LowpanIdentity.Builder mIdentityBuilder = new LowpanIdentity.Builder();
|
|
||||||
final LowpanBeaconInfo mBeaconInfo = new LowpanBeaconInfo();
|
|
||||||
|
|
||||||
public Builder setLowpanIdentity(LowpanIdentity x) {
|
|
||||||
mIdentityBuilder.setLowpanIdentity(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setName(String x) {
|
|
||||||
mIdentityBuilder.setName(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setXpanid(byte x[]) {
|
|
||||||
mIdentityBuilder.setXpanid(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setPanid(int x) {
|
|
||||||
mIdentityBuilder.setPanid(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setChannel(int x) {
|
|
||||||
mIdentityBuilder.setChannel(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setType(String x) {
|
|
||||||
mIdentityBuilder.setType(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setRssi(int x) {
|
|
||||||
mBeaconInfo.mRssi = x;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setLqi(int x) {
|
|
||||||
mBeaconInfo.mLqi = x;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setBeaconAddress(byte x[]) {
|
|
||||||
mBeaconInfo.mBeaconAddress = (x != null ? x.clone() : null);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setFlag(int x) {
|
|
||||||
mBeaconInfo.mFlags.add(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setFlags(Collection<Integer> x) {
|
|
||||||
mBeaconInfo.mFlags.addAll(x);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanBeaconInfo build() {
|
|
||||||
mBeaconInfo.mIdentity = mIdentityBuilder.build();
|
|
||||||
if (mBeaconInfo.mBeaconAddress == null) {
|
|
||||||
mBeaconInfo.mBeaconAddress = new byte[0];
|
|
||||||
}
|
|
||||||
return mBeaconInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private LowpanBeaconInfo() {}
|
|
||||||
|
|
||||||
public LowpanIdentity getLowpanIdentity() {
|
|
||||||
return mIdentity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRssi() {
|
|
||||||
return mRssi;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLqi() {
|
|
||||||
return mLqi;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getBeaconAddress() {
|
|
||||||
return mBeaconAddress.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Integer> getFlags() {
|
|
||||||
return (Collection<Integer>) mFlags.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFlagSet(int flag) {
|
|
||||||
return mFlags.contains(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
|
||||||
sb.append(mIdentity.toString());
|
|
||||||
|
|
||||||
if (mRssi != UNKNOWN_RSSI) {
|
|
||||||
sb.append(", RSSI:").append(mRssi).append("dBm");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mLqi != UNKNOWN_LQI) {
|
|
||||||
sb.append(", LQI:").append(mLqi);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mBeaconAddress.length > 0) {
|
|
||||||
sb.append(", BeaconAddress:").append(HexDump.toHexString(mBeaconAddress));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Integer flag : mFlags) {
|
|
||||||
switch (flag.intValue()) {
|
|
||||||
case FLAG_CAN_ASSIST:
|
|
||||||
sb.append(", CAN_ASSIST");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sb.append(", FLAG_").append(Integer.toHexString(flag));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(mIdentity, mRssi, mLqi, Arrays.hashCode(mBeaconAddress), mFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof LowpanBeaconInfo)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LowpanBeaconInfo rhs = (LowpanBeaconInfo) obj;
|
|
||||||
return mIdentity.equals(rhs.mIdentity)
|
|
||||||
&& Arrays.equals(mBeaconAddress, rhs.mBeaconAddress)
|
|
||||||
&& mRssi == rhs.mRssi
|
|
||||||
&& mLqi == rhs.mLqi
|
|
||||||
&& mFlags.equals(rhs.mFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
mIdentity.writeToParcel(dest, flags);
|
|
||||||
dest.writeInt(mRssi);
|
|
||||||
dest.writeInt(mLqi);
|
|
||||||
dest.writeByteArray(mBeaconAddress);
|
|
||||||
|
|
||||||
dest.writeInt(mFlags.size());
|
|
||||||
for (Integer val : mFlags) {
|
|
||||||
dest.writeInt(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
public static final @android.annotation.NonNull Creator<LowpanBeaconInfo> CREATOR =
|
|
||||||
new Creator<LowpanBeaconInfo>() {
|
|
||||||
public LowpanBeaconInfo createFromParcel(Parcel in) {
|
|
||||||
Builder builder = new Builder();
|
|
||||||
|
|
||||||
builder.setLowpanIdentity(LowpanIdentity.CREATOR.createFromParcel(in));
|
|
||||||
|
|
||||||
builder.setRssi(in.readInt());
|
|
||||||
builder.setLqi(in.readInt());
|
|
||||||
|
|
||||||
builder.setBeaconAddress(in.createByteArray());
|
|
||||||
|
|
||||||
for (int i = in.readInt(); i > 0; i--) {
|
|
||||||
builder.setFlag(in.readInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanBeaconInfo[] newArray(int size) {
|
|
||||||
return new LowpanBeaconInfo[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
parcelable LowpanChannelInfo cpp_header "android/net/lowpan/LowpanChannelInfo.h";
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides detailed information about a given channel.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanChannelInfo implements Parcelable {
|
|
||||||
|
|
||||||
public static final int UNKNOWN_POWER = Integer.MAX_VALUE;
|
|
||||||
public static final float UNKNOWN_FREQUENCY = 0.0f;
|
|
||||||
public static final float UNKNOWN_BANDWIDTH = 0.0f;
|
|
||||||
|
|
||||||
private int mIndex = 0;
|
|
||||||
private String mName = null;
|
|
||||||
private float mSpectrumCenterFrequency = UNKNOWN_FREQUENCY;
|
|
||||||
private float mSpectrumBandwidth = UNKNOWN_BANDWIDTH;
|
|
||||||
private int mMaxTransmitPower = UNKNOWN_POWER;
|
|
||||||
private boolean mIsMaskedByRegulatoryDomain = false;
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
public static LowpanChannelInfo getChannelInfoForIeee802154Page0(int index) {
|
|
||||||
LowpanChannelInfo info = new LowpanChannelInfo();
|
|
||||||
|
|
||||||
if (index < 0) {
|
|
||||||
info = null;
|
|
||||||
|
|
||||||
} else if (index == 0) {
|
|
||||||
info.mSpectrumCenterFrequency = 868300000.0f;
|
|
||||||
info.mSpectrumBandwidth = 600000.0f;
|
|
||||||
|
|
||||||
} else if (index < 11) {
|
|
||||||
info.mSpectrumCenterFrequency = 906000000.0f - (2000000.0f * 1) + 2000000.0f * (index);
|
|
||||||
info.mSpectrumBandwidth = 0; // Unknown
|
|
||||||
|
|
||||||
} else if (index < 26) {
|
|
||||||
info.mSpectrumCenterFrequency =
|
|
||||||
2405000000.0f - (5000000.0f * 11) + 5000000.0f * (index);
|
|
||||||
info.mSpectrumBandwidth = 2000000.0f;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
info = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
info.mName = Integer.toString(index);
|
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LowpanChannelInfo() {}
|
|
||||||
|
|
||||||
private LowpanChannelInfo(int index, String name, float cf, float bw) {
|
|
||||||
mIndex = index;
|
|
||||||
mName = name;
|
|
||||||
mSpectrumCenterFrequency = cf;
|
|
||||||
mSpectrumBandwidth = bw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return mName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIndex() {
|
|
||||||
return mIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxTransmitPower() {
|
|
||||||
return mMaxTransmitPower;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMaskedByRegulatoryDomain() {
|
|
||||||
return mIsMaskedByRegulatoryDomain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getSpectrumCenterFrequency() {
|
|
||||||
return mSpectrumCenterFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getSpectrumBandwidth() {
|
|
||||||
return mSpectrumBandwidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
|
||||||
sb.append("Channel ").append(mIndex);
|
|
||||||
|
|
||||||
if (mName != null && !mName.equals(Integer.toString(mIndex))) {
|
|
||||||
sb.append(" (").append(mName).append(")");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSpectrumCenterFrequency > 0.0f) {
|
|
||||||
if (mSpectrumCenterFrequency > 1000000000.0f) {
|
|
||||||
sb.append(", SpectrumCenterFrequency: ")
|
|
||||||
.append(mSpectrumCenterFrequency / 1000000000.0f)
|
|
||||||
.append("GHz");
|
|
||||||
} else if (mSpectrumCenterFrequency > 1000000.0f) {
|
|
||||||
sb.append(", SpectrumCenterFrequency: ")
|
|
||||||
.append(mSpectrumCenterFrequency / 1000000.0f)
|
|
||||||
.append("MHz");
|
|
||||||
} else {
|
|
||||||
sb.append(", SpectrumCenterFrequency: ")
|
|
||||||
.append(mSpectrumCenterFrequency / 1000.0f)
|
|
||||||
.append("kHz");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSpectrumBandwidth > 0.0f) {
|
|
||||||
if (mSpectrumBandwidth > 1000000000.0f) {
|
|
||||||
sb.append(", SpectrumBandwidth: ")
|
|
||||||
.append(mSpectrumBandwidth / 1000000000.0f)
|
|
||||||
.append("GHz");
|
|
||||||
} else if (mSpectrumBandwidth > 1000000.0f) {
|
|
||||||
sb.append(", SpectrumBandwidth: ")
|
|
||||||
.append(mSpectrumBandwidth / 1000000.0f)
|
|
||||||
.append("MHz");
|
|
||||||
} else {
|
|
||||||
sb.append(", SpectrumBandwidth: ")
|
|
||||||
.append(mSpectrumBandwidth / 1000.0f)
|
|
||||||
.append("kHz");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mMaxTransmitPower != UNKNOWN_POWER) {
|
|
||||||
sb.append(", MaxTransmitPower: ").append(mMaxTransmitPower).append("dBm");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof LowpanChannelInfo)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LowpanChannelInfo rhs = (LowpanChannelInfo) obj;
|
|
||||||
return Objects.equals(mName, rhs.mName)
|
|
||||||
&& mIndex == rhs.mIndex
|
|
||||||
&& mIsMaskedByRegulatoryDomain == rhs.mIsMaskedByRegulatoryDomain
|
|
||||||
&& mSpectrumCenterFrequency == rhs.mSpectrumCenterFrequency
|
|
||||||
&& mSpectrumBandwidth == rhs.mSpectrumBandwidth
|
|
||||||
&& mMaxTransmitPower == rhs.mMaxTransmitPower;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(
|
|
||||||
mName,
|
|
||||||
mIndex,
|
|
||||||
mIsMaskedByRegulatoryDomain,
|
|
||||||
mSpectrumCenterFrequency,
|
|
||||||
mSpectrumBandwidth,
|
|
||||||
mMaxTransmitPower);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeInt(mIndex);
|
|
||||||
dest.writeString(mName);
|
|
||||||
dest.writeFloat(mSpectrumCenterFrequency);
|
|
||||||
dest.writeFloat(mSpectrumBandwidth);
|
|
||||||
dest.writeInt(mMaxTransmitPower);
|
|
||||||
dest.writeBoolean(mIsMaskedByRegulatoryDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
public static final @android.annotation.NonNull Creator<LowpanChannelInfo> CREATOR =
|
|
||||||
new Creator<LowpanChannelInfo>() {
|
|
||||||
|
|
||||||
public LowpanChannelInfo createFromParcel(Parcel in) {
|
|
||||||
LowpanChannelInfo info = new LowpanChannelInfo();
|
|
||||||
|
|
||||||
info.mIndex = in.readInt();
|
|
||||||
info.mName = in.readString();
|
|
||||||
info.mSpectrumCenterFrequency = in.readFloat();
|
|
||||||
info.mSpectrumBandwidth = in.readFloat();
|
|
||||||
info.mMaxTransmitPower = in.readInt();
|
|
||||||
info.mIsMaskedByRegulatoryDomain = in.readBoolean();
|
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanChannelInfo[] newArray(int size) {
|
|
||||||
return new LowpanChannelInfo[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.net.IpPrefix;
|
|
||||||
import android.os.DeadObjectException;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commissioning Session.
|
|
||||||
*
|
|
||||||
* <p>This class enables a device to learn the credential needed to join a network using a technique
|
|
||||||
* called "in-band commissioning".
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanCommissioningSession {
|
|
||||||
|
|
||||||
private final ILowpanInterface mBinder;
|
|
||||||
private final LowpanBeaconInfo mBeaconInfo;
|
|
||||||
private final ILowpanInterfaceListener mInternalCallback = new InternalCallback();
|
|
||||||
private final Looper mLooper;
|
|
||||||
private Handler mHandler;
|
|
||||||
private Callback mCallback = null;
|
|
||||||
private volatile boolean mIsClosed = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback base class for {@link LowpanCommissioningSession}
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public abstract static class Callback {
|
|
||||||
public void onReceiveFromCommissioner(@NonNull byte[] packet) {};
|
|
||||||
|
|
||||||
public void onClosed() {};
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InternalCallback extends ILowpanInterfaceListener.Stub {
|
|
||||||
@Override
|
|
||||||
public void onStateChanged(String value) {
|
|
||||||
if (!mIsClosed) {
|
|
||||||
switch (value) {
|
|
||||||
case ILowpanInterface.STATE_OFFLINE:
|
|
||||||
case ILowpanInterface.STATE_FAULT:
|
|
||||||
synchronized (LowpanCommissioningSession.this) {
|
|
||||||
lockedCleanup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceiveFromCommissioner(byte[] packet) {
|
|
||||||
mHandler.post(
|
|
||||||
() -> {
|
|
||||||
synchronized (LowpanCommissioningSession.this) {
|
|
||||||
if (!mIsClosed && (mCallback != null)) {
|
|
||||||
mCallback.onReceiveFromCommissioner(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// We ignore all other callbacks.
|
|
||||||
@Override
|
|
||||||
public void onEnabledChanged(boolean value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectedChanged(boolean value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpChanged(boolean value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRoleChanged(String value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLowpanIdentityChanged(LowpanIdentity value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkNetworkAdded(IpPrefix value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkNetworkRemoved(IpPrefix value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkAddressAdded(String value) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkAddressRemoved(String value) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
LowpanCommissioningSession(
|
|
||||||
ILowpanInterface binder, LowpanBeaconInfo beaconInfo, Looper looper) {
|
|
||||||
mBinder = binder;
|
|
||||||
mBeaconInfo = beaconInfo;
|
|
||||||
mLooper = looper;
|
|
||||||
|
|
||||||
if (mLooper != null) {
|
|
||||||
mHandler = new Handler(mLooper);
|
|
||||||
} else {
|
|
||||||
mHandler = new Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBinder.addListener(mInternalCallback);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void lockedCleanup() {
|
|
||||||
// Note: this method is only called from synchronized contexts.
|
|
||||||
|
|
||||||
if (!mIsClosed) {
|
|
||||||
try {
|
|
||||||
mBinder.removeListener(mInternalCallback);
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
/* We don't care if we receive a DOE at this point.
|
|
||||||
* DOE is as good as success as far as we are concerned.
|
|
||||||
*/
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mCallback != null) {
|
|
||||||
mHandler.post(() -> mCallback.onClosed());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mCallback = null;
|
|
||||||
mIsClosed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
@NonNull
|
|
||||||
public LowpanBeaconInfo getBeaconInfo() {
|
|
||||||
return mBeaconInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
public void sendToCommissioner(@NonNull byte[] packet) {
|
|
||||||
if (!mIsClosed) {
|
|
||||||
try {
|
|
||||||
mBinder.sendToCommissioner(packet);
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
/* This method is a best-effort delivery.
|
|
||||||
* We don't care if we receive a DOE at this point.
|
|
||||||
*/
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
public synchronized void setCallback(@Nullable Callback cb, @Nullable Handler handler) {
|
|
||||||
if (!mIsClosed) {
|
|
||||||
/* This class can be created with or without a default looper.
|
|
||||||
* Also, this method can be called with or without a specific
|
|
||||||
* handler. If a handler is specified, it is to always be used.
|
|
||||||
* Otherwise, if there was a Looper specified when this object
|
|
||||||
* was created, we create a new handle based on that looper.
|
|
||||||
* Otherwise we just create a default handler object. Since we
|
|
||||||
* don't really know how the previous handler was created, we
|
|
||||||
* end up always replacing it here. This isn't a huge problem
|
|
||||||
* because this method should be called infrequently.
|
|
||||||
*/
|
|
||||||
if (handler != null) {
|
|
||||||
mHandler = handler;
|
|
||||||
} else if (mLooper != null) {
|
|
||||||
mHandler = new Handler(mLooper);
|
|
||||||
} else {
|
|
||||||
mHandler = new Handler();
|
|
||||||
}
|
|
||||||
mCallback = cb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
public synchronized void close() {
|
|
||||||
if (!mIsClosed) {
|
|
||||||
try {
|
|
||||||
mBinder.closeCommissioningSession();
|
|
||||||
|
|
||||||
lockedCleanup();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
/* We don't care if we receive a DOE at this point.
|
|
||||||
* DOE is as good as success as far as we are concerned.
|
|
||||||
*/
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
parcelable LowpanCredential cpp_header "android/net/lowpan/LowpanCredential.h";
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import com.android.internal.util.HexDump;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes a credential for a LoWPAN network.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanCredential implements Parcelable {
|
|
||||||
|
|
||||||
public static final int UNSPECIFIED_KEY_INDEX = 0;
|
|
||||||
|
|
||||||
private byte[] mMasterKey = null;
|
|
||||||
private int mMasterKeyIndex = UNSPECIFIED_KEY_INDEX;
|
|
||||||
|
|
||||||
LowpanCredential() {}
|
|
||||||
|
|
||||||
private LowpanCredential(byte[] masterKey, int keyIndex) {
|
|
||||||
setMasterKey(masterKey, keyIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private LowpanCredential(byte[] masterKey) {
|
|
||||||
setMasterKey(masterKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LowpanCredential createMasterKey(byte[] masterKey) {
|
|
||||||
return new LowpanCredential(masterKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LowpanCredential createMasterKey(byte[] masterKey, int keyIndex) {
|
|
||||||
return new LowpanCredential(masterKey, keyIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMasterKey(byte[] masterKey) {
|
|
||||||
if (masterKey != null) {
|
|
||||||
masterKey = masterKey.clone();
|
|
||||||
}
|
|
||||||
mMasterKey = masterKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMasterKeyIndex(int keyIndex) {
|
|
||||||
mMasterKeyIndex = keyIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMasterKey(byte[] masterKey, int keyIndex) {
|
|
||||||
setMasterKey(masterKey);
|
|
||||||
setMasterKeyIndex(keyIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getMasterKey() {
|
|
||||||
if (mMasterKey != null) {
|
|
||||||
return mMasterKey.clone();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMasterKeyIndex() {
|
|
||||||
return mMasterKeyIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMasterKey() {
|
|
||||||
return mMasterKey != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toSensitiveString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
|
||||||
sb.append("<LowpanCredential");
|
|
||||||
|
|
||||||
if (isMasterKey()) {
|
|
||||||
sb.append(" MasterKey:").append(HexDump.toHexString(mMasterKey));
|
|
||||||
if (mMasterKeyIndex != UNSPECIFIED_KEY_INDEX) {
|
|
||||||
sb.append(", Index:").append(mMasterKeyIndex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sb.append(" empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(">");
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
|
||||||
sb.append("<LowpanCredential");
|
|
||||||
|
|
||||||
if (isMasterKey()) {
|
|
||||||
// We don't print out the contents of the key here,
|
|
||||||
// we only do that in toSensitiveString.
|
|
||||||
sb.append(" MasterKey");
|
|
||||||
if (mMasterKeyIndex != UNSPECIFIED_KEY_INDEX) {
|
|
||||||
sb.append(", Index:").append(mMasterKeyIndex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sb.append(" empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(">");
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof LowpanCredential)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LowpanCredential rhs = (LowpanCredential) obj;
|
|
||||||
return Arrays.equals(mMasterKey, rhs.mMasterKey) && mMasterKeyIndex == rhs.mMasterKeyIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(Arrays.hashCode(mMasterKey), mMasterKeyIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeByteArray(mMasterKey);
|
|
||||||
dest.writeInt(mMasterKeyIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
public static final @android.annotation.NonNull Creator<LowpanCredential> CREATOR =
|
|
||||||
new Creator<LowpanCredential>() {
|
|
||||||
|
|
||||||
public LowpanCredential createFromParcel(Parcel in) {
|
|
||||||
LowpanCredential credential = new LowpanCredential();
|
|
||||||
|
|
||||||
credential.mMasterKey = in.createByteArray();
|
|
||||||
credential.mMasterKeyIndex = in.readInt();
|
|
||||||
|
|
||||||
return credential;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanCredential[] newArray(int size) {
|
|
||||||
return new LowpanCredential[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes the result from one channel of an energy scan.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanEnergyScanResult {
|
|
||||||
public static final int UNKNOWN = Integer.MAX_VALUE;
|
|
||||||
|
|
||||||
private int mChannel = UNKNOWN;
|
|
||||||
private int mMaxRssi = UNKNOWN;
|
|
||||||
|
|
||||||
LowpanEnergyScanResult() {}
|
|
||||||
|
|
||||||
public int getChannel() {
|
|
||||||
return mChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxRssi() {
|
|
||||||
return mMaxRssi;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setChannel(int x) {
|
|
||||||
mChannel = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMaxRssi(int x) {
|
|
||||||
mMaxRssi = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "LowpanEnergyScanResult(channel: " + mChannel + ", maxRssi:" + mMaxRssi + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.os.ServiceSpecificException;
|
|
||||||
import android.util.AndroidException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>LowpanException</code> is thrown if an action to a LoWPAN interface could not be performed
|
|
||||||
* or a LoWPAN interface property could not be fetched or changed.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanException extends AndroidException {
|
|
||||||
public LowpanException() {}
|
|
||||||
|
|
||||||
public LowpanException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This method returns LowpanException so that the caller
|
|
||||||
* can add "throw" before the invocation of this method.
|
|
||||||
* This might seem superfluous, but it is actually to
|
|
||||||
* help provide a hint to the java compiler that this
|
|
||||||
* function will not return.
|
|
||||||
*/
|
|
||||||
static LowpanException rethrowFromServiceSpecificException(ServiceSpecificException e)
|
|
||||||
throws LowpanException {
|
|
||||||
switch (e.errorCode) {
|
|
||||||
case ILowpanInterface.ERROR_DISABLED:
|
|
||||||
throw new InterfaceDisabledException(e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_WRONG_STATE:
|
|
||||||
throw new WrongStateException(e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_CANCELED:
|
|
||||||
throw new OperationCanceledException(e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_JOIN_FAILED_UNKNOWN:
|
|
||||||
throw new JoinFailedException(e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_JOIN_FAILED_AT_SCAN:
|
|
||||||
throw new JoinFailedAtScanException(e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_JOIN_FAILED_AT_AUTH:
|
|
||||||
throw new JoinFailedAtAuthException(e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_FORM_FAILED_AT_SCAN:
|
|
||||||
throw new NetworkAlreadyExistsException(e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_FEATURE_NOT_SUPPORTED:
|
|
||||||
throw new LowpanException(
|
|
||||||
e.getMessage() != null ? e.getMessage() : "Feature not supported", e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_NCP_PROBLEM:
|
|
||||||
throw new LowpanRuntimeException(
|
|
||||||
e.getMessage() != null ? e.getMessage() : "NCP problem", e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_INVALID_ARGUMENT:
|
|
||||||
throw new LowpanRuntimeException(
|
|
||||||
e.getMessage() != null ? e.getMessage() : "Invalid argument", e);
|
|
||||||
|
|
||||||
case ILowpanInterface.ERROR_UNSPECIFIED:
|
|
||||||
default:
|
|
||||||
throw new LowpanRuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
parcelable LowpanIdentity cpp_header "android/net/lowpan/LowpanIdentity.h";
|
|
||||||
@@ -1,255 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.icu.text.StringPrep;
|
|
||||||
import android.icu.text.StringPrepParseException;
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.util.Log;
|
|
||||||
import com.android.internal.util.HexDump;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes an instance of a LoWPAN network.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanIdentity implements Parcelable {
|
|
||||||
private static final String TAG = LowpanIdentity.class.getSimpleName();
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
public static final int UNSPECIFIED_CHANNEL = -1;
|
|
||||||
public static final int UNSPECIFIED_PANID = 0xFFFFFFFF;
|
|
||||||
// Builder
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
// @SystemApi
|
|
||||||
public static class Builder {
|
|
||||||
private static final StringPrep stringPrep =
|
|
||||||
StringPrep.getInstance(StringPrep.RFC3920_RESOURCEPREP);
|
|
||||||
|
|
||||||
final LowpanIdentity mIdentity = new LowpanIdentity();
|
|
||||||
|
|
||||||
private static String escape(@NonNull byte[] bytes) {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for (byte b : bytes) {
|
|
||||||
if (b >= 32 && b <= 126) {
|
|
||||||
sb.append((char) b);
|
|
||||||
} else {
|
|
||||||
sb.append(String.format("\\0x%02x", b & 0xFF));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setLowpanIdentity(@NonNull LowpanIdentity x) {
|
|
||||||
Objects.requireNonNull(x);
|
|
||||||
setRawName(x.getRawName());
|
|
||||||
setXpanid(x.getXpanid());
|
|
||||||
setPanid(x.getPanid());
|
|
||||||
setChannel(x.getChannel());
|
|
||||||
setType(x.getType());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setName(@NonNull String name) {
|
|
||||||
Objects.requireNonNull(name);
|
|
||||||
try {
|
|
||||||
mIdentity.mName = stringPrep.prepare(name, StringPrep.DEFAULT);
|
|
||||||
mIdentity.mRawName = mIdentity.mName.getBytes(StandardCharsets.UTF_8);
|
|
||||||
mIdentity.mIsNameValid = true;
|
|
||||||
} catch (StringPrepParseException x) {
|
|
||||||
Log.w(TAG, x.toString());
|
|
||||||
setRawName(name.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setRawName(@NonNull byte[] name) {
|
|
||||||
Objects.requireNonNull(name);
|
|
||||||
mIdentity.mRawName = name.clone();
|
|
||||||
mIdentity.mName = new String(name, StandardCharsets.UTF_8);
|
|
||||||
try {
|
|
||||||
String nameCheck = stringPrep.prepare(mIdentity.mName, StringPrep.DEFAULT);
|
|
||||||
mIdentity.mIsNameValid =
|
|
||||||
Arrays.equals(nameCheck.getBytes(StandardCharsets.UTF_8), name);
|
|
||||||
} catch (StringPrepParseException x) {
|
|
||||||
Log.w(TAG, x.toString());
|
|
||||||
mIdentity.mIsNameValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Non-normal names must be rendered differently to avoid confusion.
|
|
||||||
if (!mIdentity.mIsNameValid) {
|
|
||||||
mIdentity.mName = "«" + escape(name) + "»";
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setXpanid(byte x[]) {
|
|
||||||
mIdentity.mXpanid = (x != null ? x.clone() : null);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setPanid(int x) {
|
|
||||||
mIdentity.mPanid = x;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setType(@NonNull String x) {
|
|
||||||
mIdentity.mType = x;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setChannel(int x) {
|
|
||||||
mIdentity.mChannel = x;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanIdentity build() {
|
|
||||||
return mIdentity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LowpanIdentity() {}
|
|
||||||
|
|
||||||
// Instance Variables
|
|
||||||
|
|
||||||
private String mName = "";
|
|
||||||
private boolean mIsNameValid = true;
|
|
||||||
private byte[] mRawName = new byte[0];
|
|
||||||
private String mType = "";
|
|
||||||
private byte[] mXpanid = new byte[0];
|
|
||||||
private int mPanid = UNSPECIFIED_PANID;
|
|
||||||
private int mChannel = UNSPECIFIED_CHANNEL;
|
|
||||||
|
|
||||||
// Public Getters
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return mName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNameValid() {
|
|
||||||
return mIsNameValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getRawName() {
|
|
||||||
return mRawName.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getXpanid() {
|
|
||||||
return mXpanid.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPanid() {
|
|
||||||
return mPanid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return mType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getChannel() {
|
|
||||||
return mChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
|
||||||
sb.append("Name:").append(getName());
|
|
||||||
|
|
||||||
if (mType.length() > 0) {
|
|
||||||
sb.append(", Type:").append(mType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mXpanid.length > 0) {
|
|
||||||
sb.append(", XPANID:").append(HexDump.toHexString(mXpanid));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mPanid != UNSPECIFIED_PANID) {
|
|
||||||
sb.append(", PANID:").append(String.format("0x%04X", mPanid));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mChannel != UNSPECIFIED_CHANNEL) {
|
|
||||||
sb.append(", Channel:").append(mChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof LowpanIdentity)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LowpanIdentity rhs = (LowpanIdentity) obj;
|
|
||||||
return Arrays.equals(mRawName, rhs.mRawName)
|
|
||||||
&& Arrays.equals(mXpanid, rhs.mXpanid)
|
|
||||||
&& mType.equals(rhs.mType)
|
|
||||||
&& mPanid == rhs.mPanid
|
|
||||||
&& mChannel == rhs.mChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(
|
|
||||||
Arrays.hashCode(mRawName), mType, Arrays.hashCode(mXpanid), mPanid, mChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeByteArray(mRawName);
|
|
||||||
dest.writeString(mType);
|
|
||||||
dest.writeByteArray(mXpanid);
|
|
||||||
dest.writeInt(mPanid);
|
|
||||||
dest.writeInt(mChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
public static final @android.annotation.NonNull Creator<LowpanIdentity> CREATOR =
|
|
||||||
new Creator<LowpanIdentity>() {
|
|
||||||
|
|
||||||
public LowpanIdentity createFromParcel(Parcel in) {
|
|
||||||
Builder builder = new Builder();
|
|
||||||
|
|
||||||
builder.setRawName(in.createByteArray());
|
|
||||||
builder.setType(in.readString());
|
|
||||||
builder.setXpanid(in.createByteArray());
|
|
||||||
builder.setPanid(in.readInt());
|
|
||||||
builder.setChannel(in.readInt());
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanIdentity[] newArray(int size) {
|
|
||||||
return new LowpanIdentity[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,824 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.IpPrefix;
|
|
||||||
import android.net.LinkAddress;
|
|
||||||
import android.os.DeadObjectException;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceSpecificException;
|
|
||||||
import android.util.Log;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for managing a specific Low-power Wireless Personal Area Network (LoWPAN) interface.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanInterface {
|
|
||||||
private static final String TAG = LowpanInterface.class.getSimpleName();
|
|
||||||
|
|
||||||
/** Detached role. The interface is not currently attached to a network. */
|
|
||||||
public static final String ROLE_DETACHED = ILowpanInterface.ROLE_DETACHED;
|
|
||||||
|
|
||||||
/** End-device role. End devices do not route traffic for other nodes. */
|
|
||||||
public static final String ROLE_END_DEVICE = ILowpanInterface.ROLE_END_DEVICE;
|
|
||||||
|
|
||||||
/** Router role. Routers help route traffic around the mesh network. */
|
|
||||||
public static final String ROLE_ROUTER = ILowpanInterface.ROLE_ROUTER;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sleepy End-Device role.
|
|
||||||
*
|
|
||||||
* <p>End devices with this role are nominally asleep, waking up periodically to check in with
|
|
||||||
* their parent to see if there are packets destined for them. Such devices are capable of
|
|
||||||
* extraordinarilly low power consumption, but packet latency can be on the order of dozens of
|
|
||||||
* seconds(depending on how the node is configured).
|
|
||||||
*/
|
|
||||||
public static final String ROLE_SLEEPY_END_DEVICE = ILowpanInterface.ROLE_SLEEPY_END_DEVICE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sleepy-router role.
|
|
||||||
*
|
|
||||||
* <p>Routers with this role are nominally asleep, waking up periodically to check in with other
|
|
||||||
* routers and their children.
|
|
||||||
*/
|
|
||||||
public static final String ROLE_SLEEPY_ROUTER = ILowpanInterface.ROLE_SLEEPY_ROUTER;
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
public static final String ROLE_LEADER = ILowpanInterface.ROLE_LEADER;
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
public static final String ROLE_COORDINATOR = ILowpanInterface.ROLE_COORDINATOR;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Offline state.
|
|
||||||
*
|
|
||||||
* <p>This is the initial state of the LoWPAN interface when the underlying driver starts. In
|
|
||||||
* this state the NCP is idle and not connected to any network.
|
|
||||||
*
|
|
||||||
* <p>This state can be explicitly entered by calling {@link #reset()}, {@link #leave()}, or
|
|
||||||
* <code>setUp(false)</code>, with the later two only working if we were not previously in the
|
|
||||||
* {@link #STATE_FAULT} state.
|
|
||||||
*
|
|
||||||
* @see #getState()
|
|
||||||
* @see #STATE_FAULT
|
|
||||||
*/
|
|
||||||
public static final String STATE_OFFLINE = ILowpanInterface.STATE_OFFLINE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commissioning state.
|
|
||||||
*
|
|
||||||
* <p>The interface enters this state after a call to {@link #startCommissioningSession()}. This
|
|
||||||
* state may only be entered directly from the {@link #STATE_OFFLINE} state.
|
|
||||||
*
|
|
||||||
* @see #startCommissioningSession()
|
|
||||||
* @see #getState()
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static final String STATE_COMMISSIONING = ILowpanInterface.STATE_COMMISSIONING;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attaching state.
|
|
||||||
*
|
|
||||||
* <p>The interface enters this state when it starts the process of trying to find other nodes
|
|
||||||
* so that it can attach to any pre-existing network fragment, or when it is in the process of
|
|
||||||
* calculating the optimal values for unspecified parameters when forming a new network.
|
|
||||||
*
|
|
||||||
* <p>The interface may stay in this state for a prolonged period of time (or may spontaneously
|
|
||||||
* enter this state from {@link #STATE_ATTACHED}) if the underlying network technology is
|
|
||||||
* heirarchical (like ZigBeeIP) or if the device role is that of an "end-device" ({@link
|
|
||||||
* #ROLE_END_DEVICE} or {@link #ROLE_SLEEPY_END_DEVICE}). This is because such roles cannot
|
|
||||||
* create their own network fragments.
|
|
||||||
*
|
|
||||||
* @see #STATE_ATTACHED
|
|
||||||
* @see #getState()
|
|
||||||
*/
|
|
||||||
public static final String STATE_ATTACHING = ILowpanInterface.STATE_ATTACHING;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attached state.
|
|
||||||
*
|
|
||||||
* <p>The interface enters this state from {@link #STATE_ATTACHING} once it is actively
|
|
||||||
* participating on a network fragment.
|
|
||||||
*
|
|
||||||
* @see #STATE_ATTACHING
|
|
||||||
* @see #getState()
|
|
||||||
*/
|
|
||||||
public static final String STATE_ATTACHED = ILowpanInterface.STATE_ATTACHED;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fault state.
|
|
||||||
*
|
|
||||||
* <p>The interface will enter this state when the driver has detected some sort of problem from
|
|
||||||
* which it was not immediately able to recover.
|
|
||||||
*
|
|
||||||
* <p>This state can be entered spontaneously from any other state. Calling {@link #reset} will
|
|
||||||
* cause the device to return to the {@link #STATE_OFFLINE} state.
|
|
||||||
*
|
|
||||||
* @see #getState
|
|
||||||
* @see #STATE_OFFLINE
|
|
||||||
*/
|
|
||||||
public static final String STATE_FAULT = ILowpanInterface.STATE_FAULT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Network type for Thread 1.x networks.
|
|
||||||
*
|
|
||||||
* @see android.net.lowpan.LowpanIdentity#getType
|
|
||||||
* @see #getLowpanIdentity
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static final String NETWORK_TYPE_THREAD_V1 = ILowpanInterface.NETWORK_TYPE_THREAD_V1;
|
|
||||||
|
|
||||||
public static final String EMPTY_PARTITION_ID = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback base class for LowpanInterface
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public abstract static class Callback {
|
|
||||||
public void onConnectedChanged(boolean value) {}
|
|
||||||
|
|
||||||
public void onEnabledChanged(boolean value) {}
|
|
||||||
|
|
||||||
public void onUpChanged(boolean value) {}
|
|
||||||
|
|
||||||
public void onRoleChanged(@NonNull String value) {}
|
|
||||||
|
|
||||||
public void onStateChanged(@NonNull String state) {}
|
|
||||||
|
|
||||||
public void onLowpanIdentityChanged(@NonNull LowpanIdentity value) {}
|
|
||||||
|
|
||||||
public void onLinkNetworkAdded(IpPrefix prefix) {}
|
|
||||||
|
|
||||||
public void onLinkNetworkRemoved(IpPrefix prefix) {}
|
|
||||||
|
|
||||||
public void onLinkAddressAdded(LinkAddress address) {}
|
|
||||||
|
|
||||||
public void onLinkAddressRemoved(LinkAddress address) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ILowpanInterface mBinder;
|
|
||||||
private final Looper mLooper;
|
|
||||||
private final HashMap<Integer, ILowpanInterfaceListener> mListenerMap = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new LowpanInterface instance. Applications will almost always want to use {@link
|
|
||||||
* LowpanManager#getInterface LowpanManager.getInterface()} instead of this.
|
|
||||||
*
|
|
||||||
* @param context the application context
|
|
||||||
* @param service the Binder interface
|
|
||||||
* @param looper the Binder interface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public LowpanInterface(Context context, ILowpanInterface service, Looper looper) {
|
|
||||||
/* We aren't currently using the context, but if we need
|
|
||||||
* it later on we can easily add it to the class.
|
|
||||||
*/
|
|
||||||
|
|
||||||
mBinder = service;
|
|
||||||
mLooper = looper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ILowpanInterface object associated with this interface.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public ILowpanInterface getService() {
|
|
||||||
return mBinder;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public Actions
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form a new network with the given network information optional credential. Unspecified fields
|
|
||||||
* in the network information will be filled in with reasonable values. If the network
|
|
||||||
* credential is unspecified, one will be generated automatically.
|
|
||||||
*
|
|
||||||
* <p>This method will block until either the network was successfully formed or an error
|
|
||||||
* prevents the network form being formed.
|
|
||||||
*
|
|
||||||
* <p>Upon success, the interface will be up and attached to the newly formed network.
|
|
||||||
*
|
|
||||||
* @see #join(LowpanProvision)
|
|
||||||
*/
|
|
||||||
public void form(@NonNull LowpanProvision provision) throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.form(provision);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to join a new network with the given network information. This method will block
|
|
||||||
* until either the network was successfully joined or an error prevented the network from being
|
|
||||||
* formed. Upon success, the interface will be up and attached to the newly joined network.
|
|
||||||
*
|
|
||||||
* <p>Note that “joining” is distinct from “attaching”: Joining requires at least one other peer
|
|
||||||
* device to be present in order for the operation to complete successfully.
|
|
||||||
*/
|
|
||||||
public void join(@NonNull LowpanProvision provision) throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.join(provision);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attaches to the network described by identity and credential. This is similar to {@link
|
|
||||||
* #join}, except that (assuming the identity and credential are valid) it will always succeed
|
|
||||||
* and provision the interface, even if there are no peers nearby.
|
|
||||||
*
|
|
||||||
* <p>This method will block execution until the operation has completed.
|
|
||||||
*/
|
|
||||||
public void attach(@NonNull LowpanProvision provision) throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.attach(provision);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bring down the network interface and forget all non-volatile details about the current
|
|
||||||
* network.
|
|
||||||
*
|
|
||||||
* <p>This method will block execution until the operation has completed.
|
|
||||||
*/
|
|
||||||
public void leave() throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.leave();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start a new commissioning session. Will fail if the interface is attached to a network or if
|
|
||||||
* the interface is disabled.
|
|
||||||
*/
|
|
||||||
public @NonNull LowpanCommissioningSession startCommissioningSession(
|
|
||||||
@NonNull LowpanBeaconInfo beaconInfo) throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.startCommissioningSession(beaconInfo);
|
|
||||||
|
|
||||||
return new LowpanCommissioningSession(mBinder, beaconInfo, mLooper);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset this network interface as if it has been power cycled. Will bring the network interface
|
|
||||||
* down if it was previously up. Will not erase any non-volatile settings.
|
|
||||||
*
|
|
||||||
* <p>This method will block execution until the operation has completed.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void reset() throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.reset();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public Getters and Setters
|
|
||||||
|
|
||||||
/** Returns the name of this network interface. */
|
|
||||||
@NonNull
|
|
||||||
public String getName() {
|
|
||||||
try {
|
|
||||||
return mBinder.getName();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return "";
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if the interface is enabled or disabled.
|
|
||||||
*
|
|
||||||
* @see #setEnabled
|
|
||||||
* @see android.net.lowpan.LowpanException#LOWPAN_DISABLED
|
|
||||||
*/
|
|
||||||
public boolean isEnabled() {
|
|
||||||
try {
|
|
||||||
return mBinder.isEnabled();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables or disables the LoWPAN interface. When disabled, the interface is put into a
|
|
||||||
* low-power state and all commands that require the NCP to be queried will fail with {@link
|
|
||||||
* android.net.lowpan.LowpanException#LOWPAN_DISABLED}.
|
|
||||||
*
|
|
||||||
* @see #isEnabled
|
|
||||||
* @see android.net.lowpan.LowpanException#LOWPAN_DISABLED
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void setEnabled(boolean enabled) throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.setEnabled(enabled);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if the network interface is up or down.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public boolean isUp() {
|
|
||||||
try {
|
|
||||||
return mBinder.isUp();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if there is at least one peer in range.
|
|
||||||
*
|
|
||||||
* @return <code>true</code> if we have at least one other peer in range, <code>false</code>
|
|
||||||
* otherwise.
|
|
||||||
*/
|
|
||||||
public boolean isConnected() {
|
|
||||||
try {
|
|
||||||
return mBinder.isConnected();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if this interface is currently commissioned onto an existing network. If the
|
|
||||||
* interface is commissioned, the interface may be brought up using setUp().
|
|
||||||
*/
|
|
||||||
public boolean isCommissioned() {
|
|
||||||
try {
|
|
||||||
return mBinder.isCommissioned();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get interface state
|
|
||||||
*
|
|
||||||
* <h3>State Diagram</h3>
|
|
||||||
*
|
|
||||||
* <img src="LowpanInterface-1.png" />
|
|
||||||
*
|
|
||||||
* @return The current state of the interface.
|
|
||||||
* @see #STATE_OFFLINE
|
|
||||||
* @see #STATE_COMMISSIONING
|
|
||||||
* @see #STATE_ATTACHING
|
|
||||||
* @see #STATE_ATTACHED
|
|
||||||
* @see #STATE_FAULT
|
|
||||||
*/
|
|
||||||
public String getState() {
|
|
||||||
try {
|
|
||||||
return mBinder.getState();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return STATE_FAULT;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get network partition/fragment identifier. */
|
|
||||||
public String getPartitionId() {
|
|
||||||
try {
|
|
||||||
return mBinder.getPartitionId();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return EMPTY_PARTITION_ID;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
public LowpanIdentity getLowpanIdentity() {
|
|
||||||
try {
|
|
||||||
return mBinder.getLowpanIdentity();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return new LowpanIdentity();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
@NonNull
|
|
||||||
public String getRole() {
|
|
||||||
try {
|
|
||||||
return mBinder.getRole();
|
|
||||||
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
return ROLE_DETACHED;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: doc */
|
|
||||||
@Nullable
|
|
||||||
public LowpanCredential getLowpanCredential() {
|
|
||||||
try {
|
|
||||||
return mBinder.getLowpanCredential();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NonNull String[] getSupportedNetworkTypes() throws LowpanException {
|
|
||||||
try {
|
|
||||||
return mBinder.getSupportedNetworkTypes();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NonNull LowpanChannelInfo[] getSupportedChannels() throws LowpanException {
|
|
||||||
try {
|
|
||||||
return mBinder.getSupportedChannels();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listener Support
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a subclass of {@link LowpanInterface.Callback} to receive events.
|
|
||||||
*
|
|
||||||
* @param cb Subclass of {@link LowpanInterface.Callback} which will receive events.
|
|
||||||
* @param handler If not <code>null</code>, events will be dispatched via the given handler
|
|
||||||
* object. If <code>null</code>, the thread upon which events will be dispatched is
|
|
||||||
* unspecified.
|
|
||||||
* @see #registerCallback(Callback)
|
|
||||||
* @see #unregisterCallback(Callback)
|
|
||||||
*/
|
|
||||||
public void registerCallback(@NonNull Callback cb, @Nullable Handler handler) {
|
|
||||||
ILowpanInterfaceListener.Stub listenerBinder =
|
|
||||||
new ILowpanInterfaceListener.Stub() {
|
|
||||||
private Handler mHandler;
|
|
||||||
|
|
||||||
{
|
|
||||||
if (handler != null) {
|
|
||||||
mHandler = handler;
|
|
||||||
} else if (mLooper != null) {
|
|
||||||
mHandler = new Handler(mLooper);
|
|
||||||
} else {
|
|
||||||
mHandler = new Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnabledChanged(boolean value) {
|
|
||||||
mHandler.post(() -> cb.onEnabledChanged(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectedChanged(boolean value) {
|
|
||||||
mHandler.post(() -> cb.onConnectedChanged(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpChanged(boolean value) {
|
|
||||||
mHandler.post(() -> cb.onUpChanged(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRoleChanged(String value) {
|
|
||||||
mHandler.post(() -> cb.onRoleChanged(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStateChanged(String value) {
|
|
||||||
mHandler.post(() -> cb.onStateChanged(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLowpanIdentityChanged(LowpanIdentity value) {
|
|
||||||
mHandler.post(() -> cb.onLowpanIdentityChanged(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkNetworkAdded(IpPrefix value) {
|
|
||||||
mHandler.post(() -> cb.onLinkNetworkAdded(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkNetworkRemoved(IpPrefix value) {
|
|
||||||
mHandler.post(() -> cb.onLinkNetworkRemoved(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkAddressAdded(String value) {
|
|
||||||
LinkAddress la;
|
|
||||||
try {
|
|
||||||
la = new LinkAddress(value);
|
|
||||||
} catch (IllegalArgumentException x) {
|
|
||||||
Log.e(
|
|
||||||
TAG,
|
|
||||||
"onLinkAddressAdded: Bad LinkAddress \"" + value + "\", " + x);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mHandler.post(() -> cb.onLinkAddressAdded(la));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkAddressRemoved(String value) {
|
|
||||||
LinkAddress la;
|
|
||||||
try {
|
|
||||||
la = new LinkAddress(value);
|
|
||||||
} catch (IllegalArgumentException x) {
|
|
||||||
Log.e(
|
|
||||||
TAG,
|
|
||||||
"onLinkAddressRemoved: Bad LinkAddress \""
|
|
||||||
+ value
|
|
||||||
+ "\", "
|
|
||||||
+ x);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mHandler.post(() -> cb.onLinkAddressRemoved(la));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceiveFromCommissioner(byte[] packet) {
|
|
||||||
// This is only used by the LowpanCommissioningSession.
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
mBinder.addListener(listenerBinder);
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (mListenerMap) {
|
|
||||||
mListenerMap.put(System.identityHashCode(cb), listenerBinder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a subclass of {@link LowpanInterface.Callback} to receive events.
|
|
||||||
*
|
|
||||||
* <p>The thread upon which events will be dispatched is unspecified.
|
|
||||||
*
|
|
||||||
* @param cb Subclass of {@link LowpanInterface.Callback} which will receive events.
|
|
||||||
* @see #registerCallback(Callback, Handler)
|
|
||||||
* @see #unregisterCallback(Callback)
|
|
||||||
*/
|
|
||||||
public void registerCallback(Callback cb) {
|
|
||||||
registerCallback(cb, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters a previously registered callback class.
|
|
||||||
*
|
|
||||||
* @param cb Subclass of {@link LowpanInterface.Callback} which was previously registered to
|
|
||||||
* receive events.
|
|
||||||
* @see #registerCallback(Callback, Handler)
|
|
||||||
* @see #registerCallback(Callback)
|
|
||||||
*/
|
|
||||||
public void unregisterCallback(Callback cb) {
|
|
||||||
int hashCode = System.identityHashCode(cb);
|
|
||||||
synchronized (mListenerMap) {
|
|
||||||
ILowpanInterfaceListener listenerBinder = mListenerMap.get(hashCode);
|
|
||||||
|
|
||||||
if (listenerBinder != null) {
|
|
||||||
mListenerMap.remove(hashCode);
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBinder.removeListener(listenerBinder);
|
|
||||||
} catch (DeadObjectException x) {
|
|
||||||
// We ignore a dead object exception because that
|
|
||||||
// pretty clearly means our callback isn't registered.
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Active and Passive Scanning
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link android.net.lowpan.LowpanScanner} object for this interface.
|
|
||||||
*
|
|
||||||
* <p>This method allocates a new unique object for each call.
|
|
||||||
*
|
|
||||||
* @see android.net.lowpan.LowpanScanner
|
|
||||||
*/
|
|
||||||
public @NonNull LowpanScanner createScanner() {
|
|
||||||
return new LowpanScanner(mBinder);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Route Management
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a copy of the internal list of LinkAddresses.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public LinkAddress[] getLinkAddresses() throws LowpanException {
|
|
||||||
try {
|
|
||||||
String[] linkAddressStrings = mBinder.getLinkAddresses();
|
|
||||||
LinkAddress[] ret = new LinkAddress[linkAddressStrings.length];
|
|
||||||
int i = 0;
|
|
||||||
for (String str : linkAddressStrings) {
|
|
||||||
ret[i++] = new LinkAddress(str);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a copy of the internal list of networks reachable on via this link.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public IpPrefix[] getLinkNetworks() throws LowpanException {
|
|
||||||
try {
|
|
||||||
return mBinder.getLinkNetworks();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Advertise the given IP prefix as an on-mesh prefix.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void addOnMeshPrefix(IpPrefix prefix, int flags) throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.addOnMeshPrefix(prefix, flags);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an IP prefix previously advertised by this device from the list of advertised on-mesh
|
|
||||||
* prefixes.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void removeOnMeshPrefix(IpPrefix prefix) {
|
|
||||||
try {
|
|
||||||
mBinder.removeOnMeshPrefix(prefix);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
// Catch and ignore all service exceptions
|
|
||||||
Log.e(TAG, x.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Advertise this device to other devices on the mesh network as having a specific route to the
|
|
||||||
* given network. This device will then receive forwarded traffic for that network.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void addExternalRoute(IpPrefix prefix, int flags) throws LowpanException {
|
|
||||||
try {
|
|
||||||
mBinder.addExternalRoute(prefix, flags);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Revoke a previously advertised specific route to the given network.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void removeExternalRoute(IpPrefix prefix) {
|
|
||||||
try {
|
|
||||||
mBinder.removeExternalRoute(prefix);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
// Catch and ignore all service exceptions
|
|
||||||
Log.e(TAG, x.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,335 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
import com.android.internal.os.BackgroundThread;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.WeakHashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manager object for looking up LoWPAN interfaces.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanManager {
|
|
||||||
private static final String TAG = LowpanManager.class.getSimpleName();
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
// @SystemApi
|
|
||||||
public abstract static class Callback {
|
|
||||||
public void onInterfaceAdded(LowpanInterface lowpanInterface) {}
|
|
||||||
|
|
||||||
public void onInterfaceRemoved(LowpanInterface lowpanInterface) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<Integer, ILowpanManagerListener> mListenerMap = new HashMap<>();
|
|
||||||
private final Map<String, LowpanInterface> mInterfaceCache = new HashMap<>();
|
|
||||||
|
|
||||||
/* This is a WeakHashMap because we don't want to hold onto
|
|
||||||
* a strong reference to ILowpanInterface, so that it can be
|
|
||||||
* garbage collected if it isn't being used anymore. Since
|
|
||||||
* the value class holds onto this specific ILowpanInterface,
|
|
||||||
* we also need to have a weak reference to the value.
|
|
||||||
* This design pattern allows us to skip removal of items
|
|
||||||
* from this Map without leaking memory.
|
|
||||||
*/
|
|
||||||
private final Map<IBinder, WeakReference<LowpanInterface>> mBinderCache =
|
|
||||||
new WeakHashMap<>();
|
|
||||||
|
|
||||||
private final ILowpanManager mService;
|
|
||||||
private final Context mContext;
|
|
||||||
private final Looper mLooper;
|
|
||||||
|
|
||||||
// Static Methods
|
|
||||||
|
|
||||||
public static LowpanManager from(Context context) {
|
|
||||||
return (LowpanManager) context.getSystemService(Context.LOWPAN_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
public static LowpanManager getManager() {
|
|
||||||
IBinder binder = ServiceManager.getService(Context.LOWPAN_SERVICE);
|
|
||||||
|
|
||||||
if (binder != null) {
|
|
||||||
ILowpanManager service = ILowpanManager.Stub.asInterface(binder);
|
|
||||||
return new LowpanManager(service);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
LowpanManager(ILowpanManager service) {
|
|
||||||
mService = service;
|
|
||||||
mContext = null;
|
|
||||||
mLooper = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new LowpanManager instance. Applications will almost always want to use {@link
|
|
||||||
* android.content.Context#getSystemService Context.getSystemService()} to retrieve the standard
|
|
||||||
* {@link android.content.Context#LOWPAN_SERVICE Context.LOWPAN_SERVICE}.
|
|
||||||
*
|
|
||||||
* @param context the application context
|
|
||||||
* @param service the Binder interface
|
|
||||||
* @hide - hide this because it takes in a parameter of type ILowpanManager, which is a system
|
|
||||||
* private class.
|
|
||||||
*/
|
|
||||||
public LowpanManager(Context context, ILowpanManager service) {
|
|
||||||
this(context, service, BackgroundThread.get().getLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public LowpanManager(Context context, ILowpanManager service, Looper looper) {
|
|
||||||
mContext = context;
|
|
||||||
mService = service;
|
|
||||||
mLooper = looper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
@Nullable
|
|
||||||
public LowpanInterface getInterfaceNoCreate(@NonNull ILowpanInterface ifaceService) {
|
|
||||||
LowpanInterface iface = null;
|
|
||||||
|
|
||||||
synchronized (mBinderCache) {
|
|
||||||
if (mBinderCache.containsKey(ifaceService.asBinder())) {
|
|
||||||
iface = mBinderCache.get(ifaceService.asBinder()).get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return iface;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
@Nullable
|
|
||||||
public LowpanInterface getInterface(@NonNull ILowpanInterface ifaceService) {
|
|
||||||
LowpanInterface iface = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
synchronized (mBinderCache) {
|
|
||||||
if (mBinderCache.containsKey(ifaceService.asBinder())) {
|
|
||||||
iface = mBinderCache.get(ifaceService.asBinder()).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iface == null) {
|
|
||||||
String ifaceName = ifaceService.getName();
|
|
||||||
|
|
||||||
iface = new LowpanInterface(mContext, ifaceService, mLooper);
|
|
||||||
|
|
||||||
synchronized (mInterfaceCache) {
|
|
||||||
mInterfaceCache.put(iface.getName(), iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
mBinderCache.put(ifaceService.asBinder(), new WeakReference(iface));
|
|
||||||
|
|
||||||
/* Make sure we remove the object from the
|
|
||||||
* interface cache if the associated service
|
|
||||||
* dies.
|
|
||||||
*/
|
|
||||||
ifaceService
|
|
||||||
.asBinder()
|
|
||||||
.linkToDeath(
|
|
||||||
new IBinder.DeathRecipient() {
|
|
||||||
@Override
|
|
||||||
public void binderDied() {
|
|
||||||
synchronized (mInterfaceCache) {
|
|
||||||
LowpanInterface iface =
|
|
||||||
mInterfaceCache.get(ifaceName);
|
|
||||||
|
|
||||||
if ((iface != null)
|
|
||||||
&& (iface.getService() == ifaceService)) {
|
|
||||||
mInterfaceCache.remove(ifaceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return iface;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a reference to the requested LowpanInterface object. If the given interface doesn't
|
|
||||||
* exist, or it is not a LoWPAN interface, returns null.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public LowpanInterface getInterface(@NonNull String name) {
|
|
||||||
LowpanInterface iface = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
/* This synchronized block covers both branches of the enclosed
|
|
||||||
* if() statement in order to avoid a race condition. Two threads
|
|
||||||
* calling getInterface() with the same name would race to create
|
|
||||||
* the associated LowpanInterface object, creating two of them.
|
|
||||||
* Having the whole block be synchronized avoids that race.
|
|
||||||
*/
|
|
||||||
synchronized (mInterfaceCache) {
|
|
||||||
if (mInterfaceCache.containsKey(name)) {
|
|
||||||
iface = mInterfaceCache.get(name);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ILowpanInterface ifaceService = mService.getInterface(name);
|
|
||||||
|
|
||||||
if (ifaceService != null) {
|
|
||||||
iface = getInterface(ifaceService);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
return iface;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a reference to the first registered LowpanInterface object. If there are no LoWPAN
|
|
||||||
* interfaces registered, returns null.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public LowpanInterface getInterface() {
|
|
||||||
String[] ifaceList = getInterfaceList();
|
|
||||||
if (ifaceList.length > 0) {
|
|
||||||
return getInterface(ifaceList[0]);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string array containing the names of LoWPAN interfaces. This list may contain fewer
|
|
||||||
* interfaces if the calling process does not have permissions to see individual interfaces.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public String[] getInterfaceList() {
|
|
||||||
try {
|
|
||||||
return mService.getInterfaceList();
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a callback object to receive notifications when LoWPAN interfaces are added or
|
|
||||||
* removed.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void registerCallback(@NonNull Callback cb, @Nullable Handler handler)
|
|
||||||
throws LowpanException {
|
|
||||||
ILowpanManagerListener.Stub listenerBinder =
|
|
||||||
new ILowpanManagerListener.Stub() {
|
|
||||||
private Handler mHandler;
|
|
||||||
|
|
||||||
{
|
|
||||||
if (handler != null) {
|
|
||||||
mHandler = handler;
|
|
||||||
} else if (mLooper != null) {
|
|
||||||
mHandler = new Handler(mLooper);
|
|
||||||
} else {
|
|
||||||
mHandler = new Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInterfaceAdded(ILowpanInterface ifaceService) {
|
|
||||||
Runnable runnable =
|
|
||||||
() -> {
|
|
||||||
LowpanInterface iface = getInterface(ifaceService);
|
|
||||||
|
|
||||||
if (iface != null) {
|
|
||||||
cb.onInterfaceAdded(iface);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mHandler.post(runnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInterfaceRemoved(ILowpanInterface ifaceService) {
|
|
||||||
Runnable runnable =
|
|
||||||
() -> {
|
|
||||||
LowpanInterface iface = getInterfaceNoCreate(ifaceService);
|
|
||||||
|
|
||||||
if (iface != null) {
|
|
||||||
cb.onInterfaceRemoved(iface);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mHandler.post(runnable);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
mService.addListener(listenerBinder);
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (mListenerMap) {
|
|
||||||
mListenerMap.put(Integer.valueOf(System.identityHashCode(cb)), listenerBinder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
public void registerCallback(@NonNull Callback cb) throws LowpanException {
|
|
||||||
registerCallback(cb, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters a previously registered {@link LowpanManager.Callback} object.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void unregisterCallback(@NonNull Callback cb) {
|
|
||||||
Integer hashCode = Integer.valueOf(System.identityHashCode(cb));
|
|
||||||
ILowpanManagerListener listenerBinder = null;
|
|
||||||
|
|
||||||
synchronized (mListenerMap) {
|
|
||||||
listenerBinder = mListenerMap.get(hashCode);
|
|
||||||
mListenerMap.remove(hashCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listenerBinder != null) {
|
|
||||||
try {
|
|
||||||
mService.removeListener(listenerBinder);
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Attempt to unregister an unknown callback");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
public final class LowpanProperties {
|
|
||||||
|
|
||||||
public static final LowpanProperty<int[]> KEY_CHANNEL_MASK =
|
|
||||||
new LowpanStandardProperty("android.net.lowpan.property.CHANNEL_MASK", int[].class);
|
|
||||||
|
|
||||||
public static final LowpanProperty<Integer> KEY_MAX_TX_POWER =
|
|
||||||
new LowpanStandardProperty("android.net.lowpan.property.MAX_TX_POWER", Integer.class);
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
private LowpanProperties() {}
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
static final class LowpanStandardProperty<T> extends LowpanProperty<T> {
|
|
||||||
private final String mName;
|
|
||||||
private final Class<T> mType;
|
|
||||||
|
|
||||||
LowpanStandardProperty(String name, Class<T> type) {
|
|
||||||
mName = name;
|
|
||||||
mType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return mName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<T> getType() {
|
|
||||||
return mType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
public abstract class LowpanProperty<T> {
|
|
||||||
public abstract String getName();
|
|
||||||
|
|
||||||
public abstract Class<T> getType();
|
|
||||||
|
|
||||||
public void putInMap(Map map, T value) {
|
|
||||||
map.put(getName(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getFromMap(Map map) {
|
|
||||||
return (T) map.get(getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
parcelable LowpanProvision cpp_header "android/net/lowpan/LowpanProvision.h";
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes the information needed to describe a network
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanProvision implements Parcelable {
|
|
||||||
|
|
||||||
// Builder
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
// @SystemApi
|
|
||||||
public static class Builder {
|
|
||||||
private final LowpanProvision provision = new LowpanProvision();
|
|
||||||
|
|
||||||
public Builder setLowpanIdentity(@NonNull LowpanIdentity identity) {
|
|
||||||
provision.mIdentity = identity;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setLowpanCredential(@NonNull LowpanCredential credential) {
|
|
||||||
provision.mCredential = credential;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanProvision build() {
|
|
||||||
return provision;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private LowpanProvision() {}
|
|
||||||
|
|
||||||
// Instance Variables
|
|
||||||
|
|
||||||
private LowpanIdentity mIdentity = new LowpanIdentity();
|
|
||||||
private LowpanCredential mCredential = null;
|
|
||||||
|
|
||||||
// Public Getters and Setters
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public LowpanIdentity getLowpanIdentity() {
|
|
||||||
return mIdentity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public LowpanCredential getLowpanCredential() {
|
|
||||||
return mCredential;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
|
||||||
sb.append("LowpanProvision { identity => ").append(mIdentity.toString());
|
|
||||||
|
|
||||||
if (mCredential != null) {
|
|
||||||
sb.append(", credential => ").append(mCredential.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("}");
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(mIdentity, mCredential);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof LowpanProvision)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LowpanProvision rhs = (LowpanProvision) obj;
|
|
||||||
|
|
||||||
if (!mIdentity.equals(rhs.mIdentity)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Objects.equals(mCredential, rhs.mCredential)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
mIdentity.writeToParcel(dest, flags);
|
|
||||||
if (mCredential == null) {
|
|
||||||
dest.writeBoolean(false);
|
|
||||||
} else {
|
|
||||||
dest.writeBoolean(true);
|
|
||||||
mCredential.writeToParcel(dest, flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implement the Parcelable interface. */
|
|
||||||
public static final @android.annotation.NonNull Creator<LowpanProvision> CREATOR =
|
|
||||||
new Creator<LowpanProvision>() {
|
|
||||||
public LowpanProvision createFromParcel(Parcel in) {
|
|
||||||
Builder builder = new Builder();
|
|
||||||
|
|
||||||
builder.setLowpanIdentity(LowpanIdentity.CREATOR.createFromParcel(in));
|
|
||||||
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
builder.setLowpanCredential(LowpanCredential.CREATOR.createFromParcel(in));
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanProvision[] newArray(int size) {
|
|
||||||
return new LowpanProvision[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.util.AndroidRuntimeException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic runtime exception for LoWPAN operations.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanRuntimeException extends AndroidRuntimeException {
|
|
||||||
|
|
||||||
public LowpanRuntimeException() {}
|
|
||||||
|
|
||||||
public LowpanRuntimeException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanRuntimeException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LowpanRuntimeException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,326 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceSpecificException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LoWPAN Scanner
|
|
||||||
*
|
|
||||||
* <p>This class allows performing network (active) scans and energy (passive) scans.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class LowpanScanner {
|
|
||||||
private static final String TAG = LowpanScanner.class.getSimpleName();
|
|
||||||
|
|
||||||
// Public Classes
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback base class for LowpanScanner
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public abstract static class Callback {
|
|
||||||
public void onNetScanBeacon(LowpanBeaconInfo beacon) {}
|
|
||||||
|
|
||||||
public void onEnergyScanResult(LowpanEnergyScanResult result) {}
|
|
||||||
|
|
||||||
public void onScanFinished() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instance Variables
|
|
||||||
|
|
||||||
private ILowpanInterface mBinder;
|
|
||||||
private Callback mCallback = null;
|
|
||||||
private Handler mHandler = null;
|
|
||||||
private ArrayList<Integer> mChannelMask = null;
|
|
||||||
private int mTxPower = Integer.MAX_VALUE;
|
|
||||||
|
|
||||||
// Constructors/Accessors and Exception Glue
|
|
||||||
|
|
||||||
LowpanScanner(@NonNull ILowpanInterface binder) {
|
|
||||||
mBinder = binder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets an instance of {@link LowpanScanner.Callback} to receive events. */
|
|
||||||
public synchronized void setCallback(@Nullable Callback cb, @Nullable Handler handler) {
|
|
||||||
mCallback = cb;
|
|
||||||
mHandler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets an instance of {@link LowpanScanner.Callback} to receive events. */
|
|
||||||
public void setCallback(@Nullable Callback cb) {
|
|
||||||
setCallback(cb, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the channel mask to use when scanning.
|
|
||||||
*
|
|
||||||
* @param mask The channel mask to use when scanning. If <code>null</code>, any previously set
|
|
||||||
* channel mask will be cleared and all channels not masked by the current regulatory zone
|
|
||||||
* will be scanned.
|
|
||||||
*/
|
|
||||||
public void setChannelMask(@Nullable Collection<Integer> mask) {
|
|
||||||
if (mask == null) {
|
|
||||||
mChannelMask = null;
|
|
||||||
} else {
|
|
||||||
if (mChannelMask == null) {
|
|
||||||
mChannelMask = new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
mChannelMask.clear();
|
|
||||||
}
|
|
||||||
mChannelMask.addAll(mask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the current channel mask.
|
|
||||||
*
|
|
||||||
* @return the current channel mask, or <code>null</code> if no channel mask is currently set.
|
|
||||||
*/
|
|
||||||
public @Nullable Collection<Integer> getChannelMask() {
|
|
||||||
return (Collection<Integer>) mChannelMask.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a channel to the channel mask used for scanning.
|
|
||||||
*
|
|
||||||
* <p>If a channel mask was previously <code>null</code>, a new one is created containing only
|
|
||||||
* this channel. May be called multiple times to add additional channels ot the channel mask.
|
|
||||||
*
|
|
||||||
* @see #setChannelMask
|
|
||||||
* @see #getChannelMask
|
|
||||||
* @see #getTxPower
|
|
||||||
*/
|
|
||||||
public void addChannel(int channel) {
|
|
||||||
if (mChannelMask == null) {
|
|
||||||
mChannelMask = new ArrayList<>();
|
|
||||||
}
|
|
||||||
mChannelMask.add(Integer.valueOf(channel));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the maximum transmit power to be used for active scanning.
|
|
||||||
*
|
|
||||||
* <p>The actual transmit power used is the lesser of this value and the currently configured
|
|
||||||
* maximum transmit power for the interface.
|
|
||||||
*
|
|
||||||
* @see #getTxPower
|
|
||||||
*/
|
|
||||||
public void setTxPower(int txPower) {
|
|
||||||
mTxPower = txPower;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the maximum transmit power used for active scanning.
|
|
||||||
*
|
|
||||||
* @see #setTxPower
|
|
||||||
*/
|
|
||||||
public int getTxPower() {
|
|
||||||
return mTxPower;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Object> createScanOptionMap() {
|
|
||||||
Map<String, Object> map = new HashMap();
|
|
||||||
|
|
||||||
if (mChannelMask != null) {
|
|
||||||
LowpanProperties.KEY_CHANNEL_MASK.putInMap(
|
|
||||||
map, mChannelMask.stream().mapToInt(i -> i).toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mTxPower != Integer.MAX_VALUE) {
|
|
||||||
LowpanProperties.KEY_MAX_TX_POWER.putInMap(map, Integer.valueOf(mTxPower));
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start a network scan.
|
|
||||||
*
|
|
||||||
* <p>This method will return once the scan has started.
|
|
||||||
*
|
|
||||||
* @see #stopNetScan
|
|
||||||
*/
|
|
||||||
public void startNetScan() throws LowpanException {
|
|
||||||
Map<String, Object> map = createScanOptionMap();
|
|
||||||
|
|
||||||
ILowpanNetScanCallback binderListener =
|
|
||||||
new ILowpanNetScanCallback.Stub() {
|
|
||||||
public void onNetScanBeacon(LowpanBeaconInfo beaconInfo) {
|
|
||||||
Callback callback;
|
|
||||||
Handler handler;
|
|
||||||
|
|
||||||
synchronized (LowpanScanner.this) {
|
|
||||||
callback = mCallback;
|
|
||||||
handler = mHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Runnable runnable = () -> callback.onNetScanBeacon(beaconInfo);
|
|
||||||
|
|
||||||
if (handler != null) {
|
|
||||||
handler.post(runnable);
|
|
||||||
} else {
|
|
||||||
runnable.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNetScanFinished() {
|
|
||||||
Callback callback;
|
|
||||||
Handler handler;
|
|
||||||
|
|
||||||
synchronized (LowpanScanner.this) {
|
|
||||||
callback = mCallback;
|
|
||||||
handler = mHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Runnable runnable = () -> callback.onScanFinished();
|
|
||||||
|
|
||||||
if (handler != null) {
|
|
||||||
handler.post(runnable);
|
|
||||||
} else {
|
|
||||||
runnable.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBinder.startNetScan(map, binderListener);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop a network scan currently in progress.
|
|
||||||
*
|
|
||||||
* @see #startNetScan
|
|
||||||
*/
|
|
||||||
public void stopNetScan() {
|
|
||||||
try {
|
|
||||||
mBinder.stopNetScan();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start an energy scan.
|
|
||||||
*
|
|
||||||
* <p>This method will return once the scan has started.
|
|
||||||
*
|
|
||||||
* @see #stopEnergyScan
|
|
||||||
*/
|
|
||||||
public void startEnergyScan() throws LowpanException {
|
|
||||||
Map<String, Object> map = createScanOptionMap();
|
|
||||||
|
|
||||||
ILowpanEnergyScanCallback binderListener =
|
|
||||||
new ILowpanEnergyScanCallback.Stub() {
|
|
||||||
public void onEnergyScanResult(int channel, int rssi) {
|
|
||||||
Callback callback = mCallback;
|
|
||||||
Handler handler = mHandler;
|
|
||||||
|
|
||||||
if (callback == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Runnable runnable =
|
|
||||||
() -> {
|
|
||||||
if (callback != null) {
|
|
||||||
LowpanEnergyScanResult result =
|
|
||||||
new LowpanEnergyScanResult();
|
|
||||||
result.setChannel(channel);
|
|
||||||
result.setMaxRssi(rssi);
|
|
||||||
callback.onEnergyScanResult(result);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (handler != null) {
|
|
||||||
handler.post(runnable);
|
|
||||||
} else {
|
|
||||||
runnable.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onEnergyScanFinished() {
|
|
||||||
Callback callback = mCallback;
|
|
||||||
Handler handler = mHandler;
|
|
||||||
|
|
||||||
if (callback == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Runnable runnable = () -> callback.onScanFinished();
|
|
||||||
|
|
||||||
if (handler != null) {
|
|
||||||
handler.post(runnable);
|
|
||||||
} else {
|
|
||||||
runnable.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBinder.startEnergyScan(map, binderListener);
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
|
|
||||||
} catch (ServiceSpecificException x) {
|
|
||||||
throw LowpanException.rethrowFromServiceSpecificException(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop an energy scan currently in progress.
|
|
||||||
*
|
|
||||||
* @see #startEnergyScan
|
|
||||||
*/
|
|
||||||
public void stopEnergyScan() {
|
|
||||||
try {
|
|
||||||
mBinder.stopEnergyScan();
|
|
||||||
|
|
||||||
} catch (RemoteException x) {
|
|
||||||
throw x.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception indicating the form operation found a network nearby with the same identity.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class NetworkAlreadyExistsException extends LowpanException {
|
|
||||||
|
|
||||||
public NetworkAlreadyExistsException() {}
|
|
||||||
|
|
||||||
public NetworkAlreadyExistsException(String message) {
|
|
||||||
super(message, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetworkAlreadyExistsException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetworkAlreadyExistsException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception indicating this operation was canceled by the driver before it could finish.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class OperationCanceledException extends LowpanException {
|
|
||||||
|
|
||||||
public OperationCanceledException() {}
|
|
||||||
|
|
||||||
public OperationCanceledException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OperationCanceledException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected OperationCanceledException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception indicating the interface is the wrong state for an operation.
|
|
||||||
*
|
|
||||||
* @see LowpanInterface
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// @SystemApi
|
|
||||||
public class WrongStateException extends LowpanException {
|
|
||||||
|
|
||||||
public WrongStateException() {}
|
|
||||||
|
|
||||||
public WrongStateException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WrongStateException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected WrongStateException(Exception cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<HTML>
|
|
||||||
<BODY>
|
|
||||||
<p>@SystemApi</p>
|
|
||||||
<!-- @hide -->
|
|
||||||
<p>Provides classes to manage Low-power Wireless Personal Area Network (LoWPAN) functionality on the device.
|
|
||||||
Examples of such network technologies include <a href="http://threadgroup.org/">Thread</a> and
|
|
||||||
<a href="http://www.zigbee.org/zigbee-for-developers/network-specifications/zigbeeip/">ZigBee IP</a>.</p>
|
|
||||||
<p>The LoWPAN APIs provide a means by which applications can communicate
|
|
||||||
with the lower-level wireless stack that provides LoWPAN network access.</p>
|
|
||||||
|
|
||||||
<p>Some APIs may require the following user permissions:</p>
|
|
||||||
<ul>
|
|
||||||
<li>{@link android.Manifest.permission#ACCESS_LOWPAN_STATE}</li>
|
|
||||||
<li>{@link android.Manifest.permission#CHANGE_LOWPAN_STATE}</li>
|
|
||||||
<li>TBD</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p class="note"><strong>Note:</strong> Not all Android-powered devices provide LoWPAN functionality.
|
|
||||||
If your application uses these APIs, declare so with a <a
|
|
||||||
href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code <uses-feature>}</a>
|
|
||||||
element in the manifest file:</p>
|
|
||||||
<pre>
|
|
||||||
<manifest ...>
|
|
||||||
<uses-feature android:name="android.hardware.lowpan" />
|
|
||||||
...
|
|
||||||
</manifest>
|
|
||||||
</pre>
|
|
||||||
</BODY>
|
|
||||||
</HTML>
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// Copyright (C) 2017 The Android Open Source Project
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Make test APK
|
|
||||||
// ============================================================
|
|
||||||
package {
|
|
||||||
// See: http://go/android-license-faq
|
|
||||||
// A large-scale-change added 'default_applicable_licenses' to import
|
|
||||||
// all of the 'license_kinds' from "frameworks_base_license"
|
|
||||||
// to get the below license kinds:
|
|
||||||
// SPDX-license-identifier-Apache-2.0
|
|
||||||
default_applicable_licenses: ["frameworks_base_license"],
|
|
||||||
}
|
|
||||||
|
|
||||||
android_test {
|
|
||||||
name: "FrameworksLowpanApiTests",
|
|
||||||
srcs: ["**/*.java"],
|
|
||||||
// Filter all src files to just java files
|
|
||||||
jacoco: {
|
|
||||||
include_filter: ["android.net.lowpan.*"],
|
|
||||||
exclude_filter: [
|
|
||||||
"android.net.lowpan.LowpanInterfaceTest*",
|
|
||||||
"android.net.lowpan.LowpanManagerTest*",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
static_libs: [
|
|
||||||
"androidx.test.rules",
|
|
||||||
"guava",
|
|
||||||
"mockito-target-minus-junit4",
|
|
||||||
"frameworks-base-testutils",
|
|
||||||
],
|
|
||||||
libs: [
|
|
||||||
"android.test.runner",
|
|
||||||
"android.test.base",
|
|
||||||
],
|
|
||||||
platform_apis: true,
|
|
||||||
test_suites: ["device-tests"],
|
|
||||||
certificate: "platform",
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ Copyright (C) 2017 The Android Open Source Project
|
|
||||||
~
|
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
~ you may not use this file except in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
~ See the License for the specific language governing permissions and
|
|
||||||
~ limitations under the License
|
|
||||||
-->
|
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="android.net.lowpan.test">
|
|
||||||
|
|
||||||
<application>
|
|
||||||
<uses-library android:name="android.test.runner" />
|
|
||||||
<activity android:label="LowpanTestDummyLabel"
|
|
||||||
android:name="LowpanTestDummyName"
|
|
||||||
android:exported="true">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
</application>
|
|
||||||
|
|
||||||
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
|
||||||
android:targetPackage="android.net.lowpan.test"
|
|
||||||
android:label="Frameworks LoWPAN API Tests">
|
|
||||||
</instrumentation>
|
|
||||||
|
|
||||||
</manifest>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2017 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<configuration description="Runs Frameworks LoWPAN API Tests.">
|
|
||||||
<target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
|
|
||||||
<option name="test-file-name" value="FrameworksLowpanApiTests.apk" />
|
|
||||||
</target_preparer>
|
|
||||||
|
|
||||||
<option name="test-suite-tag" value="apct" />
|
|
||||||
<option name="test-tag" value="FrameworksLowpanApiTests" />
|
|
||||||
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
|
||||||
<option name="package" value="android.net.lowpan.test" />
|
|
||||||
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
|
|
||||||
</test>
|
|
||||||
</configuration>
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
# LoWPAN Unit Tests
|
|
||||||
This package contains unit tests for the android LoWPAN framework System APIs based on the
|
|
||||||
[Android Testing Support Library](http://developer.android.com/tools/testing-support-library/index.html).
|
|
||||||
The test cases are built using the [JUnit](http://junit.org/) and [Mockito](http://mockito.org/)
|
|
||||||
libraries.
|
|
||||||
|
|
||||||
## Running Tests
|
|
||||||
The easiest way to run tests is simply run
|
|
||||||
|
|
||||||
```
|
|
||||||
frameworks/base/lowpan/tests/runtests.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
`runtests.sh` will build the test project and all of its dependencies and push the APK to the
|
|
||||||
connected device. It will then run the tests on the device.
|
|
||||||
|
|
||||||
To pick up changes in framework/base, you will need to:
|
|
||||||
1. rebuild the framework library 'make -j32'
|
|
||||||
2. sync over the updated library to the device 'adb sync'
|
|
||||||
3. restart framework on the device 'adb shell stop' then 'adb shell start'
|
|
||||||
|
|
||||||
To enable syncing data to the device for first time after clean reflash:
|
|
||||||
1. adb disable-verity
|
|
||||||
2. adb reboot
|
|
||||||
3. adb remount
|
|
||||||
|
|
||||||
See below for a few example of options to limit which tests are run.
|
|
||||||
See the
|
|
||||||
[AndroidJUnitRunner Documentation](https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html)
|
|
||||||
for more details on the supported options.
|
|
||||||
|
|
||||||
```
|
|
||||||
runtests.sh -e package android.net.lowpan
|
|
||||||
runtests.sh -e class android.net.lowpan.LowpanManagerTest
|
|
||||||
```
|
|
||||||
|
|
||||||
If you manually build and push the test APK to the device you can run tests using
|
|
||||||
|
|
||||||
```
|
|
||||||
adb shell am instrument -w 'android.net.wifi.test/androidx.test.runner.AndroidJUnitRunner'
|
|
||||||
```
|
|
||||||
|
|
||||||
## Adding Tests
|
|
||||||
Tests can be added by adding classes to the src directory. JUnit4 style test cases can
|
|
||||||
be written by simply annotating test methods with `org.junit.Test`.
|
|
||||||
|
|
||||||
## Debugging Tests
|
|
||||||
If you are trying to debug why tests are not doing what you expected, you can add android log
|
|
||||||
statements and use logcat to view them. The beginning and end of every tests is automatically logged
|
|
||||||
with the tag `TestRunner`.
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [ -z $ANDROID_BUILD_TOP ]; then
|
|
||||||
echo "You need to source and lunch before you can use this script"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Running tests"
|
|
||||||
|
|
||||||
set -e # fail early
|
|
||||||
|
|
||||||
echo "+ mmma -j32 $ANDROID_BUILD_TOP/frameworks/base/lowpan/tests"
|
|
||||||
# NOTE Don't actually run the command above since this shell doesn't inherit functions from the
|
|
||||||
# caller.
|
|
||||||
make -j32 -C $ANDROID_BUILD_TOP -f build/core/main.mk MODULES-IN-frameworks-base-lowpan-tests
|
|
||||||
|
|
||||||
set -x # print commands
|
|
||||||
|
|
||||||
adb root
|
|
||||||
adb wait-for-device
|
|
||||||
|
|
||||||
adb install -r -g "$OUT/data/app/FrameworksLowpanApiTests/FrameworksLowpanApiTests.apk"
|
|
||||||
|
|
||||||
adb shell am instrument -w "$@" 'android.net.lowpan.test/androidx.test.runner.AndroidJUnitRunner'
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.test.TestLooper;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
|
||||||
|
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/** Unit tests for android.net.lowpan.LowpanInterface. */
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
@SmallTest
|
|
||||||
public class LowpanInterfaceTest {
|
|
||||||
private static final String TEST_PACKAGE_NAME = "TestPackage";
|
|
||||||
|
|
||||||
@Mock Context mContext;
|
|
||||||
@Mock ILowpanInterface mLowpanInterfaceService;
|
|
||||||
@Mock IBinder mLowpanInterfaceBinder;
|
|
||||||
@Mock ApplicationInfo mApplicationInfo;
|
|
||||||
@Mock IBinder mAppBinder;
|
|
||||||
@Mock LowpanInterface.Callback mLowpanInterfaceCallback;
|
|
||||||
|
|
||||||
private Handler mHandler;
|
|
||||||
private final TestLooper mTestLooper = new TestLooper();
|
|
||||||
private ILowpanInterfaceListener mInterfaceListener;
|
|
||||||
private LowpanInterface mLowpanInterface;
|
|
||||||
private Map<String, Object> mPropertyMap;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
when(mContext.getApplicationInfo()).thenReturn(mApplicationInfo);
|
|
||||||
when(mContext.getOpPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
|
||||||
when(mLowpanInterfaceService.getName()).thenReturn("wpan0");
|
|
||||||
when(mLowpanInterfaceService.asBinder()).thenReturn(mLowpanInterfaceBinder);
|
|
||||||
|
|
||||||
mLowpanInterface =
|
|
||||||
new LowpanInterface(mContext, mLowpanInterfaceService, mTestLooper.getLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStateChangedCallback() throws Exception {
|
|
||||||
// Register our callback
|
|
||||||
mLowpanInterface.registerCallback(mLowpanInterfaceCallback);
|
|
||||||
|
|
||||||
// Verify a listener was added
|
|
||||||
verify(mLowpanInterfaceService)
|
|
||||||
.addListener(
|
|
||||||
argThat(
|
|
||||||
listener -> {
|
|
||||||
mInterfaceListener = listener;
|
|
||||||
return listener instanceof ILowpanInterfaceListener;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Change some properties
|
|
||||||
mInterfaceListener.onStateChanged(LowpanInterface.STATE_OFFLINE);
|
|
||||||
mTestLooper.dispatchAll();
|
|
||||||
|
|
||||||
// Verify that the property was changed
|
|
||||||
verify(mLowpanInterfaceCallback)
|
|
||||||
.onStateChanged(
|
|
||||||
argThat(stateString -> stateString.equals(LowpanInterface.STATE_OFFLINE)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net.lowpan;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.test.TestLooper;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
|
||||||
|
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
/** Unit tests for android.net.lowpan.LowpanManager. */
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
@SmallTest
|
|
||||||
public class LowpanManagerTest {
|
|
||||||
private static final String TEST_PACKAGE_NAME = "TestPackage";
|
|
||||||
|
|
||||||
@Mock Context mContext;
|
|
||||||
@Mock ILowpanManager mLowpanService;
|
|
||||||
@Mock ILowpanInterface mLowpanInterfaceService;
|
|
||||||
@Mock IBinder mLowpanInterfaceBinder;
|
|
||||||
@Mock ApplicationInfo mApplicationInfo;
|
|
||||||
@Mock IBinder mAppBinder;
|
|
||||||
@Mock LowpanManager.Callback mLowpanManagerCallback;
|
|
||||||
|
|
||||||
private Handler mHandler;
|
|
||||||
private final TestLooper mTestLooper = new TestLooper();
|
|
||||||
private LowpanManager mLowpanManager;
|
|
||||||
|
|
||||||
private ILowpanManagerListener mManagerListener;
|
|
||||||
private LowpanInterface mLowpanInterface;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
when(mContext.getApplicationInfo()).thenReturn(mApplicationInfo);
|
|
||||||
when(mContext.getOpPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
|
||||||
|
|
||||||
mLowpanManager = new LowpanManager(mContext, mLowpanService, mTestLooper.getLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetEmptyInterfaceList() throws Exception {
|
|
||||||
when(mLowpanService.getInterfaceList()).thenReturn(new String[0]);
|
|
||||||
assertTrue(mLowpanManager.getInterfaceList().length == 0);
|
|
||||||
assertTrue(mLowpanManager.getInterface() == null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetInterfaceList() throws Exception {
|
|
||||||
when(mLowpanService.getInterfaceList()).thenReturn(new String[] {"wpan0"});
|
|
||||||
when(mLowpanService.getInterface("wpan0")).thenReturn(mLowpanInterfaceService);
|
|
||||||
when(mLowpanInterfaceService.getName()).thenReturn("wpan0");
|
|
||||||
when(mLowpanInterfaceService.asBinder()).thenReturn(mLowpanInterfaceBinder);
|
|
||||||
assertEquals(mLowpanManager.getInterfaceList().length, 1);
|
|
||||||
|
|
||||||
LowpanInterface iface = mLowpanManager.getInterface();
|
|
||||||
assertNotNull(iface);
|
|
||||||
assertEquals(iface.getName(), "wpan0");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRegisterCallback() throws Exception {
|
|
||||||
when(mLowpanInterfaceService.getName()).thenReturn("wpan0");
|
|
||||||
when(mLowpanInterfaceService.asBinder()).thenReturn(mLowpanInterfaceBinder);
|
|
||||||
|
|
||||||
// Register our callback
|
|
||||||
mLowpanManager.registerCallback(mLowpanManagerCallback);
|
|
||||||
|
|
||||||
// Verify a listener was added
|
|
||||||
verify(mLowpanService)
|
|
||||||
.addListener(
|
|
||||||
argThat(
|
|
||||||
listener -> {
|
|
||||||
mManagerListener = listener;
|
|
||||||
return listener instanceof ILowpanManagerListener;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Add an interface
|
|
||||||
mManagerListener.onInterfaceAdded(mLowpanInterfaceService);
|
|
||||||
mTestLooper.dispatchAll();
|
|
||||||
|
|
||||||
// Verify that the interface was added
|
|
||||||
verify(mLowpanManagerCallback)
|
|
||||||
.onInterfaceAdded(
|
|
||||||
argThat(
|
|
||||||
iface -> {
|
|
||||||
mLowpanInterface = iface;
|
|
||||||
return iface instanceof LowpanInterface;
|
|
||||||
}));
|
|
||||||
verifyNoMoreInteractions(mLowpanManagerCallback);
|
|
||||||
|
|
||||||
// This check causes the test to fail with a weird error, but I'm not sure why.
|
|
||||||
assertEquals(mLowpanInterface.getService(), mLowpanInterfaceService);
|
|
||||||
|
|
||||||
// Verify that calling getInterface on the LowpanManager object will yield the same
|
|
||||||
// LowpanInterface object.
|
|
||||||
when(mLowpanService.getInterfaceList()).thenReturn(new String[] {"wpan0"});
|
|
||||||
when(mLowpanService.getInterface("wpan0")).thenReturn(mLowpanInterfaceService);
|
|
||||||
assertEquals(mLowpanManager.getInterface(), mLowpanInterface);
|
|
||||||
|
|
||||||
// Remove the service
|
|
||||||
mManagerListener.onInterfaceRemoved(mLowpanInterfaceService);
|
|
||||||
mTestLooper.dispatchAll();
|
|
||||||
|
|
||||||
// Verify that the interface was removed
|
|
||||||
verify(mLowpanManagerCallback).onInterfaceRemoved(mLowpanInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUnregisterCallback() throws Exception {
|
|
||||||
when(mLowpanInterfaceService.getName()).thenReturn("wpan0");
|
|
||||||
when(mLowpanInterfaceService.asBinder()).thenReturn(mLowpanInterfaceBinder);
|
|
||||||
|
|
||||||
// Register our callback
|
|
||||||
mLowpanManager.registerCallback(mLowpanManagerCallback);
|
|
||||||
|
|
||||||
// Verify a listener was added
|
|
||||||
verify(mLowpanService)
|
|
||||||
.addListener(
|
|
||||||
argThat(
|
|
||||||
listener -> {
|
|
||||||
mManagerListener = listener;
|
|
||||||
return listener instanceof ILowpanManagerListener;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Add an interface
|
|
||||||
mManagerListener.onInterfaceAdded(mLowpanInterfaceService);
|
|
||||||
mTestLooper.dispatchAll();
|
|
||||||
|
|
||||||
// Verify that the interface was added
|
|
||||||
verify(mLowpanManagerCallback)
|
|
||||||
.onInterfaceAdded(
|
|
||||||
argThat(
|
|
||||||
iface -> {
|
|
||||||
mLowpanInterface = iface;
|
|
||||||
return iface instanceof LowpanInterface;
|
|
||||||
}));
|
|
||||||
verifyNoMoreInteractions(mLowpanManagerCallback);
|
|
||||||
|
|
||||||
// Unregister our callback
|
|
||||||
mLowpanManager.unregisterCallback(mLowpanManagerCallback);
|
|
||||||
|
|
||||||
// Verify the listener was removed
|
|
||||||
verify(mLowpanService).removeListener(mManagerListener);
|
|
||||||
|
|
||||||
// Verify that the callback wasn't invoked.
|
|
||||||
verifyNoMoreInteractions(mLowpanManagerCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user