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

Commit e17445f3 authored by Weilin Xu's avatar Weilin Xu
Browse files

Improve code style for HIDL bcradio service

Improved code style for HIDL broadcast radio service by:
- marking classes as final if possible;
- fixing error prones;
- replacing Slog with Slogf
- replcacing HashMap and HashSet with ArrayMap and ArraySet;
- adding missing parameter names.

Bug: 258826042
Test: atest BroadcastRadioTests
Change-Id: I37fc29f734e2f5a162c927a44661640b3db525b5
parent b8f7f8d3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import com.android.server.SystemService;

import java.util.ArrayList;

public class BroadcastRadioService extends SystemService {
public final class BroadcastRadioService extends SystemService {
    private final IRadioService mServiceImpl;

    public BroadcastRadioService(Context context) {
+1 −1
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ public final class RadioServiceUserController {
     * @return foreground user id.
     */
    public static int getCurrentUser() {
        final long identity = Binder.clearCallingIdentity();
        int userId = UserHandle.USER_NULL;
        final long identity = Binder.clearCallingIdentity();
        try {
            userId = ActivityManager.getCurrentUser();
        } catch (RuntimeException e) {
+7 −6
Original line number Diff line number Diff line
@@ -18,12 +18,13 @@ package com.android.server.broadcastradio.hal1;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.Slog;

import com.android.server.utils.Slogf;

import java.util.Map;
import java.util.Set;

class Convert {
final class Convert {

    private static final String TAG = "BcRadio1Srv.Convert";

@@ -34,12 +35,12 @@ class Convert {
     * side, which requires several separate java calls for each element.
     *
     * @param map map to convert.
     * @returns array (sized the same as map) of two-element string arrays
     * @return array (sized the same as map) of two-element string arrays
     *         (first element is the key, second is value).
     */
    static @NonNull String[][] stringMapToNative(@Nullable Map<String, String> map) {
        if (map == null) {
            Slog.v(TAG, "map is null, returning zero-elements array");
            Slogf.v(TAG, "map is null, returning zero-elements array");
            return new String[0][0];
        }

@@ -54,7 +55,7 @@ class Convert {
            i++;
        }

        Slog.v(TAG, "converted " + i + " element(s)");
        Slogf.v(TAG, "converted " + i + " element(s)");
        return arr;
    }
}
+7 −8
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;

import com.android.server.broadcastradio.RadioServiceUserController;
import com.android.server.utils.Slogf;
@@ -44,9 +43,9 @@ class Tuner extends ITuner.Stub {
    private final long mNativeContext;

    private final Object mLock = new Object();
    @NonNull private final TunerCallback mTunerCallback;
    @NonNull private final ITunerCallback mClientCallback;
    @NonNull private final IBinder.DeathRecipient mDeathRecipient;
    private final TunerCallback mTunerCallback;
    private final ITunerCallback mClientCallback;
    private final IBinder.DeathRecipient mDeathRecipient;

    private boolean mIsClosed = false;
    private boolean mIsMuted = false;
@@ -122,7 +121,7 @@ class Tuner extends ITuner.Stub {

    private boolean checkConfiguredLocked() {
        if (mTunerCallback.isInitialConfigurationDone()) return true;
        Slog.w(TAG, "Initial configuration is still pending, skipping the operation");
        Slogf.w(TAG, "Initial configuration is still pending, skipping the operation");
        return false;
    }

@@ -159,14 +158,14 @@ class Tuner extends ITuner.Stub {
            checkNotClosedLocked();
            if (mIsMuted == mute) return;
            mIsMuted = mute;
            Slog.w(TAG, "Mute via RadioService is not implemented - please handle it via app");
            Slogf.w(TAG, "Mute via RadioService is not implemented - please handle it via app");
        }
    }

    @Override
    public boolean isMuted() {
        if (!mWithAudio) {
            Slog.w(TAG, "Tuner did not request audio, pretending it was muted");
            Slogf.w(TAG, "Tuner did not request audio, pretending it was muted");
            return true;
        }
        synchronized (mLock) {
@@ -210,7 +209,7 @@ class Tuner extends ITuner.Stub {
        if (selector == null) {
            throw new IllegalArgumentException("The argument must not be a null pointer");
        }
        Slog.i(TAG, "Tuning to " + selector);
        Slogf.i(TAG, "Tuning to " + selector);
        synchronized (mLock) {
            checkNotClosedLocked();
            if (!checkConfiguredLocked()) return;
+9 −8
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@ import android.hardware.radio.RadioManager;
import android.hardware.radio.RadioTuner;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;

import com.android.server.utils.Slogf;

import java.util.List;
import java.util.Map;
@@ -42,8 +43,8 @@ class TunerCallback implements ITunerCallback {
     */
    private final long mNativeContext;

    @NonNull private final Tuner mTuner;
    @NonNull private final ITunerCallback mClientCallback;
    private final Tuner mTuner;
    private final ITunerCallback mClientCallback;

    private final AtomicReference<ProgramList.Filter> mProgramListFilter = new AtomicReference<>();
    private boolean mInitialConfigurationDone = false;
@@ -76,7 +77,7 @@ class TunerCallback implements ITunerCallback {
        try {
            func.run();
        } catch (RemoteException e) {
            Slog.e(TAG, "client died", e);
            Slogf.e(TAG, "client died", e);
        }
    }

@@ -107,7 +108,7 @@ class TunerCallback implements ITunerCallback {

    @Override
    public void onTuneFailed(int result, ProgramSelector selector) {
        Slog.e(TAG, "Not applicable for HAL 1.x");
        Slogf.e(TAG, "Not applicable for HAL 1.x");
    }

    @Override
@@ -160,7 +161,7 @@ class TunerCallback implements ITunerCallback {
        try {
            modified = mTuner.getProgramList(filter.getVendorFilter());
        } catch (IllegalStateException ex) {
            Slog.d(TAG, "Program list not ready yet");
            Slogf.d(TAG, "Program list not ready yet");
            return;
        }
        Set<RadioManager.ProgramInfo> modifiedSet = modified.stream().collect(Collectors.toSet());
@@ -175,12 +176,12 @@ class TunerCallback implements ITunerCallback {

    @Override
    public void onConfigFlagUpdated(int flag, boolean value) {
        Slog.w(TAG, "Not applicable for HAL 1.x");
        Slogf.w(TAG, "Not applicable for HAL 1.x");
    }

    @Override
    public void onParametersUpdated(Map<String, String> parameters) {
        Slog.w(TAG, "Not applicable for HAL 1.x");
        Slogf.w(TAG, "Not applicable for HAL 1.x");
    }

    @Override
Loading