如何查看FrameWork层源码(例如:PhoneWindow) android.jar

本文介绍如何在Android项目中配置SDK路径并引入android.jar文件。通过创建lib目录并将android.jar添加为库,可以方便地进行后续开发工作。

找到你的sdk路径



打开sdk路径位置

这里写图片描述
这里写图片描述

把这个android.jar拷贝到你的项目中,

建立一个lib目录,放到lib下面,点击右键,as a library,就可以双击打开了

这里写图片描述

另外你可以双击shift,去搜索

这里写图片描述

2025-08-05 14:56:55.227 4304-4304 nativeloader com.kotei.fusionpositiondemo.debug D Load libframework-connectivity-tiramisu-jni.so using APEX ns com_android_tethering for caller /apex/com.android.tethering/javalib/framework-connectivity-t.jar: ok 2025-08-05 14:56:55.272 4304-4304 re-initialized> com.kotei.fusionpositiondemo.debug W type=1400 audit(0.0:98): avc: granted { execute } for path="/data/data/com.kotei.fusionpositiondemo.debug/code_cache/startup_agents/9758b833-agent.so" dev="dm-55" ino=361267 scontext=u:r:untrusted_app:s0:c216,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c216,c256,c512,c768 tclass=file app=com.kotei.fusionpositiondemo.debug 2025-08-05 14:56:55.286 4304-4304 nativeloader com.kotei.fusionpositiondemo.debug D Load /data/user/0/com.kotei.fusionpositiondemo.debug/code_cache/startup_agents/9758b833-agent.so using system ns (caller=<unknown>): ok 2025-08-05 14:56:55.296 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug W hiddenapi: DexFile /data/data/com.kotei.fusionpositiondemo.debug/code_cache/.studio/instruments-07dd17c6.jar is in boot class path but is not in a known location 2025-08-05 14:56:55.415 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug W Redefining intrinsic method java.lang.Thread java.lang.Thread.currentThread(). This may cause the unexpected use of the original definition of java.lang.Thread java.lang.Thread.currentThread()in methods that have already been compiled. 2025-08-05 14:56:55.415 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug W Redefining intrinsic method boolean java.lang.Thread.interrupted(). This may cause the unexpected use of the original definition of boolean java.lang.Thread.interrupted()in methods that have already been compiled. 2025-08-05 14:56:55.421 4304-4304 CompatChangeReporter com.kotei.fusionpositiondemo.debug D Compat change id reported: 242716250; UID 10216; state: ENABLED ---------------------------- PROCESS STARTED (4304) for package com.kotei.fusionpositiondemo.debug ---------------------------- 2025-08-05 14:56:55.571 4304-4304 nativeloader com.kotei.fusionpositiondemo.debug D Configuring clns-9 for other apk /data/app/~~uvNMhw23neOo_A1NTEkLtA==/com.kotei.fusionpositiondemo.debug-p0bOkHYIGwiXe_JjzTFaBg==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~uvNMhw23neOo_A1NTEkLtA==/com.kotei.fusionpositiondemo.debug-p0bOkHYIGwiXe_JjzTFaBg==/lib/x86_64, permitted_path=/data:/mnt/expand:/data/user/0/com.kotei.fusionpositiondemo.debug 2025-08-05 14:56:55.575 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I AssetManager2(0x70d598f55878) locale list changing from [] to [en-US] 2025-08-05 14:56:55.577 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I AssetManager2(0x70d598f52cb8) locale list changing from [] to [en-US] 2025-08-05 14:56:55.581 4304-4304 GraphicsEnvironment com.kotei.fusionpositiondemo.debug V Currently set values for: 2025-08-05 14:56:55.581 4304-4304 GraphicsEnvironment com.kotei.fusionpositiondemo.debug V angle_gl_driver_selection_pkgs=[] 2025-08-05 14:56:55.581 4304-4304 GraphicsEnvironment com.kotei.fusionpositiondemo.debug V angle_gl_driver_selection_values=[] 2025-08-05 14:56:55.581 4304-4304 GraphicsEnvironment com.kotei.fusionpositiondemo.debug V com.kotei.fusionpositiondemo.debug is not listed in per-application setting 2025-08-05 14:56:55.581 4304-4304 GraphicsEnvironment com.kotei.fusionpositiondemo.debug V ANGLE allowlist from config: 2025-08-05 14:56:55.581 4304-4304 GraphicsEnvironment com.kotei.fusionpositiondemo.debug V com.kotei.fusionpositiondemo.debug is not listed in ANGLE allowlist or settings, returning default 2025-08-05 14:56:55.581 4304-4304 GraphicsEnvironment com.kotei.fusionpositiondemo.debug V Neither updatable production driver nor prerelease driver is supported. 2025-08-05 14:56:55.583 4304-4304 ActivityThread com.kotei.fusionpositiondemo.debug W Application com.kotei.fusionpositiondemo.debug is suspending. Debugger needs to resume to continue. 2025-08-05 14:56:55.583 4304-4304 System.out com.kotei.fusionpositiondemo.debug I Sending WAIT chunk 2025-08-05 14:56:55.584 4304-4304 System.out com.kotei.fusionpositiondemo.debug I Waiting for debugger first packet 2025-08-05 14:56:58.311 536-536 adbd adbd E failed to connect to socket 'localabstract:/com.kotei.fusionpositiondemo.debug-0/platform-1754377016312.sock': could not connect to localabstract address 'localabstract:/com.kotei.fusionpositiondemo.debug-0/platform-1754377016312.sock' 2025-08-05 14:57:03.533 4304-4307 nativeloader com.kotei.fusionpositiondemo.debug D Load libjdwp.so using system ns (caller=<unknown>): ok 2025-08-05 14:57:03.746 4304-4304 System.out com.kotei.fusionpositiondemo.debug I Debug.suspendAllAndSentVmStart 2025-08-05 14:57:04.472 4304-4304 System.out com.kotei.fusionpositiondemo.debug I Debug.suspendAllAndSendVmStart, resumed 2025-08-05 14:57:04.611 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden method Landroid/view/WindowManagerGlobal;->getInstance()Landroid/view/WindowManagerGlobal; (runtime_flags=0, domain=platform, api=unsupported) from Lcurtains/internal/WindowManagerSpy$windowManagerInstance$2; (domain=app) using reflection: allowed 2025-08-05 14:57:04.611 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden field Landroid/view/WindowManagerGlobal;->mViews:Ljava/util/ArrayList; (runtime_flags=0, domain=platform, api=unsupported) from Lcurtains/internal/WindowManagerSpy$mViewsField$2; (domain=app) using reflection: allowed 2025-08-05 14:57:04.611 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden field Landroid/app/ActivityThread;->mH:Landroid/app/ActivityThread$H; (runtime_flags=0, domain=platform, api=unsupported) from Lleakcanary/ServiceWatcher; (domain=app) using reflection: allowed 2025-08-05 14:57:04.611 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden method Landroid/app/ActivityThread;->currentActivityThread()Landroid/app/ActivityThread; (runtime_flags=0, domain=platform, api=unsupported) from Lleakcanary/ServiceWatcher$activityThreadInstance$2; (domain=app) using reflection: allowed 2025-08-05 14:57:04.612 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden field Landroid/os/Handler;->mCallback:Landroid/os/Handler$Callback; (runtime_flags=0, domain=platform, api=unsupported) from Lleakcanary/ServiceWatcher; (domain=app) using reflection: allowed 2025-08-05 14:57:04.612 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden field Landroid/util/Singleton;->mInstance:Ljava/lang/Object; (runtime_flags=0, domain=platform, api=unsupported) from Lleakcanary/ServiceWatcher; (domain=app) using reflection: allowed 2025-08-05 14:57:04.612 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden method Landroid/util/Singleton;->get()Ljava/lang/Object; (runtime_flags=0, domain=platform, api=unsupported) from Lleakcanary/ServiceWatcher; (domain=app) using reflection: allowed 2025-08-05 14:57:04.612 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden field Landroid/app/ActivityManager;->IActivityManagerSingleton:Landroid/util/Singleton; (runtime_flags=0, domain=platform, api=unsupported) from Lleakcanary/ServiceWatcher; (domain=app) using reflection: allowed 2025-08-05 14:57:04.699 4304-4376 DisplayManager com.kotei.fusionpositiondemo.debug I Choreographer implicitly registered for the refresh rate. 2025-08-05 14:57:04.705 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I AssetManager2(0x70d598f55558) locale list changing from [] to [en-US] 2025-08-05 14:57:04.948 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug W Verification of android.content.Context androidx.appcompat.app.AppCompatDelegateImpl.attachBaseContext2(android.content.Context) took 107.951ms (1593.30 bytecodes/s) (0B arena alloc) 2025-08-05 14:57:05.412 4304-4304 AppCompatDelegate com.kotei.fusionpositiondemo.debug D Checking for metadata for AppLocalesMetadataHolderService : Service not found 2025-08-05 14:57:05.413 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I AssetManager2(0x70d598f58a78) locale list changing from [] to [en-US] 2025-08-05 14:57:05.462 4304-4304 ashmem com.kotei.fusionpositiondemo.debug E Pinning is deprecated since Android Q. Please use trim or other methods. 2025-08-05 14:57:05.526 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getAllProviders: passive 2025-08-05 14:57:05.526 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getAllProviders: network 2025-08-05 14:57:05.526 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getAllProviders: fused 2025-08-05 14:57:05.526 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getAllProviders: gps 2025-08-05 14:57:05.526 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getProviders true: passive 2025-08-05 14:57:05.526 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getProviders true: fused 2025-08-05 14:57:05.526 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getProviders true: gps 2025-08-05 14:57:05.527 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getProviders false: passive 2025-08-05 14:57:05.527 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getProviders false: network 2025-08-05 14:57:05.527 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getProviders false: fused 2025-08-05 14:57:05.527 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getProviders false: gps 2025-08-05 14:57:05.527 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager getGnssHardwareModelName: Android Studio Emulator GPS 2025-08-05 14:57:05.530 4304-4375 LeakCanary com.kotei.fusionpositiondemo.debug D LeakCanary is currently disabled: Waiting for debugger to detach. 2025-08-05 14:57:05.532 4304-4376 EGL_emulation com.kotei.fusionpositiondemo.debug I Opening libGLESv1_CM_emulation.so 2025-08-05 14:57:05.532 4304-4376 EGL_emulation com.kotei.fusionpositiondemo.debug I Opening libGLESv2_emulation.so 2025-08-05 14:57:05.537 4304-4376 HWUI com.kotei.fusionpositiondemo.debug W Failed to initialize 101010-2 format, error = EGL_SUCCESS 2025-08-05 14:57:05.691 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug W Verification of void com.kotei.fusionpositioningengine.FusionPositionManager$3.onLocationChanged(android.location.Location) took 159.490ms (1078.43 bytecodes/s) (0B arena alloc) 2025-08-05 14:57:05.706 4304-4304 DesktopModeFlags com.kotei.fusionpositiondemo.debug D Toggle override initialized to: OVERRIDE_UNSET 2025-08-05 14:57:05.761 4304-4304 HWUI com.kotei.fusionpositiondemo.debug W Image decoding logging dropped! 2025-08-05 14:57:05.764 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (runtime_flags=0, domain=platform, api=unsupported) from Landroidx/appcompat/widget/ViewUtils; (domain=app) using reflection: allowed 2025-08-05 14:57:05.764 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (runtime_flags=0, domain=platform, api=unsupported) from Landroidx/appcompat/widget/ViewUtils; (domain=app) using reflection: allowed 2025-08-05 14:57:05.783 4304-4304 itiondemo.debug com.kotei.fusionpositiondemo.debug I hiddenapi: Accessing hidden field Lcom/android/internal/policy/DecorView;->mWindow:Lcom/android/internal/policy/PhoneWindow; (runtime_flags=0, domain=platform, api=unsupported) from Lcurtains/internal/WindowSpy$windowField$2; (domain=app) using reflection: allowed 2025-08-05 14:57:05.785 4304-4304 HWUI com.kotei.fusionpositiondemo.debug W Unknown dataspace 0 2025-08-05 14:57:06.288 4304-4308 itiondemo.debug com.kotei.fusionpositiondemo.debug I Compiler allocated 5042KB to compile void android.view.ViewRootImpl.performTraversals() 2025-08-05 14:57:06.422 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager onSatelliteStatusChanged: 6 2025-08-05 14:57:06.501 4304-4304 InsetsController com.kotei.fusionpositiondemo.debug D hide(ime(), fromIme=false) 2025-08-05 14:57:06.501 4304-4304 ImeTracker com.kotei.fusionpositiondemo.debug I com.kotei.fusionpositiondemo.debug:31c4fb58: onCancelled at PHASE_CLIENT_ALREADY_HIDDEN 2025-08-05 14:57:06.990 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager onSatelliteStatusChanged: 6 2025-08-05 14:57:07.976 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager onSatelliteStatusChanged: 6 2025-08-05 14:57:08.979 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager onSatelliteStatusChanged: 6 2025-08-05 14:57:09.979 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager onSatelliteStatusChanged: 6 2025-08-05 14:57:09.987 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager GPS_PROVIDER getLatitude: 37.421998333333335 2025-08-05 14:57:09.987 4304-4304 com.kotei....ionManager com.kotei.fusionpositiondemo.debug D initLocationManager GPS_PROVIDER getLongitude: -122.084 2025-08-05 14:57:10.022 4304-4304 System.out com.kotei.fusionpositiondemo.debug I 2025-08-05 14:57:10.022 [com.kotei.fusionpositionengine.FusionPosition] 初始化融合定位引擎 2025-08-05 14:57:10.023 4304-4304 nativeloader com.kotei.fusionpositiondemo.debug D Load libkoteiLocationJni.so using class loader ns clns-9 (caller=/data/app/~~uvNMhw23neOo_A1NTEkLtA==/com.kotei.fusionpositiondemo.debug-p0bOkHYIGwiXe_JjzTFaBg==/base.apk!classes2.dex): dlopen failed: library "libkoteiLocationJni.so" not found 2025-08-05 14:57:10.024 4304-4304 AndroidRuntime com.kotei.fusionpositiondemo.debug D Shutting down VM 2025-08-05 14:57:10.074 4304-4304 AndroidRuntime com.kotei.fusionpositiondemo.debug E FATAL EXCEPTION: main Process: com.kotei.fusionpositiondemo.debug, PID: 4304 java.lang.UnsatisfiedLinkError: dlopen failed: library "libkoteiLocationJni.so" not found at java.lang.Runtime.loadLibrary0(Runtime.java:1090) at java.lang.Runtime.loadLibrary0(Runtime.java:1012) at java.lang.System.loadLibrary(System.java:1765) at com.kotei.fusionpositionengine.FusionPositionJNI.<clinit>(FusionPositionJNI.java:7) at com.kotei.fusionpositionengine.FusionPosition.<init>(FusionPosition.java:42) at com.kotei.fusionpositionengine.FusionPosition.<init>(FusionPosition.java:18) at com.kotei.fusionpositionengine.FusionPosition$MInstanceHolder.<clinit>(FusionPosition.java:52) at com.kotei.fusionpositionengine.FusionPosition.getInstance(FusionPosition.java:60) at com.kotei.fusionpositioningengine.FusionPositionManager$3.onLocationChanged(FusionPositionManager.java:94) at android.location.LocationListener.onLocationChanged(LocationListener.java:63) at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3303) at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3300) at com.android.internal.listeners.ListenerExecutor.lambda$executeSafely$0(ListenerExecutor.java:127) at com.android.internal.listeners.ListenerExecutor$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at android.os.Handler.handleCallback(Handler.java:995) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loopOnce(Looper.java:248) at android.os.Looper.loop(Looper.java:338) at android.app.ActivityThread.main(ActivityThread.java:9067) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932) 2025-08-05 14:57:10.081 4304-4304 Process com.kotei.fusionpositiondemo.debug I Sending signal. PID: 4304 SIG: 9 2025-08-05 14:57:10.091 714-809 InputDispatcher system_server E channel '8dca3a2 com.kotei.fusionpositiondemo.debug/com.kotei.fusionpositioningengine.MainActivity' ~ Channel is unrecoverably broken and will be disposed! ---------------------------- PROCESS ENDED (4304) for package com.kotei.fusionpositiondemo.debug ----------------------------
08-06
[Issue Title ]: Parcel.createExceptionOrNull [Issue SubTitle ]: java.lang.SecurityException - Calling uid: 10180 doesn't match source uid: 10031 【Stack Trace】 Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tplink.omada/com.tplink.omada.sdncontroller.ui.monitor.mspv2.MspV2Activity}: java.lang.SecurityException: Calling uid: 10180 doesn't match source uid: 10031 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4634) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4845) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:113) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2931) at android.os.Handler.dispatchMessage(Handler.java:117) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:293) at android.app.ActivityThread.main(ActivityThread.java:9689) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1211) Caused by java.lang.SecurityException: Calling uid: 10180 doesn't match source uid: 10031 at android.os.Parcel.createExceptionOrNull(Parcel.java:2465) at android.os.Parcel.createException(Parcel.java:2449) at android.os.Parcel.readException(Parcel.java:2432) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142) at android.content.ContentProviderProxy.call(ContentProviderNative.java:732) at android.provider.Settings$NameValueCache.getStringForUser(Settings.java:3064) at android.provider.Settings$Global.getStringForUser(Settings.java:15519) at android.provider.Settings$Global.getString(Settings.java:15507) at android.provider.Settings$Global.getInt(Settings.java:15715) at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:426) at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:484) at com.android.internal.policy.HwPhoneWindow.<init>(HwPhoneWindow.java:92) at com.android.internal.policy.HwPolicyFactoryImpl.getHwPhoneWindow(HwPolicyFactoryImpl.java:44) at com.android.internal.policy.HwPolicyFactory.getHwPhoneWindow(HwPolicyFactory.java:53) at android.app.Activity.attach(Activity.java:8367) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4576) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4845) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:113) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2931) at android.os.Handler.dispatchMessage(Handler.java:117) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:293) at android.app.ActivityThread.main(ActivityThread.java:9689) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1211) Caused by android.os.RemoteException: Remote stack trace: at android.content.AttributionSource.enforceCallingUid(AttributionSource.java:264) at android.content.AttributionSource.enforceCallingUidAndPid(AttributionSource.java:250) at android.content.AttributionSource.<init>(AttributionSource.java:171) at android.content.AttributionSource$1.createFromParcel(AttributionSource.java:506) at android.content.AttributionSource$1.createFromParcel(AttributionSource.java:498)
最新发布
09-26
<think> 我们正在解决一个Android应用中的SecurityException,具体错误信息是“Calling uid: 10180 doesn't match source uid: 10031”。这个错误表明调用进程的用户ID(UID)与目标资源所属进程的UID不一致,导致系统阻止了访问。 根据引用内容,我们可以总结出几个关键点: 1. 引用[1]和引用[3]都提到了UID不匹配的问题,其中引用[3]特别指出在动态加载APK时可能出现这种异常,解决方法通常是确保宿主和插件使用相同的`sharedUserId`。 2. 引用[2]提到了网络请求的问题,但我们的异常似乎与网络无关,因此可能不适用。 3. 引用[4]详细说明了媒体文件访问权限的问题,指出即使获取了Uri,也需要通过`takePersistableUriPermission`来持久化权限,否则可能在应用的其他部分访问时出现权限问题。 结合我们的异常(调用UID为10180,源UID为10031),我们可以推断这可能是由于两个应用(或同一应用的不同进程)之间的UID不一致导致的。常见场景包括: - 访问其他应用的ContentProvider,且没有正确配置权限。 - 动态加载APK(插件化)时,宿主和插件的UID不一致。 - 访问媒体文件时,没有持久化Uri权限。 因此,我们将从以下几个方面提供解决方案: ### 解决方案 #### 1. 检查并配置ContentProvider权限 如果异常发生在访问ContentProvider时,确保目标ContentProvider已正确配置导出(exported)和权限授予(grantUriPermissions)。 **步骤:** - 在目标应用的AndroidManifest.xml中,检查ContentProvider的配置: ```xml <provider android:name=".MyContentProvider" android:authorities="com.example.provider" android:exported="true" <!-- 允许其他应用访问 --> android:grantUriPermissions="true"> <!-- 允许授予临时URI权限 --> </provider> ``` - 在调用方应用中使用ContentProvider时,通过Intent添加临时权限标志: ```java Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(intent); ``` #### 2. 持久化Uri权限(针对媒体文件访问) 如果访问的是媒体文件(如图片、视频),按照引用[4]的建议,在获取到Uri后立即调用`takePersistableUriPermission`来持久化权限。 **步骤:** ```java // 在获取到Uri后(例如从系统选择器返回) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK && data != null) { Uri uri = data.getData(); // 持久化读取权限 getApplicationContext().getContentResolver().takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION ); // 现在这个Uri可以在应用的其他地方使用了 } } ``` 注意:这里必须使用ApplicationContext,并且要确保在调用`takePersistableUriPermission`之前,该Uri是通过Intent返回并且已经授予了临时权限(例如通过Intent的FLAG_GRANT_READ_URI_PERMISSION)。 #### 3. 配置相同的sharedUserId(针对动态加载APK) 如果异常发生在动态加载APK(插件化)的场景中,需要确保宿主应用和插件应用使用相同的`sharedUserId`和签名。 **步骤:** - 在宿主应用和插件应用的AndroidManifest.xml中声明相同的`android:sharedUserId`: ```xml <!-- 宿主应用 --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.host" android:sharedUserId="com.example.shareduser"> ``` ```xml <!-- 插件应用 --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.plugin" android:sharedUserId="com.example.shareduser"> ``` - 使用相同的签名证书对两个应用进行签名。 #### 4. 检查权限声明 确保调用方应用已经声明了必要的权限,例如访问外部存储或跨用户交互权限: ```xml <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" /> ``` ### 调试建议 - 打印当前进程的UID,确认调用方UID确实为10180,并检查目标资源(如ContentProvider)所属应用的UID是否为10031。 ```java Log.d("UID", "Current UID: " + android.os.Process.myUid()); ``` - 检查两个应用的包名和签名信息,确认它们是否满足共享UID的条件(如果使用了sharedUserId)。 ### 相关引用 - 动态加载APK时UID不匹配会导致SecurityException[^3]。 - 媒体文件访问需要持久化URI权限[^4]。 - 跨应用访问ContentProvider需要正确配置权限[^1]。 §§相关问题§§ 1. 如何在Android中正确配置ContentProvider的权限? 2. 动态加载APK时如何确保宿主和插件的UID一致? 3. 访问媒体文件时如何持久化Uri权限? 4. Android的UID机制如何实现应用隔离? </think> ### 解决 `java.lang.SecurityException: Calling uid: 10180 doesn't match source uid: 10031` 的方法 此异常表示进程隔离机制检测到非法跨进程访问:调用方 UID(10180)与目标资源所属进程 UID(10031)不一致。根据引用内容[^1][^3][^4],以下是系统级解决方案: --- #### 1. **配置共享 UID**(针对动态加载 APK) 若涉及插件化开发(如引用[^3]),需在宿主和插件 APK 中声明相同 `sharedUserId`: ```xml <!-- 宿主和插件应用的 AndroidManifest.xml --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.host" android:sharedUserId="com.example.shareduser"> <!-- 相同字符串 --> ``` **关键步骤**: 1. 使用**相同签名证书**签名所有 APK 2. 在代码中验证 UID 一致性: ```java if (android.os.Process.myUid() != getTargetUid()) { throw new SecurityException("UID 不匹配"); } ``` --- #### 2. **持久化媒体文件权限**(针对媒体访问) 若异常发生在媒体文件访问时(如引用[^4]),需调用持久化权限方法: ```java // 获取 Uri 后立即执行 Uri mediaUri = ...; // 从 Intent 获取的 Uri getApplicationContext().getContentResolver().takePersistableUriPermission( mediaUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION ); ``` **注意**: - 必须使用 `ApplicationContext`(非 Activity Context) - 需在 `AndroidManifest.xml` 声明权限: ```xml <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> ``` --- #### 3. **认证器 UID 同步**(针对账户服务) 若涉及账户系统(如引用[^1]),检查 `Authenticator` 配置: ```xml <!-- res/xml/authenticator.xml --> <account-authenticator android:accountType="com.example.account" android:icon="@drawable/icon" android:smallIcon="@drawable/icon" android:label="@string/app_name" /> ``` **验证点**: 1. 确保 `AuthenticatorService` 与调用方使用相同 UID 2. 在服务中验证调用身份: ```java public class AuthService extends Service { @Override public IBinder onBind(Intent intent) { AccountAuthenticator authenticator = new AccountAuthenticator(this); return authenticator.getIBinder(); } } ``` --- #### 4. **跨进程通信权限加固** 通用防护措施: ```java // 在目标进程的 ContentProvider 中验证调用方 @Override public Bundle call(String method, String arg, Bundle extras) { final int callingUid = Binder.getCallingUid(); if (callingUid != Process.myUid()) { // 验证 UID 一致性 throw new SecurityException("非法跨进程访问"); } return super.call(method, arg, extras); } ``` --- ### 调试建议 1. **打印进程信息**: ```java Log.d("UID_DEBUG", "调用方UID: " + Binder.getCallingUid() + " | 当前UID: " + Process.myUid()); ``` 2. **检查签名一致性**: ```bash keytool -printcert -jarfile app.apk ``` > **关键引用**: > - 动态加载 APK 需保持 UID 一致性[^3] > - 媒体文件访问需显式持久化权限[^4] > - 账户服务需验证调用方身份[^1]
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值