| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.telephony; |
| 18 |
|
| 19 |
import android.compat.annotation.UnsupportedAppUsage; |
| 20 |
import android.os.Build; |
| 21 |
import android.text.TextUtils; |
| 22 |
import android.util.Base64; |
| 23 |
import android.util.Log; |
| 24 |
|
| 25 |
import java.security.MessageDigest; |
| 26 |
import java.security.NoSuchAlgorithmException; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public final class Rlog { |
| 35 |
|
| 36 |
private static final boolean USER_BUILD = Build.IS_USER; |
| 37 |
|
| 38 |
private Rlog() { |
| 39 |
} |
| 40 |
|
| 41 |
@UnsupportedAppUsage |
| 42 |
public static int v(String tag, String msg) { |
| 43 |
return Log.println_native(Log.LOG_ID_RADIO, Log.VERBOSE, tag, msg); |
| 44 |
} |
| 45 |
|
| 46 |
public static int v(String tag, String msg, Throwable tr) { |
| 47 |
return Log.println_native(Log.LOG_ID_RADIO, Log.VERBOSE, tag, |
| 48 |
msg + '\n' + Log.getStackTraceString(tr)); |
| 49 |
} |
| 50 |
|
| 51 |
@UnsupportedAppUsage |
| 52 |
public static int d(String tag, String msg) { |
| 53 |
return Log.println_native(Log.LOG_ID_RADIO, Log.DEBUG, tag, msg); |
| 54 |
} |
| 55 |
|
| 56 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 57 |
public static int d(String tag, String msg, Throwable tr) { |
| 58 |
return Log.println_native(Log.LOG_ID_RADIO, Log.DEBUG, tag, |
| 59 |
msg + '\n' + Log.getStackTraceString(tr)); |
| 60 |
} |
| 61 |
|
| 62 |
@UnsupportedAppUsage |
| 63 |
public static int i(String tag, String msg) { |
| 64 |
return Log.println_native(Log.LOG_ID_RADIO, Log.INFO, tag, msg); |
| 65 |
} |
| 66 |
|
| 67 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 68 |
public static int i(String tag, String msg, Throwable tr) { |
| 69 |
return Log.println_native(Log.LOG_ID_RADIO, Log.INFO, tag, |
| 70 |
msg + '\n' + Log.getStackTraceString(tr)); |
| 71 |
} |
| 72 |
|
| 73 |
@UnsupportedAppUsage |
| 74 |
public static int w(String tag, String msg) { |
| 75 |
return Log.println_native(Log.LOG_ID_RADIO, Log.WARN, tag, msg); |
| 76 |
} |
| 77 |
|
| 78 |
@UnsupportedAppUsage |
| 79 |
public static int w(String tag, String msg, Throwable tr) { |
| 80 |
return Log.println_native(Log.LOG_ID_RADIO, Log.WARN, tag, |
| 81 |
msg + '\n' + Log.getStackTraceString(tr)); |
| 82 |
} |
| 83 |
|
| 84 |
public static int w(String tag, Throwable tr) { |
| 85 |
return Log.println_native(Log.LOG_ID_RADIO, Log.WARN, tag, Log.getStackTraceString(tr)); |
| 86 |
} |
| 87 |
|
| 88 |
@UnsupportedAppUsage |
| 89 |
public static int e(String tag, String msg) { |
| 90 |
return Log.println_native(Log.LOG_ID_RADIO, Log.ERROR, tag, msg); |
| 91 |
} |
| 92 |
|
| 93 |
@UnsupportedAppUsage |
| 94 |
public static int e(String tag, String msg, Throwable tr) { |
| 95 |
return Log.println_native(Log.LOG_ID_RADIO, Log.ERROR, tag, |
| 96 |
msg + '\n' + Log.getStackTraceString(tr)); |
| 97 |
} |
| 98 |
|
| 99 |
public static int println(int priority, String tag, String msg) { |
| 100 |
return Log.println_native(Log.LOG_ID_RADIO, priority, tag, msg); |
| 101 |
} |
| 102 |
|
| 103 |
public static boolean isLoggable(String tag, int level) { |
| 104 |
return Log.isLoggable(tag, level); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public static String pii(String tag, Object pii) { |
| 115 |
String val = String.valueOf(pii); |
| 116 |
if (pii == null || TextUtils.isEmpty(val) || isLoggable(tag, Log.VERBOSE)) { |
| 117 |
return val; |
| 118 |
} |
| 119 |
return "[" + secureHash(val.getBytes()) + "]"; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public static String pii(boolean enablePiiLogging, Object pii) { |
| 130 |
String val = String.valueOf(pii); |
| 131 |
if (pii == null || TextUtils.isEmpty(val) || enablePiiLogging) { |
| 132 |
return val; |
| 133 |
} |
| 134 |
return "[" + secureHash(val.getBytes()) + "]"; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
private static String secureHash(byte[] input) { |
| 144 |
|
| 145 |
if (USER_BUILD) { |
| 146 |
return "****"; |
| 147 |
} |
| 148 |
|
| 149 |
MessageDigest messageDigest; |
| 150 |
|
| 151 |
try { |
| 152 |
messageDigest = MessageDigest.getInstance("SHA-1"); |
| 153 |
} catch (NoSuchAlgorithmException e) { |
| 154 |
return "####"; |
| 155 |
} |
| 156 |
|
| 157 |
byte[] result = messageDigest.digest(input); |
| 158 |
return Base64.encodeToString( |
| 159 |
result, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP); |
| 160 |
} |
| 161 |
} |
| 162 |
|