1 /*
2  * Copyright 2022 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 package androidx.tracing.perfetto.jni
17 
18 import androidx.tracing.perfetto.security.SafeLibLoader
19 import dalvik.annotation.optimization.CriticalNative
20 import dalvik.annotation.optimization.FastNative
21 import java.io.File
22 
23 internal object PerfettoNative {
24     private const val libraryName = "tracing_perfetto"
25 
26     // TODO(224510255): load from a file produced at build time
27     object Metadata {
28         const val version = "1.0.0"
29         val checksums =
30             mapOf(
31                 "arm64-v8a" to "a152fbd7ebaa109a9c3cf6bbb6d585aa0df08f97ae022b2090b1096a8f5e2665",
32                 "armeabi-v7a" to "b2821c9ddb77a3f070cce42be7cd3255d7ec92c868d7d518a99ed968d9018b9f",
33                 "x86" to "4cefdc75fe41deeeb2306891c25ce4db33599698cc6fcb2e82caad5aece9aa09",
34                 "x86_64" to "23daf0750238cf96bf9ea9fa1b13ae1d2eeb17644ea5439e18939ec6a8b9e5be",
35             )
36     }
37 
loadLibnull38     fun loadLib() = System.loadLibrary(libraryName)
39 
40     fun loadLib(file: File, loader: SafeLibLoader) = loader.loadLib(file, Metadata.checksums)
41 
42     @JvmStatic external fun nativeRegisterWithPerfetto()
43 
44     @FastNative @JvmStatic external fun nativeTraceEventBegin(key: Int, traceInfo: String)
45 
46     @CriticalNative @JvmStatic external fun nativeTraceEventEnd()
47 
48     @JvmStatic external fun nativeVersion(): String
49 }
50