Android在framework层添加自定义服务的流程

环境说明

  • ubuntu16.04
  • android4.1
  • java version “1.6.0_45”
  • GNU Make 3.81
  • gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)

可能有人会问,现在都2024了怎么还在用android4版本,早都过时了。确实,现在最新的都是Android13、Android14了,不过我这里主要是用于demo的演示学习使用,只要整个的流程掌握了,哪个版本的流程都是大同小异;再一个就拿Android13来说,源码100G多非常庞大,代码clone、源码编译都是很慢的,而Android4.1源码才4G多,编译运行就快多了,省时省力。

编写AIDL文件

如果不了解aidl,建议先看看:android AIDL使用demo
仿照系统中现有服务的编写方式,新增服务需要编写aidl接口(也就是提供什么服务),在frameworks/base/core/java/android/helloservice/新建aidl文件,
在这里插入图片描述
ICallBack.aidl内容如下

package android.helloservice;
interface ICallBack {void onReceive(String serverMsg);
}

IHelloService.aidl内容如下

package android.helloservice;
import android.helloservice.ICallBack;
interface IHelloService {String getHello(String send);void registerCallback(ICallBack callback);void unRegisterCallback(ICallBack callback);
}

修改frameworks/base/Android.mk,在LOCAL_SRC_FILES变量中加入新增的aidl文件

## READ ME: ########################################################
##
## When updating this list of aidl files, consider if that aidl is
## part of the SDK API.  If it is, also add it to the list below that
## is preprocessed and distributed with the SDK.  This list should
## not contain any aidl files for parcelables, but the one below should
## if you intend for 3rd parties to be able to send those objects
## across process boundaries.
##
## READ ME: ########################################################
LOCAL_SRC_FILES += \core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl \core/java/android/accessibilityservice/IAccessibilityServiceClient.aidl \core/java/com/android/internal/widget/IRemoteViewsFactory.aidl \core/java/com/android/internal/widget/IRemoteViewsAdapterConnection.aidl \//省略部分core/java/android/helloservice/ICallBack.aidl \core/java/android/helloservice/IHelloService.aidl \

执行mmm frameworks/base单编,编译成功之后会在out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/helloservice/生成如下文件在这里插入图片描述
IHelloService.java内容(androidstudio生成,aosp生成的代码紧凑不方便阅读)

