WifiConfigurationUtilTest.java revision bbb3149f3bc301e81c202438b77c45574a90a851
1/*
2 * Copyright (C) 2016 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.server.wifi;
18
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertTrue;
21
22import android.content.pm.UserInfo;
23import android.net.wifi.WifiConfiguration;
24import android.os.UserHandle;
25import android.test.suitebuilder.annotation.SmallTest;
26
27import org.junit.Test;
28
29import java.util.Arrays;
30import java.util.List;
31
32/**
33 * Unit tests for {@link com.android.server.wifi.WifiConfigurationUtil}.
34 */
35@SmallTest
36public class WifiConfigurationUtilTest {
37    static final int CURRENT_USER_ID = 0;
38    static final int CURRENT_USER_MANAGED_PROFILE_USER_ID = 10;
39    static final int OTHER_USER_ID = 11;
40    static final List<UserInfo> PROFILES = Arrays.asList(
41            new UserInfo(CURRENT_USER_ID, "owner", 0),
42            new UserInfo(CURRENT_USER_MANAGED_PROFILE_USER_ID, "managed profile", 0));
43
44    /**
45     * Test for {@link WifiConfigurationUtil.isVisibleToAnyProfile}.
46     */
47    @Test
48    public void isVisibleToAnyProfile() {
49        // Shared network configuration created by another user.
50        final WifiConfiguration configuration = new WifiConfiguration();
51        configuration.creatorUid = UserHandle.getUid(OTHER_USER_ID, 0);
52        assertTrue(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
53
54        // Private network configuration created by another user.
55        configuration.shared = false;
56        assertFalse(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
57
58        // Private network configuration created by the current user.
59        configuration.creatorUid = UserHandle.getUid(CURRENT_USER_ID, 0);
60        assertTrue(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
61
62        // Private network configuration created by the current user's managed profile.
63        configuration.creatorUid = UserHandle.getUid(CURRENT_USER_MANAGED_PROFILE_USER_ID, 0);
64        assertTrue(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
65    }
66}
67