Use a common logger Tag "AdServicesShellCommand" for all the adservices shell commands
Bug: 308009734
Test: atest AdServicesShellCommandTest, EchoCommandTest
Change-Id: I8df66398fc93e7bc5bc6206bab550f41e011d546
diff --git a/adservices/apk/java/com/android/adservices/shell/AdServicesShellCommandService.java b/adservices/apk/java/com/android/adservices/shell/AdServicesShellCommandService.java
index 85b23a5..6d7b227 100644
--- a/adservices/apk/java/com/android/adservices/shell/AdServicesShellCommandService.java
+++ b/adservices/apk/java/com/android/adservices/shell/AdServicesShellCommandService.java
@@ -20,11 +20,12 @@
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
+import android.util.Log;
-import com.android.adservices.LogUtil;
import com.android.adservices.service.FlagsFactory;
import com.android.adservices.service.shell.AdServicesShellCommandHandler;
import com.android.adservices.service.shell.ShellCommandServiceImpl;
+import com.android.internal.annotations.VisibleForTesting;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -33,6 +34,7 @@
/** Implements a service which runs the shell command in the adservices process. */
public final class AdServicesShellCommandService extends Service {
+ @VisibleForTesting static final String TAG = "AdServicesShellCommand";
/** The binder service. This field must only be accessed on the main thread. */
@Nullable private ShellCommandServiceImpl mShellCommandService;
@@ -40,7 +42,7 @@
@Override
public void onCreate() {
if (!FlagsFactory.getFlags().getAdServicesShellCommandEnabled()) {
- LogUtil.e("Shell command service is not enabled.");
+ Log.e(TAG, "Shell command service is not enabled.");
return;
}
@@ -51,7 +53,7 @@
@Override
public IBinder onBind(Intent intent) {
if (!FlagsFactory.getFlags().getAdServicesShellCommandEnabled()) {
- LogUtil.e("Shell command service is not enabled.");
+ Log.e(TAG, "Shell command service is not enabled.");
return null;
}
return Objects.requireNonNull(mShellCommandService);
@@ -62,16 +64,19 @@
if (args != null && args.length > 0 && args[0].equals("cmd")) {
boolean enabled = FlagsFactory.getFlags().getAdServicesShellCommandEnabled();
if (!enabled) {
- LogUtil.e(
- "dump(%s) called on AdServicesShellCommandService when shell command flag"
- + " was disabled",
- Arrays.toString(args));
+ Log.e(
+ TAG,
+ String.format(
+ "dump(%s) called on AdServicesShellCommandService when shell"
+ + " command flag was disabled",
+ Arrays.toString(args)));
return;
}
// need to strip the "cmd" arg
String[] realArgs = new String[args.length - 1];
System.arraycopy(args, 1, realArgs, 0, args.length - 1);
- LogUtil.w(
+ Log.w(
+ TAG,
"Using dump to call AdServicesShellCommandHandler - should NOT happen on"
+ " production");
new AdServicesShellCommandHandler(pw).run(realArgs);
diff --git a/adservices/apk/unittest/src/com/android/adservices/shell/AdServicesShellCommandServiceTest.java b/adservices/apk/unittest/src/com/android/adservices/shell/AdServicesShellCommandServiceTest.java
index b7aa937..75a4882 100644
--- a/adservices/apk/unittest/src/com/android/adservices/shell/AdServicesShellCommandServiceTest.java
+++ b/adservices/apk/unittest/src/com/android/adservices/shell/AdServicesShellCommandServiceTest.java
@@ -17,6 +17,7 @@
package com.android.adservices.shell;
import static com.android.adservices.shared.testing.common.DumpHelper.dump;
+import static com.android.adservices.shell.AdServicesShellCommandService.TAG;
import static org.mockito.Mockito.when;
@@ -86,14 +87,13 @@
public void testDump_shellCommandThroughDumpsys_flagDisabled() throws Exception {
mockGetAdServicesShellCommandEnabled(/* enabled= */ false);
String[] args = new String[] {"cmd", "echo", "hello"};
- String tag = "adservices";
- LogInterceptor logInterceptor = extendedMockito.interceptLogE(tag);
+ LogInterceptor logInterceptor = extendedMockito.interceptLogE(TAG);
expect.withMessage("cmd: echo")
.that(dump(pw -> mShellService.dump(/* fd= */ null, pw, args)))
.isEmpty();
- expect.withMessage("Log.e() calls to tag %s", tag)
- .that(logInterceptor.getPlainMessages(tag, Level.ERROR))
+ expect.withMessage("Log.e() calls to tag %s", TAG)
+ .that(logInterceptor.getPlainMessages(TAG, Level.ERROR))
.contains(
String.format(
"dump(%s) called on AdServicesShellCommandService when shell"
diff --git a/adservices/service-core/java/com/android/adservices/service/shell/AbstractShellCommand.java b/adservices/service-core/java/com/android/adservices/service/shell/AbstractShellCommand.java
index d102265..c04d751 100644
--- a/adservices/service-core/java/com/android/adservices/service/shell/AbstractShellCommand.java
+++ b/adservices/service-core/java/com/android/adservices/service/shell/AbstractShellCommand.java
@@ -21,7 +21,6 @@
abstract class AbstractShellCommand implements ShellCommand {
- static final String TAG = AbstractShellCommand.class.getSimpleName();
static final int RESULT_GENERIC_ERROR = -1;
static final int RESULT_OK = 0;
diff --git a/adservices/service-core/java/com/android/adservices/service/shell/AdServicesShellCommandHandler.java b/adservices/service-core/java/com/android/adservices/service/shell/AdServicesShellCommandHandler.java
index 99172d3..8ed8266 100644
--- a/adservices/service-core/java/com/android/adservices/service/shell/AdServicesShellCommandHandler.java
+++ b/adservices/service-core/java/com/android/adservices/service/shell/AdServicesShellCommandHandler.java
@@ -85,7 +85,7 @@
+ " the given app, when using SDK sandbox or not.";
// TODO(b/280460130): use adservice helpers for tag name / logging methods
- private static final String TAG = "AdServicesShellCmd";
+ static final String TAG = "AdServicesShellCmd";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
// Add more per API shell factory implementations as we create them.
diff --git a/adservices/service-core/java/com/android/adservices/service/shell/ArgParser.java b/adservices/service-core/java/com/android/adservices/service/shell/ArgParser.java
index b50c444..5b797fc 100644
--- a/adservices/service-core/java/com/android/adservices/service/shell/ArgParser.java
+++ b/adservices/service-core/java/com/android/adservices/service/shell/ArgParser.java
@@ -16,13 +16,12 @@
package com.android.adservices.service.shell;
+import static com.android.adservices.service.shell.AdServicesShellCommandHandler.TAG;
import static com.android.internal.util.Preconditions.checkArgument;
import android.util.ArrayMap;
import android.util.Log;
-import androidx.annotation.NonNull;
-
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
@@ -31,7 +30,6 @@
// TODO(b/322395593): Refactor ArgParser to work better after M-04 release.
final class ArgParser {
- private static final String TAG = ArgParser.class.getSimpleName();
private final ImmutableList<String> mRequiredArgs;
private final Map<String, String> mParsedArgs = new ArrayMap<>();
diff --git a/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceListCommand.java b/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceListCommand.java
index 900ff20..58facc7 100644
--- a/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceListCommand.java
+++ b/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceListCommand.java
@@ -16,6 +16,8 @@
package com.android.adservices.service.shell;
+import static com.android.adservices.service.shell.AdServicesShellCommandHandler.TAG;
+
import android.adservices.common.AdTechIdentifier;
import android.util.Log;
diff --git a/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceViewCommand.java b/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceViewCommand.java
index a17a1ab..87e785d 100644
--- a/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceViewCommand.java
+++ b/adservices/service-core/java/com/android/adservices/service/shell/CustomAudienceViewCommand.java
@@ -16,6 +16,8 @@
package com.android.adservices.service.shell;
+import static com.android.adservices.service.shell.AdServicesShellCommandHandler.TAG;
+
import android.adservices.common.AdTechIdentifier;
import android.util.Log;
diff --git a/adservices/service-core/java/com/android/adservices/service/shell/EchoCommand.java b/adservices/service-core/java/com/android/adservices/service/shell/EchoCommand.java
index 080e00f..735d25b 100644
--- a/adservices/service-core/java/com/android/adservices/service/shell/EchoCommand.java
+++ b/adservices/service-core/java/com/android/adservices/service/shell/EchoCommand.java
@@ -16,6 +16,8 @@
package com.android.adservices.service.shell;
+import static com.android.adservices.service.shell.AdServicesShellCommandHandler.TAG;
+
import android.text.TextUtils;
import android.util.Log;
diff --git a/adservices/service-core/java/com/android/adservices/service/shell/ShellCommandServiceImpl.java b/adservices/service-core/java/com/android/adservices/service/shell/ShellCommandServiceImpl.java
index 285396c..a1c215b 100644
--- a/adservices/service-core/java/com/android/adservices/service/shell/ShellCommandServiceImpl.java
+++ b/adservices/service-core/java/com/android/adservices/service/shell/ShellCommandServiceImpl.java
@@ -16,13 +16,14 @@
package com.android.adservices.service.shell;
+import static com.android.adservices.service.shell.AdServicesShellCommandHandler.TAG;
+
import android.adservices.shell.IShellCommand;
import android.adservices.shell.IShellCommandCallback;
import android.adservices.shell.ShellCommandParam;
import android.adservices.shell.ShellCommandResult;
import android.os.RemoteException;
-
-import com.android.adservices.LogUtil;
+import android.util.Log;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -53,7 +54,10 @@
.build();
callback.onResult(response);
} catch (RemoteException e) {
- LogUtil.e(e, "Unable to send result to the callback for request: %s", param);
+ Log.e(
+ TAG,
+ String.format("Unable to send result to the callback for request: %s", param),
+ e);
}
}
}