Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88982412 authored by Mark Teffeteller's avatar Mark Teffeteller
Browse files

Refactor `TestLoggingService` from a locally-started

service to a stand-alone test application

Bug: 369313906
Change-Id: I873f2a9ed4fe38023c777b0cac7f89663ea17e35
Test: atest IntrusionDetectionServiceTest
Flag: android.security.afl_api
parent ced265e1
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -23,12 +23,16 @@ android_test {
        "frameworks-base-testutils",
        "frameworks-base-testutils",
        "junit",
        "junit",
        "platform-test-annotations",
        "platform-test-annotations",
        "servicestests-utils",
        "services.core",
        "services.core",
        "truth",
        "truth",
        "Nene",
        "Nene",
        "Harrier",
        "Harrier",
        "TestApp",
        "TestApp",
    ],
    ],
    data: [
        ":TestIntrusionDetectionApp",
    ],


    platform_apis: true,
    platform_apis: true,


+4 −2
Original line number Original line Diff line number Diff line
@@ -31,10 +31,12 @@
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            </intent-filter>
            </intent-filter>
        </receiver>
        </receiver>
      <service android:name="com.android.server.security.intrusiondetection.TestLoggingService"
                 android:exported="true"/>
    </application>
    </application>


    <queries>
        <package android:name="com.android.coretests.apps.testapp" />
    </queries>

    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
         android:targetPackage="com.android.server.security.intrusiondetection.tests"
         android:targetPackage="com.android.server.security.intrusiondetection.tests"
         android:label="Frameworks IntrusionDetection Services Tests"/>
         android:label="Frameworks IntrusionDetection Services Tests"/>
+1 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true"/>
        <option name="cleanup-apks" value="true"/>
        <option name="test-file-name" value="IntrusionDetectionServiceTests.apk"/>
        <option name="test-file-name" value="IntrusionDetectionServiceTests.apk"/>
        <option name="test-file-name" value="TestIntrusionDetectionApp.apk"/>
        <option name="install-arg" value="-t" />
        <option name="install-arg" value="-t" />
    </target_preparer>
    </target_preparer>


+13 −14
Original line number Original line Diff line number Diff line
@@ -54,6 +54,7 @@ import android.os.test.TestLooper;
import android.security.intrusiondetection.IIntrusionDetectionServiceCommandCallback;
import android.security.intrusiondetection.IIntrusionDetectionServiceCommandCallback;
import android.security.intrusiondetection.IIntrusionDetectionServiceStateCallback;
import android.security.intrusiondetection.IIntrusionDetectionServiceStateCallback;
import android.security.intrusiondetection.IntrusionDetectionEvent;
import android.security.intrusiondetection.IntrusionDetectionEvent;
import android.security.intrusiondetection.IntrusionDetectionEventTransport;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.security.keystore.KeyProperties;
import android.util.Log;
import android.util.Log;
@@ -70,9 +71,8 @@ import com.android.bedstead.nene.exceptions.NeneException;
import com.android.bedstead.permissions.CommonPermissions;
import com.android.bedstead.permissions.CommonPermissions;
import com.android.bedstead.permissions.PermissionContext;
import com.android.bedstead.permissions.PermissionContext;
import com.android.bedstead.permissions.annotations.EnsureHasPermission;
import com.android.bedstead.permissions.annotations.EnsureHasPermission;
import com.android.internal.infra.AndroidFuture;
import com.android.server.ServiceThread;
import com.android.server.ServiceThread;
import com.android.server.security.intrusiondetection.TestLoggingService;
import com.android.server.security.intrusiondetection.TestLoggingService.LocalBinder;


