CameraService如何修改为强占式

实现强占camera service ,当某些应用(如手电筒)在后台打开 camera 后,当 camera app open camera 时可以强占被后台应用占有的 camera.

 

注意,由于这样修改破坏了android原生的camera service规则,有可能导致某些三方apk出现异常。

 

[SOLUTION]

1.    修改CameraService.cpp (frameworks/av/services/camera/libcameraservice/)文件

1) connect()方法,

将原来的

        Mutex::Autolock lock(mServiceLock);

        sp<BasicClient> clientTmp;

        if (!canConnectUnsafe(cameraId, clientPackageName,

                              cameraClient->asBinder(),

                              /*out*/clientTmp)) {

            return -EBUSY;

        } else if (client.get() != NULL) {

            device = static_cast<Client*>(clientTmp.get());

            return OK;

        }

修改为:

       //Mutex::Autolock lock(mServiceLock);  //注释掉

        sp<BasicClient> clientTmp;

        if (!canConnectUnsafe(cameraId, clientPackageName,

                              cameraClient->asBinder(),

                              /*out*/clientTmp)) {

            return -EBUSY;

        } else if (client.get() != NULL) {

            device = static_cast<Client*>(clientTmp.get());

            return OK;

        }

        Mutex::Autolock lock(mServiceLock); //将原来的代码移动到这里

 

 

2) canConnectUnsafe()方法

将原来的:

          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);

                return true;

            } else {

                // TODOSC: need to support 1 regular client,

                // multiple shared clients here

                ALOGW("CameraService::connect X (pid %d) rejected"

                      " (existing client).", callingPid);

                return false;

            }

        }

        mClient[cameraId].clear();

    }

修改为:

      if(mClient[cameraId] != 0){

        LOG1("CameraService::connect mClient[cameraId] != 0 ");

        client = mClient[cameraId].promote();

        if (client != 0) {

          LOG1("CameraService::connect X (pid %d)  disconnect the old client", callingPid);

         client->disconnect();

            return true;

        }

    }

 

2. 修改CameraClient.cpp(frameworks/av/services/camera/libcameraservice/)

文件的disconnect()方法:

将原来的:

    if (callingPid != mClientPid && callingPid != mServicePid) {

        ALOGW("different client - don't disconnect");

        return;

    }

修改为:

    if (callingPid != mClientPid && callingPid != mServicePid) {

        ALOGW("different client but  preemptive camera service ");

        //return;

    }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值