StatusBarTest.java revision 6179ea3196e9306d3f14361fe9ef14191b1edba6
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
17package com.android.statusbartest;
18
19import android.app.ListActivity;
20import android.app.Notification;
21import android.app.NotificationManager;
22import android.widget.ArrayAdapter;
23import android.view.View;
24import android.widget.ListView;
25import android.content.Intent;
26import android.app.PendingIntent;
27import android.app.Notification;
28import android.app.NotificationManager;
29import android.app.StatusBarManager;
30import android.content.Context;
31import android.util.AttributeSet;
32import android.os.Vibrator;
33import android.os.Bundle;
34import android.os.Handler;
35import android.util.Log;
36import android.net.Uri;
37import android.os.SystemClock;
38import android.widget.RemoteViews;
39import android.widget.Toast;
40import android.os.PowerManager;
41import android.view.View;
42import android.view.Window;
43import android.view.WindowManager;
44
45public class StatusBarTest extends TestActivity
46{
47    private final static String TAG = "StatusBarTest";
48    StatusBarManager mStatusBarManager;
49    NotificationManager mNotificationManager;
50    Handler mHandler = new Handler();
51
52    View.OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener
53            = new View.OnSystemUiVisibilityChangeListener() {
54        public void onSystemUiVisibilityChange(int visibility) {
55            Log.d(TAG, "onSystemUiVisibilityChange visibility=" + visibility);
56        }
57    };
58
59    @Override
60    protected String tag() {
61        return TAG;
62    }
63
64    @Override
65    protected Test[] tests() {
66        mStatusBarManager = (StatusBarManager)getSystemService(STATUS_BAR_SERVICE);
67        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
68
69        return mTests;
70    }
71
72    private Test[] mTests = new Test[] {
73        new Test("DISABLE_NAVIGATION") {
74            public void run() {
75                View v = findViewById(android.R.id.list);
76                v.setSystemUiVisibility(View.STATUS_BAR_DISABLE_NAVIGATION);
77            }
78        },
79        new Test("STATUS_BAR_HIDDEN") {
80            public void run() {
81                View v = findViewById(android.R.id.list);
82                v.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener);
83                v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
84            }
85        },
86        new Test("STATUS_BAR_VISIBLE") {
87            public void run() {
88                View v = findViewById(android.R.id.list);
89                v.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener);
90                v.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
91            }
92        },
93        new Test("no setSystemUiVisibility") {
94            public void run() {
95                View v = findViewById(android.R.id.list);
96                v.setOnSystemUiVisibilityChangeListener(null);
97                v.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
98            }
99        },
100        new Test("Double Remove") {
101            public void run() {
102                Log.d(TAG, "set 0");
103                mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null);
104                Log.d(TAG, "remove 1");
105                mStatusBarManager.removeIcon("tty");
106
107                SystemClock.sleep(1000);
108
109                Log.d(TAG, "set 1");
110                mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null);
111                if (false) {
112                    Log.d(TAG, "set 2");
113                    mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null);
114                }
115                Log.d(TAG, "remove 2");
116                mStatusBarManager.removeIcon("tty");
117                Log.d(TAG, "set 3");
118                mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null);
119            }
120        },
121        new Test("Hide (FLAG_FULLSCREEN)") {
122            public void run() {
123                Window win = getWindow();
124                win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
125                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
126                Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
127            }
128        },
129        new Test("Show (~FLAG_FULLSCREEN)") {
130            public void run() {
131                Window win = getWindow();
132                win.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
133                Log.d(TAG, "flags=" + Integer.toHexString(win.getAttributes().flags));
134            }
135        },
136        new Test("Immersive: Enter") {
137            public void run() {
138                setImmersive(true);
139            }
140        },
141        new Test("Immersive: Exit") {
142            public void run() {
143                setImmersive(false);
144            }
145        },
146        new Test("Priority notification") {
147            public void run() {
148                Notification not = new Notification(
149                                R.drawable.stat_sys_phone,
150                                "Incoming call from: Imperious Leader",
151                                System.currentTimeMillis()-(1000*60*60*24)
152                                );
153                not.flags |= Notification.FLAG_HIGH_PRIORITY;
154                Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
155                int id = (int)System.currentTimeMillis(); // XXX HAX
156                fullScreenIntent.putExtra("id", id);
157                not.fullScreenIntent = PendingIntent.getActivity(
158                    StatusBarTest.this,
159                    0,
160                    fullScreenIntent,
161                    PendingIntent.FLAG_CANCEL_CURRENT);
162                // if you tap on it you should get the original alert box
163                not.contentIntent = not.fullScreenIntent;
164                mNotificationManager.notify(id, not);
165            }
166        },
167        new Test("Disable Alerts") {
168            public void run() {
169                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS);
170            }
171        },
172        new Test("Disable Ticker") {
173            public void run() {
174                mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_TICKER);
175            }
176        },
177        new Test("Disable Expand in 3 sec.") {
178            public void run() {
179                mHandler.postDelayed(new Runnable() {
180                        public void run() {
181                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
182                        }
183                    }, 3000);
184            }
185        },
186        new Test("Disable Notifications in 3 sec.") {
187            public void run() {
188                mHandler.postDelayed(new Runnable() {
189                        public void run() {
190                            mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ICONS);
191                        }
192                    }, 3000);
193            }
194        },
195        new Test("Disable Expand + Notifications in 3 sec.") {
196            public void run() {
197                mHandler.postDelayed(new Runnable() {
198                        public void run() {
199                            mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND
200                                    | StatusBarManager.DISABLE_NOTIFICATION_ICONS);
201                        }
202                    }, 3000);
203            }
204        },
205        new Test("Disable Navigation") {
206            public void run() {
207                mStatusBarManager.disable(StatusBarManager.DISABLE_NAVIGATION);
208            }
209        },
210        new Test("Disable Clock") {
211            public void run() {
212                mStatusBarManager.disable(StatusBarManager.DISABLE_CLOCK);
213            }
214        },
215        new Test("Disable System Info") {
216            public void run() {
217                mStatusBarManager.disable(StatusBarManager.DISABLE_SYSTEM_INFO);
218            }
219        },
220        new Test("Disable everything in 3 sec") {
221            public void run() {
222                mHandler.postDelayed(new Runnable() {
223                        public void run() {
224                            mStatusBarManager.disable(~StatusBarManager.DISABLE_NONE);
225                        }
226                    }, 3000);
227            }
228        },
229        new Test("Enable everything") {
230            public void run() {
231                mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
232            }
233        },
234        new Test("Enable everything in 3 sec.") {
235            public void run() {
236                mHandler.postDelayed(new Runnable() {
237                        public void run() {
238                            mStatusBarManager.disable(0);
239                        }
240                    }, 3000);
241            }
242        },
243        new Test("Notify in 3 sec.") {
244            public void run() {
245                mHandler.postDelayed(new Runnable() {
246                        public void run() {
247                            mNotificationManager.notify(1,
248                                    new Notification(
249                                            R.drawable.ic_statusbar_missedcall,
250                                            "tick tick tick",
251                                            System.currentTimeMillis()-(1000*60*60*24)
252                                            ));
253                        }
254                    }, 3000);
255            }
256        },
257        new Test("Cancel Notification in 3 sec.") {
258            public void run() {
259                mHandler.postDelayed(new Runnable() {
260                        public void run() {
261                            mNotificationManager.cancel(1);
262                        }
263                    }, 3000);
264            }
265        },
266        new Test("Expand") {
267            public void run() {
268                mStatusBarManager.expand();
269            }
270        },
271        new Test("Expand in 3 sec.") {
272            public void run() {
273                mHandler.postDelayed(new Runnable() {
274                        public void run() {
275                            mStatusBarManager.expand();
276                        }
277                    }, 3000);
278            }
279        },
280        new Test("Collapse in 3 sec.") {
281            public void run() {
282                mHandler.postDelayed(new Runnable() {
283                        public void run() {
284                            mStatusBarManager.collapse();
285                        }
286                    }, 3000);
287            }
288        },
289        new Test("More icons") {
290            public void run() {
291                for (String slot: new String[] {
292                            "sync_failing",
293                            "gps",
294                            "bluetooth",
295                            "tty",
296                            "speakerphone",
297                            "mute",
298                            "wifi",
299                            "alarm_clock",
300                            "secure",
301                        }) {
302                    mStatusBarManager.setIconVisibility(slot, true);
303                }
304            }
305        },
306    };
307}
308