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

Commit b4c3a6b4 authored by Mark Teffeteller's avatar Mark Teffeteller Committed by Android (Google) Code Review
Browse files

Merge "Refactor `TestLoggingService` from a locally-started service to a...

Merge "Refactor `TestLoggingService` from a locally-started service to a stand-alone test application" into main
parents 8f7bc91f 88982412
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -23,12 +23,16 @@ android_test {
        "frameworks-base-testutils",
        "junit",
        "platform-test-annotations",
        "servicestests-utils",
        "services.core",
        "truth",
        "Nene",
        "Harrier",
        "TestApp",
    ],
    data: [
        ":TestIntrusionDetectionApp",
    ],

    platform_apis: true,

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

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

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

+13 −14
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.os.test.TestLooper;
import android.security.intrusiondetection.IIntrusionDetectionServiceCommandCallback;
import android.security.intrusiondetection.IIntrusionDetectionServiceStateCallback;
import android.security.intrusiondetection.IntrusionDetectionEvent;
import android.security.intrusiondetection.IntrusionDetectionEventTransport;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
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.PermissionContext;
import com.android.bedstead.permissions.annotations.EnsureHasPermission;
import com.android.internal.infra.AndroidFuture;
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.Ignore;
@@ -118,13 +118,16 @@ public class IntrusionDetectionServiceTest {
    private IntrusionDetectionEventTransportConnection mIntrusionDetectionEventTransportConnection;
    private DataAggregator mDataAggregator;
    private IntrusionDetectionService mIntrusionDetectionService;
    private IBinder mService;
    private TestLooper mTestLooper;
    private Looper mLooper;
    private TestLooper mTestLooperOfDataAggregator;
    private Looper mLooperOfDataAggregator;
    private FakePermissionEnforcer mPermissionEnforcer;
    private TestLoggingService mService;
    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
    public static void setDeviceOwner() {
@@ -575,8 +578,8 @@ public class IntrusionDetectionServiceTest {
    }

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

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

        ServiceConnection serviceConnection = new ServiceConnection() {
            // Called when the connection with the service is established.
            // Called when connection with the service is established.
            @Override
            public void onServiceConnected(ComponentName className, IBinder service) {
                // Because we have bound to an explicit
                // 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();
                mService = transport.getBinder();
                mBoundToLoggingService = true;
                latch.countDown();
            }
@@ -618,11 +617,11 @@ public class IntrusionDetectionServiceTest {
            public void onServiceDisconnected(ComponentName className) {
                Log.d(TAG, "onServiceDisconnected");
                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);
        latch.await(5, TimeUnit.SECONDS);

+52 −0
Original line number 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