Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1df428b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use ServiceManager.getServiceOrThrow() instead of ServiceManager.getService()" into main

parents f14e0ffe 9134069b
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -122,18 +122,20 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto
    private final Lock mBackgroundServiceLock = new ReentrantLock();
    private ExecutorService mBackgroundLoggingService = Executors.newSingleThreadExecutor();

    public PerfettoProtoLogImpl(@NonNull IProtoLogGroup[] groups) {
    public PerfettoProtoLogImpl(@NonNull IProtoLogGroup[] groups)
            throws ServiceManager.ServiceNotFoundException {
        this(null, null, null, () -> {}, groups);
    }

    public PerfettoProtoLogImpl(@NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) {
    public PerfettoProtoLogImpl(@NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups)
            throws ServiceManager.ServiceNotFoundException {
        this(null, null, null, cacheUpdater, groups);
    }

    public PerfettoProtoLogImpl(
            @NonNull String viewerConfigFilePath,
            @NonNull Runnable cacheUpdater,
            @NonNull IProtoLogGroup[] groups) {
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
        this(viewerConfigFilePath,
                null,
                new ProtoLogViewerConfigReader(() -> {
@@ -177,12 +179,14 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto
            @Nullable ViewerConfigInputStreamProvider viewerConfigInputStreamProvider,
            @Nullable ProtoLogViewerConfigReader viewerConfigReader,
            @NonNull Runnable cacheUpdater,
            @NonNull IProtoLogGroup[] groups) {
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
        this(viewerConfigFilePath, viewerConfigInputStreamProvider, viewerConfigReader,
                cacheUpdater, groups,
                ProtoLogDataSource::new,
                IProtoLogConfigurationService.Stub
                        .asInterface(ServiceManager.getService(PROTOLOG_CONFIGURATION_SERVICE))
                android.tracing.Flags.clientSideProtoLogging() ?
                    IProtoLogConfigurationService.Stub.asInterface(
                        ServiceManager.getServiceOrThrow(PROTOLOG_CONFIGURATION_SERVICE)
                    ) : null
        );
    }

@@ -222,7 +226,7 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto
        if (android.tracing.Flags.clientSideProtoLogging()) {
            mProtoLogConfigurationService = configurationService;
            Objects.requireNonNull(mProtoLogConfigurationService,
                    "ServiceManager returned a null ProtoLog Configuration Service");
                    "A null ProtoLog Configuration Service was provided!");

            try {
                var args = new ProtoLogConfigurationServiceImpl.RegisterClientArgs();
+7 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.protolog;

import android.os.ServiceManager;

import com.android.internal.protolog.common.IProtoLog;
import com.android.internal.protolog.common.IProtoLogGroup;
import com.android.internal.protolog.common.LogLevel;
@@ -76,7 +78,11 @@ public class ProtoLog {
                    groups = allGroups.toArray(new IProtoLogGroup[0]);
                }

                try {
                    sProtoLogInstance = new PerfettoProtoLogImpl(groups);
                } catch (ServiceManager.ServiceNotFoundException e) {
                    throw new RuntimeException(e);
                }
            }
        } else {
            sProtoLogInstance = new LogcatOnlyProtoLogImpl();
+18 −12
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.internal.protolog.common.ProtoLogToolInjected.Value.LO
import static com.android.internal.protolog.common.ProtoLogToolInjected.Value.VIEWER_CONFIG_PATH;

import android.annotation.Nullable;
import android.os.ServiceManager;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
@@ -106,6 +107,7 @@ public class ProtoLogImpl {
            final var groups = sLogGroups.values().toArray(new IProtoLogGroup[0]);

            if (android.tracing.Flags.perfettoProtologTracing()) {
                try {
                    File f = new File(sViewerConfigPath);
                    if (!ProtoLog.REQUIRE_PROTOLOGTOOL && !f.exists()) {
                        // TODO(b/353530422): Remove - temporary fix to unblock b/352290057
@@ -114,11 +116,15 @@ public class ProtoLogImpl {
                        Log.w(LOG_TAG, "Failed to find viewerConfigFile when setting up "
                                + ProtoLogImpl.class.getSimpleName() + ". "
                                + "Setting up without a viewer config instead...");

                        sServiceInstance = new PerfettoProtoLogImpl(sCacheUpdater, groups);
                    } else {
                        sServiceInstance =
                                new PerfettoProtoLogImpl(sViewerConfigPath, sCacheUpdater, groups);
                    }
                } catch (ServiceManager.ServiceNotFoundException e) {
                    throw new RuntimeException(e);
                }
            } else {
                var protologImpl = new LegacyProtoLogImpl(
                        sLegacyOutputFilePath, sLegacyViewerConfigPath, sCacheUpdater);