Android 打开camera视频出现无法连接相机问题

复制代码
 ActivityManager: Process com.mediatek.camera (pid 6067) has died: fg  TOP 
11-29 13:15:51.962  1164  2167 W WindowManager: Changing focus from Window{94e5330 u0 com.mediatek.camera/com.mediatek.camera.CameraActivity EXITING} to Window{a82eca3 u0 com.mediatek.camera/com.mediatek.camera.CameraActivity} displayId=0 Callers=com.android.server.wm.RootWindowContainer.updateFocusedWindowLocked:465 com.android.server.wm.WindowManagerService.updateFocusedWindowLocked:5755 com.android.server.wm.WindowState.setupWindowForRemoveOnExit:2591 com.android.server.wm.WindowState.removeIfPossible:2559 
11-29 13:15:51.971  1164  2167 W WindowManager: Failed to deliver inset state change to w=Window{a82eca3 u0 com.mediatek.camera/com.mediatek.camera.CameraActivity}
11-29 13:15:51.971  1164  2167 W WindowManager: android.os.DeadObjectException
11-29 13:15:51.971  1164  2167 W WindowManager: 	at android.os.BinderProxy.transactNative(Native Method)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at android.os.BinderProxy.transact(BinderProxy.java:571)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at android.view.IWindow$Stub$Proxy.insetsControlChanged(IWindow.java:687)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowState.notifyInsetsControlChanged(WindowState.java:3982)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.InsetsStateController.lambda$notifyPendingInsetsControlChanged$6$InsetsStateController(InsetsStateController.java:552)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.InsetsStateController$$ExternalSyntheticLambda1.run(Unknown Source:2)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowAnimator.executeAfterPrepareSurfacesRunnables(WindowAnimator.java:351)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:859)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:797)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:177)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:126)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:115)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowState.setupWindowForRemoveOnExit(WindowState.java:2593)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowState.removeIfPossible(WindowState.java:2559)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowState.access$300(WindowState.java:274)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:3057)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at android.os.IBinder$DeathRecipient.binderDied(IBinder.java:314)
11-29 13:15:51.971  1164  2167 W WindowManager: 	at android.os.BinderProxy.sendDeathNotice(BinderProxy.java:685)

ActivityManager: Death received in com.android.server.am.ActivityManagerService$AppDeathRecipient@856989b for thread android.os.BinderProxy@2406438

复制代码
11-29 13:15:51.977  1164  5703 D WindowManager: ====updateSystemUiVisibilityLw start====
11-29 13:15:51.979  1164  5703 D WindowManager: winCandidate:Window{a82eca3 u0 com.mediatek.camera/com.mediatek.camera.CameraActivity}
11-29 13:15:51.979  1164  5703 D WindowManager: java.lang.Throwable
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.DisplayPolicy.updateSystemUiVisibilityLw(DisplayPolicy.java:2563)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.DisplayPolicy.focusChangedLw(DisplayPolicy.java:2447)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.DisplayContent.updateFocusedWindowLocked(DisplayContent.java:3433)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.RootWindowContainer.updateFocusedWindowLocked(RootWindowContainer.java:465)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowManagerService.updateFocusedWindowLocked(WindowManagerService.java:5755)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:815)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:797)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:177)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:126)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:115)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowManagerService.postWindowRemoveCleanupLocked(WindowManagerService.java:2131)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowState.removeImmediately(WindowState.java:2431)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowState.removeIfPossible(WindowState.java:2567)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowState.access$300(WindowState.java:274)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:3057)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at android.os.IBinder$DeathRecipient.binderDied(IBinder.java:314)
11-29 13:15:51.979  1164  5703 D WindowManager: 	at android.os.BinderProxy.sendDeathNotice(BinderProxy.java:685)
11-29 13:15:51.979  1164  5703 D WindowManager: mFocusedWindow:null
11-29 13:15:51.980  1164  5703 D WindowManager: mTopFullscreenOpaqueWindowState:Window{a82eca3 u0 com.mediatek.camera/com.mediatek.camera.CameraActivity}
11-29 13:15:51.980  1164  5703 D WindowManager: mNotificationShade:Window{af6721d u0 NotificationShade}
11-29 13:15:51.980  1164  5703 D WindowManager: mLastFocusedWindow:Window{a82eca3 u0 com.mediatek.camera/com.mediatek.camera.CameraActivity}
11-29 13:15:51.980  1164  5703 D WindowManager: ====updateSystemUiVisibilityLw end====
复制代码
ActivityManager: Scheduling restart of crashed service com.mediatek.camera/.CameraAppService in 1000ms for start-requested
11-29 13:15:52.004  1164  5961 W ActivityTaskManager: Force removing ActivityRecord{1a10472 u0 com.mediatek.camera/.CameraActivity t27}: app died, no saved state

出现以上现象是:打开相机,拍摄视频后无法预览查看保存的视频;然后提示:

相机无法到连接,请确保已关闭会使用相机或闪光灯的应用程序。

出现以上提示的原因,因为客制化需求导致多修改了该相册其他的类,比如 PhotoPage.java类不用修改!还原修改即可

此需求是屏蔽相册里面的camera按钮,中间一个,右上角一个,当设置禁用相机,隐藏相机图标;当设置相机可用启用,恢复显示可使用。短信附件修改也是如此。

