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

Commit 68c4e0d0 authored by Romain Hunault's avatar Romain Hunault 💻
Browse files

Merge branch '41-import-pull-request-1069-from-microg-github-fcm-registration' into 'master'

Resolve "Import pull request #1069 from microG (GitHub), FCM registration"

Closes #41

See merge request e/apps/GmsCore!19
parents f5419d98 36d9082e
Loading
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -46,6 +46,13 @@ public class HttpFormClient {
            try {
                field.setAccessible(true);
                Object objVal = field.get(request);
                if (field.isAnnotationPresent(RequestContentDynamic.class)) {
                    Map<String, String> contentParams = (Map<String, String>) objVal;
                    for (Map.Entry<String, String> param : contentParams.entrySet()) {
                        appendParam(content, param.getKey(), param.getValue());
                    }
                    continue;
                }
                String value = objVal != null ? String.valueOf(objVal) : null;
                Boolean boolVal = null;
                if (field.getType().equals(boolean.class)) {
@@ -65,9 +72,7 @@ public class HttpFormClient {
                    value = valueFromBoolVal(value, boolVal, annotation.truePresent(), annotation.falsePresent());
                    if (value != null || annotation.nullPresent()) {
                        for (String key : annotation.value()) {
                            if (content.length() > 0)
                                content.append("&");
                            content.append(Uri.encode(key)).append("=").append(Uri.encode(String.valueOf(value)));
                            appendParam(content, key, value);
                        }
                    }
                }
@@ -109,6 +114,12 @@ public class HttpFormClient {
        }
    }

    private static void appendParam(StringBuilder content, String key, String value) {
        if (content.length() > 0)
            content.append("&");
        content.append(Uri.encode(key)).append("=").append(Uri.encode(String.valueOf(value)));
    }

    private static <T> T parseResponse(Class<T> tClass, HttpURLConnection connection, String result) throws IOException {
        Map<String, List<String>> headerFields = connection.getHeaderFields();
        T response;
@@ -233,6 +244,11 @@ public class HttpFormClient {
        public String value();
    }

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.FIELD)
    public @interface RequestContentDynamic {
    }

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.FIELD)
    public @interface ResponseHeader {
+8 −0
Original line number Diff line number Diff line
@@ -258,4 +258,12 @@ public class PackageUtils {
            return null;
        }
    }

    public static int targetSdkVersion(Context context, String packageName) {
        try {
            return context.getPackageManager().getApplicationInfo(packageName, 0).targetSdkVersion;
        } catch (PackageManager.NameNotFoundException e) {
            return -1;
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ class PushRegisterHandler extends Handler {
                        .checkin(LastCheckinInfo.read(context))
                        .app(packageName)
                        .delete(delete)
                        .appid(subdata.getString("appid"), subdata.getString("gmp_app_id")),
                        .extraParams(subdata),
                bundle -> sendReply(what, id, replyTo, bundle));
    }
}
+8 −4
Original line number Diff line number Diff line
@@ -70,12 +70,16 @@ public class PushRegisterManager {

    public static void completeRegisterRequest(Context context, GcmDatabase database, String requestId, RegisterRequest request, BundleCallback callback) {
        if (request.app != null) {
            if (request.appSignature == null)
                request.appSignature = PackageUtils.firstSignatureDigest(context, request.app);
            if (request.appVersion <= 0)
                request.appVersion = PackageUtils.versionCode(context, request.app);
            if (request.appVersionName == null)
                request.appVersionName = PackageUtils.versionName(context, request.app);
            if (!request.delete) {
                if (request.appSignature == null) {
                    request.appSignature = PackageUtils.firstSignatureDigest(context, request.app);
                }
                request.sdkVersion = PackageUtils.targetSdkVersion(context, request.app);
                if (!request.hasExtraParam(GcmConstants.EXTRA_APP_VERSION_NAME))
                    request.extraParam(GcmConstants.EXTRA_APP_VERSION_NAME, PackageUtils.versionName(context, request.app));
            }
        }

        GcmDatabase.App app = database.getApp(request.app);
+4 −3
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.Message;
@@ -139,7 +138,8 @@ public class PushRegisterService extends IntentService {
                        .build(Utils.getBuild(context))
                        .sender(intent.getStringExtra(EXTRA_SENDER))
                        .checkin(LastCheckinInfo.read(context))
                        .app(packageName),
                        .app(packageName)
                        .extraParams(intent.getExtras()),
                bundle -> {
                    Intent outIntent = new Intent(ACTION_C2DM_REGISTRATION);
                    outIntent.putExtras(bundle);
@@ -175,7 +175,8 @@ public class PushRegisterService extends IntentService {
                        .build(Utils.getBuild(this))
                        .sender(intent.getStringExtra(EXTRA_SENDER))
                        .checkin(LastCheckinInfo.read(this))
                        .app(packageName),
                        .app(packageName)
                        .extraParams(intent.getExtras()),
                bundle -> {
                    Intent outIntent = new Intent(ACTION_C2DM_REGISTRATION);
                    outIntent.putExtras(bundle);
Loading