• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import java.util.Arrays;
29 
30 /** ActivityAttribution Native Interface to/from JNI. */
31 public class ActivityAttributionNativeInterface {
32     private static final boolean DBG = false;
33     private static final String TAG = "ActivityAttributionNativeInterface";
34 
35     @GuardedBy("INSTANCE_LOCK")
36     private static ActivityAttributionNativeInterface sInstance;
37 
38     private static final Object INSTANCE_LOCK = new Object();
39 
40     static {
classInitNative()41         classInitNative();
42     }
43 
44     /** Get singleton instance. */
getInstance()45     public static ActivityAttributionNativeInterface getInstance() {
46         synchronized (INSTANCE_LOCK) {
47             if (sInstance == null) {
48                 sInstance = new ActivityAttributionNativeInterface();
49             }
50             return sInstance;
51         }
52     }
53 
54     /** Initializes the native interface. */
init()55     public void init() {
56         initNative();
57     }
58 
59     /** Cleanup the native interface. */
cleanup()60     public void cleanup() {
61         cleanupNative();
62     }
63 
64     /** Notify the UID and package name of the app, and the address of associated active device */
notifyActivityAttributionInfo(int uid, String packageName, String deviceAddress)65     public void notifyActivityAttributionInfo(int uid, String packageName, String deviceAddress) {
66         notifyActivityAttributionInfoNative(uid, packageName, deviceAddress);
67     }
68 
69     // Callbacks from the native stack back into the Java framework.
70     // All callbacks are routed via the Service which will disambiguate which
71     // state machine the message should be routed to.
72 
onWakeup(int activity, byte[] address)73     private void onWakeup(int activity, byte[] address) {
74         Log.i(TAG, "onWakeup() BTAA: " + activity);
75     }
76 
onActivityLogsReady(byte[] logs)77     private void onActivityLogsReady(byte[] logs) {
78         Log.i(TAG, "onActivityLogsReady() BTAA: " + Arrays.toString(logs));
79     }
80 
81     // Native methods that call into the JNI interface
classInitNative()82     private static native void classInitNative();
83 
initNative()84     private native void initNative();
85 
cleanupNative()86     private native void cleanupNative();
87 
notifyActivityAttributionInfoNative( int uid, String packageName, String deviceAddress)88     private native void notifyActivityAttributionInfoNative(
89         int uid, String packageName, String deviceAddress);
90 }
91