package com.google.firebase.messaging;

import android.text.TextUtils;
import android.util.Log;
import java.util.concurrent.TimeUnit;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public final class x {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final long f5947d = TimeUnit.DAYS.toMillis(7);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f5948a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f5949b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final long f5950c;

    public x(String str, String str2, long j5) {
        this.f5948a = str;
        this.f5949b = str2;
        this.f5950c = j5;
    }

    public static String a(String str, String str2, long j5) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("token", str);
            jSONObject.put("appVersion", str2);
            jSONObject.put("timestamp", j5);
            return jSONObject.toString();
        } catch (JSONException e2) {
            Log.w("FirebaseMessaging", "Failed to encode token: " + e2);
            return null;
        }
    }

    public static x b(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (!str.startsWith("{")) {
            return new x(str, null, 0L);
        }
        try {
            JSONObject jSONObject = new JSONObject(str);
            return new x(jSONObject.getString("token"), jSONObject.getString("appVersion"), jSONObject.getLong("timestamp"));
        } catch (JSONException e2) {
            Log.w("FirebaseMessaging", "Failed to parse token: " + e2);
            return null;
        }
    }
}
