Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cfd0f8b authored by DaVinci9196's avatar DaVinci9196 Committed by Jonathan Klee
Browse files

Add boot count service (#3374)



Co-authored-by: default avatarMarvin W <git@larma.de>
parent ec3706f2
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
package com.google.android.gms.clearcut.internal;

import com.google.android.gms.common.api.Status;

interface IBootCountCallbacks {
    void onBootCount(in Status status, int bootCount) = 0;
}
+7 −0
Original line number Diff line number Diff line
package com.google.android.gms.clearcut.internal;

import com.google.android.gms.clearcut.internal.IBootCountCallbacks;

interface IBootCountService {
    void getBootCount(IBootCountCallbacks callbacks) = 0;
}
+6 −0
Original line number Diff line number Diff line
@@ -1187,6 +1187,12 @@
            android:name="com.google.android.gms.maps.auth.ApiTokenService"
            android:exported="true"/>

        <service android:name="org.microg.gms.clearcut.BootCountService" >
            <intent-filter>
                <action android:name="com.google.android.gms.clearcut.bootcount.service.START" />
            </intent-filter>
        </service>

        <service android:name="org.microg.gms.DummyService">
            <intent-filter>
                <action android:name="com.google.android.contextmanager.service.ContextManagerService.START" />
+39 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2024 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */
package org.microg.gms.clearcut

import android.content.Context
import android.os.Parcel
import android.provider.Settings
import android.util.Log
import com.google.android.gms.clearcut.internal.IBootCountCallbacks
import com.google.android.gms.clearcut.internal.IBootCountService
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 org.microg.gms.BaseService
import org.microg.gms.common.GmsService
import org.microg.gms.utils.warnOnTransactionIssues

private const val TAG = "BootCountService"

class BootCountService : BaseService(TAG, GmsService.BOOT_COUNT) {
    override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) {
        Log.d(TAG, "handleServiceRequest")
        callback.onPostInitComplete(CommonStatusCodes.SUCCESS, BootCountServiceImpl(this), null)
    }
}

class BootCountServiceImpl(private val context: Context) : IBootCountService.Stub() {
    override fun getBootCount(callbacks: IBootCountCallbacks?) {
        Log.d(TAG, "getBootCount called")
        val bootCount = Settings.Global.getInt(context.contentResolver, Settings.Global.BOOT_COUNT, 1)
        callbacks?.onBootCount(Status.SUCCESS, bootCount)
    }

    override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean =
        warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) }
}