1 /* 2 * Copyright 2020 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 /* 18 * Defines the native interface that is used by state machine/service to 19 * send or receive messages from the native stack. This file is registered 20 * for the native methods in the corresponding JNI C++ file. 21 */ 22 package com.android.bluetooth.btservice.activityattribution; 23 24 import android.util.Log; 25 26 import com.android.internal.annotations.GuardedBy; 27 28 /** ActivityAttribution Native Interface to/from JNI. */ 29 public class ActivityAttributionNativeInterface { 30 private static final boolean DBG = false; 31 private static final String TAG = "ActivityAttributionNativeInterface"; 32 33 @GuardedBy("INSTANCE_LOCK") 34 private static ActivityAttributionNativeInterface sInstance; 35 36 private static final Object INSTANCE_LOCK = new Object(); 37 38 static { classInitNative()39 classInitNative(); 40 } 41 42 /** Get singleton instance. */ getInstance()43 public static ActivityAttributionNativeInterface getInstance() { 44 synchronized (INSTANCE_LOCK) { 45 if (sInstance == null) { 46 sInstance = new ActivityAttributionNativeInterface(); 47 } 48 return sInstance; 49 } 50 } 51 52 /** Initializes the native interface. */ init()53 public void init() { 54 initNative(); 55 } 56 57 /** Cleanup the native interface. */ cleanup()58 public void cleanup() { 59 cleanupNative(); 60 } 61 62 // Callbacks from the native stack back into the Java framework. 63 // All callbacks are routed via the Service which will disambiguate which 64 // state machine the message should be routed to. 65 onWakeup(int activity, byte[] address)66 private void onWakeup(int activity, byte[] address) { 67 Log.i(TAG, "onWakeup() BTAA: " + activity); 68 } 69 onActivityLogsReady(byte[] logs)70 private void onActivityLogsReady(byte[] logs) { 71 Log.i(TAG, "onActivityLogsReady() BTAA: " + logs); 72 } 73 74 // Native methods that call into the JNI interface classInitNative()75 private static native void classInitNative(); 76 initNative()77 private native void initNative(); 78 cleanupNative()79 private native void cleanupNative(); 80 } 81