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

Commit 32226197 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Stop supporting SerialManager.

Just was just as an example of using a system service, and now we
already use another system service (PlatformCompat).

On top of that, I heard a discussion about stopping support of this.

So let's just delete it.

Bug: 292141694
Flag: TEST_ONLY
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh -s
Change-Id: I89987a875cc8a78a43638c506d34ce896b372f11
parent 107114d1
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import java.io.IOException;
 * @hide
 */
@SystemService(Context.SERIAL_SERVICE)
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class SerialManager {
    private static final String TAG = "SerialManager";

@@ -70,8 +69,6 @@ public class SerialManager {
     * @return the serial port
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @android.ravenwood.annotation.RavenwoodThrow(blockedBy = ParcelFileDescriptor.class, reason =
            "Needs socketpair() to offer accurate emulation")
    public SerialPort openSerialPort(String name, int speed) throws IOException {
        try {
            ParcelFileDescriptor pfd = mService.openSerialPort(name);
+0 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import java.util.function.Supplier;
 *
 * @hide
 */
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public abstract class SerialManagerInternal {
    public abstract void addVirtualSerialPortForTest(@NonNull String name,
            @NonNull Supplier<ParcelFileDescriptor> supplier);
+0 −8
Original line number Diff line number Diff line
@@ -23,13 +23,10 @@ import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.hardware.ISerialManager;
import android.hardware.SerialManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.PermissionEnforcer;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.ravenwood.annotation.RavenwoodSupported.RavenwoodProvidingImplementation;
import android.ravenwood.example.BlueManager;
@@ -88,11 +85,6 @@ public class RavenwoodContext extends RavenwoodBaseContext {
                        new ClipboardManager(this, getMainThreadHandler())));
        registerService(PermissionEnforcer.class,
                Context.PERMISSION_ENFORCER_SERVICE, () -> mEnforcer);
        registerService(SerialManager.class,
                Context.SERIAL_SERVICE, memoize(() ->
                        new SerialManager(this, ISerialManager.Stub.asInterface(
                                ServiceManager.getService(Context.SERIAL_SERVICE)))
                ));

        // Additional services we provide for testing purposes
        registerService(BlueManager.class,
+0 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.platform.test.ravenwood;

import android.content.ClipboardManager;
import android.content.Context;
import android.hardware.SerialManager;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.ravenwood.example.BlueManager;
@@ -52,8 +51,6 @@ public class RavenwoodSystemServer {
        // Services provided by a typical shipping device
        sKnownServices.put(ClipboardManager.class,
                "com.android.server.FakeClipboardService$Lifecycle");
        sKnownServices.put(SerialManager.class,
                "com.android.server.SerialService$Lifecycle");

        // Additional services we provide for testing purposes
        sKnownServices.put(BlueManager.class,
+0 −99
Original line number Diff line number Diff line
/*
 * 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.ravenwoodtest.servicestest;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import android.content.Context;
import android.hardware.SerialManager;
import android.hardware.SerialManagerInternal;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.server.LocalServices;

import com.google.common.collect.Lists;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class RavenwoodServicesTest {
    private static final String TEST_VIRTUAL_PORT = "virtual:example";

    private Context mContext;

    @Before
    public void setUp() {
        mContext = InstrumentationRegistry.getInstrumentation().getContext();
    }

    @Test
    public void testDefined() {
        final SerialManager fromName = (SerialManager)
                mContext.getSystemService(Context.SERIAL_SERVICE);
        final SerialManager fromClass =
                mContext.getSystemService(SerialManager.class);
        assertNotNull(fromName);
        assertNotNull(fromClass);
        assertEquals(fromName, fromClass);

        assertNotNull(LocalServices.getService(SerialManagerInternal.class));
    }

    @Test
    public void testSimple() {
        // Verify that we can obtain a manager, and talk to the backend service, and that no
        // serial ports are configured by default
        final SerialManager service = (SerialManager)
                mContext.getSystemService(Context.SERIAL_SERVICE);
        final String[] ports = service.getSerialPorts();
        final String[] refPorts = mContext.getResources().getStringArray(
                com.android.internal.R.array.config_serialPorts);
        assertArrayEquals(refPorts, ports);
    }

    @Test
    public void testDriven() {
        final SerialManager service = (SerialManager)
                mContext.getSystemService(Context.SERIAL_SERVICE);
        final SerialManagerInternal internal = LocalServices.getService(
                SerialManagerInternal.class);

        internal.addVirtualSerialPortForTest(TEST_VIRTUAL_PORT, () -> {
            throw new UnsupportedOperationException(
                    "Needs socketpair() to offer accurate emulation");
        });
        try {
            final String[] ports = service.getSerialPorts();
            for (var port : ports) {
                if (TEST_VIRTUAL_PORT.equals(port)) {
                    return; // Pass
                }
            }
            fail("Virtual port " + TEST_VIRTUAL_PORT + " not found. Actual="
                    + Lists.newArrayList(ports));
        } finally {
            internal.removeVirtualSerialPortForTest(TEST_VIRTUAL_PORT);
        }
    }
}
Loading