/** This file is auto-generated.  DO NOT MODIFY.*/
package android.helloservice;
public interface IHelloService extends android.os.IInterface
{/** Default implementation for IHelloService. */public static class Default implements android.helloservice.IHelloService{@Override public java.lang.String getHello(java.lang.String send) throws android.os.RemoteException{return null;}@Override public void registerCallback(android.helloservice.ICallBack callback) throws android.os.RemoteException{}@Override public void unRegisterCallback(android.helloservice.ICallBack callback) throws android.os.RemoteException{}@Overridepublic android.os.IBinder asBinder() {return null;}}/** Local-side IPC implementation stub class. */public static abstract class Stub extends android.os.Binder implements android.helloservice.IHelloService{/** Construct the stub at attach it to the interface. */public Stub(){this.attachInterface(this, DESCRIPTOR);}/*** Cast an IBinder object into an android.helloservice.IHelloService interface,* generating a proxy if needed.*/public static android.helloservice.IHelloService asInterface(android.os.IBinder obj){if ((obj==null)) {return null;}android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);if (((iin!=null)&&(iin instanceof android.helloservice.IHelloService))) {return ((android.helloservice.IHelloService)iin);}return new android.helloservice.IHelloService.Stub.Proxy(obj);}@Override public android.os.IBinder asBinder(){return this;}@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException{java.lang.String descriptor = DESCRIPTOR;if (code >= android.os.IBinder.FIRST_CALL_TRANSACTION && code <= android.os.IBinder.LAST_CALL_TRANSACTION) {data.enforceInterface(descriptor);}switch (code){case INTERFACE_TRANSACTION:{reply.writeString(descriptor);return true;}}switch (code){case TRANSACTION_getHello:{java.lang.String _arg0;_arg0 = data.readString();java.lang.String _result = this.getHello(_arg0);reply.writeNoException();reply.writeString(_result);break;}case TRANSACTION_registerCallback:{android.helloservice.ICallBack _arg0;_arg0 = android.helloservice.ICallBack.Stub.asInterface(data.readStrongBinder());this.registerCallback(_arg0);reply.writeNoException();break;}case TRANSACTION_unRegisterCallback:{android.helloservice.ICallBack _arg0;_arg0 = android.helloservice.ICallBack.Stub.asInterface(data.readStrongBinder());this.unRegisterCallback(_arg0);reply.writeNoException();break;}default:{return super.onTransact(code, data, reply, flags);}}return true;}private static class Proxy implements android.helloservice.IHelloService{private android.os.IBinder mRemote;Proxy(android.os.IBinder remote){mRemote = remote;}@Override public android.os.IBinder asBinder(){return mRemote;}public java.lang.String getInterfaceDescriptor(){return DESCRIPTOR;}@Override public java.lang.String getHello(java.lang.String send) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();java.lang.String _result;try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeString(send);boolean _status = mRemote.transact(Stub.TRANSACTION_getHello, _data, _reply, 0);_reply.readException();_result = _reply.readString();}finally {_reply.recycle();_data.recycle();}return _result;}@Override public void registerCallback(android.helloservice.ICallBack callback) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeStrongInterface(callback);boolean _status = mRemote.transact(Stub.TRANSACTION_registerCallback, _data, _reply, 0);_reply.readException();}finally {_reply.recycle();_data.recycle();}}@Override public void unRegisterCallback(android.helloservice.ICallBack callback) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeStrongInterface(callback);boolean _status = mRemote.transact(Stub.TRANSACTION_unRegisterCallback, _data, _reply, 0);_reply.readException();}finally {_reply.recycle();_data.recycle();}}}static final int TRANSACTION_getHello = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);static final int TRANSACTION_registerCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);static final int TRANSACTION_unRegisterCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);}public static final java.lang.String DESCRIPTOR = "android.helloservice.IHelloService";public java.lang.String getHello(java.lang.String send) throws android.os.RemoteException;public void registerCallback(android.helloservice.ICallBack callback) throws android.os.RemoteException;public void unRegisterCallback(android.helloservice.ICallBack callback) throws android.os.RemoteException;
}

ICallBack.java内容(androidstudio生成)

/** This file is auto-generated.  DO NOT MODIFY.*/
package android.helloservice;
public interface ICallBack extends android.os.IInterface
{/** Default implementation for ICallBack. */public static class Default implements android.helloservice.ICallBack{@Override public void onReceive(java.lang.String serverMsg) throws android.os.RemoteException{}@Overridepublic android.os.IBinder asBinder() {return null;}}/** Local-side IPC implementation stub class. */public static abstract class Stub extends android.os.Binder implements android.helloservice.ICallBack{/** Construct the stub at attach it to the interface. */public Stub(){this.attachInterface(this, DESCRIPTOR);}/*** Cast an IBinder object into an android.helloservice.ICallBack interface,* generating a proxy if needed.*/public static android.helloservice.ICallBack asInterface(android.os.IBinder obj){if ((obj==null)) {return null;}android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);if (((iin!=null)&&(iin instanceof android.helloservice.ICallBack))) {return ((android.helloservice.ICallBack)iin);}return new android.helloservice.ICallBack.Stub.Proxy(obj);}@Override public android.os.IBinder asBinder(){return this;}@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException{java.lang.String descriptor = DESCRIPTOR;if (code >= android.os.IBinder.FIRST_CALL_TRANSACTION && code <= android.os.IBinder.LAST_CALL_TRANSACTION) {data.enforceInterface(descriptor);}switch (code){case INTERFACE_TRANSACTION:{reply.writeString(descriptor);return true;}}switch (code){case TRANSACTION_onReceive:{java.lang.String _arg0;_arg0 = data.readString();this.onReceive(_arg0);reply.writeNoException();break;}default:{return super.onTransact(code, data, reply, flags);}}return true;}private static class Proxy implements android.helloservice.ICallBack{private android.os.IBinder mRemote;Proxy(android.os.IBinder remote){mRemote = remote;}@Override public android.os.IBinder asBinder(){return mRemote;}public java.lang.String getInterfaceDescriptor(){return DESCRIPTOR;}@Override public void onReceive(java.lang.String serverMsg) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeString(serverMsg);boolean _status = mRemote.transact(Stub.TRANSACTION_onReceive, _data, _reply, 0);_reply.readException();}finally {_reply.recycle();_data.recycle();}}}static final int TRANSACTION_onReceive = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);}public static final java.lang.String DESCRIPTOR = "android.helloservice.ICallBack";public void onReceive(java.lang.String serverMsg) throws android.os.RemoteException;
}

