1 /*
2 * Copyright (C) 2023 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 #define LOG_TAG "SmallAreaDetectionController"
18
19 #include <gui/SurfaceComposerClient.h>
20 #include <nativehelper/JNIHelp.h>
21 #include <nativehelper/ScopedPrimitiveArray.h>
22
23 #include "jni.h"
24 #include "utils/Log.h"
25
26 namespace android {
nativeUpdateSmallAreaDetection(JNIEnv * env,jclass clazz,jintArray jappIds,jfloatArray jthresholds)27 static void nativeUpdateSmallAreaDetection(JNIEnv* env, jclass clazz, jintArray jappIds,
28 jfloatArray jthresholds) {
29 if (jappIds == nullptr || jthresholds == nullptr) return;
30
31 ScopedIntArrayRO appIds(env, jappIds);
32 ScopedFloatArrayRO thresholds(env, jthresholds);
33
34 if (appIds.size() != thresholds.size()) {
35 ALOGE("appIds size exceeds thresholds size!");
36 return;
37 }
38
39 std::vector<int32_t> appIdVector;
40 std::vector<float> thresholdVector;
41 size_t size = appIds.size();
42 appIdVector.reserve(size);
43 thresholdVector.reserve(size);
44 for (int i = 0; i < size; i++) {
45 appIdVector.push_back(static_cast<int32_t>(appIds[i]));
46 thresholdVector.push_back(static_cast<float>(thresholds[i]));
47 }
48 SurfaceComposerClient::updateSmallAreaDetection(appIdVector, thresholdVector);
49 }
50
nativeSetSmallAreaDetectionThreshold(JNIEnv * env,jclass clazz,jint appId,jfloat threshold)51 static void nativeSetSmallAreaDetectionThreshold(JNIEnv* env, jclass clazz, jint appId,
52 jfloat threshold) {
53 SurfaceComposerClient::setSmallAreaDetectionThreshold(appId, threshold);
54 }
55
56 static const JNINativeMethod gMethods[] = {
57 {"nativeUpdateSmallAreaDetection", "([I[F)V", (void*)nativeUpdateSmallAreaDetection},
58 {"nativeSetSmallAreaDetectionThreshold", "(IF)V",
59 (void*)nativeSetSmallAreaDetectionThreshold},
60 };
61
register_android_server_display_smallAreaDetectionController(JNIEnv * env)62 int register_android_server_display_smallAreaDetectionController(JNIEnv* env) {
63 return jniRegisterNativeMethods(env, "com/android/server/display/SmallAreaDetectionController",
64 gMethods, NELEM(gMethods));
65 }
66
67 }; // namespace android
68