Skip to content

Commit

Permalink
Base: Add ClientTelemetry API and dummy (#2376)
Browse files Browse the repository at this point in the history
Co-authored-by: Marvin W <git@larma.de>
  • Loading branch information
DaVinci9196 and mar-v-in authored Aug 10, 2024
1 parent 2a81612 commit ebdacd0
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 1 deletion.
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.common.internal;

parcelable MethodInvocation;
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.common.internal;

parcelable TelemetryData;
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.common.internal.service;

import com.google.android.gms.common.internal.TelemetryData;

interface IClientTelemetryService {
void log(in TelemetryData data) = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

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

import android.os.Parcel;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;
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;

import org.microg.gms.utils.ToStringHelper;

@SafeParcelable.Class
public class MethodInvocation extends AbstractSafeParcelable {

@Field(1)
final int methodKey;
@Field(2)
final int resultStatusCode;
@Field(3)
final int connectionResultStatusCode;
@Field(4)
final long startTimeMillis;
@Field(5)
final long endTimeMillis;
@Field(6)
@Nullable
final String callingModuleId;
@Field(7)
@Nullable
final String callingEntryPoint;
@Field(8)
final int serviceId;
@Field(value = 9, defaultValue = "-1")
final int latencyMillis;

@Constructor
public MethodInvocation(@Param(1) int methodKey, @Param(2) int resultStatusCode, @Param(3) int connectionResultStatusCode, @Param(4) long startTimeMillis, @Param(5) long endTimeMillis, @Param(6) @Nullable String callingModuleId, @Param(7) @Nullable String callingEntryPoint, @Param(8) int serviceId, @Param(9) int latencyMillis) {
this.methodKey = methodKey;
this.resultStatusCode = resultStatusCode;
this.connectionResultStatusCode = connectionResultStatusCode;
this.startTimeMillis = startTimeMillis;
this.endTimeMillis = endTimeMillis;
this.callingModuleId = callingModuleId;
this.callingEntryPoint = callingEntryPoint;
this.serviceId = serviceId;
this.latencyMillis = latencyMillis;
}

@NonNull
@Override
public String toString() {
return ToStringHelper.name("MethodInvocation")
.field("methodKey", methodKey)
.field("resultStatusCode", resultStatusCode)
.field("connectionResultStatusCode", connectionResultStatusCode)
.field("startTimeMillis", startTimeMillis)
.field("endTimeMillis", endTimeMillis)
.field("callingModuleId", callingModuleId)
.field("callingEntryPoint", callingEntryPoint)
.field("serviceId", serviceId)
.field("latencyMillis", latencyMillis)
.end();
}

public static SafeParcelableCreatorAndWriter<MethodInvocation> CREATOR = findCreator(MethodInvocation.class);

@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

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

import android.os.Parcel;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;
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;

import org.microg.gms.utils.ToStringHelper;

import java.util.List;

@SafeParcelable.Class
public class TelemetryData extends AbstractSafeParcelable {

@Field(1)
final int telemetryConfigVersion;
@Field(2)
@Nullable
List<MethodInvocation> methodInvocations;

@Constructor
public TelemetryData(@Param(1) int telemetryConfigVersion, @Param(2) @Nullable List<MethodInvocation> methodInvocations) {
this.telemetryConfigVersion = telemetryConfigVersion;
this.methodInvocations = methodInvocations;
}

@NonNull
@Override
public String toString() {
return ToStringHelper.name("TelemetryData")
.field("telemetryConfigVersion", telemetryConfigVersion)
.field("methodInvocations", methodInvocations)
.end();
}

@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}

public static SafeParcelableCreatorAndWriter<TelemetryData> CREATOR = findCreator(TelemetryData.class);

}
7 changes: 6 additions & 1 deletion play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,12 @@
</intent-filter>
</service>

<service android:name="org.microg.gms.common.ClientTelemetryService">
<intent-filter>
<action android:name="com.google.android.gms.common.telemetry.service.START" />
</intent-filter>
</service>

<service android:name="org.microg.gms.DummyService">
<intent-filter>
<action android:name="com.google.android.contextmanager.service.ContextManagerService.START" />
Expand Down Expand Up @@ -1006,7 +1012,6 @@
<action android:name="com.google.android.gms.chromesync.service.START" />
<action android:name="com.google.android.gms.common.download.START" />
<action android:name="com.google.android.gms.common.service.START" />
<action android:name="com.google.android.gms.common.telemetry.service.START" />
<action android:name="com.google.android.gms.config.START" />
<action android:name="com.google.android.gms.constellation.service.START" />
<action android:name="com.google.android.gms.deviceconnection.service.START" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package org.microg.gms.common

import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.google.android.gms.common.Feature
import com.google.android.gms.common.api.CommonStatusCodes
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.common.internal.TelemetryData
import com.google.android.gms.common.internal.service.IClientTelemetryService
import org.microg.gms.BaseService

private const val TAG = "ClientTelemetryService"

class ClientTelemetryService : BaseService(TAG, GmsService.TELEMETRY) {
override fun handleServiceRequest(callback: IGmsCallbacks?, request: GetServiceRequest?, service: GmsService?) {
Log.d(TAG, "handleServiceRequest start by $request")
callback?.onPostInitCompleteWithConnectionInfo(
CommonStatusCodes.SUCCESS,
ClientTelemetryServiceImpl(lifecycle),
ConnectionInfo().apply {
features = arrayOf(Feature("CLIENT_TELEMETRY", 1))
}
)
}
}

class ClientTelemetryServiceImpl(override val lifecycle: Lifecycle) :
IClientTelemetryService.Stub(), LifecycleOwner {

override fun log(data: TelemetryData?) {
Log.d(TAG, "log: $data")
}

}

0 comments on commit ebdacd0

Please sign in to comment.