1 /* 2 * Copyright (C) 2020 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.providers.contacts.util; 18 19 import android.net.Uri; 20 21 public final class LogFields { 22 23 private final int apiType; 24 25 private final int uriType; 26 27 // The type is from LogUtils.TaskType 28 private final int taskType; 29 30 private final boolean callerIsSyncAdapter; 31 32 private final long startNanos; 33 34 private Exception exception; 35 36 private Uri resultUri; 37 38 private int resultCount; 39 40 private int mMethodCalled; 41 42 private int uid; 43 LogFields( int apiType, int uriType, int taskType, boolean callerIsSyncAdapter, long startNanos)44 public LogFields( 45 int apiType, int uriType, int taskType, boolean callerIsSyncAdapter, long startNanos) { 46 this.apiType = apiType; 47 this.uriType = uriType; 48 this.taskType = taskType; 49 this.callerIsSyncAdapter = callerIsSyncAdapter; 50 this.startNanos = startNanos; 51 } 52 getApiType()53 public int getApiType() { 54 return apiType; 55 } 56 getUriType()57 public int getUriType() { 58 return uriType; 59 } 60 getTaskType()61 public int getTaskType() { 62 return taskType; 63 } 64 isCallerIsSyncAdapter()65 public boolean isCallerIsSyncAdapter() { 66 return callerIsSyncAdapter; 67 } 68 getStartNanos()69 public long getStartNanos() { 70 return startNanos; 71 } 72 getException()73 public Exception getException() { 74 return exception; 75 } 76 getResultUri()77 public Uri getResultUri() { 78 return resultUri; 79 } 80 getResultCount()81 public int getResultCount() { 82 return resultCount; 83 } 84 getMethodCalled()85 public int getMethodCalled() { 86 return mMethodCalled; 87 } 88 getUid()89 public int getUid() { 90 return uid; 91 } 92 93 public static final class Builder { 94 private int apiType; 95 private int uriType; 96 private int taskType; 97 private boolean callerIsSyncAdapter; 98 private long startNanos; 99 private Exception exception; 100 private Uri resultUri; 101 private int resultCount; 102 private int mMethodCalled; 103 104 private int uid; 105 Builder()106 private Builder() { 107 } 108 aLogFields()109 public static Builder aLogFields() { 110 return new Builder(); 111 } 112 setApiType(int apiType)113 public Builder setApiType(int apiType) { 114 this.apiType = apiType; 115 return this; 116 } 117 setUriType(int uriType)118 public Builder setUriType(int uriType) { 119 this.uriType = uriType; 120 return this; 121 } 122 setTaskType(int taskType)123 public Builder setTaskType(int taskType) { 124 this.taskType = taskType; 125 return this; 126 } 127 setCallerIsSyncAdapter(boolean callerIsSyncAdapter)128 public Builder setCallerIsSyncAdapter(boolean callerIsSyncAdapter) { 129 this.callerIsSyncAdapter = callerIsSyncAdapter; 130 return this; 131 } 132 setStartNanos(long startNanos)133 public Builder setStartNanos(long startNanos) { 134 this.startNanos = startNanos; 135 return this; 136 } 137 setException(Exception exception)138 public Builder setException(Exception exception) { 139 this.exception = exception; 140 return this; 141 } 142 setResultUri(Uri resultUri)143 public Builder setResultUri(Uri resultUri) { 144 this.resultUri = resultUri; 145 return this; 146 } 147 setResultCount(int resultCount)148 public Builder setResultCount(int resultCount) { 149 this.resultCount = resultCount; 150 return this; 151 } 152 153 /** 154 * Sets the method called. 155 * 156 * @param methodCalled The method called. 157 * @return This {@code Builder} object for chaining. 158 */ setMethodCalled(int methodCalled)159 public Builder setMethodCalled(int methodCalled) { 160 this.mMethodCalled = methodCalled; 161 return this; 162 } 163 setUid(int uid)164 public Builder setUid(int uid) { 165 this.uid = uid; 166 return this; 167 } 168 build()169 public LogFields build() { 170 LogFields logFields = 171 new LogFields(apiType, uriType, taskType, callerIsSyncAdapter, startNanos); 172 logFields.resultCount = this.resultCount; 173 logFields.exception = this.exception; 174 logFields.resultUri = this.resultUri; 175 logFields.uid = this.uid; 176 logFields.mMethodCalled = this.mMethodCalled; 177 return logFields; 178 } 179 } 180 } 181