Board bringup changes with all basic configs
Issue: FP2P-100
Change-Id: I050af472ed2196d60d56e35c4821e324746443ca
diff --git a/camera_detect/init.fp.camera_detect.sh b/camera_detect/init.fp.camera_detect.sh
new file mode 100644
index 0000000..eca1d46
--- /dev/null
+++ b/camera_detect/init.fp.camera_detect.sh
@@ -0,0 +1,100 @@
+#!/system/bin/sh
+
+# Copyright 2017-2020 Fairphone B.V.
+#
+# 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.
+#
+
+set -e
+set -u
+set -x
+
+readonly PERSIST_PATH="persist"
+readonly PROP_PATH="fp2.cam"
+
+readonly ANY_FRAGMENT="any"
+readonly SUBDEV_FRAGMENT="dev"
+readonly SENSOR_FRAGMENT="sensor"
+readonly CHANGED_FRAGMENT="changed"
+
+readonly POSITIONS="main front"
+
+readonly MAIN_SENSORS_PATTERN="(ov8865_q8v18a|ov12870)"
+readonly FRONT_SENSORS_PATTERN="(ov2685|ov5670)"
+
+readonly SYSFS_PATH="/sys/devices/fd8c0000.qcom,msm-cam/video4linux/*/name"
+
+
+function _detect_front_sensor() {
+ local sensor_name=`cat ${SYSFS_PATH} | grep -o -E "${FRONT_SENSORS_PATTERN}"`
+ setprop \
+ "${PROP_PATH}.front.${SENSOR_FRAGMENT}" \
+ "${sensor_name}"
+}
+
+
+function _detect_main_sensor() {
+ local sensor_name=`cat ${SYSFS_PATH} | grep -o -E "${MAIN_SENSORS_PATTERN}"`
+ setprop \
+ "${PROP_PATH}.main.${SENSOR_FRAGMENT}" \
+ "${sensor_name}"
+}
+
+
+# Compare persist.* property with new property to detect if main or front
+# Sensor has changed.
+#
+# Sets *.changed property to 1 for any sensor that has changed.
+#
+# Overwrites persist.* property with new sensor name.
+function _detect_and_persist_sensor_change() {
+ local changed_any_sensor=0
+
+ for pos in ${POSITIONS}; do
+ local changed_sensor=0
+
+ local property="${PROP_PATH}.${pos}.${SENSOR_FRAGMENT}"
+
+ local old_sensor="$(getprop "${PERSIST_PATH}.${property}")"
+ local new_sensor="$(getprop "${property}")"
+
+ # advocate change if:
+ # a sensor is detected in the current position
+ # AND a persist value is set (a camera was previously installed)
+ # AND a different sensor is detected than stored in the persist value
+ if [[ -n "${new_sensor}" ]] \
+ && [[ -n "${old_sensor}" ]] \
+ && [[ "${old_sensor}" != "${new_sensor}" ]] ; then
+ setprop "${PROP_PATH}.${pos}.${CHANGED_FRAGMENT}" "1"
+ changed_any_sensor=1
+ fi
+
+ # set new persist value with the new sensor name if it's non-empty
+ if [[ -n "${new_sensor}" ]]; then
+ setprop "${PERSIST_PATH}.${property}" "${new_sensor}"
+ fi
+ done
+
+ echo "${changed_any_sensor}"
+}
+
+
+function _camera_detect_service() {
+ _detect_main_sensor
+ _detect_front_sensor
+ local changed_any_sensor="$(_detect_and_persist_sensor_change)"
+ setprop "${PROP_PATH}.${ANY_FRAGMENT}.${CHANGED_FRAGMENT}" \
+ "${changed_any_sensor}"
+}
+
+_camera_detect_service