1956f54b391677d78379729dd14518edddf3c7660Etan Cohen/*
2956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Copyright (C) 2016 The Android Open Source Project
3956f54b391677d78379729dd14518edddf3c7660Etan Cohen *
4956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Licensed under the Apache License, Version 2.0 (the "License");
5956f54b391677d78379729dd14518edddf3c7660Etan Cohen * you may not use this file except in compliance with the License.
6956f54b391677d78379729dd14518edddf3c7660Etan Cohen * You may obtain a copy of the License at
7956f54b391677d78379729dd14518edddf3c7660Etan Cohen *
8956f54b391677d78379729dd14518edddf3c7660Etan Cohen *      http://www.apache.org/licenses/LICENSE-2.0
9956f54b391677d78379729dd14518edddf3c7660Etan Cohen *
10956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Unless required by applicable law or agreed to in writing, software
11956f54b391677d78379729dd14518edddf3c7660Etan Cohen * distributed under the License is distributed on an "AS IS" BASIS,
12956f54b391677d78379729dd14518edddf3c7660Etan Cohen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13956f54b391677d78379729dd14518edddf3c7660Etan Cohen * See the License for the specific language governing permissions and
14956f54b391677d78379729dd14518edddf3c7660Etan Cohen * limitations under the License.
15956f54b391677d78379729dd14518edddf3c7660Etan Cohen */
16956f54b391677d78379729dd14518edddf3c7660Etan Cohen
17956f54b391677d78379729dd14518edddf3c7660Etan Cohenpackage com.android.server.wifi.nan;
18956f54b391677d78379729dd14518edddf3c7660Etan Cohen
19956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport java.lang.reflect.Field;
20956f54b391677d78379729dd14518edddf3c7660Etan Cohen
21956f54b391677d78379729dd14518edddf3c7660Etan Cohen/**
22956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Mock class for NAN HAL. Provides access to HAL API and to callbacks. To
23956f54b391677d78379729dd14518edddf3c7660Etan Cohen * extend:
24956f54b391677d78379729dd14518edddf3c7660Etan Cohen * <ul>
25956f54b391677d78379729dd14518edddf3c7660Etan Cohen * <li>HAL API: create a {@code public void} method which takes any fixed
26956f54b391677d78379729dd14518edddf3c7660Etan Cohen * arguments (e.g. a {@code short transactionId} and a second argument to
27956f54b391677d78379729dd14518edddf3c7660Etan Cohen * provide the rest of the argument as a JSON string: {@code String jsonArgs}.
28956f54b391677d78379729dd14518edddf3c7660Etan Cohen * <li>Callbacks from HAL: create a {@code public static native} function which
29956f54b391677d78379729dd14518edddf3c7660Etan Cohen * is used to trigger the callback from the test harness. The arguments are
30956f54b391677d78379729dd14518edddf3c7660Etan Cohen * similar to the HAL API arguments.
31956f54b391677d78379729dd14518edddf3c7660Etan Cohen * </ul>
32956f54b391677d78379729dd14518edddf3c7660Etan Cohen */
33956f54b391677d78379729dd14518edddf3c7660Etan Cohenpublic class WifiNanHalMock {
34e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    public void getCapabilitiesHalMockNative(short transactionId) {
35e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen        throw new IllegalStateException("Please mock this class!");
36e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen    }
37e36f5903f5d236a29dc94c8bdb215807ae75f5a1Etan Cohen
38956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public void enableHalMockNative(short transactionId, String jsonArgs) {
39956f54b391677d78379729dd14518edddf3c7660Etan Cohen        throw new IllegalStateException("Please mock this class!");
40956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
41956f54b391677d78379729dd14518edddf3c7660Etan Cohen
42956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public void disableHalMockNative(short transactionId) {
43956f54b391677d78379729dd14518edddf3c7660Etan Cohen        throw new IllegalStateException("Please mock this class!");
44956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
45956f54b391677d78379729dd14518edddf3c7660Etan Cohen
46956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public void publishHalMockNative(short transactionId, String jsonArgs) {
47956f54b391677d78379729dd14518edddf3c7660Etan Cohen        throw new IllegalStateException("Please mock this class!");
48956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
49956f54b391677d78379729dd14518edddf3c7660Etan Cohen
50956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public void publishCancelHalMockNative(short transactionId, String jsonArgs) {
51956f54b391677d78379729dd14518edddf3c7660Etan Cohen        throw new IllegalStateException("Please mock this class!");
52956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
53956f54b391677d78379729dd14518edddf3c7660Etan Cohen
54956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public void subscribeHalMockNative(short transactionId, String jsonArgs) {
55956f54b391677d78379729dd14518edddf3c7660Etan Cohen        throw new IllegalStateException("Please mock this class!");
56956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
57956f54b391677d78379729dd14518edddf3c7660Etan Cohen
58956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public void subscribeCancelHalMockNative(short transactionId, String jsonArgs) {
59956f54b391677d78379729dd14518edddf3c7660Etan Cohen        throw new IllegalStateException("Please mock this class!");
60956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
61956f54b391677d78379729dd14518edddf3c7660Etan Cohen
62956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public void transmitFollowupHalMockNative(short transactionId, String jsonArgs) {
63956f54b391677d78379729dd14518edddf3c7660Etan Cohen        throw new IllegalStateException("Please mock this class!");
64956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
65956f54b391677d78379729dd14518edddf3c7660Etan Cohen
66956f54b391677d78379729dd14518edddf3c7660Etan Cohen    /*
67956f54b391677d78379729dd14518edddf3c7660Etan Cohen     * trigger callbacks - called by test harness with arguments passed by JSON
68956f54b391677d78379729dd14518edddf3c7660Etan Cohen     * string.
69956f54b391677d78379729dd14518edddf3c7660Etan Cohen     */
70956f54b391677d78379729dd14518edddf3c7660Etan Cohen
71956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static native void callNotifyResponse(short transactionId, String jsonArgs);
72956f54b391677d78379729dd14518edddf3c7660Etan Cohen
73956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static native void callPublishTerminated(String jsonArgs);
74956f54b391677d78379729dd14518edddf3c7660Etan Cohen
75956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static native void callSubscribeTerminated(String jsonArgs);
76956f54b391677d78379729dd14518edddf3c7660Etan Cohen
77956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static native void callFollowup(String jsonArgs);
78956f54b391677d78379729dd14518edddf3c7660Etan Cohen
79956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static native void callMatch(String jsonArgs);
80956f54b391677d78379729dd14518edddf3c7660Etan Cohen
81956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static native void callDiscEngEvent(String jsonArgs);
82956f54b391677d78379729dd14518edddf3c7660Etan Cohen
83956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static native void callDisabled(String jsonArgs);
84956f54b391677d78379729dd14518edddf3c7660Etan Cohen
85956f54b391677d78379729dd14518edddf3c7660Etan Cohen    /**
86956f54b391677d78379729dd14518edddf3c7660Etan Cohen     * initialize NAN mock
87956f54b391677d78379729dd14518edddf3c7660Etan Cohen     */
88956f54b391677d78379729dd14518edddf3c7660Etan Cohen    private static native int initNanHalMock();
89956f54b391677d78379729dd14518edddf3c7660Etan Cohen
90956f54b391677d78379729dd14518edddf3c7660Etan Cohen    public static void initNanHalMockLibrary() throws Exception {
91956f54b391677d78379729dd14518edddf3c7660Etan Cohen        Field field = WifiNanNative.class.getDeclaredField("sNanNativeInit");
92956f54b391677d78379729dd14518edddf3c7660Etan Cohen        field.setAccessible(true);
93956f54b391677d78379729dd14518edddf3c7660Etan Cohen        field.setBoolean(null, true);
94956f54b391677d78379729dd14518edddf3c7660Etan Cohen
95956f54b391677d78379729dd14518edddf3c7660Etan Cohen        initNanHalMock();
96956f54b391677d78379729dd14518edddf3c7660Etan Cohen    }
97956f54b391677d78379729dd14518edddf3c7660Etan Cohen}
98