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

Commit 66513108 authored by Roman Kalukiewicz's avatar Roman Kalukiewicz Committed by Android (Google) Code Review
Browse files

Merge "Create the shell command for the supervision service." into main

parents 18a73369 7e550527
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.supervision.ISupervisionManager;
import android.content.Context;

import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ShellCallback;

import com.android.internal.util.DumpUtils;
import com.android.server.SystemService;
@@ -28,7 +30,9 @@ import com.android.server.SystemService;
import java.io.FileDescriptor;
import java.io.PrintWriter;

/** Service for handling system supervision. */
/**
 * Service for handling system supervision.
 */
public class SupervisionService extends ISupervisionManager.Stub {
    private static final String LOG_TAG = "SupervisionService";

@@ -44,8 +48,20 @@ public class SupervisionService extends ISupervisionManager.Stub {
    }

    @Override
    protected void dump(@NonNull FileDescriptor fd,
            @NonNull PrintWriter fout, @Nullable String[] args) {
    public void onShellCommand(
            @Nullable FileDescriptor in,
            @Nullable FileDescriptor out,
            @Nullable FileDescriptor err,
            @NonNull String[] args,
            @Nullable ShellCallback callback,
            @NonNull ResultReceiver resultReceiver) throws RemoteException {
        new SupervisionServiceShellCommand(this)
                .exec(this, in, out, err, args, callback, resultReceiver);
    }

    @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());
+61 −0
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.server.supervision;

import android.os.ShellCommand;

import java.io.PrintWriter;

public class SupervisionServiceShellCommand extends ShellCommand {
    private final SupervisionService mService;

    public SupervisionServiceShellCommand(SupervisionService mService) {
        this.mService = mService;
    }

    @Override
    public int onCommand(String cmd) {
        if (cmd == null) {
            return handleDefaultCommands(null);
        }
        final PrintWriter pw = getOutPrintWriter();
        switch (cmd) {
            case "help": return help(pw);
            case "is-enabled": return isEnabled(pw);
            default: return handleDefaultCommands(cmd);
        }
    }

    private int help(PrintWriter pw) {
        pw.println("Supervision service commands:");
        pw.println("  help");
        pw.println("      Prints this help text");
        pw.println("  is-enabled");
        pw.println("      Is supervision enabled");
        return 0;
    }

    private int isEnabled(PrintWriter pw) {
        pw.println(mService.isSupervisionEnabled());
        return 0;
    }

    @Override
    public void onHelp() {
        help(getOutPrintWriter());
    }
}