diff options
author | Etan Cohen <etancohen@google.com> | 2017-05-08 21:07:52 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-05-08 21:07:54 +0000 |
commit | d37cf4983e33284fc00f2e8cab05214bd044d6a4 (patch) | |
tree | 7cf4916ad5faf7ff1022d335ad9c81fe3f70c9ce /service | |
parent | 4a5bd37a54b45b5ec76fdd4ddf0fba4a0eede3bf (diff) | |
parent | dc929704e04d634eff04dfd55024b18578be9717 (diff) |
Merge "[AWARE] Add wifiaware shell command interface"
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java | 9 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java | 72 |
2 files changed, 81 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java index fa695cd82..49e3bb9a7 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java @@ -32,6 +32,8 @@ import android.os.Binder; import android.os.HandlerThread; import android.os.IBinder; import android.os.RemoteException; +import android.os.ResultReceiver; +import android.os.ShellCallback; import android.util.Log; import android.util.SparseArray; import android.util.SparseIntArray; @@ -371,6 +373,13 @@ public class WifiAwareServiceImpl extends IWifiAwareManager.Stub { } @Override + public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, + String[] args, ShellCallback callback, ResultReceiver resultReceiver) { + (new WifiAwareShellCommand(mStateManager)).exec(this, in, out, err, args, callback, + resultReceiver); + } + + @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission( android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { diff --git a/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java b/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java new file mode 100644 index 000000000..de8bfa73b --- /dev/null +++ b/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2017 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.wifi.aware; + +import android.app.AppGlobals; +import android.content.pm.IPackageManager; +import android.os.Binder; +import android.os.ShellCommand; + +import java.io.PrintWriter; + +/** + * Interprets and executes 'adb shell cmd wifiaware [args]'. + */ +public class WifiAwareShellCommand extends ShellCommand { + private final WifiAwareStateManager mStateManager; + private final IPackageManager mPM; + + WifiAwareShellCommand(WifiAwareStateManager stateManager) { + mStateManager = stateManager; + mPM = AppGlobals.getPackageManager(); + } + + @Override + public int onCommand(String cmd) { + checkRootPermission(); + + final PrintWriter pw = getOutPrintWriter(); + try { + switch (cmd != null ? cmd : "") { + default: + return handleDefaultCommands(cmd); + } + } catch (Exception e) { + pw.println("Exception: " + e); + } + return -1; + } + + private void checkRootPermission() { + final int uid = Binder.getCallingUid(); + if (uid == 0) { + // Root can do anything. + return; + } + throw new SecurityException("Uid " + uid + " does not have access to wifiaware commands"); + } + + @Override + public void onHelp() { + final PrintWriter pw = getOutPrintWriter(); + + pw.println("Wi-Fi Aware (wifiaware) commands:"); + pw.println(" help"); + pw.println(" Print this help text."); + pw.println(); + } +} |