编写系统服务

上面aidl是定义服务接口,下面开始编写一个系统服务来实现接口。参考系统服务MountService.java的路径编写frameworks/base/services/java/com/android/server/HelloService.java

package com.android.server;import android.content.Context;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
import android.helloservice.ICallBack;
import android.helloservice.IHelloService;
public class HelloService extends IHelloService.Stub {private static final String TAG = "HelloService";private RemoteCallbackList<ICallBack> callbackList = new RemoteCallbackList();private Context context;public HelloService(Context context) {this.context = context;Log.d(TAG, "HelloService() init");}@Overridepublic String getHello(String send) throws RemoteException {Log.d(TAG, "getHello() called with: send = [" + send + "]");int num = callbackList.beginBroadcast();for (int i = 0; i < num; i++) {ICallBack callback = callbackList.getBroadcastItem(i);if (callback != null) {callback.onReceive("callback from HelloService with:" + send);}}callbackList.finishBroadcast();return send + ",server receive ok";}@Overridepublic void registerCallback(ICallBack callback) throws RemoteException {callbackList.register(callback);Log.d(TAG, "registerCallback() called with: callback = [" + callback + "]");}@Overridepublic void unRegisterCallback(ICallBack callback) throws RemoteException {callbackList.unregister(callback);Log.d(TAG, "unRegisterCallback() called with: callback = [" + callback + "]");}
}

注册系统服务

所有系统服务都运行在名为 system_server 的进程中,我们也要把服务加入进去。系统中已有很多服务了,我们把它加入到最后,修改frameworks/base/services/java/com/android/server/SystemServer.java

 	@Overridepublic void run() {...省略部分try {Slog.i(TAG, "Entropy Mixer");ServiceManager.addService("entropy", new EntropyMixer());//HelloService的name必须唯一Slog.i(TAG, "HelloService");ServiceManager.addService("HelloService", new HelloService(context));}}

执行mmm frameworks/base/services/java/编译service模块
执行make snod重新打包system.img
执行emulator重启模拟器,发现一直停留在重启界面。在这里插入图片描述
无奈,执行make -j30(本机16核32线程)重编也报错,提示如下

PRODUCT_COPY_FILES device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml ignored.
Checking API: checkapi-current
target Java: services (out/target/common/obj/JAVA_LIBRARIES/services_intermediates/classes)
out/target/common/obj/PACKAGING/public_api.txt:10084: error 2: Added package android.helloservice******************************
You have tried to change the API from what has been previously approved.To make these errors go away, you have two choices:1) You can add "@hide" javadoc comments to the methods, etc. listed in theerrors above.2) You can update current.txt by executing the following command:make update-apiTo submit the revised current.txt to the main Android repository,you will need approval.
******************************

根据错误提示执行下面命令

make update-api
make -j30
emulator

模拟器重启成功,且看到HelloService相关日志,说明HelloService服务添加成功。

I/InputManager(  147): Starting input manager
D/PermissionCache(   35): checking android.permission.ACCESS_SURFACE_FLINGER for uid=1000 => granted (1193 us)
I/WindowManager(  147): Enabled StrictMode logging for WMThread's Looper
I/SystemServer(  147): HelloService
D/HelloService(  147): HelloService() init
I/SystemServer(  147): No Bluetooh Service (emulator)

App调用服务

framework层添加服务成功后,app如何使用服务呢?有两种方式,下面一一讲解

方式1:拿到AIDL文件直接访问

为了方便开发,用androidstudio新建一个项目名字就叫Hello。把上面的两个aidl文件复制到项目,保持aidl的包名结构,在这里插入图片描述

MainActivity内容如下,其中ServiceManager会报红不用管,因为等下我们要拷贝项目到aosp源码环境下编译,源码环境下可以正常编过。

