Skip to content

Commit

Permalink
Fitness: Add FITNESS_CONFIG & FITNESS_SESSIONS dummy (#2600)
Browse files Browse the repository at this point in the history
Co-authored-by: Marvin W <[email protected]>
  • Loading branch information
DaVinci9196 and mar-v-in authored Dec 14, 2024
1 parent b9b7278 commit f0698a1
Show file tree
Hide file tree
Showing 54 changed files with 3,231 additions and 202 deletions.
1 change: 1 addition & 0 deletions play-services-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation project(':play-services-cronet-core')
implementation project(':play-services-droidguard-core')
implementation project(':play-services-fido-core')
implementation project(':play-services-fitness-core')
implementation project(':play-services-gmscompliance-core')
implementation project(':play-services-location-core')
implementation project(':play-services-location-core-base')
Expand Down
13 changes: 0 additions & 13 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -831,17 +831,6 @@
</intent-filter>
</service>

<!-- fitness -->

<service
android:name="com.google.android.gms.fitness.service.history.FitHistoryBroker"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.fitness.HistoryApi" />
</intent-filter>
</service>

<!-- backup -->

<activity
Expand Down Expand Up @@ -1068,13 +1057,11 @@
<action android:name="com.google.android.gms.fido.u2f.thirdparty.START" />
<action android:name="com.google.android.gms.fido.u2f.zeroparty.START" />
<action android:name="com.google.android.gms.fitness.BleApi" />
<action android:name="com.google.android.gms.fitness.ConfigApi" />
<action android:name="com.google.android.gms.fitness.GoalsApi" />
<action android:name="com.google.android.gms.fitness.GoogleFitnessService.START" />
<action android:name="com.google.android.gms.fitness.InternalApi" />
<action android:name="com.google.android.gms.fitness.RecordingApi" />
<action android:name="com.google.android.gms.fitness.SensorsApi" />
<action android:name="com.google.android.gms.fitness.SessionsApi" />
<action android:name="com.google.android.gms.fonts.service.START" />
<action android:name="com.google.android.gms.freighter.service.START" />
<action android:name="com.google.android.gms.growth.service.START" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.content.Context
import android.os.Bundle
import android.os.Parcel
import android.util.Log
import androidx.core.content.getSystemService
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.google.android.gms.common.ConnectionResult
Expand All @@ -20,6 +19,7 @@ import com.google.android.gms.common.api.Scope
import com.google.android.gms.common.internal.*
import com.google.android.gms.signin.internal.*
import org.microg.gms.BaseService
import org.microg.gms.auth.AuthConstants
import org.microg.gms.common.GmsService
import org.microg.gms.common.PackageUtils
import org.microg.gms.utils.warnOnTransactionIssues
Expand Down Expand Up @@ -60,10 +60,12 @@ class SignInServiceImpl(val context: Context, override val lifecycle: Lifecycle,

override fun signIn(request: SignInRequest?, callbacks: ISignInCallbacks?) {
Log.d(TAG, "signIn($request)")
val account = request?.request?.account
val result = if (account == null || context.getSystemService<AccountManager>()?.getAccountsByType(account.type)?.contains(account) != true)
ConnectionResult(ConnectionResult.SIGN_IN_REQUIRED) else ConnectionResult(ConnectionResult.SUCCESS)
runCatching {
val accountManager = AccountManager.get(context)
val account = request?.request?.account?.let { if (it.name == AuthConstants.DEFAULT_ACCOUNT) accountManager.getAccountsByType(it.type).firstOrNull() else it }
val result = if (account == null || !accountManager.getAccountsByType(account.type).contains(account))
ConnectionResult(ConnectionResult.SIGN_IN_REQUIRED) else ConnectionResult(ConnectionResult.SUCCESS)
Log.d(TAG, "signIn: account -> ${account?.name}")
callbacks?.onSignIn(SignInResponse().apply {
connectionResult = result
response = ResolveAccountResponse().apply {
Expand Down
4 changes: 3 additions & 1 deletion play-services-fitness/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ android {
}

dependencies {
// Dependencies from play-services-fitness:21.2.0
api 'androidx.collection:collection:1.0.0'
api project(':play-services-base')
api project(':play-services-base-core')
api project(':play-services-basement')
api project(':play-services-tasks')

annotationProcessor project(':safe-parcel-processor')
}
50 changes: 50 additions & 0 deletions play-services-fitness/core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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-fitness')

implementation project(':play-services-base-core')
}

android {
namespace "org.microg.gms.fitness.core"

compileSdkVersion androidCompileSdk
buildToolsVersion "$androidBuildVersionTools"

defaultConfig {
versionName version
minSdkVersion androidMinSdk
targetSdkVersion androidTargetSdk
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'MissingTranslation', 'GetLocales'
}

compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

kotlinOptions {
jvmTarget = 1.8
}
}

// Not publishable yet
// apply from: '../../gradle/publish-android.gradle'

description = 'microG service implementation for play-services-fitness'
37 changes: 37 additions & 0 deletions play-services-fitness/core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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"
xmlns:tools="http://schemas.android.com/tools">

<application>
<service
android:name="com.google.android.gms.fitness.service.config.FitConfigBroker"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.fitness.ConfigApi" />
</intent-filter>
</service>

<service
android:name="com.google.android.gms.fitness.service.history.FitHistoryBroker"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.fitness.HistoryApi" />
</intent-filter>
</service>

<service
android:name="com.google.android.gms.fitness.service.sessions.FitSessionsBroker"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.fitness.SessionsApi" />
</intent-filter>
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.fitness.service.config

import android.os.Parcel
import android.util.Log
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.common.api.Status
import com.google.android.gms.common.internal.GetServiceRequest
import com.google.android.gms.common.internal.IGmsCallbacks
import com.google.android.gms.fitness.internal.IGoogleFitConfigApi
import com.google.android.gms.fitness.request.DataTypeCreateRequest
import com.google.android.gms.fitness.request.DisableFitRequest
import com.google.android.gms.fitness.request.ReadDataTypeRequest
import org.microg.gms.BaseService
import org.microg.gms.common.GmsService
import org.microg.gms.utils.warnOnTransactionIssues

private const val TAG = "FitConfigBroker"

class FitConfigBroker : BaseService(TAG, GmsService.FITNESS_CONFIG) {
override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) {
callback.onPostInitComplete(CommonStatusCodes.SUCCESS, FitConfigBrokerImpl(), null)
}
}

class FitConfigBrokerImpl : IGoogleFitConfigApi.Stub() {

override fun createCustomDataType(request: DataTypeCreateRequest?) {
Log.d(TAG, "Not implemented createCustomDataType: $request")
}

override fun readDataType(request: ReadDataTypeRequest?) {
Log.d(TAG, "Not implemented readDataType: $request")
}

override fun disableFit(request: DisableFitRequest?) {
Log.d(TAG, "Method <disableFit> Called: $request")
try {
request?.callback?.onResult(Status.SUCCESS)
} catch (e: Exception) {
Log.w(TAG, "disableFit Error $e")
}
}

override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean =
warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.google.android.gms.fitness.service.history

import android.os.Bundle
import android.os.Parcel
import android.util.Log
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.common.internal.GetServiceRequest
Expand All @@ -27,6 +28,7 @@ import com.google.android.gms.fitness.request.ReadStatsRequest
import com.google.android.gms.fitness.request.SessionChangesRequest
import org.microg.gms.BaseService
import org.microg.gms.common.GmsService
import org.microg.gms.utils.warnOnTransactionIssues

private const val TAG = "FitHistoryBroker"

Expand Down Expand Up @@ -98,4 +100,6 @@ class FitHistoryBrokerImpl : IGoogleFitHistoryApi.Stub() {
Log.d(TAG, "Not implemented getSessionChanges: $request")
}

override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean =
warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.fitness.service.sessions;

import android.os.Parcel
import android.util.Log
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.common.internal.GetServiceRequest
import com.google.android.gms.common.internal.IGmsCallbacks
import com.google.android.gms.fitness.internal.IGoogleFitSessionsApi
import com.google.android.gms.fitness.request.SessionInsertRequest
import com.google.android.gms.fitness.request.SessionReadRequest
import com.google.android.gms.fitness.request.SessionRegistrationRequest
import com.google.android.gms.fitness.request.SessionStartRequest
import com.google.android.gms.fitness.request.SessionStopRequest
import com.google.android.gms.fitness.request.SessionUnregistrationRequest
import org.microg.gms.BaseService
import org.microg.gms.common.GmsService
import org.microg.gms.utils.warnOnTransactionIssues

private const val TAG = "FitSessionsBroker"

class FitSessionsBroker : BaseService(TAG, GmsService.FITNESS_SESSIONS) {
override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) {
callback.onPostInitComplete(CommonStatusCodes.SUCCESS, FitSessionsBrokerImpl(), null)
}
}

class FitSessionsBrokerImpl : IGoogleFitSessionsApi.Stub() {
override fun startRequest(startRequest: SessionStartRequest?) {
Log.d(TAG, "Not implemented startRequest: $startRequest")
}

override fun stopRequest(stopRequest: SessionStopRequest?) {
Log.d(TAG, "Not implemented stopRequest: $stopRequest")
}

override fun insertRequest(insetRequest: SessionInsertRequest?) {
Log.d(TAG, "Not implemented insertRequest: $insetRequest")
}

override fun readRequest(readRequest: SessionReadRequest?) {
Log.d(TAG, "Not implemented readRequest: $readRequest")
}

override fun registrationRequest(registrationRequest: SessionRegistrationRequest?) {
Log.d(TAG, "Not implemented registrationRequest: $registrationRequest")
}

override fun unRegistrationRequest(unRegistrationRequest: SessionUnregistrationRequest?) {
Log.d(TAG, "Not implemented unRegistrationRequest: $unRegistrationRequest")
}

override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean =
warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) }
}
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.fitness.internal;

import com.google.android.gms.fitness.result.DataTypeResult;

interface IDataTypeCallback {
void onDataType(in DataTypeResult dataTypeResult) = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.fitness.internal;

import com.google.android.gms.fitness.request.DataTypeCreateRequest;
import com.google.android.gms.fitness.request.DisableFitRequest;
import com.google.android.gms.fitness.request.ReadDataTypeRequest;

interface IGoogleFitConfigApi {
void createCustomDataType(in DataTypeCreateRequest request) = 0;
void readDataType(in ReadDataTypeRequest request) = 1;
void disableFit(in DisableFitRequest request) = 21;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
package com.google.android.gms.fitness.internal;

import com.google.android.gms.fitness.request.SessionStartRequest;
import com.google.android.gms.fitness.request.SessionStopRequest;
import com.google.android.gms.fitness.request.SessionInsertRequest;
import com.google.android.gms.fitness.request.SessionReadRequest;
import com.google.android.gms.fitness.request.SessionRegistrationRequest;
import com.google.android.gms.fitness.request.SessionUnregistrationRequest;

interface IGoogleFitSessionsApi {
void startRequest(in SessionStartRequest startRequest) = 0;
void stopRequest(in SessionStopRequest stopRequest) = 1;
void insertRequest(in SessionInsertRequest insetRequest) = 2;
void readRequest(in SessionReadRequest readRequest) = 3;
void registrationRequest(in SessionRegistrationRequest registrationRequest) = 4;
void unRegistrationRequest(in SessionUnregistrationRequest unRegistrationRequest) = 5;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
package com.google.android.gms.fitness.internal;

import com.google.android.gms.fitness.result.SessionReadResult;

interface ISessionReadCallback {
void onResult(in SessionReadResult sessionReadResult) = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
package com.google.android.gms.fitness.internal;

import com.google.android.gms.fitness.result.SessionStopResult;

interface ISessionStopCallback {
void onResult(in SessionStopResult sessionStopReult) = 0;
}
Loading

0 comments on commit f0698a1

Please sign in to comment.