1.相册只需要修改此类: AlbumSetPage.java

/vendor/mediatek/proprietary/packages/apps/Gallery2/src/com/android/gallery3d/app/AlbumSetPage.java

private void showCameraButton() {

if (mCameraButton == null && !setupCameraButton()) return;

//*/ add set invisibility
int camValue = Settings.System.getInt(mActivity.getAndroidContext().getContentResolver(),"tyd_disable_camera", 0);
mCameraButton.setVisibility(camValue == 0 ? View.VISIBLE : View.GONE);
/*/
mCameraButton.setVisibility(View.VISIBLE);
//*/

}
@Override

protected boolean onCreateActionBar(Menu menu) {

MenuItem cameraItem = menu.findItem(R.id.action_camera);

//*/add set invisibility
int camValue = Settings.System.getInt(mActivity.getAndroidContext().getContentResolver(),"tyd_disable_camera", 0);
cameraItem.setVisible(camValue != 1);
/*/
cameraItem.setVisible(GalleryUtils.isCameraAvailable(activity));
//*/

FilterUtils.setupMenuItems(mActionBar, mMediaSet.getPath(), false);

2./vendor/mediatek/proprietary/packages/apps/Gallery2/src/com/android/gallery3d/app/AlbumPage.java

@Override
protected boolean onCreateActionBar(Menu menu) {

//*/add setVisible
int camValue = Settings.System.getInt(mActivity.getAndroidContext().getContentResolver(),"tyd_disable_camera", 0);
menu.findItem(R.id.action_camera).setVisible(camValue != 1);
/*/
menu.findItem(R.id.action_camera).setVisible(
MediaSetUtils.isCameraSource(mMediaSetPath)
&& GalleryUtils.isCameraAvailable(mActivity));
//*/

3.短信只需要修改此类: AttachmentTypeSelectorAdapter.java

根据存值条件判断是否显示还是隐藏

/vendor/mediatek/proprietary/packages/apps/Mms/src/com/android/mms/ui/AttachmentTypeSelectorAdapter.java

protected static List<IconListItem> getData (int mode, Context context) {

List<IconListItem> data = new ArrayList<IconListItem>(8);

addItem(data, context.getString(R.string.attach_image),

R.drawable.ic_attach_picture_holo_light, ADD_IMAGE);

/*/add set camera invisible
addItem(data, context.getString(R.string.attach_take_photo),
R.drawable.ic_attach_capture_picture_holo_light, TAKE_PICTURE);
/*/
int camValue = android.provider.Settings.System.getInt(context.getContentResolver(),"tyd_disable_camera", 0);
if(camValue == 1){//隐藏不添加
}else {//显示添加
addItem(data, context.getString(R.string.attach_take_photo),
R.drawable.ic_attach_capture_picture_holo_light, TAKE_PICTURE);
}
//*/

addItem(data, context.getString(R.string.attach_video),

R.drawable.ic_attach_video_holo_light, ADD_VIDEO);

/*/add,set camera invisible
addItem(data, context.getString(R.string.attach_record_video),
R.drawable.ic_attach_capture_video_holo_light, RECORD_VIDEO);
/*/
int camValue2 = android.provider.Settings.System.getInt(context.getContentResolver(),"tyd_disable_camera", 0);
if(camValue2 == 1){ //隐藏不添加
} else { //显示添加
addItem(data, context.getString(R.string.attach_record_video),
R.drawable.ic_attach_capture_video_holo_light, RECORD_VIDEO);
}
//*/

if (MmsConfig.getAllowAttachAudio()) {

addItem(data, context.getString(R.string.attach_sound),

R.drawable.ic_attach_audio_holo_light, ADD_SOUND);

}

差点点吓到我了,还以为真是有什么其他服务模块占用了相机,那就难以排查了,好在做了多方面的验证和测试,最终发现是之前需求修改导致的!

最后,如果log中发现"Fail to connect to camera service"

才表示相机的服务是被其他模块占用了,所以,应该在打开相机之前关闭掉其他服务,hhh, but i dont know how to close others service !if you know,plaese tell me for studying relatively。

相关推荐
YRr YRr26 分钟前
全面解析Astra+深度相机模块:组件、功能与应用
数码相机
红米饭配南瓜汤1 小时前
Android显示系统(02)- OpenGL ES - 概述
android·音视频·图形渲染
CV-King2 小时前
计算机视觉硬件知识点整理六:工业相机选型
人工智能·数码相机·计算机视觉
m0_726965982 小时前
Android笔记【12】脚手架Scaffold和导航Navigation
android·笔记
xiaoerbuyu12332 小时前
Android直接播放麦克风采集到的声音
android
李艺为3 小时前
RePlugin调试时执行Gradle任务rpInstallAndRunPluginDebug失败原因分析
android·java·gradle·android studio
MorleyOlsen3 小时前
【Android Debug Bridge】adb常用指令(更新中)
android·adb
小安25 小时前
android 简单实现录音功能
android
诸神黄昏EX6 小时前
Android KEY的哪些事儿
android
薯条不要番茄酱7 小时前
【JavaEE初阶】落霞与孤鹜齐飞,秋水共长天一色 - (重点)线程
android·java·java-ee