diff options
| author | 2024-08-27 16:52:41 +0000 | |
|---|---|---|
| committer | 2024-08-27 16:52:41 +0000 | |
| commit | fc990b40b47dc6df666f56c1b080a8a1f991a372 (patch) | |
| tree | c27f9ea597f4980dfc7dd28fb25f47a2f28d4052 | |
| parent | da0d38eb3fb1f75ee5da7257431342f2266a673c (diff) | |
| parent | 8beaf2ce8853ca4341be223c8921eee4d5c1c44c (diff) | |
Merge "Create a stub for SupervisionService." into main
| -rw-r--r-- | AconfigFlags.bp | 16 | ||||
| -rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 17 | ||||
| -rw-r--r-- | core/java/android/app/supervision/ISupervisionManager.aidl | 25 | ||||
| -rw-r--r-- | core/java/android/app/supervision/SupervisionManager.java | 57 | ||||
| -rw-r--r-- | core/java/android/app/supervision/flags.aconfig | 10 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 10 | ||||
| -rw-r--r-- | services/Android.bp | 2 | ||||
| -rw-r--r-- | services/java/com/android/server/SystemServer.java | 7 | ||||
| -rw-r--r-- | services/supervision/Android.bp | 22 | ||||
| -rw-r--r-- | services/supervision/java/com/android/server/supervision/SupervisionService.java | 67 |
10 files changed, 233 insertions, 0 deletions
diff --git a/AconfigFlags.bp b/AconfigFlags.bp index b4127c5660f7..3c5686bd6d13 100644 --- a/AconfigFlags.bp +++ b/AconfigFlags.bp @@ -26,6 +26,7 @@ aconfig_declarations_group { "android.app.flags-aconfig-java", "android.app.ondeviceintelligence-aconfig-java", "android.app.smartspace.flags-aconfig-java", + "android.app.supervision.flags-aconfig-java", "android.app.usage.flags-aconfig-java", "android.app.wearable.flags-aconfig-java", "android.appwidget.flags-aconfig-java", @@ -1212,6 +1213,21 @@ java_aconfig_library { defaults: ["framework-minus-apex-aconfig-java-defaults"], } +// Supervision +aconfig_declarations { + name: "android.app.supervision.flags-aconfig", + exportable: true, + package: "android.app.supervision.flags", + container: "system", + srcs: ["core/java/android/app/supervision/flags.aconfig"], +} + +java_aconfig_library { + name: "android.app.supervision.flags-aconfig-java", + aconfig_declarations: "android.app.supervision.flags-aconfig", + defaults: ["framework-minus-apex-aconfig-java-defaults"], +} + // SurfaceFlinger java_aconfig_library { name: "surfaceflinger_flags_java_lib", diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index cb38cf297cf6..8b3ee24db025 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -48,6 +48,8 @@ import android.app.sdksandbox.SdkSandboxManagerFrameworkInitializer; import android.app.search.SearchUiManager; import android.app.slice.SliceManager; import android.app.smartspace.SmartspaceManager; +import android.app.supervision.ISupervisionManager; +import android.app.supervision.SupervisionManager; import android.app.time.TimeManager; import android.app.timedetector.TimeDetector; import android.app.timedetector.TimeDetectorImpl; @@ -1703,6 +1705,21 @@ public final class SystemServiceRegistry { return new E2eeContactKeysManager(ctx); }}); + registerService(Context.SUPERVISION_SERVICE, SupervisionManager.class, + new CachedServiceFetcher<>() { + @Override + public SupervisionManager createService(ContextImpl ctx) + throws ServiceNotFoundException { + if (!android.app.supervision.flags.Flags.supervisionApi()) { + throw new ServiceNotFoundException( + "SupervisionManager is not supported"); + } + IBinder iBinder = ServiceManager.getServiceOrThrow( + Context.SUPERVISION_SERVICE); + ISupervisionManager service = ISupervisionManager.Stub.asInterface(iBinder); + return new SupervisionManager(ctx, service); + } + }); // DO NOT do a flag check like this unless the flag is read-only. // (because this code is executed during preload in zygote.) // If the flag is mutable, the check should be inside CachedServiceFetcher. diff --git a/core/java/android/app/supervision/ISupervisionManager.aidl b/core/java/android/app/supervision/ISupervisionManager.aidl new file mode 100644 index 000000000000..8d25cad2fc67 --- /dev/null +++ b/core/java/android/app/supervision/ISupervisionManager.aidl @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2024, 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.app.supervision; + +/** + * Internal IPC interface to the supervision service. + * {@hide} + */ +interface ISupervisionManager { + boolean isSupervisionEnabled(); +} diff --git a/core/java/android/app/supervision/SupervisionManager.java b/core/java/android/app/supervision/SupervisionManager.java new file mode 100644 index 000000000000..8611a92074c0 --- /dev/null +++ b/core/java/android/app/supervision/SupervisionManager.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2024 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.app.supervision; + +import android.annotation.SystemService; +import android.compat.annotation.UnsupportedAppUsage; +import android.content.Context; +import android.os.RemoteException; + +/** + * Service for handling parental supervision. + * + * @hide + */ +@SystemService(Context.SUPERVISION_SERVICE) +public class SupervisionManager { + private final Context mContext; + private final ISupervisionManager mService; + + /** + * @hide + */ + @UnsupportedAppUsage + public SupervisionManager(Context context, ISupervisionManager service) { + mContext = context; + mService = service; + } + + /** + * Returns whether the device is supervised. + * + * @hide + */ + public boolean isSupervisionEnabled() { + try { + return mService.isSupervisionEnabled(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + +} diff --git a/core/java/android/app/supervision/flags.aconfig b/core/java/android/app/supervision/flags.aconfig new file mode 100644 index 000000000000..bcb5b3636c95 --- /dev/null +++ b/core/java/android/app/supervision/flags.aconfig @@ -0,0 +1,10 @@ +package: "android.app.supervision.flags" +container: "system" + +flag { + name: "supervision_api" + is_exported: true + namespace: "supervision" + description: "Flag to enable the SupervisionService" + bug: "340351729" +}
\ No newline at end of file diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 9c711bcb1521..3bf0f0324716 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -6711,6 +6711,16 @@ public abstract class Context { public static final String PROTOLOG_CONFIGURATION_SERVICE = "protolog_configuration"; /** + * Use with {@link #getSystemService(String)} to retrieve a + * {@link android.app.supervision.SupervisionManager}. + * + * @see #getSystemService(String) + * @see android.app.supervision.SupervisionManager + * @hide + */ + public static final String SUPERVISION_SERVICE = "supervision"; + + /** * Determine whether the given permission is allowed for a particular * process and user ID running in the system. * diff --git a/services/Android.bp b/services/Android.bp index 0006455f41b0..653cd3c3b680 100644 --- a/services/Android.bp +++ b/services/Android.bp @@ -136,6 +136,7 @@ filegroup { ":services.searchui-sources", ":services.smartspace-sources", ":services.soundtrigger-sources", + ":services.supervision-sources", ":services.systemcaptions-sources", ":services.translation-sources", ":services.texttospeech-sources", @@ -237,6 +238,7 @@ system_java_library { "services.searchui", "services.smartspace", "services.soundtrigger", + "services.supervision", "services.systemcaptions", "services.translation", "services.texttospeech", diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 37e7cfc6ef98..da3ada8671df 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -256,6 +256,7 @@ import com.android.server.stats.bootstrap.StatsBootstrapAtomService; import com.android.server.stats.pull.StatsPullAtomService; import com.android.server.statusbar.StatusBarManagerService; import com.android.server.storage.DeviceStorageMonitorService; +import com.android.server.supervision.SupervisionService; import com.android.server.systemcaptions.SystemCaptionsManagerService; import com.android.server.telecom.TelecomLoaderService; import com.android.server.testharness.TestHarnessModeService; @@ -1598,6 +1599,12 @@ public final class SystemServer implements Dumpable { mSystemServiceManager.startService(ROLE_SERVICE_CLASS); t.traceEnd(); + if (android.app.supervision.flags.Flags.supervisionApi()) { + t.traceBegin("StartSupervisionService"); + mSystemServiceManager.startService(SupervisionService.Lifecycle.class); + t.traceEnd(); + } + if (!isTv) { t.traceBegin("StartVibratorManagerService"); mSystemServiceManager.startService(VibratorManagerService.Lifecycle.class); diff --git a/services/supervision/Android.bp b/services/supervision/Android.bp new file mode 100644 index 000000000000..93a0c4af7891 --- /dev/null +++ b/services/supervision/Android.bp @@ -0,0 +1,22 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +filegroup { + name: "services.supervision-sources", + srcs: ["java/**/*.java"], + path: "java", + visibility: ["//frameworks/base/services"], +} + +java_library_static { + name: "services.supervision", + defaults: ["platform_service_defaults"], + srcs: [":services.supervision-sources"], + libs: ["services.core"], +} diff --git a/services/supervision/java/com/android/server/supervision/SupervisionService.java b/services/supervision/java/com/android/server/supervision/SupervisionService.java new file mode 100644 index 000000000000..a4ef629492e7 --- /dev/null +++ b/services/supervision/java/com/android/server/supervision/SupervisionService.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2024 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.supervision; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.app.supervision.ISupervisionManager; +import android.content.Context; + + +import com.android.internal.util.DumpUtils; +import com.android.server.SystemService; + +import java.io.FileDescriptor; +import java.io.PrintWriter; + +/** Service for handling system supervision. */ +public class SupervisionService extends ISupervisionManager.Stub { + private static final String LOG_TAG = "SupervisionService"; + + private final Context mContext; + + public SupervisionService(Context context) { + mContext = context.createAttributionContext("SupervisionService"); + } + + @Override + public boolean isSupervisionEnabled() { + return false; + } + + @Override + protected void dump(@NonNull FileDescriptor fd, + @NonNull PrintWriter fout, @Nullable String[] args) { + if (!DumpUtils.checkDumpPermission(mContext, LOG_TAG, fout)) return; + + fout.println("Supervision enabled: " + isSupervisionEnabled()); + } + + public static class Lifecycle extends SystemService { + private final SupervisionService mSupervisionService; + + public Lifecycle(@NonNull Context context) { + super(context); + mSupervisionService = new SupervisionService(context); + } + + @Override + public void onStart() { + publishBinderService(Context.SUPERVISION_SERVICE, mSupervisionService); + } + } +} |