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 com.android.internal.statusbar.IStatusBarService;
     21 
     22 import java.io.PrintWriter;
     23 
     24 public class StatusBarShellCommand extends ShellCommand {
     25 
     26     private final IStatusBarService mInterface;
     27 
     28     public StatusBarShellCommand(StatusBarManagerService service) {
     29         mInterface = service;
     30     }
     31 
     32     @Override
     33     public int onCommand(String cmd) {
     34         if (cmd == null) {
     35             return handleDefaultCommands(cmd);
     36         }
     37         try {
     38             switch (cmd) {
     39                 case "expand-notifications":
     40                     return runExpandNotifications();
     41                 case "expand-settings":
     42                     return runExpandSettings();
     43                 case "collapse":
     44                     return runCollapse();
     45                 case "add-tile":
     46                     return runAddTile();
     47                 case "remove-tile":
     48                     return runRemoveTile();
     49                 case "click-tile":
     50                     return runClickTile();
     51                 default:
     52                     return handleDefaultCommands(cmd);
     53             }
     54         } catch (RemoteException e) {
     55             final PrintWriter pw = getOutPrintWriter();
     56             pw.println("Remote exception: " + e);
     57         }
     58         return -1;
     59     }
     60 
     61     private int runAddTile() throws RemoteException {
     62         mInterface.addTile(ComponentName.unflattenFromString(getNextArgRequired()));
     63         return 0;
     64     }
     65 
     66     private int runRemoveTile() throws RemoteException {
     67         mInterface.remTile(ComponentName.unflattenFromString(getNextArgRequired()));
     68         return 0;
     69     }
     70 
     71     private int runClickTile() throws RemoteException {
     72         mInterface.clickTile(ComponentName.unflattenFromString(getNextArgRequired()));
     73         return 0;
     74     }
     75 
     76     private int runCollapse() throws RemoteException {
     77         mInterface.collapsePanels();
     78         return 0;
     79     }
     80 
     81     private int runExpandSettings() throws RemoteException {
     82         mInterface.expandSettingsPanel(null);
     83         return 0;
     84     }
     85 
     86     private int runExpandNotifications() throws RemoteException {
     87         mInterface.expandNotificationsPanel();
     88         return 0;
     89     }
     90 
     91     @Override
     92     public void onHelp() {
     93         final PrintWriter pw = getOutPrintWriter();
     94         pw.println("Status bar commands:");
     95         pw.println("  help");
     96         pw.println("    Print this help text.");
     97         pw.println("");
     98         pw.println("  expand-notifications");
     99         pw.println("    Open the notifications panel.");
    100         pw.println("");
    101         pw.println("  expand-settings");
    102         pw.println("    Open the notifications panel and expand quick settings if present.");
    103         pw.println("");
    104         pw.println("  collapse");
    105         pw.println("    Collapse the notifications and settings panel.");
    106         pw.println("");
    107         pw.println("  add-tile COMPONENT");
    108         pw.println("    Add a TileService of the specified component");
    109         pw.println("");
    110         pw.println("  remove-tile COMPONENT");
    111         pw.println("    Remove a TileService of the specified component");
    112         pw.println("");
    113         pw.println("  click-tile COMPONENT");
    114         pw.println("    Click on a TileService of the specified component");
    115         pw.println("");
    116     }
    117 }
    118