Home | History | Annotate | Download | only in statusbar
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
      5  * except in compliance with the License. You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the
     10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     11  * KIND, either express or implied. See the License for the specific language governing
     12  * permissions and limitations under the License.
     13  */
     14 
     15 package com.android.server.statusbar;
     16 
     17 import android.content.ComponentName;
     18 import android.os.RemoteException;
     19 import android.os.ShellCommand;
     20 import android.service.quicksettings.TileService;
     21 
     22 import com.android.internal.statusbar.IStatusBarService;
     23 
     24 import java.io.PrintWriter;
     25 
     26 public class StatusBarShellCommand extends ShellCommand {
     27 
     28     private final IStatusBarService mInterface;
     29 
     30     public StatusBarShellCommand(StatusBarManagerService service) {
     31         mInterface = service;
     32     }
     33 
     34     @Override
     35     public int onCommand(String cmd) {
     36         if (cmd == null) {
     37             return handleDefaultCommands(cmd);
     38         }
     39         try {
     40             switch (cmd) {
     41                 case "expand-notifications":
     42                     return runExpandNotifications();
     43                 case "expand-settings":
     44                     return runExpandSettings();
     45                 case "collapse":
     46                     return runCollapse();
     47                 case "add-tile":
     48                     return runAddTile();
     49                 case "remove-tile":
     50                     return runRemoveTile();
     51                 case "click-tile":
     52                     return runClickTile();
     53                 case "check-support":
     54                     final PrintWriter pw = getOutPrintWriter();
     55                     pw.println(String.valueOf(TileService.isQuickSettingsSupported()));
     56                     return 0;
     57                 default:
     58                     return handleDefaultCommands(cmd);
     59             }
     60         } catch (RemoteException e) {
     61             final PrintWriter pw = getOutPrintWriter();
     62             pw.println("Remote exception: " + e);
     63         }
     64         return -1;
     65     }
     66 
     67     private int runAddTile() throws RemoteException {
     68         mInterface.addTile(ComponentName.unflattenFromString(getNextArgRequired()));
     69         return 0;
     70     }
     71 
     72     private int runRemoveTile() throws RemoteException {
     73         mInterface.remTile(ComponentName.unflattenFromString(getNextArgRequired()));
     74         return 0;
     75     }
     76 
     77     private int runClickTile() throws RemoteException {
     78         mInterface.clickTile(ComponentName.unflattenFromString(getNextArgRequired()));
     79         return 0;
     80     }
     81 
     82     private int runCollapse() throws RemoteException {
     83         mInterface.collapsePanels();
     84         return 0;
     85     }
     86 
     87     private int runExpandSettings() throws RemoteException {
     88         mInterface.expandSettingsPanel(null);
     89         return 0;
     90     }
     91 
     92     private int runExpandNotifications() throws RemoteException {
     93         mInterface.expandNotificationsPanel();
     94         return 0;
     95     }
     96 
     97     @Override
     98     public void onHelp() {
     99         final PrintWriter pw = getOutPrintWriter();
    100         pw.println("Status bar commands:");
    101         pw.println("  help");
    102         pw.println("    Print this help text.");
    103         pw.println("");
    104         pw.println("  expand-notifications");
    105         pw.println("    Open the notifications panel.");
    106         pw.println("");
    107         pw.println("  expand-settings");
    108         pw.println("    Open the notifications panel and expand quick settings if present.");
    109         pw.println("");
    110         pw.println("  collapse");
    111         pw.println("    Collapse the notifications and settings panel.");
    112         pw.println("");
    113         pw.println("  add-tile COMPONENT");
    114         pw.println("    Add a TileService of the specified component");
    115         pw.println("");
    116         pw.println("  remove-tile COMPONENT");
    117         pw.println("    Remove a TileService of the specified component");
    118         pw.println("");
    119         pw.println("  click-tile COMPONENT");
    120         pw.println("    Click on a TileService of the specified component");
    121         pw.println("");
    122         pw.println("  check-support");
    123         pw.println("    Check if this device supports QS + APIs");
    124         pw.println("");
    125     }
    126 }
    127