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 17 package com.android.server.wifi.nan; 18 19 import 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 */ 33 public class WifiNanHalMock { getCapabilitiesHalMockNative(short transactionId)34 public void getCapabilitiesHalMockNative(short transactionId) { 35 throw new IllegalStateException("Please mock this class!"); 36 } 37 enableHalMockNative(short transactionId, String jsonArgs)38 public void enableHalMockNative(short transactionId, String jsonArgs) { 39 throw new IllegalStateException("Please mock this class!"); 40 } 41 disableHalMockNative(short transactionId)42 public void disableHalMockNative(short transactionId) { 43 throw new IllegalStateException("Please mock this class!"); 44 } 45 publishHalMockNative(short transactionId, String jsonArgs)46 public void publishHalMockNative(short transactionId, String jsonArgs) { 47 throw new IllegalStateException("Please mock this class!"); 48 } 49 publishCancelHalMockNative(short transactionId, String jsonArgs)50 public void publishCancelHalMockNative(short transactionId, String jsonArgs) { 51 throw new IllegalStateException("Please mock this class!"); 52 } 53 subscribeHalMockNative(short transactionId, String jsonArgs)54 public void subscribeHalMockNative(short transactionId, String jsonArgs) { 55 throw new IllegalStateException("Please mock this class!"); 56 } 57 subscribeCancelHalMockNative(short transactionId, String jsonArgs)58 public void subscribeCancelHalMockNative(short transactionId, String jsonArgs) { 59 throw new IllegalStateException("Please mock this class!"); 60 } 61 transmitFollowupHalMockNative(short transactionId, String jsonArgs)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 callNotifyResponse(short transactionId, String jsonArgs)71 public static native void callNotifyResponse(short transactionId, String jsonArgs); 72 callPublishTerminated(String jsonArgs)73 public static native void callPublishTerminated(String jsonArgs); 74 callSubscribeTerminated(String jsonArgs)75 public static native void callSubscribeTerminated(String jsonArgs); 76 callFollowup(String jsonArgs)77 public static native void callFollowup(String jsonArgs); 78 callMatch(String jsonArgs)79 public static native void callMatch(String jsonArgs); 80 callDiscEngEvent(String jsonArgs)81 public static native void callDiscEngEvent(String jsonArgs); 82 callDisabled(String jsonArgs)83 public static native void callDisabled(String jsonArgs); 84 85 /** 86 * initialize NAN mock 87 */ initNanHalMock()88 private static native int initNanHalMock(); 89 initNanHalMockLibrary()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