APK calls hidden api
Example of calling SerialService
1,修改frameworks\base\core\java\android\hardware\SerialManager.java
Add the following code:
public static SerialManager getInstance(Context context){
mSerialManager = (SerialManager)context.getSystemService(Context.SERIAL_SERVICE);
return mSerialManager;
}
2. Compile the code to generate class.jar
Command: ./buildall_userdebug.sh B5528BIO
After successful compilation, it will generate
out\target\common\obj\JAVA_LIBRARIES\framework_intermediates\classes.jar
3. Rename classes.jar to framework.jar and import it into android studio, as shown in the figure:
4. Add the following code under build.gradle under project
5. Call the SerialManager.java --> getInstance () method
Calling getSerialPorts() app needs to obtain android.permission.SERIAL_PORT permission
If a non-system app obtains this permission, an error will be reported. You need to modify the default configuration of android studio as follows:
Then compile and generate apk, build this apk into the system,
- Create a folder under Packages/apps/, add the android.mk file, and import the apk generated by the studio, as shown in the figure:
- anroid.mk modify compilation
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyApplicition
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := MyApplicition.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PREBUILT_JNI_LIBS := \
@lib/armeabi-v7a/liben_data_bundle.so \
@lib/armeabi-v7a/libgnustl_shared.so \
@lib/armeabi-v7a/libhmm_gesture_hwr_zh.so \
@lib/armeabi-v7a/libhwrword.so \
@lib/armeabi-v7a/libpinyin_data_bundle.so
LOCAL_MODULE_PATH := $(TARGET_OUT)/app
LOCAL_CERTIFICATE := platform
LOCAL_DEX_PREOPT := false
LOCAL_PACKAGE_NAME := MyApplicition
LOCAL_PRIVATE_PLATFORM_APIS := true
include $(BUILD_PREBUILT)
- device\mediatek\mt6761\device.mk add macro
PRODUCT_PACKAGES += MyApplicition
- ./buildall_userdebug.sh B5528BIO
Successful compilation will generate apk under system/app