package com.hai.hello;import android.app.Activity;
import android.helloservice.ICallBack;
import android.helloservice.IHelloService;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.view.View;public class MainActivity extends Activity {private static final String TAG = "MainActivity";IHelloService mService;ICallBack.Stub callback = new ICallBack.Stub() {@Overridepublic void onReceive(String serverMsg) throws RemoteException {Log.d(TAG, "onReceive() called with: serverMsg = [" + serverMsg + "]");}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mService = IHelloService.Stub.asInterface(ServiceManager.getService("HelloService"));Log.d(TAG, "onCreate: " + mService);try {mService.registerCallback(callback);} catch (RemoteException e) {throw new RuntimeException(e);}try {mService.getHello("client say hello");} catch (RemoteException e) {throw new RuntimeException(e);}try {mService.unRegisterCallback(callback);} catch (RemoteException e) {throw new RuntimeException(e);}}
}

把项目拷贝到packages/experimental/目录下。参考此目录下的其他app的项目结构,移除不要的文件,最终Hello的目录结构如图在这里插入图片描述
Android.mk内容如下

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
#LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_SRC_FILES += aidl/android/helloservice/IHelloService.aidl
LOCAL_SRC_FILES += aidl/android/helloservice/ICallBack.aidl
LOCAL_PACKAGE_NAME := Hello
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)

执行以下命令单编Hello项目,重启模拟器,

mmm packages/experimental/Hello
make snod
emulator

在这里插入图片描述
点击启动app,从日志可以看到Hello app启动成功并和HelloService正确交互了。

方式2:通过getSystemService访问

为了方便开发者使用,我们也提供通用接口context.getSystemService()方式获取服务。仿照AccountManager我们也写一个类就叫HelloManager吧,
frameworks/base/core/java/android/helloservice/HelloManager.java内容如下

package android.helloservice;
import android.content.Context;
import android.helloservice.ICallBack;
import android.helloservice.IHelloService;
import android.os.RemoteException;
import android.util.Log;public class HelloManager {private static final String TAG = "HelloManager";private Context context;private IHelloService service;public HelloManager(Context context, IHelloService service) {this.context = context;this.service = service;Log.d(TAG, "HelloManager()");}public String getHello(String send) {try {return service.getHello(send);} catch (RemoteException ex) {throw new RuntimeException(ex);}}public void registerCallback(ICallBack callback) {try {service.registerCallback(callback);} catch (RemoteException ex) {throw new RuntimeException(ex);}}public void unRegisterCallback(ICallBack callback) {try {service.unRegisterCallback(callback);} catch (RemoteException ex) {throw new RuntimeException(ex);}}
}

HelloManager写好之后需要注册到context中,修改frameworks/base/core/java/android/app/ContextImpl.java如下:

import android.helloservice.IHelloService;
import android.helloservice.HelloManager; 
static {...省略部分   registerService(ACCESSIBILITY_SERVICE, new ServiceFetcher() {public Object getService(ContextImpl ctx) {return AccessibilityManager.getInstance(ctx);}});registerService("HelloService", new ServiceFetcher() {public Object createService(ContextImpl ctx) {IBinder b = ServiceManager.getService("HelloService");IHelloService service = IHelloService.Stub.asInterface(b);return new HelloManager(ctx, service);}});registerService(ACTIVITY_SERVICE, new ServiceFetcher() {public Object createService(ContextImpl ctx) {return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());}});

然后是app使用,这里还是使用Hello项目,修改MainActivity内容如下

package com.hai.hello;
import android.app.Activity;
import android.helloservice.ICallBack;
import android.helloservice.IHelloService;
import android.helloservice.HelloManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.view.View;public class MainActivity extends Activity {private static final String TAG = "MainActivity";IHelloService mService;ICallBack.Stub callback = new ICallBack.Stub() {@Overridepublic void onReceive(String serverMsg) throws RemoteException {Log.d(TAG, "onReceive() called with: serverMsg = [" + serverMsg + "]");}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);HelloManager helloManager=(HelloManager) getSystemService("HelloService");Log.d(TAG, "HelloManager onCreate: " + mService);helloManager.registerCallback(callback);helloManager.getHello("client say hello");helloManager.unRegisterCallback(callback);}
}

