1e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam/*
2e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * Copyright (C) 2015 The Android Open Source Project
3e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam *
4e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * Licensed under the Apache License, Version 2.0 (the "License");
5e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * you may not use this file except in compliance with the License.
6e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * You may obtain a copy of the License at
7e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam *
8e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam *      http://www.apache.org/licenses/LICENSE-2.0
9e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam *
10e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * Unless required by applicable law or agreed to in writing, software
11e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * distributed under the License is distributed on an "AS IS" BASIS,
12e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * See the License for the specific language governing permissions and
14e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam * limitations under the License.
15e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam */
16e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
17e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lampackage com.android.setupwizardlib.test;
18e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
19e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport android.annotation.SuppressLint;
206be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lamimport android.app.Dialog;
21e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport android.content.Context;
229f9367672191190f903955d09a4314d40869acc6Maurice Lamimport android.os.Build.VERSION;
239f9367672191190f903955d09a4314d40869acc6Maurice Lamimport android.os.Build.VERSION_CODES;
24803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lamimport android.os.Handler;
25803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lamimport android.os.HandlerThread;
26803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lamimport android.os.SystemClock;
27e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport android.test.AndroidTestCase;
28e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport android.test.suitebuilder.annotation.SmallTest;
29e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport android.view.View;
30e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport android.view.Window;
31e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport android.view.WindowManager;
32e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
33803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lamimport com.android.setupwizardlib.test.util.MockWindow;
34e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lamimport com.android.setupwizardlib.util.SystemBarHelper;
35e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
36e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lampublic class SystemBarHelperTest extends AndroidTestCase {
37e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
38e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    private static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
39e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
40e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SuppressLint("InlinedApi")
41e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    private static final int DEFAULT_IMMERSIVE_FLAGS =
42e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
43e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
44e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
45e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
46e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
476be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam    @SuppressLint("InlinedApi")
486be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam    private static final int DIALOG_IMMERSIVE_FLAGS =
496be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
506be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
516be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam
52e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SmallTest
53e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    public void testAddVisibilityFlagView() {
54e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final View view = createViewWithSystemUiVisibility(0x456);
55e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        SystemBarHelper.addVisibilityFlag(view, 0x1400);
569f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
579f9367672191190f903955d09a4314d40869acc6Maurice Lam            // Check that result is 0x1456, because 0x1400 | 0x456 = 0x1456.
589f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals("View visibility should be 0x1456", 0x1456, view.getSystemUiVisibility());
599f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
60e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
61e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
62e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SmallTest
63e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    public void testRemoveVisibilityFlagView() {
64e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final View view = createViewWithSystemUiVisibility(0x456);
65e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        SystemBarHelper.removeVisibilityFlag(view, 0x1400);
669f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
679f9367672191190f903955d09a4314d40869acc6Maurice Lam            // Check that result is 0x56, because 0x456 & ~0x1400 = 0x56.
689f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals("View visibility should be 0x56", 0x56, view.getSystemUiVisibility());
699f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
70e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
71e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
72e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SmallTest
73e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    public void testAddVisibilityFlagWindow() {
74e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final Window window = createWindowWithSystemUiVisibility(0x456);
75e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        SystemBarHelper.addVisibilityFlag(window, 0x1400);
769f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
779f9367672191190f903955d09a4314d40869acc6Maurice Lam            // Check that result is 0x1456 = 0x1400 | 0x456.
789f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals("View visibility should be 0x1456", 0x1456,
799f9367672191190f903955d09a4314d40869acc6Maurice Lam                    window.getAttributes().systemUiVisibility);
809f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
81e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
82e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
83e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SmallTest
84e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    public void testRemoveVisibilityFlagWindow() {
85e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final Window window = createWindowWithSystemUiVisibility(0x456);
86e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        SystemBarHelper.removeVisibilityFlag(window, 0x1400);
879f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
889f9367672191190f903955d09a4314d40869acc6Maurice Lam            // Check that result is 0x56 = 0x456 & ~0x1400.
899f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals("View visibility should be 0x56", 0x56,
909f9367672191190f903955d09a4314d40869acc6Maurice Lam                    window.getAttributes().systemUiVisibility);
919f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
92e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
93e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
94e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SmallTest
95e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    public void testHideSystemBarsWindow() {
96e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final Window window = createWindowWithSystemUiVisibility(0x456);
97e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        SystemBarHelper.hideSystemBars(window);
989f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
999f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals("DEFAULT_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
1009f9367672191190f903955d09a4314d40869acc6Maurice Lam                    DEFAULT_IMMERSIVE_FLAGS | 0x456,
1019f9367672191190f903955d09a4314d40869acc6Maurice Lam                    window.getAttributes().systemUiVisibility);
1029f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals(
1039f9367672191190f903955d09a4314d40869acc6Maurice Lam                    "DEFAULT_IMMERSIVE_FLAGS should be added to decorView's systemUiVisibility",
1049f9367672191190f903955d09a4314d40869acc6Maurice Lam                    DEFAULT_IMMERSIVE_FLAGS | 0x456,
1059f9367672191190f903955d09a4314d40869acc6Maurice Lam                    window.getDecorView().getSystemUiVisibility());
10699231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            assertEquals("Navigation bar should be transparent", window.getNavigationBarColor(), 0);
10799231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            assertEquals("Status bar should be transparent", window.getStatusBarColor(), 0);
10899231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        }
10999231ff98b97a82811f889636ad6dae6d371275bMaurice Lam    }
11099231ff98b97a82811f889636ad6dae6d371275bMaurice Lam
11199231ff98b97a82811f889636ad6dae6d371275bMaurice Lam    @SmallTest
11299231ff98b97a82811f889636ad6dae6d371275bMaurice Lam    public void testShowSystemBarsWindow() {
11399231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        final Window window = createWindowWithSystemUiVisibility(0x456);
11499231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        SystemBarHelper.showSystemBars(window, getContext());
11599231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
11699231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            assertEquals(
11799231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    "DEFAULT_IMMERSIVE_FLAGS should be removed from window's systemUiVisibility",
11899231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    0x456 & ~DEFAULT_IMMERSIVE_FLAGS,
11999231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    window.getAttributes().systemUiVisibility);
12099231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            assertEquals(
12199231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    "DEFAULT_IMMERSIVE_FLAGS should be removed from decorView's systemUiVisibility",
12299231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    0x456 & ~DEFAULT_IMMERSIVE_FLAGS,
12399231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    window.getDecorView().getSystemUiVisibility());
12499231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            assertEquals("Navigation bar should not be transparent",
12599231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    window.getNavigationBarColor(), 0xff000000);
12699231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            assertEquals("Status bar should not be transparent",
12799231ff98b97a82811f889636ad6dae6d371275bMaurice Lam                    window.getStatusBarColor(), 0xff000000);
1289f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
129e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
130e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
131e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SmallTest
132803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam    public void testHideSystemBarsNoInfiniteLoop() throws InterruptedException {
133803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        final TestWindow window = new TestWindow(getContext(), null);
134803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        final HandlerThread thread = new HandlerThread("SystemBarHelperTest");
135803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        thread.start();
136803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        final Handler handler = new Handler(thread.getLooper());
137803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        handler.post(new Runnable() {
138803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam            @Override
139803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam            public void run() {
140803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam                SystemBarHelper.hideSystemBars(window);
141803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam            }
142803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        });
143803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        SystemClock.sleep(500);  // Wait for the looper to drain all the messages
144803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        thread.quit();
145803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        // Initial peek + 3 retries = 4 tries total
146899caf2cf473e512567832d283e9750679f0bf4dMaurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
147899caf2cf473e512567832d283e9750679f0bf4dMaurice Lam            assertEquals("Peek decor view should give up after 4 tries", 4,
148899caf2cf473e512567832d283e9750679f0bf4dMaurice Lam                    window.peekDecorViewCount);
149899caf2cf473e512567832d283e9750679f0bf4dMaurice Lam        }
150803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam    }
151803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam
152803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam    @SmallTest
1536be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam    public void testHideSystemBarsDialog() {
1546be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam        final Dialog dialog = new Dialog(mContext);
1556be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
1566be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam            final WindowManager.LayoutParams attrs = dialog.getWindow().getAttributes();
1576be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam            attrs.systemUiVisibility = 0x456;
1586be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam            dialog.getWindow().setAttributes(attrs);
1596be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam        }
1606be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam
1616be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam        SystemBarHelper.hideSystemBars(dialog);
1626be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
1636be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam            assertEquals("DIALOG_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
1646be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam                    DIALOG_IMMERSIVE_FLAGS | 0x456,
1656be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam                    dialog.getWindow().getAttributes().systemUiVisibility);
1666be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam        }
1676be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam    }
1686be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam
1696be36beb1bdcd9211c504bbb1647d1f610ba2185Maurice Lam    @SmallTest
170e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    public void testSetBackButtonVisibleTrue() {
171e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final Window window = createWindowWithSystemUiVisibility(0x456);
172e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        SystemBarHelper.setBackButtonVisible(window, true);
1739f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
1749f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals("View visibility should be 0x456", 0x456,
1759f9367672191190f903955d09a4314d40869acc6Maurice Lam                    window.getAttributes().systemUiVisibility);
1769f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
177e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
178e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
179e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    @SmallTest
180e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    public void testSetBackButtonVisibleFalse() {
181e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final Window window = createWindowWithSystemUiVisibility(0x456);
182e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        SystemBarHelper.setBackButtonVisible(window, false);
1839f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
1849f9367672191190f903955d09a4314d40869acc6Maurice Lam            assertEquals("STATUS_BAR_DISABLE_BACK should be added to systemUiVisibility",
1859f9367672191190f903955d09a4314d40869acc6Maurice Lam                    0x456 | STATUS_BAR_DISABLE_BACK, window.getAttributes().systemUiVisibility);
1869f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
187e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
188e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
189e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    private View createViewWithSystemUiVisibility(int vis) {
190e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final View view = new View(getContext());
1919f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
1929f9367672191190f903955d09a4314d40869acc6Maurice Lam            view.setSystemUiVisibility(vis);
1939f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
194e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        return view;
195e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
196e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
197e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    private Window createWindowWithSystemUiVisibility(int vis) {
198e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        final Window window = new TestWindow(getContext(), createViewWithSystemUiVisibility(vis));
1999f9367672191190f903955d09a4314d40869acc6Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
2009f9367672191190f903955d09a4314d40869acc6Maurice Lam            WindowManager.LayoutParams attrs = window.getAttributes();
2019f9367672191190f903955d09a4314d40869acc6Maurice Lam            attrs.systemUiVisibility = vis;
2029f9367672191190f903955d09a4314d40869acc6Maurice Lam            window.setAttributes(attrs);
2039f9367672191190f903955d09a4314d40869acc6Maurice Lam        }
204e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        return window;
205e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
206e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
207803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam    private static class TestWindow extends MockWindow {
208e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
209e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        private View mDecorView;
210803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        public int peekDecorViewCount = 0;
211e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
21299231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        private int mNavigationBarColor = -1;
21399231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        private int mStatusBarColor = -1;
21499231ff98b97a82811f889636ad6dae6d371275bMaurice Lam
215e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        public TestWindow(Context context, View decorView) {
216e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            super(context);
217e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            mDecorView = decorView;
218e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        }
219e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
220e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        @Override
221e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        public View getDecorView() {
222e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            return mDecorView;
223e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        }
224e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
225e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        @Override
226e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        public View peekDecorView() {
227803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam            peekDecorViewCount++;
228e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam            return mDecorView;
229e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        }
230e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
231e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        @Override
232803f8b1dc47a4adebfab7434b6d8e410f80de14fMaurice Lam        public void setNavigationBarColor(int i) {
23399231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            mNavigationBarColor = i;
23499231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        }
23599231ff98b97a82811f889636ad6dae6d371275bMaurice Lam
23699231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        @Override
23799231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        public int getNavigationBarColor() {
23899231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            return mNavigationBarColor;
239e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        }
240e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam
241e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        @Override
242e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        public void setStatusBarColor(int i) {
24399231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            mStatusBarColor = i;
24499231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        }
24599231ff98b97a82811f889636ad6dae6d371275bMaurice Lam
24699231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        @Override
24799231ff98b97a82811f889636ad6dae6d371275bMaurice Lam        public int getStatusBarColor() {
24899231ff98b97a82811f889636ad6dae6d371275bMaurice Lam            return mStatusBarColor;
249e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam        }
250e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam    }
251e96ec75d23e82b352ab1393dbac8d6372ceb62d7Maurice Lam}
252