日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BindeService

發布時間:2025/3/15 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BindeService 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?App 綁定service

fun bindService() {val i = Intent("com.example.iffyservice.Iffyservice")i.setPackage("com.example.iffyservice")if (bindService(i, this, Service.BIND_AUTO_CREATE)) {println("綁定成功")} else {println("綁定失敗")}} ContextImpl @Overridepublic boolean bindService(Intent service, ServiceConnection conn, int flags) {warnIfCallingFromSystemProcess();return bindServiceCommon(service, conn, flags, null, mMainThread.getHandler(), null,getUser());}private boolean bindServiceCommon(Intent service, ServiceConnection conn, int flags,String instanceName, Handler handler, Executor executor, UserHandle user) {//調用AMS的bindIsolatedServiceint res = ActivityManager.getService().bindIsolatedService(mMainThread.getApplicationThread(), getActivityToken(), service,service.resolveTypeIfNeeded(getContentResolver()),sd, flags, instanceName, getOpPackageName(), user.getIdentifier());}

???? ActivityManagerService bindIsolatedService

public int bindIsolatedService(IApplicationThread caller, IBinder token, Intent service,String resolvedType, IServiceConnection connection, int flags, String instanceName,String callingPackage, int userId) throws TransactionTooLargeException {enforceNotIsolatedCaller("bindService");//調用ActiveServices的bindServiceLockedsynchronized(this) {return mServices.bindServiceLocked(caller, token, service,resolvedType, connection, flags, instanceName, callingPackage, userId);}}

ActiveServices 啟動service

int bindServiceLocked(IApplicationThread caller, IBinder token, Intent service,String resolvedType, final IServiceConnection connection, int flags,String instanceName, String callingPackage, final int userId)throws TransactionTooLargeException {//BIND_AUTO_CREATE時候 創建serviceif ((flags&Context.BIND_AUTO_CREATE) != 0) {s.lastActivity = SystemClock.uptimeMillis();if (bringUpServiceLocked(s, service.getFlags(), callerFg, false,permissionsReviewRequired) != null) {return 0;}}}private String bringUpServiceLocked(ServiceRecord r, int intentFlags, boolean execInFg,boolean whileRestarting, boolean permissionsReviewRequired)throws TransactionTooLargeException {if (!isolated) {app = mAm.getProcessRecordLocked(procName, r.appInfo.uid, false);if (DEBUG_MU) Slog.v(TAG_MU, "bringUpServiceLocked: appInfo.uid=" + r.appInfo.uid+ " app=" + app);if (app != null && app.thread != null) {try {app.addPackage(r.appInfo.packageName, r.appInfo.longVersionCode, mAm.mProcessStats);//啟動ServicerealStartServiceLocked(r, app, execInFg);return null;} catch (TransactionTooLargeException e) {throw e;} catch (RemoteException e) {Slog.w(TAG, "Exception when starting service " + r.shortInstanceName, e);}// If a dead object exception was thrown -- fall through to// restart the application.}} }private final void realStartServiceLocked(ServiceRecord r,ProcessRecord app, boolean execInFg) throws RemoteException {//ActivityThread startServiceapp.thread.scheduleCreateService(r, r.serviceInfo,mAm.compatibilityInfoForPackage(r.serviceInfo.applicationInfo),app.getReportedProcState());}

ActivityThread

public final void scheduleCreateService(IBinder token,ServiceInfo info, CompatibilityInfo compatInfo, int processState) {updateProcessState(processState, false);CreateServiceData s = new CreateServiceData();s.token = token;s.info = info;s.compatInfo = compatInfo;//Handler create ServicesendMessage(H.CREATE_SERVICE, s);}case CREATE_SERVICE:Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, ("serviceCreate: " + String.valueOf(msg.obj)));handleCreateService((CreateServiceData)msg.obj);Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);break;private void handleCreateService(CreateServiceData data) {//工廠用于創建下面這些東西 //public class AppComponentFactory* @see #instantiateApplication* @see #instantiateActivity* @see #instantiateClassLoader* @see #instantiateService* @see #instantiateReceiver* @see #instantiateProvider*/service = packageInfo.getAppFactory().instantiateService(cl, data.info.name, data.intent); }

ActiveServices

int bindServiceLocked(IApplicationThread caller, IBinder token, Intent service,String resolvedType, final IServiceConnection connection, int flags,String instanceName, String callingPackage, final int userId)throws TransactionTooLargeException {//service已經存在就直接回調app的onServiceConnectedif (s.app != null && b.intent.received) {// Service is already running, so we can immediately// publish the connection.try {c.conn.connected(s.name, b.intent.binder, false);} catch (Exception e) {Slog.w(TAG, "Failure sending service " + s.shortInstanceName+ " to connection " + c.conn.asBinder()+ " (in " + c.binding.client.processName + ")", e);}// If this is the first app connected back to this binding,// and the service had previously asked to be told when// rebound, then do so.if (b.intent.apps.size() == 1 && b.intent.doRebind) {requestServiceBindingLocked(s, b.intent, callerFg, true);}} else if (!b.intent.requested) {//Service沒有bind的話就去bindrequestServiceBindingLocked(s, b.intent, callerFg, false);}}private final boolean requestServiceBindingLocked(ServiceRecord r, IntentBindRecord i,boolean execInFg, boolean rebind) throws TransactionTooLargeException {//thread 是 IApplicationThread zygote fork出來的r.app.thread.scheduleBindService(r, i.intent.getIntent(), rebind,r.app.getReportedProcState()); } ActivityThread.ApplicationThread public final void scheduleBindService(IBinder token, Intent intent,boolean rebind, int processState) {updateProcessState(processState, false);BindServiceData s = new BindServiceData();s.token = token;s.intent = intent;s.rebind = rebind;if (DEBUG_SERVICE)Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid="+ Binder.getCallingUid() + " pid=" + Binder.getCallingPid());sendMessage(H.BIND_SERVICE, s);}public void handleMessage(Message msg) {case BIND_SERVICE:Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind");handleBindService((BindServiceData)msg.obj);Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);break;}private void handleBindService(BindServiceData data) {Service s = mServices.get(data.token);if (DEBUG_SERVICE)Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind);if (s != null) {try {data.intent.setExtrasClassLoader(s.getClassLoader());data.intent.prepareToEnterProcess();try {if (!data.rebind) {IBinder binder = s.onBind(data.intent);//調用AMS publishServiceActivityManager.getService().publishService(data.token, data.intent, binder);}} catch (RemoteException ex) {throw ex.rethrowFromSystemServer();}} }}

?

??? ActivityManagerService 發布Service

ActivityManagerService 發布Servicepublic void publishService(IBinder token, Intent intent, IBinder service) {// Refuse possible leaked file descriptorsif (intent != null && intent.hasFileDescriptors() == true) {throw new IllegalArgumentException("File descriptors passed in Intent");}synchronized(this) {if (!(token instanceof ServiceRecord)) {throw new IllegalArgumentException("Invalid service token");}mServices.publishServiceLocked((ServiceRecord)token, intent, service);}} ActiveServices ActiveServices void publishServiceLocked(ServiceRecord r, Intent intent, IBinder service) {for (int conni = connections.size() - 1; conni >= 0; conni--) {ArrayList<ConnectionRecord> clist = connections.valueAt(conni);for (int i=0; i<clist.size(); i++) {ConnectionRecord c = clist.get(i);c.conn.connected(r.name, service, false);}} }

會調用client app的OnServiceconnected?

override fun onServiceConnected(name: ComponentName?, service: IBinder?) {mIMyAidlInterface =IMyAidlInterface.Stub.asInterface(service) }

?

總結

以上是生活随笔為你收集整理的BindeService的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 天天操夜夜操狠狠操 | 久久五 | 成人综合区 | 久久精品国产亚洲AV黑人 | 色妞ww精品视频7777 | 欧美日韩国产中文字幕 | 亚洲精品aa | 波多野结衣在线观看一区 | 日日干,夜夜操 | 亚洲欧美日韩精品久久 | 色婷婷综合久久久中文字幕 | 亚洲精品久久久蜜桃 | 国产成人精品免高潮在线观看 | 欧美色射 | 欧美一区综合 | av天天有 | 欧美1区2区 | 久久亚洲综合色图 | 欧美一区二区三区小说 | 久久av资源站 | 黄色三级在线 | 亚洲国产v | 精品妇女一区二区三区 | www黄色网 | 一区二区视 | 无码精品在线视频 | 天天躁日日躁狠狠躁伊人 | 五月的婷婷 | 国产午夜影院 | 深夜久久久 | 午夜视频网址 | 欧美大喷水吹潮合集在线观看 | 久久久精品视频在线 | 亚洲三区在线播放 | 欧美三级午夜理伦三级 | 性xxxxx大片免费视频 | 美女一区二区三区四区 | 亚洲精品高清在线观看 | 97免费超碰 | 玖玖在线免费视频 | 91天天色 | 波多野结衣免费看 | 狠狠爱综合网 | www.精品视频 | 色呦呦麻豆 | 在线观看欧美国产 | 999精品在线观看 | 午夜av影视 | 欧美男女激情 | 91日批 | 肉色丝袜脚交一区二区 | 精品久久ai | 91精品婷婷国产综合久久竹菊 | 99热91| 亚洲性综合 | 亚洲午夜精品久久久久久人妖 | 草碰在线视频 | 久久精品不卡 | 麻豆黄色片 | 岛国精品资源网站 | 欧美视频不卡 | 日韩Av无码精品 | 亚洲免费在线观看视频 | 手机成人av在线 | 免费三级大片 | 正在播放一区二区 | 青青艹视频 | 50度灰在线 | 国产精品自拍偷拍 | 午夜片在线 | 伊人春色在线视频 | 亚洲天天操 | 久久老熟女一区二区三区 | 快播av在线| 欧美 亚洲 一区 | 国产在线观看 | 色偷偷噜噜噜亚洲男人 | 88福利视频| 国产性猛交xx乱 | 国内精久久久久久久久久人 | 欧美巨鞭大战丰满少妇 | 久久久亚洲欧美 | 国产人妖一区二区 | 涩涩资源站| 中文字幕人妻伦伦 | 成人av专区 | 亚洲一区自拍偷拍 | 午夜丁香婷婷 | 国产一级二级三级视频 | 久久一区二区三区四区 | 污网在线看 | 中出精品 | 成人午夜剧场视频网站 | 无码精品一区二区免费 | 黄色美女av | 啪啪网页 | 欧美三级在线视频 | 欧美成人精品在线观看 | 亚洲成人aa|