执行下面命令

mmm packages/experimental/Hello/
make update-api
make -j30
emulator

模拟器重启后看到如下日志,说明getSystemService的方式也访问成功。
在这里插入图片描述
参考:
Android 添加系统服务的完整流程SystemService
为Android系统的Application Frameworks层增加硬件访问服务
为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/370186.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于YOLOv5的人脸目标检测

本文是在之前的基于yolov5的人脸关键点检测项目上扩展来的。因为人脸目标检测的效果将直接影响到人脸关键点检测的效果&#xff0c;因此本文主要讲解利用yolov5训练人脸目标检测(关键点检测可以看我人脸关键点检测文章) 基于yolov5的人脸关键点检测&#xff1a;人脸关键点检测…

复现YOLO_ORB_SLAM3_with_pointcloud_map项目记录

文章目录 1.环境问题2.遇到的问题2.1编译问题1 monotonic_clock2.2 associate.py2.3 associate.py问题 3.运行问题 1.环境问题 首先环境大家就按照github上的指定环境安装即可 环境怎么安装网上大把的资源&#xff0c;自己去找。 2.遇到的问题 2.1编译问题1 monotonic_cloc…

Android增量更新----java版

一、背景 开发过程中&#xff0c;随着apk包越来越大&#xff0c;全量更新会使得耗时&#xff0c;同时浪费流量&#xff0c;为了节省时间&#xff0c;使用增量更新解决。网上很多文章都不是很清楚&#xff0c;没有手把手教学&#xff0c;使得很多初学者&#xff0c;摸不着头脑&a…

jmeter测试工具学习

1.双击jar包打开&#xff0c;发现那个bat打不开 2.新建plan之后编辑添加线程组 会加入500*5次请求 3.添加HTTP请求 添加字段 为了让http请求发送到不同的分片&#xff0c;要把userid随机化 4.添加监听器 5.聚合报告

Wish卖家必读:如何安全有效地进行店铺测评

Wish以其独特的商业模式和先进的技术在电商领域独树一帜。作为北美和欧洲最大的移动电商平台之一&#xff0c;Wish拥有庞大的用户基础&#xff0c;其中90%的卖家来自中国&#xff0c;这不仅显示了其在全球电商市场中的影响力&#xff0c;也反映了其对中国卖家的吸引力。 Wish平…

vxe-table合并行数据;element-plus的el-table动态合并行

文章目录 一、vxe-table合并行数据1.代码 二、使用element-plus的el-table动态合并行2.代码 注意&#xff1a;const fields 是要合并的字段 一、vxe-table合并行数据 1.代码 <vxe-tableborderresizableheight"500":scroll-y"{enabled: false}":span-m…

Ubuntu 22.04远程自动登录桌面环境

如果需要远程自动登录桌面环境&#xff0c;首先需要将Ubuntu的自动登录打开&#xff0c;在【settings】-【user】下面 然后要设置【Sharing】进行桌面共享&#xff0c;Ubuntu有自带的桌面共享功能&#xff0c;不需要另外去安装xrdp或者vnc之类的工具了 点开【Remote Desktop】…

window系统openssl开发环境搭建(VS2017)

window系统openssl开发环境搭建 VS2017 一、下载openssl二、安装openssl三、openssl项目配置3.1 配置include文件3.2 配置openssl动态库四、编写openssl测试代码五、问题总结5.1 问题 一5.2 问题二一、下载openssl https://slproweb.com/products/Win32OpenSSL.html 根据自己…

CTF实战:从入门到提升

CTF实战&#xff1a;从入门到提升 &#x1f680;前言 没有网络安全就没有国家安全&#xff0c;网络安全不仅关系到国家整体信息安全&#xff0c;也关系到民生安全。近年来&#xff0c;随着全国各行各业信息化的发展&#xff0c;网络与信息安全得到了进一步重视&#xff0c;越…

【总线】AXI4第八课时:介绍AXI的 “原子访问“ :独占访问(Exclusive Access)和锁定访问(Locked Access)

