Home | History | Annotate | Download | only in statusbartest
      1 /*
      2  * Copyright (C) 2007 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 
     17 package com.android.statusbartest;
     18 
     19 import android.app.Notification;
     20 import android.app.NotificationManager;
     21 import android.view.View;
     22 import android.content.Intent;
     23 import android.app.PendingIntent;
     24 import android.app.StatusBarManager;
     25 import android.os.Handler;
     26 import android.util.Log;
     27 import android.os.SystemClock;
     28 import android.view.Window;
     29 import android.view.WindowManager;
     30 
     31 public class StatusBarTest extends TestActivity
     32 {
     33     private final static String TAG = "StatusBarTest";
     34     StatusBarManager mStatusBarManager;
     35     NotificationManager mNotificationManager;
     36     Handler mHandler = new Handler();
     37     int mUiVisibility = 0;
     38     View mListView;
     39 
     40     View.OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener
     41             = new View.OnSystemUiVisibilityChangeListener() {
     42         public void onSystemUiVisibilityChange(int visibility) {
     43             Log.d(TAG, "onSystemUiVisibilityChange visibility=" + visibility);
     44         }
     45     };
     46 
     47     @Override
     48     protected String tag() {
     49         return TAG;
     50     }
     51 
     52     @Override
     53     protected Test[] tests() {
     54         mStatusBarManager = (StatusBarManager)getSystemService(STATUS_BAR_SERVICE);
     55         mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
     56 
     57         return mTests;
     58     }
     59 
     60     @Override
     61     public void onResume() {
     62         super.onResume();
     63 
     64         mListView = findViewById(android.R.id.list);
     65         mListView.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener);
     66     }
     67 
     68     private Test[] mTests = new Test[] {
     69         new Test("toggle LOW_PROFILE (lights out)") {
     70             public void run() {
     71                 if (0 != (mUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE)) {
     72                     mUiVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
     73                 } else {
     74                     mUiVisibility |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
     75                 }
     76                 mListView.setSystemUiVisibility(mUiVisibility);
     77             }
     78         },
     79         new Test("toggle HIDE_NAVIGATION") {
     80             public void run() {
     81                 if (0 != (mUiVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)) {
     82                     mUiVisibility &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
     83                 } else {
     84                     mUiVisibility |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
     85                 }
     86                 mListView.setSystemUiVisibility(mUiVisibility);
     87 
     88             }
     89         },
     90         new Test("clear SYSTEM_UI_FLAGs") {
     91             public void run() {
     92                 mUiVisibility = 0;
     93                 mListView.setSystemUiVisibility(mUiVisibility);
     94             }
     95         },
     96 //        new Test("no setSystemUiVisibility") {
     97 //            public void run() {
     98 //                View v = findViewById(android.R.id.list);
     99 //                v.setOnSystemUiVisibilityChangeListener(null);
    100 //                v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
    101 //            }
    102 //        },
    103         new Test("systemUiVisibility: STATUS_BAR_DISABLE_HOME") {
    104             public void run() {
    105                 mListView.setSystemUiVisibility(View.STATUS_BAR_DISABLE_HOME);
    106             }
    107         },
    108         new Test("Double Remove") {
    109             public void run() {
    110                 Log.d(TAG, "set 0");
    111                 mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null);
    112                 Log.d(TAG, "remove 1");
    113                 mStatusBarManager.removeIcon("tty");
    114 
    115                 SystemClock.sleep(1000);
    116 
    117                 Log.d(TAG, "set 1");
    118                 mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null);
    119                 if (false) {
    120                     Log.d(TAG, "set 2");
    121                     mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null);
    122                 }
    123                 Log.d(TAG, "remove 2");
    124                 mStatusBarManager.removeIcon("tty");
    125                 Log.d(TAG, "set 3");
    126                 mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null);
    127             }
    128         },
    129         new Test("Hide (FLAG_FULLSCREEN)") {
    130             public void run() {
    131                 Window win = getWindow();
    132                 win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    133                         WindowManager.LayoutParams.FLAG_FULLSCREEN);
    134                 Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
    135             }
    136         },
    137         new Test("Show (~FLAG_FULLSCREEN)") {
    138             public void run() {
    139                 Window win = getWindow();
    140                 win.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    141                 Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
    142             }
    143         },
    144         new Test("Immersive: Enter") {
    145             public void run() {
    146                 setImmersive(true);
    147             }
    148         },
    149         new Test("Immersive: Exit") {
    150             public void run() {
    151                 setImmersive(false);
    152             }
    153         },
    154         new Test("Priority notification") {
    155             public void run() {
    156                 Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
    157                 int id = (int)System.currentTimeMillis(); // XXX HAX
    158                 fullScreenIntent.putExtra("id", id);
    159                 PendingIntent pi = PendingIntent.getActivity(
    160                     StatusBarTest.this,
    161                     0,
    162                     fullScreenIntent,
    163                     PendingIntent.FLAG_CANCEL_CURRENT);
    164                 Notification not = new Notification.Builder(StatusBarTest.this)
    165                         .setSmallIcon(R.drawable.stat_sys_phone)
    166                         .setWhen(System.currentTimeMillis() - (1000 * 60 * 60 * 24))
    167                         .setContentTitle("Incoming call")
    168                         .setContentText("from: Imperious Leader")
    169                         .setContentIntent(pi)
    170                         .setFullScreenIntent(pi, true)
    171                         .setPriority(Notification.PRIORITY_HIGH)
    172                         .build();
    173 
    174                 mNotificationManager.notify(id, not);
    175             }
    176         },
    177         new Test("Disable Alerts") {
    178             public void run() {
    179                 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS);
    180             }
    181         },
    182         new Test("Disable Ticker") {
    183             public void run() {
    184                 mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER);
    185             }
    186         },
    187         new Test("Disable Expand in 3 sec.") {
    188             public void run() {
    189                 mHandler.postDelayed(new Runnable() {
    190                         public void run() {
    191                             mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
    192                         }
    193                     }, 3000);
    194             }
    195         },
    196         new Test("Disable Notifications in 3 sec.") {
    197             public void run() {
    198                 mHandler.postDelayed(new Runnable() {
    199                         public void run() {
    200                             mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS);
    201                         }
    202                     }, 3000);
    203             }
    204         },
    205         new Test("Disable Expand + Notifications in 3 sec.") {
    206             public void run() {
    207                 mHandler.postDelayed(new Runnable() {
    208                         public void run() {
    209                             mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND
    210                                     | StatusBarManager.DISABLE_NOTIFICATION_ICONS);
    211                         }
    212                     }, 3000);
    213             }
    214         },
    215         new Test("Disable Home (StatusBarManager)") {
    216             public void run() {
    217                 mStatusBarManager.disable(StatusBarManager.DISABLE_HOME);
    218             }
    219         },
    220         new Test("Disable Back (StatusBarManager)") {
    221             public void run() {
    222                 mStatusBarManager.disable(StatusBarManager.DISABLE_BACK);
    223             }
    224         },
    225         new Test("Disable Recent (StatusBarManager)") {
    226             public void run() {
    227                 mStatusBarManager.disable(StatusBarManager.DISABLE_RECENT);
    228             }
    229         },
    230         new Test("Disable Clock") {
    231             public void run() {
    232                 mStatusBarManager.disable(StatusBarManager.DISABLE_CLOCK);
    233             }
    234         },
    235         new Test("Disable System Info") {
    236             public void run() {
    237                 mStatusBarManager.disable(StatusBarManager.DISABLE_SYSTEM_INFO);
    238             }
    239         },
    240         new Test("Disable everything in 3 sec") {
    241             public void run() {
    242                 mHandler.postDelayed(new Runnable() {
    243                         public void run() {
    244                             mStatusBarManager.disable(~StatusBarManager.DISABLE_NONE);
    245                         }
    246                     }, 3000);
    247             }
    248         },
    249         new Test("Enable everything") {
    250             public void run() {
    251                 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
    252             }
    253         },
    254         new Test("Enable everything in 3 sec.") {
    255             public void run() {
    256                 mHandler.postDelayed(new Runnable() {
    257                         public void run() {
    258                             mStatusBarManager.disable(0);
    259                         }
    260                     }, 3000);
    261             }
    262         },
    263         new Test("Notify in 3 sec.") {
    264             public void run() {
    265                 mHandler.postDelayed(new Runnable() {
    266                         public void run() {
    267                             mNotificationManager.notify(1,
    268                                     new Notification(
    269                                             R.drawable.ic_statusbar_missedcall,
    270                                             "tick tick tick",
    271                                             System.currentTimeMillis()-(1000*60*60*24)
    272                                             ));
    273                         }
    274                     }, 3000);
    275             }
    276         },
    277         new Test("Cancel Notification in 3 sec.") {
    278             public void run() {
    279                 mHandler.postDelayed(new Runnable() {
    280                         public void run() {
    281                             mNotificationManager.cancel(1);
    282                         }
    283                     }, 3000);
    284             }
    285         },
    286         new Test("Expand notifications") {
    287             public void run() {
    288                 mStatusBarManager.expandNotificationsPanel();
    289             }
    290         },
    291         new Test(" ... in 3 sec.") {
    292             public void run() {
    293                 mHandler.postDelayed(new Runnable() {
    294                         public void run() {
    295                             mStatusBarManager.expandNotificationsPanel();
    296                         }
    297                     }, 3000);
    298             }
    299         },
    300         new Test("Expand settings") {
    301             public void run() {
    302                 mStatusBarManager.expandSettingsPanel();
    303             }
    304         },
    305         new Test(" ... in 3 sec.") {
    306             public void run() {
    307                 mHandler.postDelayed(new Runnable() {
    308                         public void run() {
    309                             mStatusBarManager.expandSettingsPanel();
    310                         }
    311                     }, 3000);
    312             }
    313         },
    314         new Test("Collapse panels in 3 sec.") {
    315             public void run() {
    316                 mHandler.postDelayed(new Runnable() {
    317                         public void run() {
    318                             mStatusBarManager.collapsePanels();
    319                         }
    320                     }, 3000);
    321             }
    322         },
    323         new Test("More icons") {
    324             public void run() {
    325                 for (String slot: new String[] {
    326                             "sync_failing",
    327                             "gps",
    328                             "bluetooth",
    329                             "tty",
    330                             "speakerphone",
    331                             "mute",
    332                             "wifi",
    333                             "alarm_clock",
    334                             "secure",
    335                         }) {
    336                     mStatusBarManager.setIconVisibility(slot, true);
    337                 }
    338             }
    339         },
    340     };
    341 }
    342