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