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

Commit a1a27167 authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Add heartbeat feature for MCS

parent f8be4c53
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
gen/
bin/
build/
.gradle/
user.gradle
local.properties
.directory
+0 −47
Original line number Diff line number Diff line
/*
 * Copyright 2013-2015 µg Project Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.microg.gms.gcm;

import android.content.Context;
import android.util.Log;

import org.microg.gms.checkin.LastCheckinInfo;
import org.microg.gms.common.PackageUtils;
import org.microg.gms.common.Utils;

import java.io.IOException;

public class GcmManager {
    private static final String TAG = "GmsGcmManager";

    public static String register(Context context, String app, String sender, String info) {
        try {
            return new RegisterRequest()
                    .build(Utils.getBuild(context))
                    .sender(sender)
                    .info(info)
                    .checkin(LastCheckinInfo.read(context))
                    .app(app, PackageUtils.firstSignatureDigest(context, app), PackageUtils.versionCode(context, app))
                    .getResponse()
                    .token;
        } catch (IOException e) {
            Log.w(TAG, e);
        }

        return null;
    }
}
+25 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package org.microg.gms.gcm;

import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
@@ -25,6 +26,12 @@ import android.os.Message;
import android.os.Messenger;
import android.util.Log;

import org.microg.gms.checkin.LastCheckinInfo;
import org.microg.gms.common.PackageUtils;
import org.microg.gms.common.Utils;

import java.io.IOException;

public class PushRegisterService extends IntentService {
    private static final String TAG = "GmsGcmRegisterSvc";

@@ -66,7 +73,7 @@ public class PushRegisterService extends IntentService {
        Log.d(TAG, "register[req]: " + extras);
        Intent outIntent = new Intent("com.google.android.c2dm.intent.REGISTRATION");
        outIntent.setPackage(app);
        String regId = GcmManager.register(this, app, sender, null);
        String regId = register(this, app, sender, null);
        if (regId != null) {
            outIntent.putExtra("registration_id", regId);
        } else {
@@ -87,6 +94,23 @@ public class PushRegisterService extends IntentService {
        sendOrderedBroadcast(outIntent, null);
    }

    public static String register(Context context, String app, String sender, String info) {
        try {
            return new RegisterRequest()
                    .build(Utils.getBuild(context))
                    .sender(sender)
                    .info(info)
                    .checkin(LastCheckinInfo.read(context))
                    .app(app, PackageUtils.firstSignatureDigest(context, app), PackageUtils.versionCode(context, app))
                    .getResponse()
                    .token;
        } catch (IOException e) {
            Log.w(TAG, e);
        }

        return null;
    }

    private void unregister(Intent intent) {

    }
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package org.microg.gms.gcm.mcs;

public class Constants {
    public static final int MCS_HEARTBEAT_PING_TAG = 0;
    public static final int MCS_HEARTBEAT_ACK_TAG = 1;
    public static final int MCS_LOGIN_REQUEST_TAG = 2;
    public static final int MCS_LOGIN_RESPONSE_TAG = 3;
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import java.io.InputStream;
import static org.microg.gms.gcm.mcs.Constants.MCS_CLOSE_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_DATA_MESSAGE_STANZA_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_HEARTBEAT_ACK_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_HEARTBEAT_PING_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_IQ_STANZA_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_LOGIN_REQUEST_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_LOGIN_RESPONSE_TAG;
@@ -94,6 +95,8 @@ public class McsInputStream {
    private static Message read(int mcsTag, byte[] bytes, int len) throws IOException {
        Wire wire = new Wire();
        switch (mcsTag) {
            case MCS_HEARTBEAT_PING_TAG:
                return wire.parseFrom(bytes, 0, len, HeartbeatPing.class);
            case MCS_HEARTBEAT_ACK_TAG:
                return wire.parseFrom(bytes, 0, len, HeartbeatAck.class);
            case MCS_LOGIN_REQUEST_TAG:
Loading