Skip to content

Commit

Permalink
threadnetwork: Add stub implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-v-in committed Nov 3, 2024
1 parent 36fedfa commit a780fa3
Show file tree
Hide file tree
Showing 20 changed files with 682 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public enum GmsService {
POTOKENS(285, "com.google.android.gms.potokens.service.START"),
OCR_INTERNAL(281, "com.google.android.gms.ocr.service.internal.START"),
APP_SET(300, "com.google.android.gms.appset.service.START"),
THREAD_NETWORK(305, "com.google.android.gms.threadnetwork.service.START"),
MODULE_INSTALL(308, "com.google.android.gms.chimera.container.moduleinstall.ModuleInstallService.START"),
IN_APP_REACH(315, "com.google.android.gms.inappreach.service.START"),
APP_ERRORS(334, "com.google.android.gms.apperrors.service.START_APP_ERROR"),
Expand Down
1 change: 1 addition & 0 deletions play-services-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
implementation project(':play-services-recaptcha-core')
implementation project(':play-services-safetynet-core')
implementation project(':play-services-tapandpay-core')
implementation project(':play-services-threadnetwork-core')
implementation project(':play-services-vision-core')
implementation project(':play-services-wearable-core')

Expand Down
44 changes: 44 additions & 0 deletions play-services-threadnetwork/build.gradle
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions play-services-threadnetwork/core/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 16 additions & 0 deletions play-services-threadnetwork/core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions play-services-threadnetwork/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: 2024 microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.threadnetwork;

parcelable ThreadBorderAgent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.threadnetwork;

parcelable ThreadNetworkCredentials;
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit a780fa3

Please sign in to comment.