Android 5.1 解决打开手电筒后,无法打开相机问题

直接贴代码,按照faq修改后,无法实现预期效果,稍微修改后即可实现

diff --git a/alps/frameworks/av/services/camera/libcameraservice/CameraService.cpp b/alps/frameworks/av/services/camera/libcameraservice/CameraService.cpp
old mode 100644
new mode 100755
index 8e92c4d..0f3165b
--- a/alps/frameworks/av/services/camera/libcameraservice/CameraService.cpp
+++ b/alps/frameworks/av/services/camera/libcameraservice/CameraService.cpp
@@ -667,6 +667,7 @@ bool CameraService::canConnectUnsafe(int cameraId,
     if (mClient[cameraId] != 0) {
         client = mClient[cameraId].promote();
         if (client != 0) {
+            /*
             if (remoteCallback == client->getRemote()) {
                 LOG1("CameraService::connect X (pid %d) (the same client)",
                      callingPid);
@@ -677,7 +678,12 @@ bool CameraService::canConnectUnsafe(int cameraId,
                 ALOGW("CameraService::connect X (pid %d) rejected"
                       " (existing client).", callingPid);
                 return false;
-            }
+            }*/
+            //add by mtk start
+             LOG1("CameraService::connect X (pid %d)  disconnect the old client", callingPid);
+         client->disconnect();
+            return true;
+            //add by mtk end
         }
         mClient[cameraId].clear();
     }
@@ -794,7 +800,7 @@ status_t CameraService::connect(
 
     sp<Client> client;
     {
-        Mutex::Autolock lock(mServiceLock);
+        //Mutex::Autolock lock(mServiceLock);//del by mtk
         sp<BasicClient> clientTmp;
         if (!canConnectUnsafe(cameraId, clientPackageName,
                               cameraClient->asBinder(),
@@ -804,6 +810,7 @@ status_t CameraService::connect(
             device = static_cast<Client*>(clientTmp.get());
             return OK;
         }
+        Mutex::Autolock lock(mServiceLock);//add by mtk 
 
         status = connectHelperLocked(/*out*/client,
                                      cameraClient,
diff --git a/alps/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp b/alps/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp
old mode 100644
new mode 100755
index ce23b2a..d6725b1
--- a/alps/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp
+++ b/alps/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp
@@ -271,7 +271,7 @@ void CameraClient::disconnect() {
     // Allow both client and the media server to disconnect at all times
     if (callingPid != mClientPid && callingPid != mServicePid) {
         ALOGW("different client - don't disconnect");
-        return;
+       // return;//del by mtk
     }
 
     if (mClientPid <= 0) {
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java
old mode 100644
new mode 100755
index 8e0c772..881fef0
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java
@@ -39,6 +39,7 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements
             = new AnimationIcon(R.drawable.ic_signal_flashlight_disable_animation);
     private final FlashlightController mFlashlightController;
     private long mWasLastOn;
+    private boolean misClick =false;
 
     public FlashlightTile(Host host) {
         super(host);
@@ -71,8 +72,11 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements
             return;
         }
         boolean newState = !mState.value;
+        misClick =true;
+        //System.out.println("handleClick handleClick newState========="+newState);
         mFlashlightController.setFlashlight(newState);
         refreshState(newState ? UserBoolean.USER_TRUE : UserBoolean.USER_FALSE);
+        
     }
 
     @Override
@@ -93,7 +97,7 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements
                 mHandler.postAtTime(mRecentlyOnTimeout, mWasLastOn + RECENTLY_ON_DURATION_MILLIS);
             }
         }
-
+        
         // Always show the tile when the flashlight is or was recently on. This is needed because
         // the camera is not available while it is being used for the flashlight.
         state.visible = mWasLastOn != 0 || mFlashlightController.isAvailable();
@@ -128,7 +132,19 @@ public class FlashlightTile extends QSTile<QSTile.BooleanState> implements
 
     @Override
     public void onFlashlightAvailabilityChanged(boolean available) {
-        refreshState();
+        //System.out.println("misClick========="+misClick+"--mFlashlightController.isAvailable()="+mFlashlightController.isAvailable()+"--available===="+available);
+        if(misClick){
+            refreshState();
+            misClick = false;
+        }else{
+            //refreshState(false);
+            //refreshState(available);
+            boolean newState = !mState.value;
+            //System.out.println("---newState====="+newState);
+        mFlashlightController.setFlashlight(false);
+        refreshState(newState ? UserBoolean.USER_TRUE : UserBoolean.USER_FALSE);
+        }
+        //refreshState();
     }
 
     private Runnable mRecentlyOnTimeout = new Runnable() {

 

posted @ 2020-05-25 19:39  稻香鱼  阅读(587)  评论(0)    收藏  举报