ThreadNetworkCredentials

public final class ThreadNetworkCredentials extends Object
implements Parcelable

Data interface for managing Thread Network Credentials.

An example usage of creating Thread Network Credentials with random Active Operational Dataset:

ThreadNetworkCredentials threadCredentials =
     ThreadNetworkCredentials.newRandomizedBuilder().build();
 
or random Dataset with given Network Name:
ThreadNetworkCredentials threadCredentials =
   ThreadNetworkCredentials.newRandomizedBuilder()
     .setNetworkName("MyThreadNet")
     .build();
 
If the Thread Active Operational Dataset is already known, you can simply use:
ThreadNetworkCredentials threadCredentials =
     ThreadNetworkCredentials.fromActiveOperationalDataset(activeOperationalDataset);
 
To retrieve Thread network credentials from the ActivityResult of the IntentSender returned by ThreadNetworkClient APIs, use fromIntentSenderResultData(Intent):
ThreadNetworkCredentials threadCredentials =
     ThreadNetworkCredentials.fromIntentSenderResultData(activityResult.getData());
 

Nested Class Summary

class ThreadNetworkCredentials.Builder Builder for constructing ThreadNetworkCredentials instances. 
class ThreadNetworkCredentials.ChannelMaskEntry The Channel Mask Entry of Thread Operational Dataset. 
class ThreadNetworkCredentials.SecurityPolicy The class represents Thread Security Policy. 
class ThreadNetworkCredentials.Timestamp The timestamp of Thread Operational Dataset. 

Constant Summary

int CHANNEL_MAX_2P4GHZ The maximum 2.4GHz channel.
int CHANNEL_MIN_2P4GHZ The minimum 2.4GHz channel.
int CHANNEL_PAGE_2P4GHZ The 2.4 GHz channel page.
int LENGTH_EXTENDED_PANID The length of Extended PAN ID that can be set by ThreadNetworkCredentials.Builder.setExtendedPanId(byte[]).
int LENGTH_MAX_NETWORK_NAME The maximum length of NetworkName that can be set by ThreadNetworkCredentials.Builder.setNetworkName(String).
int LENGTH_MAX_OPERATIONAL_DATASET The maximum length of Operational Dataset that can be set by fromActiveOperationalDataset(byte[]).
int LENGTH_MAX_SECURITY_POLICY_FLAGS The maximum length of Security Policy Flags that can be set by ThreadNetworkCredentials.SecurityPolicy.SecurityPolicy(int, byte[]).
int LENGTH_MESH_LOCAL_PREFIX The length of Mesh-Local Prefix that can be set by ThreadNetworkCredentials.Builder.setMeshLocalPrefix(byte[]).
int LENGTH_MIN_NETWORK_NAME The minimum length of Network Name that can be set by ThreadNetworkCredentials.Builder.setNetworkName(String).
int LENGTH_MIN_SECURITY_POLICY_FLAGS The minimum length of Security Policy Flags that can be set by ThreadNetworkCredentials.SecurityPolicy.SecurityPolicy(int, byte[]).
int LENGTH_NETWORK_KEY The length of Network Key that can be set by ThreadNetworkCredentials.Builder.setNetworkKey(byte[]).
int LENGTH_PSKC The length of PSKc that can be set by ThreadNetworkCredentials.Builder.setPskc(byte[]).
byte MESH_LOCAL_PREFIX_FIRST_BYTE The fisrt byte of Mesh-Local Prefix that can be set by ThreadNetworkCredentials.Builder.setMeshLocalPrefix(byte[]).

Inherited Constant Summary

Field Summary

public static final ThreadNetworkCredentials.ChannelMaskEntry DEFAULT_CHANNEL_MASK The default channel mask which enables all 2.4GHz channels.
public static final ThreadNetworkCredentials.SecurityPolicy DEFAULT_SECURITY_POLICY The default Thread 1.2 Security Policy.

Public Method Summary

