1 /* 2 * Copyright (C) 2021 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.imsserviceentitlement.debug; 18 19 import android.os.Build; 20 import android.os.SystemProperties; 21 import android.text.TextUtils; 22 23 import java.util.Optional; 24 25 /** Provides API for debugging and not allow to debug on user build. */ 26 public final class DebugUtils { 27 private static final String PROP_PII_LOGGABLE = "dbg.imsse.pii_loggable"; 28 private static final String PROP_SERVER_URL_OVERRIDE = "persist.dbg.imsse.server_url"; 29 private static final String BUILD_TYPE_USER = "user"; 30 DebugUtils()31 private DebugUtils() {} 32 33 /** 34 * Tells if current build is user-debug or eng build which is debuggable. 35 * 36 * @see {@link android.os.Build.TYPE} 37 */ isDebugBuild()38 public static boolean isDebugBuild() { 39 return !BUILD_TYPE_USER.equals(Build.TYPE); 40 } 41 42 /** Returns {@code true} if allow to print PII data for debugging. */ isPiiLoggable()43 public static boolean isPiiLoggable() { 44 if (!isDebugBuild()) { 45 return false; 46 } 47 48 return SystemProperties.getBoolean(PROP_PII_LOGGABLE, false); 49 } 50 51 /** 52 * Returns {@link Optional} if testing server url was set in system property. 53 */ getOverrideServerUrl()54 public static Optional<String> getOverrideServerUrl() { 55 if (!isDebugBuild()) { 56 return Optional.empty(); 57 } 58 59 String urlOverride = SystemProperties.get(PROP_SERVER_URL_OVERRIDE, ""); 60 if (TextUtils.isEmpty(urlOverride)) { 61 return Optional.empty(); 62 } 63 64 return Optional.of(urlOverride); 65 } 66 } 67