In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what are the new modules for framwork", the content is simple and clear, and I hope it can help you solve your doubts. Let the editor lead you to study and learn about "what are the new modules for framwork".
It is mainly based on the current Framework module of the Android system to add an independent module. At present, it is only a very simple framework layer to call the native layer (later, according to the progress of learning, the hal layer will be added, as well as aidl, stub, asynchronous). The basic ideas are as follows:
Add framework interface to the application, that is, SDK APIframework calls the native code, that is, the jni part of the jni part to achieve the final function is actually a very simple log printing, as long as the purpose is to review the framework development process. Previously, API was added to the existing mechanism of Android, but this attempt to add an independent module is just a personal idea. It is not clear what the standard practice of Android to add a new independent module is, just as learning.
Add framework interface, namely SDK API, to the application
Create a new pmps directory in the framework/base directory, create the\ java\ android\ pmps\ PmpsManager.java file in the pmps directory, and enter the code:
Package android.pmps
Import android.util.Log
Public class PmpsManager
{
Private static final String LOG_TAG = "PmpsManager"
Static {
System.loadLibrary ("pmps_jni")
}
Public PmpsManager () {
Log.i (LOG_TAG, "PmpsManager constructor ().")
}
Public native static void sayHello ()
}
PmpsManager provides the relevant API for the application layer, such as sayHello (). Here, the native method of JNI is called directly. It is worth noting that PmpsManager loads the System.loadLibrary in ("pmps_jni") loads the libpmps_jni.so file that will be generated in step 3 of the article.
There is another detail to pay attention to. We can first take a look at the Android.mk file in the framework/base directory, which contains a paragraph:
# FRAMEWORKS_BASE_SUBDIRS comes from build/core/pathmap.mk
LOCAL_SRC_FILES: = $(call find-other-java-files,$ (FRAMEWORKS_BASE_SUBDIRS))
Let's take a look at build/core/pathmap.mk, and there's a passage.
FRAMEWORKS_BASE_SUBDIRS: =\
$(addsuffix / java,\
Core\
Graphics\
Location\
Media\
Opengl\
Sax\
Telephony\
Wifi\
* *\
Keystore\
Voip\
)
In other words, we need to add the pmps directory to the build/core/pathmap.mk file as follows:
FRAMEWORKS_BASE_SUBDIRS: =\
$(addsuffix / java,\
Core\
Graphics\
Location\
Media\
Opengl\
Sax\
Telephony\
Wifi\
* *\
Keystore\
Voip\
Pmps\
)
Then we can compile the newly added module with the mmm command.
Compiled by mmm framework/base, the generated file is out/target/product/generic/system/framework/framework.jar
After the code has been compiled, you can do the next thing.
2.framework calls native code, that is, the jni part
Publicnative static void sayHello () in the previous step can be called by the application layer. Of course, we can encapsulate it in framework to achieve more complex functions, such as:
/ / api
Public int sayHelloFirst ()
{
/ / omitted code.
Return sayHello ()
}
/ / declaration
Public native static void sayHello ()
Partial realization of functions by 3.jni
In this step, the function of calling in framework can be realized by writing native code, and the specific function can be realized or the relevant drivers of hale layer can be called to complete the hardware operation function.
At present, you are simply printing the information.
It's worth noting that you implement the JNI_OnLoad function, and you can override the JNI_OnUnLoad function if necessary.
/ * / / device/libs/android_runtime/android_media_MediaPlayer.cpp
**
* * Copyright 2007, the Android Open Source Project.
**
* * Licensed under theApache License, Version 2.0 (the "License")
* * you may not usethis file except in compliance with the License.
* * You may obtain acopy of the License at
**
* * http://www.apache.org/licenses/LICENSE-2.0
**
* * Unless required byapplicable law or agreed to in writing, software
* * distributed underthe License is distributed on an "ASIS" BASIS
* WITHOUT WARRANTIESOR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licensefor the specific language governing permissions and
* * limitations underthe License.
, /
# define LOG_NDEBUG 0
# define LOG_TAG "PmpsManager-JNI"
# include "utils/Log.h"
# include
# include
# include
# include
# include
# include "jni.h"
# include "JNIHelp.h"
# include "android_runtime/AndroidRuntime.h"
/ /-
Using namespaceandroid
Static voidandroid_pmps_PmpsManager_sayHello (JNIEnv * env, jobject thiz)
{
LOGV ("sayHello ()")
}
Static constJNINativeMethod method_table [] = {
{"sayHello", "() V", (void*) android_pmps_PmpsManager_sayHello}
}
/ / This function onlyregisters the native methods
Intregister_android_pmps_PmpsManager (JNIEnv * env) {
Inti
LOGI ("JNI_OnLoad:register_android_pmps_PmpsPlayer")
ReturnAndroidRuntime::registerNativeMethods (env
"android/pmps/PmpsManager", method_table, NELEM (method_table))
}
JintJNI_OnLoad (JavaVM* vm, void* reserved)
{
JNIEnv* env = NULL
Jint result =-1
If (vm- > GetEnv ((void**) & env,JNI_VERSION_1_4)! = JNI_OK) {
LOGE ("ERROR: GetEnvfailed\ n")
Goto bail
}
Assert (env! = NULL)
If (register_android_pmps_PmpsManager (env) < 0) {
LOGE ("ERROR: PmpsManager nativeregistration failed\ n")
Goto bail
}
/ * success-- return valid version number*/
Result = JNI_VERSION_1_4
Bail:
Return result
}
The above is all the content of the article "what are the new modules of framwork?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.