大家好,欢迎来到今天的总线学习时间!如果你对电子设计、特别是FPGA和SoC设计感兴趣&#xff0c;那你绝对不能错过我们今天的主角——AXI4总线。作为ARM公司AMBA总线家族中的佼佼者&#xff0c;AXI4以其高性能和高度可扩展性&#xff0c;成为了现代电子系统中不可或缺的通信桥梁…

力扣习题--找不同

目录 前言 题目和解析 1、找不同 2、 思路和解析 总结 前言 本系列的所有习题均来自于力扣网站LeetBook - 力扣&#xff08;LeetCode&#xff09;全球极客挚爱的技术成长平台 题目和解析 1、找不同 给定两个字符串 s 和 t &#xff0c;它们只包含小写字母。 字符串 t…

Web 基础与 HTTP 协议

Web 基础与 HTTP 协议 一、Web 基础1.1域名和 DNS域名的概念Hosts 文件DNS&#xff08;Domain Name System 域名系统&#xff09;域名注册 1.2网页与 HTML网页概述HTML 概述网站和主页Web1.0 与 Web2.0 1.3静态网页与动态网页静态网页动态网页 二、HTTP 协议1.1HTTP 协议概述1.…

跨界客户服务:拓展服务边界,创造更多价值

在当今这个日新月异的商业时代&#xff0c;跨界合作已不再是新鲜词汇&#xff0c;它如同一股强劲的东风&#xff0c;吹散了行业间的壁垒&#xff0c;为企业服务创新开辟了前所未有的广阔天地。特别是在客户服务领域&#xff0c;跨界合作正以前所未有的深度和广度&#xff0c;拓…

刷题之多数元素(leetcode)

多数元素 哈希表解法&#xff1a; class Solution { public:/*int majorityElement(vector<int>& nums) {//map记录元素出现的次数&#xff0c;遍历map&#xff0c;求出出现次数最多的元素unordered_map<int,int>map;for(int i0;i<nums.size();i){map[nu…

llama2阅读: logits是什么?

Logits是一个在深度学习中&#xff0c;几乎一直都有的概念&#xff0c;它意味着模型unnormalized final scores. 然后你可以通过softmax得到模型针对你class的概率分布。 而在llama2的代码中&#xff0c;同样有logits的使用&#xff0c;那么针对llama2&#xff0c;logits的作用…

英国“王曼爱华”指的是哪几所高校?中英双语介绍

中文版 英国“王曼爱华”指的是伦敦大学国王学院、曼彻斯特大学、爱丁堡大学和华威大学这四所院校。以下是对伦敦大学国王学院、曼彻斯特大学、爱丁堡大学和华威大学这四所英国顶尖大学的详细介绍&#xff0c;包括它们的建校历史、专业优势、优秀校友和地理位置。 伦敦大学国…

HTTP协议格式

目录 正文&#xff1a; 1.概述 2.主要特点 3.请求协议格式 4.响应协议格式 5.响应状态码 总结&#xff1a; 正文&#xff1a; 1.概述 HTTP 协议是用于传输超文本数据&#xff08;如 HTML&#xff09;的应用层协议&#xff0c;它建立在传输层协议 TCP/IP 之上。当我们在…

C语言之常用内存函数以及模拟实现

目录 前言 一、memcpy的使用和模拟实现 二、memmove的使用和模拟实现 三、memset的使用和模拟实现 四、memcmp的使用和模拟实现 总结 前言 本文主要讲述C语言中常用的内存函数&#xff1a;memcpy、memmove、memset、memcmp。内容不多&#xff0c;除了了解如何使用&#x…

remix测试文件测试智能合约

remix内其实也是可以通过编写测试文件来测试智能合约的&#xff0c;需要使用插件自动生成框架以及测试结果。本文介绍一个简单的HelloWorld合约来讲解 安装插件多重检测&#xff1a; &#xff08;solidity unit testing&#xff09; 编译部署HelloWorld合约 // SPDX-License-…

Unity中TimeLine的一些用法

Unity中TimeLine的一些用法 概念其他 概念 无Track模式&#xff08;PlayableAsset、PlayableBehaviour&#xff09; 1. 两者关系 运行在PlayableTrack中作用 PlayableBehaviour 实际执行的脚本字段并不会显示在timeline面板上 PlayableAsset PlayableBehaviour的包装器&#x…