VancedMicroG/play-services-api/src/main/java/com/google/android/gms/clearcut/LogEventParcelable.java

117 lines
3.9 KiB
Java
Raw Normal View History

2015-10-15 01:18:33 +00:00
/*
2017-06-12 22:11:15 +00:00
* Copyright (C) 2013-2017 microG Project Team
2015-10-15 01:18:33 +00:00
*
* 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 com.google.android.gms.clearcut;
2016-09-16 21:05:05 +00:00
import android.util.Base64;
2021-09-11 07:36:50 +00:00
import com.google.android.gms.phenotype.ExperimentToken;
import com.google.android.gms.phenotype.GenericDimension;
2016-09-16 21:05:05 +00:00
import com.google.android.gms.playlog.internal.PlayLoggerContext;
2015-10-15 01:18:33 +00:00
import org.microg.safeparcel.AutoSafeParcelable;
2016-09-16 21:05:05 +00:00
import org.microg.safeparcel.SafeParceled;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder;
2020-08-31 23:20:37 +00:00
import java.nio.charset.StandardCharsets;
2016-09-16 21:05:05 +00:00
import java.util.Arrays;
2015-10-15 01:18:33 +00:00
public class LogEventParcelable extends AutoSafeParcelable {
2021-09-11 07:36:50 +00:00
@Field(1)
2016-09-16 21:05:05 +00:00
private int versionCode = 1;
2021-09-11 07:36:50 +00:00
@Field(2)
2016-09-16 21:05:05 +00:00
public final PlayLoggerContext context;
2021-09-11 07:36:50 +00:00
@Field(3)
2016-09-16 21:05:05 +00:00
public final byte[] bytes;
2021-09-11 07:36:50 +00:00
@Field(4)
2016-09-16 21:05:05 +00:00
public final int[] testCodes;
2021-09-11 07:36:50 +00:00
@Field(5)
2016-09-16 21:05:05 +00:00
public final String[] mendelPackages;
2021-09-11 07:36:50 +00:00
@Field(6)
2016-09-16 21:05:05 +00:00
public final int[] experimentIds;
2021-09-11 07:36:50 +00:00
@Field(7)
2016-09-16 21:05:05 +00:00
public final byte[][] experimentTokens;
2021-09-11 07:36:50 +00:00
@Field(8)
2016-09-16 21:05:05 +00:00
public final boolean addPhenotypeExperimentTokens;
2021-09-11 07:36:50 +00:00
@Field(9)
public final ExperimentToken[] experimentTokenParcelables;
@Field(10)
public final GenericDimension[] genericDimensions;
2016-09-16 21:05:05 +00:00
private LogEventParcelable() {
context = null;
bytes = null;
testCodes = experimentIds = null;
mendelPackages = null;
experimentTokens = null;
addPhenotypeExperimentTokens = false;
2021-09-11 07:36:50 +00:00
experimentTokenParcelables = null;
genericDimensions = null;
2016-09-16 21:05:05 +00:00
}
public LogEventParcelable(PlayLoggerContext context, byte[] bytes, int[] testCodes, String[] mendelPackages, int[] experimentIds, byte[][] experimentTokens, boolean addPhenotypeExperimentTokens) {
this.context = context;
this.bytes = bytes;
this.testCodes = testCodes;
this.mendelPackages = mendelPackages;
this.experimentIds = experimentIds;
this.experimentTokens = experimentTokens;
this.addPhenotypeExperimentTokens = addPhenotypeExperimentTokens;
2021-09-11 07:36:50 +00:00
experimentTokenParcelables = null;
genericDimensions = null;
2016-09-16 21:05:05 +00:00
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("LogEventParcelable[")
.append(versionCode).append(", ").append(context)
.append(", LogEventBytes: ").append(getBytesAsString());
if (testCodes != null) sb.append(", TestCodes: ").append(Arrays.toString(testCodes));
if (mendelPackages != null)
sb.append(", MendelPackages: ").append(Arrays.toString(mendelPackages));
if (experimentIds != null)
sb.append(", ExperimentIds: ").append(Arrays.toString(experimentIds));
if (experimentTokens != null)
sb.append(", ExperimentTokens: ").append(Arrays.toString(experimentTokens));
return sb.append(", AddPhenotypeExperimentTokens: ").append(addPhenotypeExperimentTokens)
.append(']').toString();
}
private String getBytesAsString() {
if (bytes == null) return "null";
try {
2020-08-31 23:20:37 +00:00
CharsetDecoder d = StandardCharsets.US_ASCII.newDecoder();
2016-09-16 21:05:05 +00:00
CharBuffer r = d.decode(ByteBuffer.wrap(bytes));
return r.toString();
} catch (Exception e) {
return Base64.encodeToString(bytes, Base64.NO_WRAP);
}
}
2015-10-15 01:18:33 +00:00
2020-08-31 23:27:05 +00:00
public static final Creator<LogEventParcelable> CREATOR = new AutoCreator<>(LogEventParcelable.class);
2015-10-15 01:18:33 +00:00
}