diff options
author | Roshan Pius <rpius@google.com> | 2020-01-08 11:00:12 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-01-08 11:36:45 -0800 |
commit | 929e6e1536ba7f7cff8551a06a89e1b903fce1c6 (patch) | |
tree | 2569906ab9dfa9f2f1b070fa2d2a45257d233dd5 | |
parent | 7a96efbad8d681f7c0d9411e5bd7946fc3fd0072 (diff) |
wifi: Use new @SystemApi for shell command handling
Bug: 147344816
Test: "adb shell cmd wifi set-wifi-enabled enabled"
Test: "adb shell cmd wifi set-wifi-enabled disabled"
Test: make com.android.wifi & ensured that the shell command @hide API's
no longer show up in appcompat analysis.
Change-Id: I502c4b3be64d47a110155b877ef6bc3c89101c62
9 files changed, 41 insertions, 33 deletions
diff --git a/service/jarjar-rules-shared.txt b/service/jarjar-rules-shared.txt index 7faeb64e8..09ae5d907 100644 --- a/service/jarjar-rules-shared.txt +++ b/service/jarjar-rules-shared.txt @@ -18,6 +18,7 @@ rule android.util.BackupUtils* com.android.server.x.wifi.util.BackupUtils@1 rule android.util.LocalLog* com.android.server.x.wifi.util.LocalLog@1 rule android.util.Rational* com.android.server.x.wifi.util.Rational@1 +rule android.os.BasicShellCommandHandler* com.android.server.x.wifi.os.BasicShellCommandHandler@1 rule android.os.HandlerExecutor* com.android.server.x.wifi.os.HandlerExecutor@1 # Use our statically linked bouncy castle library diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 8b3a3213f..e8fae501b 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -83,12 +83,11 @@ import android.os.HandlerExecutor; import android.os.IBinder; import android.os.Looper; import android.os.Message; +import android.os.ParcelFileDescriptor; import android.os.PersistableBundle; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; -import android.os.ResultReceiver; -import android.os.ShellCallback; import android.os.UserHandle; import android.os.UserManager; import android.os.WorkSource; @@ -2841,10 +2840,12 @@ public class WifiServiceImpl extends BaseWifiService { } @Override - public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, - String[] args, ShellCallback callback, ResultReceiver resultReceiver) { - (new WifiShellCommand(mWifiInjector)).exec(this, in, out, err, - args, callback, resultReceiver); + public int handleShellCommand(@NonNull ParcelFileDescriptor in, + @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, + @NonNull String[] args) { + return new WifiShellCommand(mWifiInjector).exec( + this, in.getFileDescriptor(), out.getFileDescriptor(), err.getFileDescriptor(), + args); } @Override diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java index 940c610a0..afbcba3c5 100644 --- a/service/java/com/android/server/wifi/WifiShellCommand.java +++ b/service/java/com/android/server/wifi/WifiShellCommand.java @@ -21,9 +21,9 @@ import android.net.wifi.IWifiManager; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiScanner; import android.net.wifi.wificond.WifiCondManager; +import android.os.BasicShellCommandHandler; import android.os.Binder; import android.os.ServiceManager; -import android.os.ShellCommand; import com.android.server.wifi.util.ApConfigUtil; @@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit; * Permissions: currently root permission is required for most * commands, which is checked using {@link #checkRootPermission()}. */ -public class WifiShellCommand extends ShellCommand { +public class WifiShellCommand extends BasicShellCommandHandler { private final ClientModeImpl mClientModeImpl; private final WifiLockManager mWifiLockManager; private final WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager; diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java index cc768aa8a..3d769a5dd 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java @@ -38,8 +38,8 @@ import android.net.wifi.aware.ConfigRequest; import android.net.wifi.aware.PublishConfig; import android.net.wifi.aware.SubscribeConfig; import android.net.wifi.util.HexEncoding; +import android.os.BasicShellCommandHandler; import android.os.RemoteException; -import android.os.ShellCommand; import android.text.TextUtils; import android.util.Log; import android.util.SparseIntArray; @@ -162,7 +162,7 @@ public class WifiAwareNativeApi implements WifiAwareShellCommand.DelegatedShellC * @return -1 if parameter not recognized or invalid value, 0 otherwise. */ @Override - public int onCommand(ShellCommand parentShell) { + public int onCommand(BasicShellCommandHandler parentShell) { final PrintWriter pw = parentShell.getErrPrintWriter(); String subCmd = parentShell.getNextArgRequired(); @@ -290,7 +290,7 @@ public class WifiAwareNativeApi implements WifiAwareShellCommand.DelegatedShellC } @Override - public void onHelp(String command, ShellCommand parentShell) { + public void onHelp(String command, BasicShellCommandHandler parentShell) { final PrintWriter pw = parentShell.getOutPrintWriter(); pw.println(" " + command); diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java index 4172a412f..5e76897a2 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java @@ -29,7 +29,7 @@ import android.hardware.wifi.V1_2.IWifiNanIfaceEventCallback; import android.hardware.wifi.V1_2.NanDataPathChannelInfo; import android.hardware.wifi.V1_2.NanDataPathScheduleUpdateInd; import android.net.wifi.util.HexEncoding; -import android.os.ShellCommand; +import android.os.BasicShellCommandHandler; import android.util.Log; import android.util.SparseArray; import android.util.SparseIntArray; @@ -89,7 +89,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub imp * @return -1 if parameter not recognized or invalid value, 0 otherwise. */ @Override - public int onCommand(ShellCommand parentShell) { + public int onCommand(BasicShellCommandHandler parentShell) { final PrintWriter pwe = parentShell.getErrPrintWriter(); final PrintWriter pwo = parentShell.getOutPrintWriter(); @@ -148,7 +148,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub imp } @Override - public void onHelp(String command, ShellCommand parentShell) { + public void onHelp(String command, BasicShellCommandHandler parentShell) { final PrintWriter pw = parentShell.getOutPrintWriter(); pw.println(" " + command); diff --git a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java index cd697ceac..6158607be 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java @@ -17,6 +17,7 @@ package com.android.server.wifi.aware; import android.Manifest; +import android.annotation.NonNull; import android.app.AppOpsManager; import android.content.Context; import android.content.pm.PackageManager; @@ -35,9 +36,8 @@ import android.os.Binder; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; +import android.os.ParcelFileDescriptor; import android.os.RemoteException; -import android.os.ResultReceiver; -import android.os.ShellCallback; import android.provider.Settings; import android.util.Log; import android.util.SparseArray; @@ -436,9 +436,12 @@ public class WifiAwareServiceImpl extends IWifiAwareManager.Stub { } @Override - public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, - String[] args, ShellCallback callback, ResultReceiver resultReceiver) { - mShellCommand.exec(this, in, out, err, args, callback, resultReceiver); + public int handleShellCommand(@NonNull ParcelFileDescriptor in, + @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, + @NonNull String[] args) { + return mShellCommand.exec( + this, in.getFileDescriptor(), out.getFileDescriptor(), err.getFileDescriptor(), + args); } @Override diff --git a/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java b/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java index a2f604686..61afe1a8e 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java @@ -16,8 +16,8 @@ package com.android.server.wifi.aware; +import android.os.BasicShellCommandHandler; import android.os.Binder; -import android.os.ShellCommand; import android.text.TextUtils; import android.util.Log; @@ -28,7 +28,7 @@ import java.util.Map; /** * Interprets and executes 'adb shell cmd wifiaware [args]'. */ -public class WifiAwareShellCommand extends ShellCommand { +public class WifiAwareShellCommand extends BasicShellCommandHandler { private static final String TAG = "WifiAwareShellCommand"; private Map<String, DelegatedShellCommand> mDelegatedCommands = new HashMap<>(); @@ -107,7 +107,7 @@ public class WifiAwareShellCommand extends ShellCommand { * Execute the specified command. Use the parent shell to obtain arguments. Note that the * first argument (which specified the delegated shell) has already been extracted. */ - int onCommand(ShellCommand parentShell); + int onCommand(BasicShellCommandHandler parentShell); /** * Reset all parameters to their default values. @@ -119,7 +119,7 @@ public class WifiAwareShellCommand extends ShellCommand { * as a first argument as an assist (prevents hard-coding of that string in multiple * places). */ - void onHelp(String command, ShellCommand parentShell); + void onHelp(String command, BasicShellCommandHandler parentShell); } } diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java index bdf1b728e..2c4d8365c 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java @@ -35,12 +35,12 @@ import android.net.wifi.aware.SubscribeConfig; import android.net.wifi.aware.WifiAwareManager; import android.net.wifi.aware.WifiAwareNetworkSpecifier; import android.net.wifi.util.HexEncoding; +import android.os.BasicShellCommandHandler; import android.os.Bundle; import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.os.RemoteException; -import android.os.ShellCommand; import android.os.SystemClock; import android.os.UserHandle; import android.text.TextUtils; @@ -259,7 +259,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe * @return -1 if parameter not recognized or invalid value, 0 otherwise. */ @Override - public int onCommand(ShellCommand parentShell) { + public int onCommand(BasicShellCommandHandler parentShell) { final PrintWriter pw_err = parentShell.getErrPrintWriter(); final PrintWriter pw_out = parentShell.getOutPrintWriter(); @@ -360,7 +360,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe } @Override - public void onHelp(String command, ShellCommand parentShell) { + public void onHelp(String command, BasicShellCommandHandler parentShell) { final PrintWriter pw = parentShell.getOutPrintWriter(); pw.println(" " + command); diff --git a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java index 659553656..13946c86d 100644 --- a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java +++ b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java @@ -18,6 +18,7 @@ package com.android.server.wifi.rtt; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE; +import android.annotation.NonNull; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; @@ -37,15 +38,14 @@ import android.net.wifi.rtt.RangingResultCallback; import android.net.wifi.rtt.ResponderConfig; import android.net.wifi.rtt.ResponderLocation; import android.net.wifi.rtt.WifiRttManager; +import android.os.BasicShellCommandHandler; import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.os.Looper; +import android.os.ParcelFileDescriptor; import android.os.PowerManager; import android.os.RemoteException; -import android.os.ResultReceiver; -import android.os.ShellCallback; -import android.os.ShellCommand; import android.os.UserHandle; import android.os.WorkSource; import android.os.WorkSource.WorkChain; @@ -123,7 +123,7 @@ public class RttServiceImpl extends IWifiRttManager.Stub { "override_assume_no_privilege"; private static final int CONTROL_PARAM_OVERRIDE_ASSUME_NO_PRIVILEGE_DEFAULT = 0; - private class RttShellCommand extends ShellCommand { + private class RttShellCommand extends BasicShellCommandHandler { private Map<String, Integer> mControlParams = new HashMap<>(); @Override @@ -381,9 +381,12 @@ public class RttServiceImpl extends IWifiRttManager.Stub { } @Override - public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, - String[] args, ShellCallback callback, ResultReceiver resultReceiver) { - mShellCommand.exec(this, in, out, err, args, callback, resultReceiver); + public int handleShellCommand(@NonNull ParcelFileDescriptor in, + @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, + @NonNull String[] args) { + return mShellCommand.exec( + this, in.getFileDescriptor(), out.getFileDescriptor(), err.getFileDescriptor(), + args); } /** |