1 /* 2 * Copyright (C) 2022 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.adservices.service.stats; 18 19 import static android.adservices.common.AdServicesStatusUtils.STATUS_INTERNAL_ERROR; 20 import static android.adservices.common.AdServicesStatusUtils.STATUS_INVALID_ARGUMENT; 21 import static android.adservices.common.AdServicesStatusUtils.STATUS_JS_SANDBOX_UNAVAILABLE; 22 import static android.adservices.common.AdServicesStatusUtils.STATUS_TIMEOUT; 23 24 import com.android.adservices.service.exception.FilterException; 25 import com.android.adservices.service.js.JSSandboxIsNotAvailableException; 26 27 import com.google.common.util.concurrent.UncheckedTimeoutException; 28 29 /** Util class for AdServicesLogger */ 30 public class AdServicesLoggerUtil { 31 /** enum type value for any field in a telemetry atom that should be unset. */ 32 public static final int FIELD_UNSET = -1; 33 34 /** @return the resultCode corresponding to the type of exception to be used in logging. */ getResultCodeFromException(Throwable t)35 public static int getResultCodeFromException(Throwable t) { 36 if (t instanceof FilterException) { 37 return FilterException.getResultCode(t); 38 } else if (t instanceof UncheckedTimeoutException) { 39 return STATUS_TIMEOUT; 40 } else if (t instanceof JSSandboxIsNotAvailableException) { 41 return STATUS_JS_SANDBOX_UNAVAILABLE; 42 } else if (t instanceof IllegalArgumentException) { 43 return STATUS_INVALID_ARGUMENT; 44 } else { 45 return STATUS_INTERNAL_ERROR; 46 } 47 } 48 } 49