diff options
| author | 2019-12-10 09:49:15 +0000 | |
|---|---|---|
| committer | 2019-12-10 09:49:15 +0000 | |
| commit | 745fe374e1582722433ae64d028b532a6804ec7c (patch) | |
| tree | 54ee5e8e1f52b88bd238d6ca9bd1b15308c40770 | |
| parent | 88efc22f267180f1ca1d0eccdcdea6b0843cc351 (diff) | |
| parent | feb6023ccf1cebacbb2039e21acfa01248103bdb (diff) | |
Merge "Revert "Make media command be a shell command""
| -rw-r--r-- | cmds/media/Android.bp | 8 | ||||
| -rw-r--r-- | cmds/media/MODULE_LICENSE_APACHE2 | 0 | ||||
| -rw-r--r-- | cmds/media/NOTICE | 190 | ||||
| -rwxr-xr-x | cmds/media/media | 3 | ||||
| -rw-r--r-- | cmds/media/src/com/android/commands/media/Media.java (renamed from services/core/java/com/android/server/media/MediaShellCommand.java) | 196 | ||||
| -rwxr-xr-x[-rw-r--r--] | cmds/media/src/com/android/commands/media/VolumeCtrl.java (renamed from services/core/java/com/android/server/media/VolumeCtrl.java) | 106 | ||||
| -rw-r--r-- | services/core/java/com/android/server/media/MediaSessionService.java | 8 |
7 files changed, 351 insertions, 160 deletions
diff --git a/cmds/media/Android.bp b/cmds/media/Android.bp new file mode 100644 index 000000000000..7879c53684a7 --- /dev/null +++ b/cmds/media/Android.bp @@ -0,0 +1,8 @@ +// Copyright 2013 The Android Open Source Project +// + +java_binary { + name: "media", + wrapper: "media", + srcs: ["**/*.java"], +} diff --git a/cmds/media/MODULE_LICENSE_APACHE2 b/cmds/media/MODULE_LICENSE_APACHE2 new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/cmds/media/MODULE_LICENSE_APACHE2 diff --git a/cmds/media/NOTICE b/cmds/media/NOTICE new file mode 100644 index 000000000000..c5b1efa7aac7 --- /dev/null +++ b/cmds/media/NOTICE @@ -0,0 +1,190 @@ + + Copyright (c) 2005-2008, 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. + + 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. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/cmds/media/media b/cmds/media/media new file mode 100755 index 000000000000..00c3915f2e65 --- /dev/null +++ b/cmds/media/media @@ -0,0 +1,3 @@ +#!/system/bin/sh +export CLASSPATH=/system/framework/media.jar +exec app_process /system/bin com.android.commands.media.Media "$@" diff --git a/services/core/java/com/android/server/media/MediaShellCommand.java b/cmds/media/src/com/android/commands/media/Media.java index 20df271a1de2..1e915f8232d3 100644 --- a/services/core/java/com/android/server/media/MediaShellCommand.java +++ b/cmds/media/src/com/android/commands/media/Media.java @@ -1,27 +1,29 @@ /* - * Copyright (C) 2019 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.media; +** +** Copyright 2013, 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.commands.media; import android.app.ActivityThread; import android.content.Context; import android.media.MediaMetadata; import android.media.session.ISessionManager; import android.media.session.MediaController; -import android.media.session.MediaSession; +import android.media.session.MediaController.PlaybackInfo; +import android.media.session.MediaSession.QueueItem; import android.media.session.MediaSessionManager; import android.media.session.PlaybackState; import android.os.Bundle; @@ -29,41 +31,59 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; -import android.os.ShellCommand; import android.os.SystemClock; -import android.text.TextUtils; +import android.util.AndroidException; import android.view.InputDevice; import android.view.KeyCharacterMap; import android.view.KeyEvent; +import com.android.internal.os.BaseCommand; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.io.PrintWriter; +import java.io.PrintStream; import java.util.List; -/** - * ShellCommand for MediaSessionService. - */ -public class MediaShellCommand extends ShellCommand { +public class Media extends BaseCommand { // This doesn't belongs to any package. Setting the package name to empty string. private static final String PACKAGE_NAME = ""; private static ActivityThread sThread; private static MediaSessionManager sMediaSessionManager; private ISessionManager mSessionService; - private PrintWriter mWriter; - private PrintWriter mErrorWriter; + + /** + * Command-line entry point. + * + * @param args The command-line arguments + */ + public static void main(String[] args) { + (new Media()).run(args); + } @Override - public int onCommand(String cmd) { - mWriter = getOutPrintWriter(); - mErrorWriter = getErrPrintWriter(); + public void onShowUsage(PrintStream out) { + out.println( + "usage: media [subcommand] [options]\n" + + " media dispatch KEY\n" + + " media list-sessions\n" + + " media monitor <tag>\n" + + " media volume [options]\n" + + "\n" + + "media dispatch: dispatch a media key to the system.\n" + + " KEY may be: play, pause, play-pause, mute, headsethook,\n" + + " stop, next, previous, rewind, record, fast-forword.\n" + + "media list-sessions: print a list of the current sessions.\n" + + "media monitor: monitor updates to the specified session.\n" + + " Use the tag from list-sessions.\n" + + "media volume: " + VolumeCtrl.USAGE + ); + } - if (TextUtils.isEmpty(cmd)) { - return handleDefaultCommands(cmd); - } + @Override + public void onRun() throws Exception { if (sThread == null) { - Looper.prepare(); + Looper.prepareMainLooper(); sThread = ActivityThread.systemMain(); Context context = sThread.getSystemContext(); sMediaSessionManager = @@ -72,47 +92,25 @@ public class MediaShellCommand extends ShellCommand { mSessionService = ISessionManager.Stub.asInterface(ServiceManager.checkService( Context.MEDIA_SESSION_SERVICE)); if (mSessionService == null) { - throw new IllegalStateException( + System.err.println(NO_SYSTEM_ERROR_CODE); + throw new AndroidException( "Can't connect to media session service; is the system running?"); } - try { - if (cmd.equals("dispatch")) { - runDispatch(); - } else if (cmd.equals("list-sessions")) { - runListSessions(); - } else if (cmd.equals("monitor")) { - runMonitor(); - } else if (cmd.equals("volume")) { - runVolume(); - } else { - showError("Error: unknown command '" + cmd + "'"); - return -1; - } - } catch (Exception e) { - showError(e.toString()); - return -1; - } - return 0; - } + String op = nextArgRequired(); - @Override - public void onHelp() { - mWriter.println("usage: media_session [subcommand] [options]"); - mWriter.println(" media_session dispatch KEY"); - mWriter.println(" media_session dispatch KEY"); - mWriter.println(" media_session list-sessions"); - mWriter.println(" media_session monitor <tag>"); - mWriter.println(" media_session volume [options]"); - mWriter.println(); - mWriter.println("media_session dispatch: dispatch a media key to the system."); - mWriter.println(" KEY may be: play, pause, play-pause, mute, headsethook,"); - mWriter.println(" stop, next, previous, rewind, record, fast-forword."); - mWriter.println("media_session list-sessions: print a list of the current sessions."); - mWriter.println("media_session monitor: monitor updates to the specified session."); - mWriter.println(" Use the tag from list-sessions."); - mWriter.println("media_session volume: " + VolumeCtrl.USAGE); - mWriter.println(); + if (op.equals("dispatch")) { + runDispatch(); + } else if (op.equals("list-sessions")) { + runListSessions(); + } else if (op.equals("monitor")) { + runMonitor(); + } else if (op.equals("volume")) { + runVolume(); + } else { + showError("Error: unknown command '" + op + "'"); + return; + } } private void sendMediaKey(KeyEvent event) { @@ -123,7 +121,7 @@ public class MediaShellCommand extends ShellCommand { } private void runMonitor() throws Exception { - String id = getNextArgRequired(); + String id = nextArgRequired(); if (id == null) { showError("Error: must include a session id"); return; @@ -135,8 +133,7 @@ public class MediaShellCommand extends ShellCommand { for (MediaController controller : controllers) { try { if (controller != null && id.equals(controller.getTag())) { - MediaShellCommand.ControllerMonitor monitor = - new MediaShellCommand.ControllerMonitor(controller); + ControllerMonitor monitor = new ControllerMonitor(controller); monitor.run(); success = true; break; @@ -146,15 +143,15 @@ public class MediaShellCommand extends ShellCommand { } } } catch (Exception e) { - mErrorWriter.println("***Error monitoring session*** " + e.getMessage()); + System.out.println("***Error monitoring session*** " + e.getMessage()); } if (!success) { - mErrorWriter.println("No session found with id " + id); + System.out.println("No session found with id " + id); } } private void runDispatch() throws Exception { - String cmd = getNextArgRequired(); + String cmd = nextArgRequired(); int keycode; if ("play".equals(cmd)) { keycode = KeyEvent.KEYCODE_MEDIA_PLAY; @@ -189,73 +186,68 @@ public class MediaShellCommand extends ShellCommand { KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD)); } - void showError(String errMsg) { - onHelp(); - mErrorWriter.println(errMsg); - } - class ControllerCallback extends MediaController.Callback { @Override public void onSessionDestroyed() { - mWriter.println("onSessionDestroyed. Enter q to quit."); + System.out.println("onSessionDestroyed. Enter q to quit."); } @Override public void onSessionEvent(String event, Bundle extras) { - mWriter.println("onSessionEvent event=" + event + ", extras=" + extras); + System.out.println("onSessionEvent event=" + event + ", extras=" + extras); } @Override public void onPlaybackStateChanged(PlaybackState state) { - mWriter.println("onPlaybackStateChanged " + state); + System.out.println("onPlaybackStateChanged " + state); } @Override public void onMetadataChanged(MediaMetadata metadata) { String mmString = metadata == null ? null : "title=" + metadata .getDescription(); - mWriter.println("onMetadataChanged " + mmString); + System.out.println("onMetadataChanged " + mmString); } @Override - public void onQueueChanged(List<MediaSession.QueueItem> queue) { - mWriter.println("onQueueChanged, " + public void onQueueChanged(List<QueueItem> queue) { + System.out.println("onQueueChanged, " + (queue == null ? "null queue" : " size=" + queue.size())); } @Override public void onQueueTitleChanged(CharSequence title) { - mWriter.println("onQueueTitleChange " + title); + System.out.println("onQueueTitleChange " + title); } @Override public void onExtrasChanged(Bundle extras) { - mWriter.println("onExtrasChanged " + extras); + System.out.println("onExtrasChanged " + extras); } @Override - public void onAudioInfoChanged(MediaController.PlaybackInfo info) { - mWriter.println("onAudioInfoChanged " + info); + public void onAudioInfoChanged(PlaybackInfo info) { + System.out.println("onAudioInfoChanged " + info); } } private class ControllerMonitor { private final MediaController mController; - private final MediaShellCommand.ControllerCallback mControllerCallback; + private final ControllerCallback mControllerCallback; ControllerMonitor(MediaController controller) { mController = controller; - mControllerCallback = new MediaShellCommand.ControllerCallback(); + mControllerCallback = new ControllerCallback(); } void printUsageMessage() { try { - mWriter.println("V2Monitoring session " + mController.getTag() + System.out.println("V2Monitoring session " + mController.getTag() + "... available commands: play, pause, next, previous"); } catch (RuntimeException e) { - mWriter.println("Error trying to monitor session!"); + System.out.println("Error trying to monitor session!"); } - mWriter.println("(q)uit: finish monitoring"); + System.out.println("(q)uit: finish monitoring"); } void run() throws RemoteException { @@ -266,7 +258,7 @@ public class MediaShellCommand extends ShellCommand { try { mController.registerCallback(mControllerCallback); } catch (RuntimeException e) { - mErrorWriter.println("Error registering monitor callback"); + System.out.println("Error registering monitor callback"); } } }; @@ -292,7 +284,7 @@ public class MediaShellCommand extends ShellCommand { } else if ("previous".equals(line)) { dispatchKeyCode(KeyEvent.KEYCODE_MEDIA_PREVIOUS); } else { - mErrorWriter.println("Invalid command: " + line); + System.out.println("Invalid command: " + line); } synchronized (this) { @@ -324,19 +316,19 @@ public class MediaShellCommand extends ShellCommand { mController.dispatchMediaButtonEvent(down); mController.dispatchMediaButtonEvent(up); } catch (RuntimeException e) { - mErrorWriter.println("Failed to dispatch " + keyCode); + System.out.println("Failed to dispatch " + keyCode); } } } private void runListSessions() { - mWriter.println("Sessions:"); + System.out.println("Sessions:"); try { List<MediaController> controllers = sMediaSessionManager.getActiveSessions(null); for (MediaController controller : controllers) { if (controller != null) { try { - mWriter.println(" tag=" + controller.getTag() + System.out.println(" tag=" + controller.getTag() + ", package=" + controller.getPackageName()); } catch (RuntimeException e) { // ignore @@ -344,7 +336,7 @@ public class MediaShellCommand extends ShellCommand { } } } catch (Exception e) { - mErrorWriter.println("***Error listing sessions***"); + System.out.println("***Error listing sessions***"); } } diff --git a/services/core/java/com/android/server/media/VolumeCtrl.java b/cmds/media/src/com/android/commands/media/VolumeCtrl.java index 7a2666566ea2..1629c6f178f0 100644..100755 --- a/services/core/java/com/android/server/media/VolumeCtrl.java +++ b/cmds/media/src/com/android/commands/media/VolumeCtrl.java @@ -1,20 +1,21 @@ /* - * Copyright (C) 2019 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.media; +** +** Copyright 2016, 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.commands.media; import android.content.Context; import android.media.AudioManager; @@ -25,41 +26,45 @@ import android.util.AndroidException; import com.android.internal.os.BaseCommand; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.lang.ArrayIndexOutOfBoundsException; + /** * Command line tool to exercise AudioService.setStreamVolume() * and AudioService.adjustStreamVolume() */ public class VolumeCtrl { - private static final String TAG = "VolumeCtrl"; + private final static String TAG = "VolumeCtrl"; // --stream affects --set, --adj or --get options. // --show affects --set and --adj options. // --get can be used with --set, --adj or by itself. - public static final String USAGE = new String("the options are as follows: \n" - + "\t\t--stream STREAM selects the stream to control, see AudioManager.STREAM_*\n" - + "\t\t controls AudioManager.STREAM_MUSIC if no stream is specified\n" - + "\t\t--set INDEX sets the volume index value\n" - + "\t\t--adj DIRECTION adjusts the volume, use raise|same|lower for the direction\n" - + "\t\t--get outputs the current volume\n" - + "\t\t--show shows the UI during the volume change\n" - + "\texamples:\n" - + "\t\tadb shell media volume --show --stream 3 --set 11\n" - + "\t\tadb shell media volume --stream 0 --adj lower\n" - + "\t\tadb shell media volume --stream 3 --get\n" - ); - - private static final int VOLUME_CONTROL_MODE_SET = 1; - private static final int VOLUME_CONTROL_MODE_ADJUST = 2; - - private static final String ADJUST_LOWER = "lower"; - private static final String ADJUST_SAME = "same"; - private static final String ADJUST_RAISE = "raise"; - - /** - * Runs a given MediaShellCommand - */ - public static void run(MediaShellCommand cmd) throws Exception { + public final static String USAGE = new String( + "the options are as follows: \n" + + "\t\t--stream STREAM selects the stream to control, see AudioManager.STREAM_*\n" + + "\t\t controls AudioManager.STREAM_MUSIC if no stream is specified\n"+ + "\t\t--set INDEX sets the volume index value\n" + + "\t\t--adj DIRECTION adjusts the volume, use raise|same|lower for the direction\n" + + "\t\t--get outputs the current volume\n" + + "\t\t--show shows the UI during the volume change\n" + + "\texamples:\n" + + "\t\tadb shell media volume --show --stream 3 --set 11\n" + + "\t\tadb shell media volume --stream 0 --adj lower\n" + + "\t\tadb shell media volume --stream 3 --get\n" + ); + + private final static int VOLUME_CONTROL_MODE_SET = 1; + private final static int VOLUME_CONTROL_MODE_ADJUST = 2; + + private final static String ADJUST_LOWER = "lower"; + private final static String ADJUST_SAME = "same"; + private final static String ADJUST_RAISE = "raise"; + + public static void run(BaseCommand cmd) throws Exception { //---------------------------------------- // Default parameters int stream = AudioManager.STREAM_MUSIC; @@ -73,7 +78,7 @@ public class VolumeCtrl { // read options String option; String adjustment = null; - while ((option = cmd.getNextOption()) != null) { + while ((option = cmd.nextOption()) != null) { switch (option) { case "--show": showUi = true; @@ -83,17 +88,17 @@ public class VolumeCtrl { log(LOG_V, "will get volume"); break; case "--stream": - stream = Integer.decode(cmd.getNextArgRequired()).intValue(); + stream = Integer.decode(cmd.nextArgRequired()).intValue(); log(LOG_V, "will control stream=" + stream + " (" + streamName(stream) + ")"); break; case "--set": - volIndex = Integer.decode(cmd.getNextArgRequired()).intValue(); + volIndex = Integer.decode(cmd.nextArgRequired()).intValue(); mode = VOLUME_CONTROL_MODE_SET; log(LOG_V, "will set volume to index=" + volIndex); break; case "--adj": mode = VOLUME_CONTROL_MODE_ADJUST; - adjustment = cmd.getNextArgRequired(); + adjustment = cmd.nextArgRequired(); log(LOG_V, "will adjust volume"); break; default: @@ -135,7 +140,7 @@ public class VolumeCtrl { if ((volIndex > audioService.getStreamMaxVolume(stream)) || (volIndex < audioService.getStreamMinVolume(stream))) { cmd.showError(String.format("Error: invalid volume index %d for stream %d " - + "(should be in [%d..%d])", volIndex, stream, + + "(should be in [%d..%d])", volIndex, stream, audioService.getStreamMinVolume(stream), audioService.getStreamMaxVolume(stream))); return; @@ -144,7 +149,7 @@ public class VolumeCtrl { //---------------------------------------- // Non-interactive test - final int flag = showUi ? AudioManager.FLAG_SHOW_UI : 0; + final int flag = showUi? AudioManager.FLAG_SHOW_UI : 0; final String pack = cmd.getClass().getPackage().getName(); if (mode == VOLUME_CONTROL_MODE_SET) { audioService.setStreamVolume(stream, volIndex, flag, pack/*callingPackage*/); @@ -152,9 +157,9 @@ public class VolumeCtrl { audioService.adjustStreamVolume(stream, adjDir, flag, pack); } if (doGet) { - log(LOG_V, "volume is " + audioService.getStreamVolume(stream) - + " in range [" + audioService.getStreamMinVolume(stream) - + ".." + audioService.getStreamMaxVolume(stream) + "]"); + log(LOG_V, "volume is " + audioService.getStreamVolume(stream) + + " in range [" + audioService.getStreamMinVolume(stream) + + ".." + audioService.getStreamMaxVolume(stream) + "]"); } } @@ -176,4 +181,5 @@ public class VolumeCtrl { return "invalid stream"; } } + } diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index 2cb7e3b62479..c25e206d9104 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -70,7 +70,6 @@ import android.os.RemoteCallbackList; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ServiceManager; -import android.os.ShellCallback; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; @@ -1043,13 +1042,6 @@ public class MediaSessionService extends SystemService implements Monitor { private boolean mVoiceButtonHandled = false; @Override - public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, - String[] args, ShellCallback callback, ResultReceiver resultReceiver) { - (new MediaShellCommand()).exec(this, in, out, err, args, callback, - resultReceiver); - } - - @Override public ISession createSession(String packageName, ISessionCallback cb, String tag, Bundle sessionInfo, int userId) throws RemoteException { final int pid = Binder.getCallingPid(); |