DO NOT MERGE Add location shell commands to R
Test: manual Bug: 154624964 Change-Id: I60bb117c680d8ff8db0901b67f1d0ce8627091ea
This commit is contained in:
@@ -169,7 +169,11 @@ public class ServiceWatcher implements ServiceConnection {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return component.toShortString() + "@" + version + "[u" + userId + "]";
|
||||
if (component == null) {
|
||||
return "none";
|
||||
} else {
|
||||
return component.toShortString() + "@" + version + "[u" + userId + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.ICancellationSignal;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.ServiceType;
|
||||
import android.os.PowerManagerInternal;
|
||||
@@ -2599,6 +2600,14 @@ public class LocationManagerService extends ILocationManager.Stub {
|
||||
return manager.getMockProviderRequests();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleShellCommand(ParcelFileDescriptor in, ParcelFileDescriptor out,
|
||||
ParcelFileDescriptor err, String[] args) {
|
||||
return new LocationShellCommand(this).exec(
|
||||
this, in.getFileDescriptor(), out.getFileDescriptor(), err.getFileDescriptor(),
|
||||
args);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.location;
|
||||
|
||||
import android.os.BasicShellCommandHandler;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Interprets and executes 'adb shell cmd location [args]'.
|
||||
*/
|
||||
class LocationShellCommand extends BasicShellCommandHandler {
|
||||
|
||||
private final LocationManagerService mService;
|
||||
|
||||
LocationShellCommand(LocationManagerService service) {
|
||||
mService = Objects.requireNonNull(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onCommand(String cmd) {
|
||||
if (cmd == null) {
|
||||
return handleDefaultCommands(null);
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case "set-location-enabled": {
|
||||
int userId = parseUserId();
|
||||
boolean enabled = Boolean.parseBoolean(getNextArgRequired());
|
||||
mService.setLocationEnabledForUser(enabled, userId);
|
||||
return 0;
|
||||
}
|
||||
case "send-extra-command": {
|
||||
String provider = getNextArgRequired();
|
||||
String command = getNextArgRequired();
|
||||
mService.sendExtraCommand(provider, command, null);
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return handleDefaultCommands(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
private int parseUserId() {
|
||||
final String option = getNextOption();
|
||||
if (option != null) {
|
||||
if (option.equals("--user")) {
|
||||
return UserHandle.parseUserArg(getNextArgRequired());
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Expected \"--user\" option, but got \"" + option + "\" instead");
|
||||
}
|
||||
}
|
||||
|
||||
return UserHandle.USER_CURRENT_OR_SELF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHelp() {
|
||||
PrintWriter pw = getOutPrintWriter();
|
||||
pw.println("Location service commands:");
|
||||
pw.println(" help or -h");
|
||||
pw.println(" Print this help text.");
|
||||
pw.println(" set-location-enabled [--user <USER_ID>] true|false");
|
||||
pw.println(" Sets the master location switch enabled state.");
|
||||
pw.println(" send-extra-command <PROVIDER> <COMMAND>");
|
||||
pw.println(" Sends the given extra command to the given provider.");
|
||||
pw.println();
|
||||
pw.println(" Common commands that may be supported by the gps provider, depending on");
|
||||
pw.println(" hardware and software configurations:");
|
||||
pw.println(" delete_aiding_data - requests deletion of any predictive aiding data");
|
||||
pw.println(" force_time_injection - requests NTP time injection to chipset");
|
||||
pw.println(" force_psds_injection - "
|
||||
+ "requests predictive aiding data injection to chipset");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user