static ThreadNetworkCredentials
fromActiveOperationalDataset(byte[] activeOperationalDataset)
Creates a new ThreadNetworkCredentials instance with given Thread Active Operational Dataset which is encoded as Thread TLV list.
static ThreadNetworkCredentials
byte[]
getActiveOperationalDataset()
Returns the Thread active operational dataset as encoded Thread TLV list.
ThreadNetworkCredentials.Timestamp
getActiveTimestamp()
Returns the Active Timestamp in the Thread active operational dataset.
int
getChannel()
Returns the Channel in the Thread active operational dataset.
Set<ThreadNetworkCredentials.ChannelMaskEntry>
getChannelMasks()
Returns the Channel Masks in the Thread active operational dataset.
int
getChannelPage()
Returns the Channel Page in the Thread active operational dataset.
long
getCreatedAtMillis()
Returns the Unix epoch in Milliseconds the ThreadNetworkCredentials instance is created at.
byte[]
getExtendedPanId()
Returns the Extended PAN ID in the Thread active operational dataset.
byte[]
getMeshLocalPrefix()
Returns the Mesh-Local Prefix in the Thread active operational dataset.
byte[]
getNetworkKey()
Returns the Network Key in the Thread active operational dataset.
String
getNetworkName()
Returns the network name if it is included in the Thread active operational dataset.
int
getPanId()
Returns the PAN ID in the Thread active operational dataset.
byte[]
getPskc()
Returns the PSKc in the Thread active operational dataset.
ThreadNetworkCredentials.SecurityPolicy
getSecurityPolicy()
Returns the Security Policy in the Thread active operational dataset.
long
getUpdatedAtMillis()
Returns the Unix epoch in Milliseconds the ThreadNetworkCredentials instance is updated at.
static ThreadNetworkCredentials.Builder
newRandomizedBuilder()
Creates a new ThreadNetworkCredentials.Builder instance for creating ThreadNetworkCredentials instances with randomly generated credentials.
String
void
writeToParcel(Parcel dest, int flags)

Inherited Method Summary

Constants

public static final int CHANNEL_MAX_2P4GHZ

The maximum 2.4GHz channel.

Constant Value: 26

public static final int CHANNEL_MIN_2P4GHZ

The minimum 2.4GHz channel.

Constant Value: 11

public static final int CHANNEL_PAGE_2P4GHZ

The 2.4 GHz channel page.

Constant Value: 0

public static final int LENGTH_EXTENDED_PANID

The length of Extended PAN ID that can be set by ThreadNetworkCredentials.Builder.setExtendedPanId(byte[]).

Constant Value: 8

public static final int LENGTH_MAX_NETWORK_NAME

The maximum length of NetworkName that can be set by ThreadNetworkCredentials.Builder.setNetworkName(String).

Constant Value: 16

public static final int LENGTH_MAX_OPERATIONAL_DATASET

The maximum length of Operational Dataset that can be set by fromActiveOperationalDataset(byte[]).

Constant Value: 254

public static final int LENGTH_MAX_SECURITY_POLICY_FLAGS

The maximum length of Security Policy Flags that can be set by ThreadNetworkCredentials.SecurityPolicy.SecurityPolicy(int, byte[]).

Constant Value: 2

public static final int LENGTH_MESH_LOCAL_PREFIX

The length of Mesh-Local Prefix that can be set by ThreadNetworkCredentials.Builder.setMeshLocalPrefix(byte[]).

Constant Value: 8

public static final int LENGTH_MIN_NETWORK_NAME

The minimum length of Network Name that can be set by ThreadNetworkCredentials.Builder.setNetworkName(String).

Constant Value: 1

public static final int LENGTH_MIN_SECURITY_POLICY_FLAGS

The minimum length of Security Policy Flags that can be set by ThreadNetworkCredentials.SecurityPolicy.SecurityPolicy(int, byte[]).

Constant Value: 1

public static final int LENGTH_NETWORK_KEY

The length of Network Key that can be set by ThreadNetworkCredentials.Builder.setNetworkKey(byte[]).

Constant Value: 16

public static final int LENGTH_PSKC

The length of PSKc that can be set by ThreadNetworkCredentials.Builder.setPskc(byte[]).

