嵌入式系统移植 - Framewrok : 客制化系统 API 接口给到应用

本文详细介绍了Android系统服务如AMS、PMS、WMS的C/S架构及IPC远程调用原理,探讨了客制化系统API的设计模式,特别是AIDL的使用,并提供了打包流程与注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

客制化系统 API 接口

说明

在 Android 中, 所有的系统服务(AMS, PMS, WMS)都是采用 C / S 进行 IPC 远程调用的

// 例如: 
ActivityManagerService 需要通过 ActivityManager 进行调用.
PackageManagerService 需要通过 PakcageManager 进行调用.
WindowsManagerService 需要通过 WindowsManager 进行调用.

当系统层面添加 API 接口时, 需要更新对应的 class/jar 文件给到应用, 问题是什么?
jar包文件通常在 IDE(Android Studio) 里面已经封装好了:

如果把 class.jar 做 Unzip 修改会存在:
个别 class 方法重名
API 版本不一致(例如 21 对应的是 4.4, 23 对应的是 6.0)

设计模式

  • aidl
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package android.helper;

oneway interface IPowerEventListener {
  	void onBacklightChange(boolean on);
}
  • singleton class
package android.helper;

import android.annotation.SdkConstant;
import android.annotation.SystemApi;
import android.content.Context;
import android.util.Log;

import android.os.PowerManager;
import android.helper.IPowerEventListener;

public final class PowerManagerHelper extends Helper {
    private static final String TAG = "PowerManagerHelper";
	
	private final PowerManager mPowerManager;
	
	public PowerManagerHelper(Context context) {
		super(context);
		mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
	}
	
	private static PowerManagerHelper _this = null;
	public static PowerManagerHelper getInstance(Context context) {
		if(null == _this) {
			synchronized(PowerManagerHelper.class) {
				try {
					if(null == _this) {
					    _this = new PowerManagerHelper(context);
					}	
				} catch (Exception ex) {
				    Log.e(TAG, "PowerManagerHelper getInstance error.", ex);
				}	
			}
		}

		return _this;
	}

	public void setForceShutdownTime(long delayMillis) {
	    // do thing
	}

	public void setNoOpsShutdownTime(long delayMillis) {
	    // do thing
	}

	public void setPowerEventListener(IPowerEventListener listener) {
	    // mPowerManager.setPowerEventListener(listener);
	}
}

如何打包

Android SDK编译出来在: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/

拷贝 class 到路径其他地方, 使用 jar 命令: jar cvfm system-custom.jar ./classdir
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值