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 #define LOG_TAG "SyntheticPasswordManager"
18 
19 #include <nativehelper/JNIHelp.h>
20 #include "jni.h"
21 
22 #include <android_runtime/Log.h>
23 #include <utils/Timers.h>
24 #include <utils/misc.h>
25 #include <utils/String8.h>
26 #include <utils/Log.h>
27 #include <gatekeeper/password_handle.h>
28 
29 
30 namespace android {
31 
android_server_SyntheticPasswordManager_nativeSidFromPasswordHandle(JNIEnv * env,jobject,jbyteArray handleArray)32 static jlong android_server_SyntheticPasswordManager_nativeSidFromPasswordHandle(JNIEnv* env, jobject, jbyteArray handleArray) {
33 
34     jbyte* data = (jbyte*)env->GetPrimitiveArrayCritical(handleArray, NULL);
35 
36     if (data != NULL) {
37         const gatekeeper::password_handle_t *handle =
38                 reinterpret_cast<const gatekeeper::password_handle_t *>(data);
39         jlong sid = handle->user_id;
40         env->ReleasePrimitiveArrayCritical(handleArray, data, JNI_ABORT);
41         return sid;
42     } else {
43         return 0;
44     }
45 }
46 
47 static const JNINativeMethod sMethods[] = {
48      /* name, signature, funcPtr */
49     {"nativeSidFromPasswordHandle", "([B)J", (void*)android_server_SyntheticPasswordManager_nativeSidFromPasswordHandle},
50 };
51 
register_android_server_SyntheticPasswordManager(JNIEnv * env)52 int register_android_server_SyntheticPasswordManager(JNIEnv* env) {
53     return jniRegisterNativeMethods(env, "com/android/server/locksettings/SyntheticPasswordManager",
54                                     sMethods, NELEM(sMethods));
55 }
56 
57 } /* namespace android */
58