diff options
author | Collin Fijalkovich <cfijalkovich@google.com> | 2021-02-08 17:24:06 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-02-08 17:24:06 +0000 |
commit | 4512e77b7c2abd979822c7da0eb0bc3e26be8ede (patch) | |
tree | 9b558cd2103dca37368334220dcc168a44ad5714 | |
parent | 14a82f79831856b0619901b179df017c4062d9b5 (diff) | |
parent | a5ceac1196b5aa4cd78440fe7b8a3a4ea506c496 (diff) |
Merge "Introduce TracingServiceProxy System Services"
-rw-r--r-- | core/java/Android.bp | 5 | ||||
-rw-r--r-- | core/java/android/tracing/ITracingServiceProxy.aidl | 32 | ||||
-rw-r--r-- | core/java/android/tracing/OWNERS | 2 | ||||
-rw-r--r-- | data/etc/privapp-permissions-platform.xml | 2 | ||||
-rw-r--r-- | libs/tracingproxy/Android.bp | 42 | ||||
-rw-r--r-- | services/core/java/com/android/server/tracing/OWNERS | 2 | ||||
-rw-r--r-- | services/core/java/com/android/server/tracing/TracingServiceProxy.java | 99 | ||||
-rw-r--r-- | services/java/com/android/server/SystemServer.java | 6 |
8 files changed, 190 insertions, 0 deletions
diff --git a/core/java/Android.bp b/core/java/Android.bp index fb27f74211fb..af5df769ffad 100644 --- a/core/java/Android.bp +++ b/core/java/Android.bp @@ -7,3 +7,8 @@ filegroup { name: "IDropBoxManagerService.aidl", srcs: ["com/android/internal/os/IDropBoxManagerService.aidl"], } + +filegroup { + name: "ITracingServiceProxy.aidl", + srcs: ["android/tracing/ITracingServiceProxy.aidl"], +} diff --git a/core/java/android/tracing/ITracingServiceProxy.aidl b/core/java/android/tracing/ITracingServiceProxy.aidl new file mode 100644 index 000000000000..4520db3915a2 --- /dev/null +++ b/core/java/android/tracing/ITracingServiceProxy.aidl @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2020, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.tracing; + +/** + * Binder interface for the TracingServiceProxy running in system_server. + * + * {@hide} + */ +interface ITracingServiceProxy +{ + /** + * Notifies system tracing app that a tracing session has ended. If a session is repurposed + * for use in a bugreport, sessionStolen can be set to indicate that tracing has ended but + * there is no buffer available to dump. + */ + oneway void notifyTraceSessionEnded(boolean sessionStolen); +} diff --git a/core/java/android/tracing/OWNERS b/core/java/android/tracing/OWNERS new file mode 100644 index 000000000000..f5de4eb05c54 --- /dev/null +++ b/core/java/android/tracing/OWNERS @@ -0,0 +1,2 @@ +cfijalkovich@google.com +carmenjackson@google.com diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml index e6ab5c4aaf98..5b32641cc811 100644 --- a/data/etc/privapp-permissions-platform.xml +++ b/data/etc/privapp-permissions-platform.xml @@ -460,6 +460,8 @@ applications that come with the platform <permission name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND"/> <!-- Permissions required for quick settings tile --> <permission name="android.permission.STATUS_BAR"/> + <!-- Permissions required to query Betterbug --> + <permission name="android.permission.QUERY_ALL_PACKAGES"/> </privapp-permissions> <privapp-permissions package="com.android.tv"> diff --git a/libs/tracingproxy/Android.bp b/libs/tracingproxy/Android.bp new file mode 100644 index 000000000000..67f407ff7599 --- /dev/null +++ b/libs/tracingproxy/Android.bp @@ -0,0 +1,42 @@ +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Provides C++ wrappers for system services. + +cc_library_shared { + name: "libtracingproxy", + + aidl: { + export_aidl_headers: true, + include_dirs: [ + "frameworks/base/core/java", + ], + }, + + srcs: [ + ":ITracingServiceProxy.aidl", + ], + + shared_libs: [ + "libbinder", + "libutils", + ], + + cflags: [ + "-Wall", + "-Werror", + "-Wunused", + "-Wunreachable-code", + ], +} diff --git a/services/core/java/com/android/server/tracing/OWNERS b/services/core/java/com/android/server/tracing/OWNERS new file mode 100644 index 000000000000..f5de4eb05c54 --- /dev/null +++ b/services/core/java/com/android/server/tracing/OWNERS @@ -0,0 +1,2 @@ +cfijalkovich@google.com +carmenjackson@google.com diff --git a/services/core/java/com/android/server/tracing/TracingServiceProxy.java b/services/core/java/com/android/server/tracing/TracingServiceProxy.java new file mode 100644 index 000000000000..8f227489740f --- /dev/null +++ b/services/core/java/com/android/server/tracing/TracingServiceProxy.java @@ -0,0 +1,99 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.tracing; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.os.UserHandle; +import android.tracing.ITracingServiceProxy; +import android.util.Log; + +import com.android.server.SystemService; + +/** + * TracingServiceProxy is the system_server intermediary between the Perfetto tracing daemon and the + * system tracing app Traceur. + * + * @hide + */ +public class TracingServiceProxy extends SystemService { + private static final String TAG = "TracingServiceProxy"; + + public static final String TRACING_SERVICE_PROXY_BINDER_NAME = "tracing.proxy"; + + private static final String TRACING_APP_PACKAGE_NAME = "com.android.traceur"; + private static final String TRACING_APP_ACTIVITY = "com.android.traceur.StopTraceService"; + + // Keep this in sync with the definitions in TraceService + private static final String INTENT_ACTION_NOTIFY_SESSION_STOPPED = + "com.android.traceur.NOTIFY_SESSION_STOPPED"; + private static final String INTENT_ACTION_NOTIFY_SESSION_STOLEN = + "com.android.traceur.NOTIFY_SESSION_STOLEN"; + + private final Context mContext; + private final PackageManager mPackageManager; + + private final ITracingServiceProxy.Stub mTracingServiceProxy = new ITracingServiceProxy.Stub() { + /** + * Notifies system tracing app that a tracing session has ended. If a session is repurposed + * for use in a bugreport, sessionStolen can be set to indicate that tracing has ended but + * there is no buffer available to dump. + */ + @Override + public void notifyTraceSessionEnded(boolean sessionStolen) { + notifyTraceur(sessionStolen); + } + }; + + public TracingServiceProxy(Context context) { + super(context); + mContext = context; + mPackageManager = context.getPackageManager(); + } + + @Override + public void onStart() { + publishBinderService(TRACING_SERVICE_PROXY_BINDER_NAME, mTracingServiceProxy); + } + + private void notifyTraceur(boolean sessionStolen) { + final Intent intent = new Intent(); + + try { + // Validate that Traceur is a system app. + PackageInfo info = mPackageManager.getPackageInfo(TRACING_APP_PACKAGE_NAME, + PackageManager.MATCH_SYSTEM_ONLY); + + intent.setClassName(info.packageName, TRACING_APP_ACTIVITY); + if (sessionStolen) { + intent.setAction(INTENT_ACTION_NOTIFY_SESSION_STOLEN); + } else { + intent.setAction(INTENT_ACTION_NOTIFY_SESSION_STOPPED); + } + + try { + mContext.startForegroundServiceAsUser(intent, UserHandle.SYSTEM); + } catch (RuntimeException e) { + Log.e(TAG, "Failed to notifyTraceSessionEnded", e); + } + } catch (NameNotFoundException e) { + Log.e(TAG, "Failed to locate Traceur", e); + } + } +} diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index c355b2f627cc..62c3f43d2676 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -175,6 +175,7 @@ import com.android.server.telecom.TelecomLoaderService; import com.android.server.testharness.TestHarnessModeService; import com.android.server.textclassifier.TextClassificationManagerService; import com.android.server.textservices.TextServicesManagerService; +import com.android.server.tracing.TracingServiceProxy; import com.android.server.trust.TrustManagerService; import com.android.server.tv.TvInputManagerService; import com.android.server.tv.TvRemoteService; @@ -2207,6 +2208,11 @@ public final class SystemServer { mSystemServiceManager.startService(AppBindingService.Lifecycle.class); t.traceEnd(); + // Perfetto TracingServiceProxy + t.traceBegin("startTracingServiceProxy"); + mSystemServiceManager.startService(TracingServiceProxy.class); + t.traceEnd(); + // It is now time to start up the app processes... t.traceBegin("MakeVibratorServiceReady"); |