Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba5aa5b4 authored by Danny Baumann's avatar Danny Baumann Committed by Arne Coucheron
Browse files

CameraServiceProxy: Loosen UID check conditionally

Also allow media UID for camera-in-mediaserver devices.

Change-Id: I34e9ddb49adc78ba0589e3d64918eca7d675ec98
parent 6f1a8b35
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
<!--
     Copyright (C) 2012-2015 The CyanogenMod Project
     Copyright (C) 2017-2020 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>
    <!-- Whether to allow process with media UID to access CameraServiceProxy -->
    <bool name="config_allowMediaUidForCameraServiceProxy">false</bool>
</resources>
+20 −0
Original line number Diff line number Diff line
<!--
     Copyright (C) 2012-2015 The CyanogenMod Project
     Copyright (C) 2017-2020 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>
    <!-- Whether to allow process with media UID to access CameraServiceProxy -->
    <java-symbol type="bool" name="config_allowMediaUidForCameraServiceProxy" />
</resources>
+7 −2
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class CameraServiceProxy extends SystemService
    private static final IBinder nfcInterfaceToken = new Binder();

    private final boolean mNotifyNfc;
    private final boolean mAllowMediaUid;

    private ScheduledThreadPoolExecutor mLogWriterService = new ScheduledThreadPoolExecutor(
            /*corePoolSize*/ 1);
@@ -176,7 +177,8 @@ public class CameraServiceProxy extends SystemService
    private final ICameraServiceProxy.Stub mCameraServiceProxy = new ICameraServiceProxy.Stub() {
        @Override
        public void pingForUserUpdate() {
            if (Binder.getCallingUid() != Process.CAMERASERVER_UID) {
            if (Binder.getCallingUid() != Process.CAMERASERVER_UID
                    && (!mAllowMediaUid || Binder.getCallingUid() != Process.MEDIA_UID)) {
                Slog.e(TAG, "Calling UID: " + Binder.getCallingUid() + " doesn't match expected " +
                        " camera service UID!");
                return;
@@ -187,7 +189,8 @@ public class CameraServiceProxy extends SystemService
        @Override
        public void notifyCameraState(String cameraId, int newCameraState, int facing,
                String clientName, int apiLevel) {
            if (Binder.getCallingUid() != Process.CAMERASERVER_UID) {
            if (Binder.getCallingUid() != Process.CAMERASERVER_UID
                    && (!mAllowMediaUid || Binder.getCallingUid() != Process.MEDIA_UID)) {
                Slog.e(TAG, "Calling UID: " + Binder.getCallingUid() + " doesn't match expected " +
                        " camera service UID!");
                return;
@@ -210,6 +213,8 @@ public class CameraServiceProxy extends SystemService

        mNotifyNfc = SystemProperties.getInt(NFC_NOTIFICATION_PROP, 0) > 0;
        if (DEBUG) Slog.v(TAG, "Notify NFC behavior is " + (mNotifyNfc ? "active" : "disabled"));
        mAllowMediaUid = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_allowMediaUidForCameraServiceProxy);
        // Don't keep any extra logging threads if not needed
        mLogWriterService.setKeepAliveTime(1, TimeUnit.SECONDS);
        mLogWriterService.allowCoreThreadTimeOut(true);