ActivityManagerInternalTest.java revision e736185ee90e0f19a7092542cadab4cf561a5703
1/* 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 25import com.android.server.AppOpsService; 26 27import org.junit.Before; 28import org.junit.Test; 29import org.junit.runner.RunWith; 30 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 { 49 private ActivityManagerService mAms; 50 private ActivityManagerInternal mAmi; 51 @Before 52 public void setUp() { 53 mAms = new ActivityManagerService((AppOpsService) null); 54 mAmi = mAms.new LocalService(); 55 } 56 57 @Test 58 public void testNotifyNetworkPolicyRulesUpdated() { 59 // For checking there is no crash when there are no active uid records. 60 mAmi.notifyNetworkPolicyRulesUpdated(111, 11); 61 62 // Insert active uid records. 63 final UidRecord record1 = addActiveUidRecord(222, 22); 64 final UidRecord record2 = addActiveUidRecord(333, 33); 65 // Notify that network policy rules are updated for uid 222. 66 mAmi.notifyNetworkPolicyRulesUpdated(222, 44); 67 assertEquals("UidRecord for uid 222 should be updated", 68 44L, record1.lastNetworkUpdatedProcStateSeq); 69 assertEquals("UidRecord for uid 333 should not be updated", 70 33L, record2.lastNetworkUpdatedProcStateSeq); 71 } 72 73 private UidRecord addActiveUidRecord(int uid, long lastNetworkUpdatedProcStateSeq) { 74 final UidRecord record = new UidRecord(uid); 75 record.lastNetworkUpdatedProcStateSeq = lastNetworkUpdatedProcStateSeq; 76 mAms.mActiveUids.put(uid, record); 77 return record; 78 } 79} 80