blob: b5934ee82f8b54e66822213b6274da53f32576f6 [file] [log] [blame]
Sudheer Shankae7361852017-03-07 11:51:46 -08001/*
2 * Copyright (C) 2017 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.am;
18
19import static org.junit.Assert.assertEquals;
20
21import android.app.ActivityManagerInternal;
22import android.support.test.filters.SmallTest;
23import android.support.test.runner.AndroidJUnit4;
24
Sudheer Shankae7361852017-03-07 11:51:46 -080025import org.junit.Before;
26import org.junit.Test;
27import org.junit.runner.RunWith;
Sudheer Shanka51ab3ac2017-03-07 15:38:01 -080028import org.mockito.Mock;
29import org.mockito.MockitoAnnotations;
Sudheer Shankae7361852017-03-07 11:51:46 -080030
31/**
32 * Test class for {@link ActivityManagerInternal}.
33 *
34 * To run the tests, use
35 *
36 * runtest -c com.android.server.am.ActivityManagerInternalTest frameworks-services
37 *
38 * or the following steps:
39 *
40 * Build: m FrameworksServicesTests
41 * Install: adb install -r \
42 * ${ANDROID_PRODUCT_OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk
43 * Run: adb shell am instrument -e class com.android.server.am.ActivityManagerInternalTest -w \
44 * com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
45 */
46@SmallTest
47@RunWith(AndroidJUnit4.class)
48public class ActivityManagerInternalTest {
Sudheer Shanka51ab3ac2017-03-07 15:38:01 -080049 @Mock private ActivityManagerService.Injector mMockInjector;
50
Sudheer Shankae7361852017-03-07 11:51:46 -080051 private ActivityManagerService mAms;
52 private ActivityManagerInternal mAmi;
53 @Before
54 public void setUp() {
Sudheer Shanka51ab3ac2017-03-07 15:38:01 -080055 MockitoAnnotations.initMocks(this);
56
57 mAms = new ActivityManagerService(mMockInjector);
Sudheer Shankae7361852017-03-07 11:51:46 -080058 mAmi = mAms.new LocalService();
59 }
60
61 @Test
62 public void testNotifyNetworkPolicyRulesUpdated() {
63 // For checking there is no crash when there are no active uid records.
64 mAmi.notifyNetworkPolicyRulesUpdated(111, 11);
65
66 // Insert active uid records.
67 final UidRecord record1 = addActiveUidRecord(222, 22);
68 final UidRecord record2 = addActiveUidRecord(333, 33);
69 // Notify that network policy rules are updated for uid 222.
70 mAmi.notifyNetworkPolicyRulesUpdated(222, 44);
71 assertEquals("UidRecord for uid 222 should be updated",
72 44L, record1.lastNetworkUpdatedProcStateSeq);
73 assertEquals("UidRecord for uid 333 should not be updated",
74 33L, record2.lastNetworkUpdatedProcStateSeq);
75 }
76
77 private UidRecord addActiveUidRecord(int uid, long lastNetworkUpdatedProcStateSeq) {
78 final UidRecord record = new UidRecord(uid);
79 record.lastNetworkUpdatedProcStateSeq = lastNetworkUpdatedProcStateSeq;
80 mAms.mActiveUids.put(uid, record);
81 return record;
82 }
83}