import org.junit.Before;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Ignore;
@@ -118,13 +118,16 @@ public class IntrusionDetectionServiceTest {
    private IntrusionDetectionEventTransportConnection mIntrusionDetectionEventTransportConnection;
    private IntrusionDetectionEventTransportConnection mIntrusionDetectionEventTransportConnection;
    private DataAggregator mDataAggregator;
    private DataAggregator mDataAggregator;
    private IntrusionDetectionService mIntrusionDetectionService;
    private IntrusionDetectionService mIntrusionDetectionService;
    private IBinder mService;
    private TestLooper mTestLooper;
    private TestLooper mTestLooper;
    private Looper mLooper;
    private Looper mLooper;
    private TestLooper mTestLooperOfDataAggregator;
    private TestLooper mTestLooperOfDataAggregator;
    private Looper mLooperOfDataAggregator;
    private Looper mLooperOfDataAggregator;
    private FakePermissionEnforcer mPermissionEnforcer;
    private FakePermissionEnforcer mPermissionEnforcer;
    private TestLoggingService mService;
    private boolean mBoundToLoggingService = false;
    private boolean mBoundToLoggingService = false;
    private static final String TEST_PKG =
        "com.android.coretests.apps.testapp";
    private static final String TEST_SERVICE = TEST_PKG + ".TestLoggingService";


    @BeforeClass
    @BeforeClass
    public static void setDeviceOwner() {
    public static void setDeviceOwner() {
@@ -575,8 +578,8 @@ public class IntrusionDetectionServiceTest {
    }
    }


    @Test
    @Test
    public void test_StartBackupTransportService() {
    public void test_StartIntrusionDetectionEventTransportService() {
        final String TAG = "test_StartBackupTransportService";
        final String TAG = "test_StartIntrusionDetectionEventTransportService";
        ServiceConnection serviceConnection = null;
        ServiceConnection serviceConnection = null;


        assertEquals(false, mBoundToLoggingService);
        assertEquals(false, mBoundToLoggingService);
@@ -598,17 +601,13 @@ public class IntrusionDetectionServiceTest {
    private ServiceConnection startTestService() throws SecurityException, InterruptedException {
    private ServiceConnection startTestService() throws SecurityException, InterruptedException {
        final String TAG = "startTestService";
        final String TAG = "startTestService";
        final CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch latch = new CountDownLatch(1);
        IntrusionDetectionEventTransport transport = new IntrusionDetectionEventTransport();


        ServiceConnection serviceConnection = new ServiceConnection() {
        ServiceConnection serviceConnection = new ServiceConnection() {
            // Called when the connection with the service is established.
            // Called when connection with the service is established.
            @Override
            @Override
            public void onServiceConnected(ComponentName className, IBinder service) {
            public void onServiceConnected(ComponentName className, IBinder service) {
                // Because we have bound to an explicit
                mService = transport.getBinder();
                // service that is running in our own process, we can
                // cast its IBinder to a concrete class and directly access it.
                Log.d(TAG, "onServiceConnected");
                LocalBinder binder = (LocalBinder) service;
                mService = binder.getService();
                mBoundToLoggingService = true;
                mBoundToLoggingService = true;
                latch.countDown();
                latch.countDown();
            }
            }
@@ -618,11 +617,11 @@ public class IntrusionDetectionServiceTest {
            public void onServiceDisconnected(ComponentName className) {
            public void onServiceDisconnected(ComponentName className) {
                Log.d(TAG, "onServiceDisconnected");
                Log.d(TAG, "onServiceDisconnected");
                mBoundToLoggingService = false;
                mBoundToLoggingService = false;
                latch.countDown();
            }
            }
        };
        };


        Intent intent = new Intent(mContext, TestLoggingService.class);
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(TEST_PKG, TEST_SERVICE));
        mContext.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
        mContext.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
        latch.await(5, TimeUnit.SECONDS);
        latch.await(5, TimeUnit.SECONDS);


+52 −0
Original line number Original line Diff line number Diff line
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_team: "trendy_team_platform_security",
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
}

android_test_helper_app {
    name: "TestIntrusionDetectionApp",

    static_libs: [
        "androidx.test.core",
        "androidx.test.rules",
        "androidx.test.runner",
        "compatibility-device-util-axt",
        "frameworks-base-testutils",
        "junit",
        "platform-test-annotations",
        "services.core",
        "servicestests-utils",
        "coretests-aidl",
        "truth",
        "Nene",
        "Harrier",
    ],

    srcs: ["**/*.java"],

    platform_apis: true,
    certificate: "platform",
    dxflags: ["--multi-dex"],
    optimize: {
        enabled: false,
    },
}
Loading