diff options
3 files changed, 106 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/ServiceWatcher.java b/services/core/java/com/android/server/ServiceWatcher.java index cfb79aa3a210..b1b5ec01df6a 100644 --- a/services/core/java/com/android/server/ServiceWatcher.java +++ b/services/core/java/com/android/server/ServiceWatcher.java @@ -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 + "]"; + } } } diff --git a/services/core/java/com/android/server/location/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java index 4f8708a7599a..b2bf1fce0d07 100644 --- a/services/core/java/com/android/server/location/LocationManagerService.java +++ b/services/core/java/com/android/server/location/LocationManagerService.java @@ -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; @@ -2600,6 +2601,14 @@ public class LocationManagerService extends ILocationManager.Stub { } @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)) { return; diff --git a/services/core/java/com/android/server/location/LocationShellCommand.java b/services/core/java/com/android/server/location/LocationShellCommand.java new file mode 100644 index 000000000000..909873f07993 --- /dev/null +++ b/services/core/java/com/android/server/location/LocationShellCommand.java @@ -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"); + } +} |