1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.telephony.statslib; 18 19 import android.util.StatsEvent; 20 21 import java.io.Serializable; 22 import java.util.Objects; 23 24 /** AtomsSerializablePulledTestInfo class */ 25 public class AtomsSerializablePulledTestInfo extends AtomsPulled implements Serializable { 26 27 private static final long serialVersionUID = 804402117L; // 0x2FF233C5 28 29 /** atom #1 : test atom #1 type */ 30 private int mType; 31 32 /** atom #2 : test atom #2 count */ 33 private int mCount; 34 35 /** transient variable which will not be persisted */ 36 private transient int mTransient; 37 38 /** Constructor of AtomsTestInfo */ AtomsSerializablePulledTestInfo()39 public AtomsSerializablePulledTestInfo() {} 40 41 /** Constructor of AtomsSerializablePulledTestInfo */ AtomsSerializablePulledTestInfo(int type, int count)42 public AtomsSerializablePulledTestInfo(int type, int count) { 43 mType = type; 44 mCount = count; 45 } 46 47 /** 48 * Copy Constructor of AtomsSerializablePulledTestInfo 49 * 50 * @param info The info param to copy from. 51 */ AtomsSerializablePulledTestInfo(AtomsSerializablePulledTestInfo info)52 public AtomsSerializablePulledTestInfo(AtomsSerializablePulledTestInfo info) { 53 mType = info.mType; 54 mCount = info.mCount; 55 } 56 57 /** 58 * Write the atom information to be recorded to the builder according to the type in order. 59 * 60 * @param builder Builder class for StatsEvent Builder object. 61 */ 62 @Override build(StatsEvent.Builder builder)63 public void build(StatsEvent.Builder builder) { 64 builder.writeInt(mType); // atom #1 65 builder.writeInt(mCount); // atom #2 66 } 67 68 /** Return atom id defined in proto. */ 69 @Override getStatsId()70 public int getStatsId() { 71 return 702; 72 } 73 74 /** Return copy of the AtomsTestInfo */ 75 @Override copy()76 public AtomsPulled copy() { 77 return new AtomsSerializablePulledTestInfo(this); 78 } 79 80 @Override getDimension()81 public String getDimension() { 82 return Integer.toString(mType); 83 } 84 accumulate(AtomsPulled info)85 public void accumulate(AtomsPulled info) { 86 if (!(info instanceof AtomsSerializablePulledTestInfo)) { 87 return; 88 } 89 AtomsSerializablePulledTestInfo atomsSerializablePulledTestInfo = 90 (AtomsSerializablePulledTestInfo) info; 91 this.mCount += atomsSerializablePulledTestInfo.getCount(); 92 this.mTransient += atomsSerializablePulledTestInfo.getTransient(); 93 } 94 getType()95 public int getType() { 96 return mType; 97 } 98 setType(int type)99 public void setType(int type) { 100 mType = type; 101 } 102 getCount()103 public int getCount() { 104 return mCount; 105 } 106 setCount(int count)107 public void setCount(int count) { 108 mCount = count; 109 } 110 setTransient(int aTransient)111 public void setTransient(int aTransient) { 112 mTransient = aTransient; 113 } 114 getTransient()115 public int getTransient() { 116 return mTransient; 117 } 118 119 @Override toString()120 public String toString() { 121 return "AtomsSerializablePulledTestInfo{" 122 + "mType=" 123 + mType 124 + ", mCount=" 125 + mCount 126 + ", mTransient=" 127 + mTransient 128 + '}'; 129 } 130 131 @Override equals(Object o)132 public boolean equals(Object o) { 133 if (this == o) return true; 134 if (!(o instanceof AtomsSerializablePulledTestInfo)) return false; 135 AtomsSerializablePulledTestInfo that = (AtomsSerializablePulledTestInfo) o; 136 return mType == that.mType && mCount == that.mCount && mTransient == that.mTransient; 137 } 138 139 @Override hashCode()140 public int hashCode() { 141 return Objects.hash(mType, mCount, mTransient); 142 } 143 } 144