1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.provider; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Binder; 22 import android.os.ParcelFileDescriptor; 23 import android.os.RemoteException; 24 import android.os.ResultReceiver; 25 26 import java.io.IOException; 27 import java.io.FileDescriptor; 28 import java.io.PrintWriter; 29 30 /** 31 * Class that allows to pass shell commands sent to device_config service 32 * (provided in the platform) to the service provided by this mainline module. 33 * 34 * @hide 35 */ 36 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 37 public final class DeviceConfigShellCommandHandler { DeviceConfigShellCommandHandler()38 private DeviceConfigShellCommandHandler() { 39 // fully static class 40 } 41 42 /** 43 * Runs a shell command in the service defined in this module. 44 * 45 * @param inPfd standard input 46 * @param outPfd standard output 47 * @param errPfd standard error 48 * @param args arguments passed to the command. Can be empty. The first argument 49 * is typically a subcommand, such as {@code run} for 50 * {@code adb shell cmd jobscheduler run}. 51 * @return the status code returned from the {@code cmd} command. 52 */ handleShellCommand( @onNull ParcelFileDescriptor inPfd, @NonNull ParcelFileDescriptor outPfd, @NonNull ParcelFileDescriptor errPfd, @NonNull String[] args)53 static public int handleShellCommand( 54 @NonNull ParcelFileDescriptor inPfd, 55 @NonNull ParcelFileDescriptor outPfd, 56 @NonNull ParcelFileDescriptor errPfd, 57 @NonNull String[] args) { 58 Binder newBinder = (Binder) DeviceConfigInitializer 59 .getDeviceConfigServiceManager() 60 .getDeviceConfigUpdatableServiceRegisterer() 61 .get(); 62 return newBinder.handleShellCommand(inPfd, outPfd, errPfd, args); 63 } 64 } 65