Repo Created
This commit is contained in:
parent
eb305e2886
commit
a8c22c65db
4784 changed files with 329907 additions and 2 deletions
44
play-services-threadnetwork/build.gradle
Normal file
44
play-services-threadnetwork/build.gradle
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
android {
|
||||
namespace "com.google.android.gms.threadnetwork"
|
||||
|
||||
compileSdkVersion androidCompileSdk
|
||||
buildToolsVersion "$androidBuildVersionTools"
|
||||
|
||||
buildFeatures {
|
||||
aidl = true
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
versionName version
|
||||
minSdkVersion androidMinSdk
|
||||
targetSdkVersion androidTargetSdk
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing to publish yet
|
||||
//apply from: '../gradle/publish-android.gradle'
|
||||
|
||||
description = 'microG implementation of play-services-threadnetwork'
|
||||
|
||||
dependencies {
|
||||
// Dependencies from play-services-threadnetwork:16.2.1
|
||||
api project(':play-services-base')
|
||||
api project(':play-services-basement')
|
||||
api project(':play-services-tasks')
|
||||
|
||||
annotationProcessor project(':safe-parcel-processor')
|
||||
}
|
||||
49
play-services-threadnetwork/core/build.gradle
Normal file
49
play-services-threadnetwork/core/build.gradle
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
dependencies {
|
||||
api project(':play-services-threadnetwork')
|
||||
|
||||
implementation project(':play-services-base-core')
|
||||
implementation "androidx.annotation:annotation:$annotationVersion"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "org.microg.gms.threadnetwork.core"
|
||||
|
||||
compileSdkVersion androidCompileSdk
|
||||
buildToolsVersion "$androidBuildVersionTools"
|
||||
|
||||
defaultConfig {
|
||||
versionName version
|
||||
minSdkVersion androidMinSdk
|
||||
targetSdkVersion androidTargetSdk
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = 1.8
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing to publish yet
|
||||
//apply from: '../../gradle/publish-android.gradle'
|
||||
|
||||
description = 'microG service implementation for play-services-threadnetwork'
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
~ SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application>
|
||||
<service
|
||||
android:name="org.microg.gms.threadnetwork.ThreadNetworkService"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.gms.threadnetwork.service.START" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.microg.gms.threadnetwork
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.google.android.gms.common.ConnectionResult
|
||||
import com.google.android.gms.common.Feature
|
||||
import com.google.android.gms.common.api.CommonStatusCodes
|
||||
import com.google.android.gms.common.api.Status
|
||||
import com.google.android.gms.common.api.internal.IStatusCallback
|
||||
import com.google.android.gms.common.internal.ConnectionInfo
|
||||
import com.google.android.gms.common.internal.GetServiceRequest
|
||||
import com.google.android.gms.common.internal.IGmsCallbacks
|
||||
import com.google.android.gms.threadnetwork.ThreadBorderAgent
|
||||
import com.google.android.gms.threadnetwork.ThreadNetworkCredentials
|
||||
import com.google.android.gms.threadnetwork.ThreadNetworkStatusCodes
|
||||
import com.google.android.gms.threadnetwork.internal.*
|
||||
import org.microg.gms.BaseService
|
||||
import org.microg.gms.common.GmsService
|
||||
|
||||
private const val TAG = "ThreadNetworkService"
|
||||
|
||||
class ThreadNetworkService : BaseService(TAG, GmsService.THREAD_NETWORK) {
|
||||
override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) {
|
||||
val connectionInfo = ConnectionInfo()
|
||||
connectionInfo.features = arrayOf(Feature("threadnetwork", 8))
|
||||
callback.onPostInitCompleteWithConnectionInfo(
|
||||
ConnectionResult.SUCCESS, ThreadNetworkServiceImpl(this, request.packageName).asBinder(), connectionInfo
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class ThreadNetworkServiceImpl(private val context: Context, private val packageName: String) : IThreadNetworkService.Stub() {
|
||||
private val THREAD_NETWORK_NOT_FOUND = Status(ThreadNetworkStatusCodes.THREAD_NETWORK_NOT_FOUND, "THREAD_NETWORK_NOT_FOUND")
|
||||
|
||||
override fun addCredentials(callback: IStatusCallback?, borderAgent: ThreadBorderAgent?, credentials: ThreadNetworkCredentials?) {
|
||||
if (borderAgent == null || credentials == null) {
|
||||
runCatching { callback?.onResult(Status(CommonStatusCodes.DEVELOPER_ERROR, "Illegal arguments")) }
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "Not yet implemented: addCredentials")
|
||||
runCatching { callback?.onResult(Status.SUCCESS) }
|
||||
}
|
||||
|
||||
override fun removeCredentials(callback: IStatusCallback?, borderAgent: ThreadBorderAgent?) {
|
||||
if (borderAgent == null) {
|
||||
runCatching { callback?.onResult(Status(CommonStatusCodes.DEVELOPER_ERROR, "Illegal arguments")) }
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "Not yet implemented: removeCredentials")
|
||||
runCatching { callback?.onResult(Status.SUCCESS) }
|
||||
}
|
||||
|
||||
override fun getAllCredentials(callbacks: IThreadNetworkServiceCallbacks?) {
|
||||
Log.d(TAG, "Not yet implemented: getAllCredentials")
|
||||
runCatching { callbacks?.onCredentials(Status.SUCCESS, emptyList()) }
|
||||
}
|
||||
|
||||
override fun getCredentialsByExtendedPanId(callback: IGetCredentialsByExtendedPanIdCallback?, extendedPanId: ByteArray?) {
|
||||
if (extendedPanId == null) {
|
||||
runCatching { callback?.onCredentials(Status(CommonStatusCodes.DEVELOPER_ERROR, "Illegal arguments"), null) }
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "Not yet implemented: getCredentialsByExtendedPanId")
|
||||
runCatching { callback?.onCredentials(THREAD_NETWORK_NOT_FOUND, null) }
|
||||
}
|
||||
|
||||
override fun getCredentialsByBorderAgent(callbacks: IThreadNetworkServiceCallbacks?, borderAgent: ThreadBorderAgent?) {
|
||||
if (borderAgent == null) {
|
||||
runCatching { callbacks?.onCredentials(Status(CommonStatusCodes.DEVELOPER_ERROR, "Illegal arguments"), emptyList()) }
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "Not yet implemented: getCredentialsByBorderAgent: $borderAgent")
|
||||
runCatching { callbacks?.onCredentials(Status.SUCCESS, emptyList()) }
|
||||
}
|
||||
|
||||
override fun getPreferredCredentials(callback: IGetPreferredCredentialsCallback?) {
|
||||
Log.d(TAG, "Not yet implemented: getPreferredCredentials")
|
||||
runCatching { callback?.onPreferredCredentials(THREAD_NETWORK_NOT_FOUND, null) }
|
||||
}
|
||||
|
||||
override fun isPreferredCredentials(callback: IIsPreferredCredentialsCallback?, credentials: ThreadNetworkCredentials?) {
|
||||
if (credentials == null) {
|
||||
runCatching { callback?.onIsPreferredCredentials(Status(CommonStatusCodes.DEVELOPER_ERROR, "Illegal arguments"), false) }
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "Not yet implemented: isPreferredCredentials: $credentials")
|
||||
runCatching { callback?.onIsPreferredCredentials(THREAD_NETWORK_NOT_FOUND, false) }
|
||||
}
|
||||
|
||||
}
|
||||
6
play-services-threadnetwork/src/main/AndroidManifest.xml
Normal file
6
play-services-threadnetwork/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
~ SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest />
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork;
|
||||
|
||||
parcelable ThreadBorderAgent;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork;
|
||||
|
||||
parcelable ThreadNetworkCredentials;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork.internal;
|
||||
|
||||
import android.content.IntentSender;
|
||||
import com.google.android.gms.common.api.Status;
|
||||
|
||||
interface IGetCredentialsByExtendedPanIdCallback {
|
||||
void onCredentials(in Status status, in @nullable IntentSender intentSender) = 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork.internal;
|
||||
|
||||
import android.content.IntentSender;
|
||||
import com.google.android.gms.common.api.Status;
|
||||
|
||||
interface IGetPreferredCredentialsCallback {
|
||||
void onPreferredCredentials(in Status status, in @nullable IntentSender intentSender) = 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork.internal;
|
||||
|
||||
import com.google.android.gms.common.api.Status;
|
||||
|
||||
interface IIsPreferredCredentialsCallback {
|
||||
void onIsPreferredCredentials(in Status status, boolean isPreferred) = 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork.internal;
|
||||
|
||||
import com.google.android.gms.common.api.internal.IStatusCallback;
|
||||
|
||||
import com.google.android.gms.threadnetwork.ThreadBorderAgent;
|
||||
import com.google.android.gms.threadnetwork.ThreadNetworkCredentials;
|
||||
|
||||
import com.google.android.gms.threadnetwork.internal.IGetCredentialsByExtendedPanIdCallback;
|
||||
import com.google.android.gms.threadnetwork.internal.IGetPreferredCredentialsCallback;
|
||||
import com.google.android.gms.threadnetwork.internal.IIsPreferredCredentialsCallback;
|
||||
import com.google.android.gms.threadnetwork.internal.IThreadNetworkServiceCallbacks;
|
||||
|
||||
interface IThreadNetworkService {
|
||||
void addCredentials(IStatusCallback callback, in ThreadBorderAgent borderAgent, in ThreadNetworkCredentials credentials) = 0;
|
||||
void removeCredentials(IStatusCallback callback, in ThreadBorderAgent borderAgent) = 1;
|
||||
void getAllCredentials(IThreadNetworkServiceCallbacks callbacks) = 3;
|
||||
void getCredentialsByExtendedPanId(IGetCredentialsByExtendedPanIdCallback callback, in byte[] extendedPanId) = 4;
|
||||
void getCredentialsByBorderAgent(IThreadNetworkServiceCallbacks callbacks, in ThreadBorderAgent borderAgent) = 5;
|
||||
void getPreferredCredentials(IGetPreferredCredentialsCallback callback) = 7;
|
||||
void isPreferredCredentials(IIsPreferredCredentialsCallback callback, in ThreadNetworkCredentials credentials) = 8;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork.internal;
|
||||
|
||||
import com.google.android.gms.common.api.Status;
|
||||
|
||||
import com.google.android.gms.threadnetwork.ThreadNetworkCredentials;
|
||||
|
||||
interface IThreadNetworkServiceCallbacks {
|
||||
void onCredentials(in Status status, in List<ThreadNetworkCredentials> credentials) = 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Notice: Portions of this file are reproduced from work created and shared by Google and used
|
||||
* according to terms described in the Creative Commons 4.0 Attribution License.
|
||||
* See https://developers.google.com/readme/policies for details.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks the result of {@link ThreadNetworkClient#isPreferredCredentials(ThreadNetworkCredentials)}.
|
||||
*/
|
||||
@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({IsPreferredCredentialsResult.PREFERRED_CREDENTIALS_NOT_FOUND, IsPreferredCredentialsResult.PREFERRED_CREDENTIALS_NOT_MATCHED, IsPreferredCredentialsResult.PREFERRED_CREDENTIALS_MATCHED})
|
||||
public @interface IsPreferredCredentialsResult {
|
||||
/**
|
||||
* The preferred Thread network credentials don't exist.
|
||||
*/
|
||||
int PREFERRED_CREDENTIALS_NOT_FOUND = -1;
|
||||
/**
|
||||
* The preferred Thread network credentials don't match given credentials.
|
||||
*/
|
||||
int PREFERRED_CREDENTIALS_NOT_MATCHED = 0;
|
||||
/**
|
||||
* The preferred Thread network credentials match given credentials.
|
||||
*/
|
||||
int PREFERRED_CREDENTIALS_MATCHED = 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Notice: Portions of this file are reproduced from work created and shared by Google and used
|
||||
* according to terms described in the Creative Commons 4.0 Attribution License.
|
||||
* See https://developers.google.com/readme/policies for details.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork;
|
||||
|
||||
import android.os.Parcel;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable;
|
||||
import com.google.android.gms.common.internal.safeparcel.SafeParcelable;
|
||||
import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter;
|
||||
|
||||
/**
|
||||
* Data interface for Thread Border Agent.
|
||||
*/
|
||||
@SafeParcelable.Class
|
||||
public class ThreadBorderAgent extends AbstractSafeParcelable {
|
||||
@Field(value = 2, getterName = "getId")
|
||||
private final byte[] id;
|
||||
|
||||
@Constructor
|
||||
public ThreadBorderAgent(@Param(2) byte[] id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id which uniquely identifies a Thread Border Agent device.
|
||||
*/
|
||||
public byte[] getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ThreadBorderAgent.Builder} for constructing a {@link ThreadBorderAgent}.
|
||||
*
|
||||
* @param id the id which uniquely identifies a Border Agent. The length must be 16 bytes.
|
||||
* @throws IllegalArgumentException if the id is not of length 16 bytes.
|
||||
*/
|
||||
public static Builder newBuilder(byte[] id) {
|
||||
if (id.length != 16) throw new IllegalArgumentException("the id is not of length 16 bytes");
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for constructing {@link ThreadBorderAgent} instances.
|
||||
*/
|
||||
public static class Builder {
|
||||
private byte[] id;
|
||||
|
||||
private Builder(byte[] id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link ThreadBorderAgent} as configured by this builder.
|
||||
*/
|
||||
public ThreadBorderAgent build() {
|
||||
return new ThreadBorderAgent(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
CREATOR.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
private static String byteArrayToHex(byte[] a) {
|
||||
StringBuilder sb = new StringBuilder(a.length * 2);
|
||||
for (byte b : a) sb.append(String.format("%02x", b));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ThreadBorderAgent{" + byteArrayToHex(id) + "}";
|
||||
}
|
||||
|
||||
public static final SafeParcelableCreatorAndWriter<ThreadBorderAgent> CREATOR = findCreator(ThreadBorderAgent.class);
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Notice: Portions of this file are reproduced from work created and shared by Google and used
|
||||
* according to terms described in the Creative Commons 4.0 Attribution License.
|
||||
* See https://developers.google.com/readme/policies for details.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork;
|
||||
|
||||
public interface ThreadNetworkClient {
|
||||
}
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Notice: Portions of this file are reproduced from work created and shared by Google and used
|
||||
* according to terms described in the Creative Commons 4.0 Attribution License.
|
||||
* See https://developers.google.com/readme/policies for details.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork;
|
||||
|
||||
import android.os.Parcel;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable;
|
||||
import com.google.android.gms.common.internal.safeparcel.SafeParcelable;
|
||||
import com.google.android.gms.common.internal.safeparcel.SafeParcelableCreatorAndWriter;
|
||||
|
||||
/**
|
||||
* Data interface for managing Thread Network Credentials.
|
||||
*/
|
||||
@SafeParcelable.Class
|
||||
public class ThreadNetworkCredentials extends AbstractSafeParcelable {
|
||||
/**
|
||||
* The minimum 2.4GHz channel.
|
||||
*/
|
||||
public static final int CHANNEL_MIN_2P4GHZ = 11;
|
||||
/**
|
||||
* The maximum 2.4GHz channel.
|
||||
*/
|
||||
public static final int CHANNEL_MAX_2P4GHZ = 26;
|
||||
/**
|
||||
* The 2.4 GHz channel page.
|
||||
*/
|
||||
public static final int CHANNEL_PAGE_2P4GHZ = 0;
|
||||
|
||||
/**
|
||||
* The length of Extended PAN ID that can be set by {@link ThreadNetworkCredentials.Builder#setExtendedPanId(byte[])}.
|
||||
*/
|
||||
public static final int LENGTH_EXTENDED_PANID = 8;
|
||||
/**
|
||||
* The maximum length of NetworkName that can be set by {@link ThreadNetworkCredentials.Builder#setNetworkName(String)}.
|
||||
*/
|
||||
public static final int LENGTH_MAX_NETWORK_NAME = 16;
|
||||
/**
|
||||
* The maximum length of Operational Dataset that can be set by {@link #fromActiveOperationalDataset(byte[])}.
|
||||
*/
|
||||
public static final int LENGTH_MAX_OPERATIONAL_DATASET = 256;
|
||||
/**
|
||||
* The maximum length of Security Policy Flags that can be set by {@link ThreadNetworkCredentials.SecurityPolicy#SecurityPolicy(int, byte[])}.
|
||||
*/
|
||||
public static final int LENGTH_MAX_SECURITY_POLICY_FLAGS = 2;
|
||||
/**
|
||||
* The length of Mesh-Local Prefix that can be set by {@link ThreadNetworkCredentials.Builder#setMeshLocalPrefix(byte[])}.
|
||||
*/
|
||||
public static final int LENGTH_MESH_LOCAL_PREFIX = 8;
|
||||
/**
|
||||
* The minimum length of Network Name that can be set by {@link ThreadNetworkCredentials.Builder#setNetworkName(String)}.
|
||||
*/
|
||||
public static final int LENGTH_MIN_NETWORK_NAME = 1;
|
||||
/**
|
||||
* The minimum length of Security Policy Flags that can be set by {@link ThreadNetworkCredentials.SecurityPolicy#SecurityPolicy(int, byte[])}.
|
||||
*/
|
||||
public static final int LENGTH_MIN_SECURITY_POLICY_FLAGS = 1;
|
||||
/**
|
||||
* The length of Network Key that can be set by {@link ThreadNetworkCredentials.Builder#setNetworkKey(byte[])}.
|
||||
*/
|
||||
public static final int LENGTH_NETWORK_KEY = 16;
|
||||
/**
|
||||
* The length of PSKc that can be set by {@link ThreadNetworkCredentials.Builder#setPskc(byte[])}.
|
||||
*/
|
||||
public static final int LENGTH_PSKC = 16;
|
||||
/**
|
||||
* The fisrt byte of Mesh-Local Prefix that can be set by {@link ThreadNetworkCredentials.Builder#setMeshLocalPrefix(byte[])}.
|
||||
*/
|
||||
public static final byte MESH_LOCAL_PREFIX_FIRST_BYTE = -3;
|
||||
|
||||
/**
|
||||
* The default channel mask which enables all 2.4GHz channels.
|
||||
*/
|
||||
public static final ThreadNetworkCredentials.ChannelMaskEntry DEFAULT_CHANNEL_MASK = new ChannelMaskEntry(0, new byte[]{0, 31, -1, -32});
|
||||
/**
|
||||
* The default Thread 1.2 Security Policy.
|
||||
*/
|
||||
public static final ThreadNetworkCredentials.SecurityPolicy DEFAULT_SECURITY_POLICY = new SecurityPolicy(672, new byte[]{-1, -8});
|
||||
|
||||
@Field(value = 1, getterName = "getActiveOperationalDataset")
|
||||
private final byte[] activeOperationalDataset;
|
||||
@Field(value = 2, getterName = "getCreatedAtMillis")
|
||||
private final long createdAtMillis;
|
||||
@Field(value = 3, getterName = "getUpdatedAtMillis")
|
||||
private final long updatedAtMillis;
|
||||
|
||||
@Constructor
|
||||
public ThreadNetworkCredentials(@Param(1) byte[] activeOperationalDataset, @Param(2) long createdAtMillis, @Param(3) long updatedAtMillis) {
|
||||
this.activeOperationalDataset = activeOperationalDataset;
|
||||
this.createdAtMillis = createdAtMillis;
|
||||
this.updatedAtMillis = updatedAtMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Thread active operational dataset as encoded Thread TLV list.
|
||||
*/
|
||||
public byte[] getActiveOperationalDataset() {
|
||||
return activeOperationalDataset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Unix epoch in Milliseconds the {@link 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
|
||||
* {@link ThreadNetworkClient#addCredentials(ThreadBorderAgent, ThreadNetworkCredentials)}. Zero will be returned
|
||||
* if this instance is not returned by ThreadNetworkClient methods (e.g. created with
|
||||
* {@link #fromActiveOperationalDataset(byte[])}).
|
||||
*/
|
||||
public long getCreatedAtMillis() {
|
||||
return createdAtMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Unix epoch in Milliseconds the {@link 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
|
||||
* {@link ThreadNetworkClient#addCredentials(ThreadBorderAgent, ThreadNetworkCredentials). Zero will be returned
|
||||
* if this instance is not returned by ThreadNetworkClient methods (e.g. created with
|
||||
* {@link #fromActiveOperationalDataset(byte[])}).
|
||||
*/
|
||||
public long getUpdatedAtMillis() {
|
||||
return updatedAtMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Channel Mask Entry of Thread Operational Dataset.
|
||||
*/
|
||||
public static class ChannelMaskEntry {
|
||||
private final int page;
|
||||
private final byte[] mask;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ChannelMaskEntry} object.
|
||||
*
|
||||
* @throws IllegalArgumentException if page exceeds range [0, 255].
|
||||
*/
|
||||
public ChannelMaskEntry(int page, byte[] mask) {
|
||||
if (page < 0 || page > 255) throw new IllegalArgumentException("page exceeds range [0, 255].");
|
||||
this.page = page;
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Channel Mask.
|
||||
*/
|
||||
public byte[] getMask() {
|
||||
return mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Channel Page.
|
||||
*/
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The class represents Thread Security Policy.
|
||||
*/
|
||||
public static class SecurityPolicy {
|
||||
private final int rotationTimeHours;
|
||||
private final byte[] flags;
|
||||
|
||||
/**
|
||||
* Creates a new {@link SecurityPolicy} object.
|
||||
*
|
||||
* @param rotationTimeHours the value for Thread key rotation in hours. Must be in range of 0x1-0xffff.
|
||||
* @param flags security policy flags with length of either 1 byte for Thread 1.1 or 2 bytes for Thread 1.2 or higher.
|
||||
* @throws IllegalArgumentException if {@code rotationTimeHours} is not in range of 0x1-0xffff or
|
||||
* length of flags is smaller than {@link ThreadNetworkCredentials#LENGTH_MIN_SECURITY_POLICY_FLAGS}.
|
||||
*/
|
||||
public SecurityPolicy(int rotationTimeHours, byte[] flags) {
|
||||
if (rotationTimeHours < 1 || rotationTimeHours > 0xffff) throw new IllegalArgumentException("rotationTimeHours is not in range of 0x1-0xffff");
|
||||
if (flags.length < LENGTH_MIN_SECURITY_POLICY_FLAGS) throw new IllegalArgumentException("length of flags is smaller than LENGTH_MIN_SECURITY_POLICY_FLAGS");
|
||||
this.rotationTimeHours = rotationTimeHours;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 1 byte flags for Thread 1.1 or 2 bytes flags for Thread 1.2.
|
||||
*/
|
||||
public byte[] getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Security Policy Rotation Time in hours.
|
||||
*/
|
||||
public int getRotationTimeHours() {
|
||||
return rotationTimeHours;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
CREATOR.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final SafeParcelableCreatorAndWriter<ThreadNetworkCredentials> CREATOR = findCreator(ThreadNetworkCredentials.class);
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Notice: Portions of this file are reproduced from work created and shared by Google and used
|
||||
* according to terms described in the Creative Commons 4.0 Attribution License.
|
||||
* See https://developers.google.com/readme/policies for details.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.threadnetwork;
|
||||
|
||||
import com.google.android.gms.common.api.CommonStatusCodes;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
|
||||
/**
|
||||
* Status codes for {@link ThreadNetworkClient} methods result {@link Task} failures.
|
||||
* <p>
|
||||
* The codes are supplementary to common status codes in {@link CommonStatusCodes}.
|
||||
*/
|
||||
public class ThreadNetworkStatusCodes extends CommonStatusCodes {
|
||||
/**
|
||||
* Operation is not permitted.
|
||||
*/
|
||||
public static final int PERMISSION_DENIED = 44000;
|
||||
/**
|
||||
* Local Wi-Fi or Ethernet network is not connected.
|
||||
*/
|
||||
public static final int LOCAL_NETWORK_NOT_CONNECTED = 44001;
|
||||
/**
|
||||
* Operation is not supported on current platform.
|
||||
*/
|
||||
public static final int PLATFORM_NOT_SUPPORTED = 44002;
|
||||
/**
|
||||
* Failed to add Thread network credentials because the storage quota is exceeded.
|
||||
*/
|
||||
public static final int MAX_STORAGE_SIZE_EXCEEDED = 44003;
|
||||
public static final int THREAD_NETWORK_NOT_FOUND = 44004;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue