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.nan;
18
19import java.lang.reflect.Field;
20
21/**
22 * Mock class for NAN HAL. Provides access to HAL API and to callbacks. To
23 * extend:
24 * <ul>
25 * <li>HAL API: create a {@code public void} method which takes any fixed
26 * arguments (e.g. a {@code short transactionId} and a second argument to
27 * provide the rest of the argument as a JSON string: {@code String jsonArgs}.
28 * <li>Callbacks from HAL: create a {@code public static native} function which
29 * is used to trigger the callback from the test harness. The arguments are
30 * similar to the HAL API arguments.
31 * </ul>
32 */
33public class WifiNanHalMock {
34    public void getCapabilitiesHalMockNative(short transactionId) {
35        throw new IllegalStateException("Please mock this class!");
36    }
37
38    public void enableHalMockNative(short transactionId, String jsonArgs) {
39        throw new IllegalStateException("Please mock this class!");
40    }
41
42    public void disableHalMockNative(short transactionId) {
43        throw new IllegalStateException("Please mock this class!");
44    }
45
46    public void publishHalMockNative(short transactionId, String jsonArgs) {
47        throw new IllegalStateException("Please mock this class!");
48    }
49
50    public void publishCancelHalMockNative(short transactionId, String jsonArgs) {
51        throw new IllegalStateException("Please mock this class!");
52    }
53
54    public void subscribeHalMockNative(short transactionId, String jsonArgs) {
55        throw new IllegalStateException("Please mock this class!");
56    }
57
58    public void subscribeCancelHalMockNative(short transactionId, String jsonArgs) {
59        throw new IllegalStateException("Please mock this class!");
60    }
61
62    public void transmitFollowupHalMockNative(short transactionId, String jsonArgs) {
63        throw new IllegalStateException("Please mock this class!");
64    }
65
66    /*
67     * trigger callbacks - called by test harness with arguments passed by JSON
68     * string.
69     */
70
71    public static native void callNotifyResponse(short transactionId, String jsonArgs);
72
73    public static native void callPublishTerminated(String jsonArgs);
74
75    public static native void callSubscribeTerminated(String jsonArgs);
76
77    public static native void callFollowup(String jsonArgs);
78
79    public static native void callMatch(String jsonArgs);
80
81    public static native void callDiscEngEvent(String jsonArgs);
82
83    public static native void callDisabled(String jsonArgs);
84
85    /**
86     * initialize NAN mock
87     */
88    private static native int initNanHalMock();
89
90    public static void initNanHalMockLibrary() throws Exception {
91        Field field = WifiNanNative.class.getDeclaredField("sNanNativeInit");
92        field.setAccessible(true);
93        field.setBoolean(null, true);
94
95        initNanHalMock();
96    }
97}
98