Constant Value: 16

public static final byte MESH_LOCAL_PREFIX_FIRST_BYTE

The fisrt byte of Mesh-Local Prefix that can be set by ThreadNetworkCredentials.Builder.setMeshLocalPrefix(byte[]).

Constant Value: -3

Fields

public static final ThreadNetworkCredentials.ChannelMaskEntry DEFAULT_CHANNEL_MASK

The default channel mask which enables all 2.4GHz channels.

public static final ThreadNetworkCredentials.SecurityPolicy DEFAULT_SECURITY_POLICY

The default Thread 1.2 Security Policy.

Public Methods

public static ThreadNetworkCredentials fromActiveOperationalDataset (byte[] activeOperationalDataset)

Creates a new ThreadNetworkCredentials instance with given Thread Active Operational Dataset which is encoded as Thread TLV list.

Throws
IllegalArgumentException if length of activeOperationalDataset is larger than LENGTH_MAX_OPERATIONAL_DATASET, activeOperationalDataset is malformed or there are missing Thread TLVs.

public static ThreadNetworkCredentials fromIntentSenderResultData (Intent data)

Parses out the data from the ActivityResult returned by ThreadNetworkClient.getPreferredCredentials() or ThreadNetworkClient.getCredentialsByExtendedPanId(byte[]). This method should only be called for a success case to interpret the result data.

Throws
IllegalArgumentException if no valid Thread credentials included in data.

public byte[] getActiveOperationalDataset ()

Returns the Thread active operational dataset as encoded Thread TLV list.

public ThreadNetworkCredentials.Timestamp getActiveTimestamp ()

Returns the Active Timestamp in the Thread active operational dataset.

public int getChannel ()

Returns the Channel in the Thread active operational dataset.

public Set<ThreadNetworkCredentials.ChannelMaskEntry> getChannelMasks ()

Returns the Channel Masks in the Thread active operational dataset.

public int getChannelPage ()

Returns the Channel Page in the Thread active operational dataset.

public long getCreatedAtMillis ()

Returns the Unix epoch in Milliseconds the ThreadNetworkCredentials instance is created at. Note that this is the time when the Thread network credentials is first added to the Thread Network service via ThreadNetworkClient.addCredentials(ThreadBorderAgent, ThreadNetworkCredentials). Zero will be returned if this instance is not returned by ThreadNetworkClient methods (e.g. created with fromActiveOperationalDataset(byte[])).

public byte[] getExtendedPanId ()

Returns the Extended PAN ID in the Thread active operational dataset.

public byte[] getMeshLocalPrefix ()

Returns the Mesh-Local Prefix in the Thread active operational dataset.

public byte[] getNetworkKey ()

Returns the Network Key in the Thread active operational dataset.

public String getNetworkName ()

Returns the network name if it is included in the Thread active operational dataset.

public int getPanId ()

Returns the PAN ID in the Thread active operational dataset.

public byte[] getPskc ()

Returns the PSKc in the Thread active operational dataset.

public ThreadNetworkCredentials.SecurityPolicy getSecurityPolicy ()

Returns the Security Policy in the Thread active operational dataset.

public long getUpdatedAtMillis ()

Returns the Unix epoch in Milliseconds the ThreadNetworkCredentials instance is updated at. Note that this is the time when the Thread network credentials was last added/updated to the Thread Network service via ThreadNetworkClient.addCredentials(ThreadBorderAgent, ThreadNetworkCredentials). Zero will be returned if this instance is not returned by ThreadNetworkClient methods (e.g. created with fromActiveOperationalDataset(byte[])).

public static ThreadNetworkCredentials.Builder newRandomizedBuilder ()

Creates a new ThreadNetworkCredentials.Builder instance for creating ThreadNetworkCredentials instances with randomly generated credentials.

If there are requirements on specific parameters, set it explicitly with their setters in ThreadNetworkCredentials.Builder. For example, it's likely that a readable Thread Network Name should be set with ThreadNetworkCredentials.Builder.setNetworkName(String).

public String toString ()

public void writeToParcel (Parcel dest, int flags)