diff options
author | Karthik Ravi Shankar <karthikrs@google.com> | 2017-03-26 02:46:48 -0700 |
---|---|---|
committer | Karthik Ravi Shankar <karthikrs@google.com> | 2017-03-31 08:37:12 -0700 |
commit | 74db2a3667e69138e2af8ea4ff053a43cc262aa8 (patch) | |
tree | b6e48f7dcc0ed10cbb223b4c7a984e09becaf779 /cmds/vr/src | |
parent | 99493dbc94989d4493ca6acb0db265a02f49f62e (diff) |
Add vr persistent mode enable/disable
Persistent vr mode toggle control is needed sometimes from command line.
This also adds the infrastructure for future vr commands.
Bug: 36071574
Test: adb shell vr set-persistent-vr-mode-enabled true
adb shell dumpsys vrmanager
>> Persistent VR mode is currently: enabled
adb shell vr set-persistent-vr-mode-enabled false
adb shell dumpsys vrmanager
>> Persistent VR mode is currently: disabled
Change-Id: I47a858e0696a907e746d50e2c6ca3d18197864a7
Signed-off-by: Karthik Ravi Shankar <karthikrs@google.com>
Diffstat (limited to 'cmds/vr/src')
-rw-r--r-- | cmds/vr/src/com/android/commands/vr/Vr.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/cmds/vr/src/com/android/commands/vr/Vr.java b/cmds/vr/src/com/android/commands/vr/Vr.java new file mode 100644 index 000000000000..3fb40fbc2ca9 --- /dev/null +++ b/cmds/vr/src/com/android/commands/vr/Vr.java @@ -0,0 +1,78 @@ +/* + * 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.commands.vr; + +import android.content.Context; +import android.os.RemoteException; +import android.os.ServiceManager; + +import android.service.vr.IVrManager; +import com.android.internal.os.BaseCommand; + +import java.io.PrintStream; + +public final class Vr extends BaseCommand { + + /** + * Command-line entry point. + * + * @param args The command-line arguments + */ + public static void main(String[] args) { + (new Vr()).run(args); + } + + private static final String COMMAND_SET_PERSISTENT_VR_MODE_ENABLED = "set-persistent-vr-mode-enabled"; + + private IVrManager mVrService; + + @Override + public void onShowUsage(PrintStream out) { + out.println( + "usage: vr [subcommand]\n" + + "usage: vr set-persistent-vr-mode-enabled [true|false]\n" + ); + } + + @Override + public void onRun() throws Exception { + mVrService = IVrManager.Stub.asInterface(ServiceManager.getService(Context.VR_SERVICE)); + if (mVrService == null) { + showError("Error: Could not access the Vr Manager. Is the system running?"); + return; + } + + String command = nextArgRequired(); + switch (command) { + case COMMAND_SET_PERSISTENT_VR_MODE_ENABLED: + runSetPersistentVrModeEnabled(); + break; + default: + throw new IllegalArgumentException ("unknown command '" + command + "'"); + } + } + + private void runSetPersistentVrModeEnabled() throws RemoteException { + String enableStr = nextArg(); + boolean enabled = Boolean.parseBoolean(enableStr); + try { + mVrService.setPersistentVrModeEnabled(enabled); + } catch (RemoteException re) { + System.err.println("Error: Can't set persistent mode " + re); + } + } +} |