diff options
| -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-- | services/core/java/com/android/server/media/MediaSessionService.java | 8 | ||||
| -rw-r--r-- | services/core/java/com/android/server/media/MediaShellCommand.java (renamed from cmds/media/src/com/android/commands/media/Media.java) | 196 | ||||
| -rw-r--r--[-rwxr-xr-x] | services/core/java/com/android/server/media/VolumeCtrl.java (renamed from cmds/media/src/com/android/commands/media/VolumeCtrl.java) | 106 |
7 files changed, 160 insertions, 351 deletions
diff --git a/cmds/media/Android.bp b/cmds/media/Android.bp deleted file mode 100644 index 7879c53684a7..000000000000 --- a/cmds/media/Android.bp +++ /dev/null @@ -1,8 +0,0 @@ -// 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 deleted file mode 100644 index e69de29bb2d1..000000000000 --- a/cmds/media/MODULE_LICENSE_APACHE2 +++ /dev/null diff --git a/cmds/media/NOTICE b/cmds/media/NOTICE deleted file mode 100644 index c5b1efa7aac7..000000000000 --- a/cmds/media/NOTICE +++ /dev/null @@ -1,190 +0,0 @@ - - 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 deleted file mode 100755 index 00c3915f2e65..000000000000 --- a/cmds/media/media +++ /dev/null @@ -1,3 +0,0 @@ -#!/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/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index c25e206d9104..2cb7e3b62479 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -70,6 +70,7 @@ 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; @@ -1042,6 +1043,13 @@ 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(); diff --git a/cmds/media/src/com/android/commands/media/Media.java b/services/core/java/com/android/server/media/MediaShellCommand.java index 1e915f8232d3..20df271a1de2 100644 --- a/cmds/media/src/com/android/commands/media/Media.java +++ b/services/core/java/com/android/server/media/MediaShellCommand.java @@ -1,29 +1,27 @@ /* -** -** 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; + * 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; 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.MediaController.PlaybackInfo; -import android.media.session.MediaSession.QueueItem; +import android.media.session.MediaSession; import android.media.session.MediaSessionManager; import android.media.session.PlaybackState; import android.os.Bundle; @@ -31,59 +29,41 @@ 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.util.AndroidException; +import android.text.TextUtils; 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.PrintStream; +import java.io.PrintWriter; import java.util.List; -public class Media extends BaseCommand { +/** + * ShellCommand for MediaSessionService. + */ +public class MediaShellCommand extends ShellCommand { // 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; - - /** - * Command-line entry point. - * - * @param args The command-line arguments - */ - public static void main(String[] args) { - (new Media()).run(args); - } + private PrintWriter mWriter; + private PrintWriter mErrorWriter; @Override - 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 - ); - } + public int onCommand(String cmd) { + mWriter = getOutPrintWriter(); + mErrorWriter = getErrPrintWriter(); - @Override - public void onRun() throws Exception { + if (TextUtils.isEmpty(cmd)) { + return handleDefaultCommands(cmd); + } if (sThread == null) { - Looper.prepareMainLooper(); + Looper.prepare(); sThread = ActivityThread.systemMain(); Context context = sThread.getSystemContext(); sMediaSessionManager = @@ -92,25 +72,47 @@ public class Media extends BaseCommand { mSessionService = ISessionManager.Stub.asInterface(ServiceManager.checkService( Context.MEDIA_SESSION_SERVICE)); if (mSessionService == null) { - System.err.println(NO_SYSTEM_ERROR_CODE); - throw new AndroidException( + throw new IllegalStateException( "Can't connect to media session service; is the system running?"); } - String op = nextArgRequired(); - - 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; + 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; + } + + @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(); } private void sendMediaKey(KeyEvent event) { @@ -121,7 +123,7 @@ public class Media extends BaseCommand { } private void runMonitor() throws Exception { - String id = nextArgRequired(); + String id = getNextArgRequired(); if (id == null) { showError("Error: must include a session id"); return; @@ -133,7 +135,8 @@ public class Media extends BaseCommand { for (MediaController controller : controllers) { try { if (controller != null && id.equals(controller.getTag())) { - ControllerMonitor monitor = new ControllerMonitor(controller); + MediaShellCommand.ControllerMonitor monitor = + new MediaShellCommand.ControllerMonitor(controller); monitor.run(); success = true; break; @@ -143,15 +146,15 @@ public class Media extends BaseCommand { } } } catch (Exception e) { - System.out.println("***Error monitoring session*** " + e.getMessage()); + mErrorWriter.println("***Error monitoring session*** " + e.getMessage()); } if (!success) { - System.out.println("No session found with id " + id); + mErrorWriter.println("No session found with id " + id); } } private void runDispatch() throws Exception { - String cmd = nextArgRequired(); + String cmd = getNextArgRequired(); int keycode; if ("play".equals(cmd)) { keycode = KeyEvent.KEYCODE_MEDIA_PLAY; @@ -186,68 +189,73 @@ public class Media extends BaseCommand { 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() { - System.out.println("onSessionDestroyed. Enter q to quit."); + mWriter.println("onSessionDestroyed. Enter q to quit."); } @Override public void onSessionEvent(String event, Bundle extras) { - System.out.println("onSessionEvent event=" + event + ", extras=" + extras); + mWriter.println("onSessionEvent event=" + event + ", extras=" + extras); } @Override public void onPlaybackStateChanged(PlaybackState state) { - System.out.println("onPlaybackStateChanged " + state); + mWriter.println("onPlaybackStateChanged " + state); } @Override public void onMetadataChanged(MediaMetadata metadata) { String mmString = metadata == null ? null : "title=" + metadata .getDescription(); - System.out.println("onMetadataChanged " + mmString); + mWriter.println("onMetadataChanged " + mmString); } @Override - public void onQueueChanged(List<QueueItem> queue) { - System.out.println("onQueueChanged, " + public void onQueueChanged(List<MediaSession.QueueItem> queue) { + mWriter.println("onQueueChanged, " + (queue == null ? "null queue" : " size=" + queue.size())); } @Override public void onQueueTitleChanged(CharSequence title) { - System.out.println("onQueueTitleChange " + title); + mWriter.println("onQueueTitleChange " + title); } @Override public void onExtrasChanged(Bundle extras) { - System.out.println("onExtrasChanged " + extras); + mWriter.println("onExtrasChanged " + extras); } @Override - public void onAudioInfoChanged(PlaybackInfo info) { - System.out.println("onAudioInfoChanged " + info); + public void onAudioInfoChanged(MediaController.PlaybackInfo info) { + mWriter.println("onAudioInfoChanged " + info); } } private class ControllerMonitor { private final MediaController mController; - private final ControllerCallback mControllerCallback; + private final MediaShellCommand.ControllerCallback mControllerCallback; ControllerMonitor(MediaController controller) { mController = controller; - mControllerCallback = new ControllerCallback(); + mControllerCallback = new MediaShellCommand.ControllerCallback(); } void printUsageMessage() { try { - System.out.println("V2Monitoring session " + mController.getTag() + mWriter.println("V2Monitoring session " + mController.getTag() + "... available commands: play, pause, next, previous"); } catch (RuntimeException e) { - System.out.println("Error trying to monitor session!"); + mWriter.println("Error trying to monitor session!"); } - System.out.println("(q)uit: finish monitoring"); + mWriter.println("(q)uit: finish monitoring"); } void run() throws RemoteException { @@ -258,7 +266,7 @@ public class Media extends BaseCommand { try { mController.registerCallback(mControllerCallback); } catch (RuntimeException e) { - System.out.println("Error registering monitor callback"); + mErrorWriter.println("Error registering monitor callback"); } } }; @@ -284,7 +292,7 @@ public class Media extends BaseCommand { } else if ("previous".equals(line)) { dispatchKeyCode(KeyEvent.KEYCODE_MEDIA_PREVIOUS); } else { - System.out.println("Invalid command: " + line); + mErrorWriter.println("Invalid command: " + line); } synchronized (this) { @@ -316,19 +324,19 @@ public class Media extends BaseCommand { mController.dispatchMediaButtonEvent(down); mController.dispatchMediaButtonEvent(up); } catch (RuntimeException e) { - System.out.println("Failed to dispatch " + keyCode); + mErrorWriter.println("Failed to dispatch " + keyCode); } } } private void runListSessions() { - System.out.println("Sessions:"); + mWriter.println("Sessions:"); try { List<MediaController> controllers = sMediaSessionManager.getActiveSessions(null); for (MediaController controller : controllers) { if (controller != null) { try { - System.out.println(" tag=" + controller.getTag() + mWriter.println(" tag=" + controller.getTag() + ", package=" + controller.getPackageName()); } catch (RuntimeException e) { // ignore @@ -336,7 +344,7 @@ public class Media extends BaseCommand { } } } catch (Exception e) { - System.out.println("***Error listing sessions***"); + mErrorWriter.println("***Error listing sessions***"); } } diff --git a/cmds/media/src/com/android/commands/media/VolumeCtrl.java b/services/core/java/com/android/server/media/VolumeCtrl.java index 1629c6f178f0..7a2666566ea2 100755..100644 --- a/cmds/media/src/com/android/commands/media/VolumeCtrl.java +++ b/services/core/java/com/android/server/media/VolumeCtrl.java @@ -1,21 +1,20 @@ /* -** -** 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; + * 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; import android.content.Context; import android.media.AudioManager; @@ -26,45 +25,41 @@ 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 final static String TAG = "VolumeCtrl"; + private static final 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 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 { + 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 { //---------------------------------------- // Default parameters int stream = AudioManager.STREAM_MUSIC; @@ -78,7 +73,7 @@ public class VolumeCtrl { // read options String option; String adjustment = null; - while ((option = cmd.nextOption()) != null) { + while ((option = cmd.getNextOption()) != null) { switch (option) { case "--show": showUi = true; @@ -88,17 +83,17 @@ public class VolumeCtrl { log(LOG_V, "will get volume"); break; case "--stream": - stream = Integer.decode(cmd.nextArgRequired()).intValue(); + stream = Integer.decode(cmd.getNextArgRequired()).intValue(); log(LOG_V, "will control stream=" + stream + " (" + streamName(stream) + ")"); break; case "--set": - volIndex = Integer.decode(cmd.nextArgRequired()).intValue(); + volIndex = Integer.decode(cmd.getNextArgRequired()).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.nextArgRequired(); + adjustment = cmd.getNextArgRequired(); log(LOG_V, "will adjust volume"); break; default: @@ -140,7 +135,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; @@ -149,7 +144,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*/); @@ -157,9 +152,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) + "]"); } } @@ -181,5 +176,4 @@ public class VolumeCtrl { return "invalid stream"; } } - } |