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.libraries.entitlement.utils; 18 19 import android.os.Build; 20 import android.os.SystemProperties; 21 import android.text.TextUtils; 22 import android.util.Log; 23 24 import androidx.annotation.NonNull; 25 26 /** Provides API for debugging and not allow to debug on user build. */ 27 public final class DebugUtils { 28 private static final String TAG = "ServiceEntitlement"; 29 30 private static final String PROP_PII_LOGGABLE = "dbg.se.pii_loggable"; 31 private static final String BUILD_TYPE_USER = "user"; 32 private static final String PROP_FAKE_EAP_AKA_RESPONSE = 33 "persist.entitlement.fake_eap_aka_response"; 34 DebugUtils()35 private DebugUtils() {} 36 37 /** Logs PII data if allowed. */ logPii(String message)38 public static void logPii(String message) { 39 if (isPiiLoggable()) { 40 Log.d(TAG, message); 41 } 42 } 43 44 /** 45 * Get the bypass EAP-AKA response. This is only available on debug builds and can be set by 46 * running the following commands, where {@code response} should be the expected response from 47 * an EAP-AKA request: 48 * adb root 49 * adb shell setprop persist.entitlement.fake_eap_aka_response response 50 * 51 * @return The bypass EAP-AKA response, or an empty string if it is either not set or the device 52 * is not on a debug build. 53 */ 54 @NonNull getBypassEapAkaResponse()55 public static String getBypassEapAkaResponse() { 56 String bypassResponse = SystemProperties.get(PROP_FAKE_EAP_AKA_RESPONSE); 57 if (TextUtils.isEmpty(bypassResponse) || !isDebugBuild()) { 58 return ""; 59 } 60 return bypassResponse; 61 } 62 isDebugBuild()63 private static boolean isDebugBuild() { 64 return !BUILD_TYPE_USER.equals(Build.TYPE); 65 } 66 isPiiLoggable()67 private static boolean isPiiLoggable() { 68 if (!isDebugBuild()) { 69 return false; 70 } 71 72 return SystemProperties.getBoolean(PROP_PII_LOGGABLE, false); 73 } 74 } 75