Makoto Onuki | 9498621 | 2018-04-11 16:24:46 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.server.content; |
| 17 | |
| 18 | import android.content.IContentService; |
| 19 | import android.content.Intent; |
| 20 | import android.os.RemoteException; |
| 21 | import android.os.ShellCommand; |
| 22 | |
| 23 | import java.io.PrintWriter; |
| 24 | |
| 25 | public class ContentShellCommand extends ShellCommand { |
| 26 | final IContentService mInterface; |
| 27 | |
| 28 | ContentShellCommand(IContentService service) { |
| 29 | mInterface = service; |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public int onCommand(String cmd) { |
| 34 | if (cmd == null) { |
| 35 | return handleDefaultCommands(cmd); |
| 36 | } |
| 37 | |
| 38 | final PrintWriter pw = getOutPrintWriter(); |
| 39 | try { |
| 40 | switch(cmd) { |
| 41 | case "reset-today-stats": |
| 42 | return runResetTodayStats(); |
| 43 | default: |
| 44 | return handleDefaultCommands(cmd); |
| 45 | } |
| 46 | } catch (RemoteException e) { |
| 47 | pw.println("Remote exception: " + e); |
| 48 | } |
| 49 | return -1; |
| 50 | } |
| 51 | |
| 52 | private int runResetTodayStats() throws RemoteException { |
| 53 | mInterface.resetTodayStats(); |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void onHelp() { |
| 59 | final PrintWriter pw = getOutPrintWriter(); |
| 60 | pw.println("Content service commands:"); |
| 61 | pw.println(" help"); |
| 62 | pw.println(" Print this help text."); |
| 63 | pw.println(""); |
| 64 | pw.println(" reset-today-stats"); |
| 65 | pw.println(" Reset 1-day sync stats."); |
| 66 | pw.println(); |
| 67 | } |
| 68 | } |