Vivekbalachandar M | 7af3d83 | 2020-02-12 15:56:09 +0530 | [diff] [blame] | 1 | #!/system/bin/sh |
| 2 | |
| 3 | # Copyright 2017-2020 Fairphone B.V. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | set -e |
| 19 | set -u |
| 20 | |
| 21 | readonly FILES_TO_WIPE="\ |
| 22 | com.google.android.GoogleCamera/shared_prefs/com.google.android.GoogleCamera_preferences.xml \ |
| 23 | com.android.camera2/shared_prefs/com.android.camera2_preferences.xml |
| 24 | " |
| 25 | readonly PREFERENCE_TO_WIPE_CACHE_FRONT="CachedSupportedPictureSizes_Build_Camera1" |
| 26 | readonly PREFERENCE_TO_WIPE_RES_FRONT="pref_camera_picturesize_front_key" |
| 27 | readonly PREFERENCE_TO_WIPE_CACHE_MAIN="CachedSupportedPictureSizes_Build_Camera0" |
| 28 | readonly PREFERENCE_TO_WIPE_RES_MAIN="pref_camera_picturesize_back_key" |
| 29 | |
| 30 | readonly FRONT_CAM_CHANGED_PROPERTY="fp2.cam.front.changed" |
| 31 | readonly MAIN_CAM_CHANGED_PROPERTY="fp2.cam.main.changed" |
| 32 | |
| 33 | readonly FRONT_CAM_CHANGED="$(getprop "${FRONT_CAM_CHANGED_PROPERTY}")" |
| 34 | readonly MAIN_CAM_CHANGED="$(getprop "${MAIN_CAM_CHANGED_PROPERTY}")" |
| 35 | |
| 36 | |
| 37 | # Precondition: file_to_wipe exists |
| 38 | function _remove_preferences() { |
| 39 | local file_to_wipe="$(readlink -f "$1")" |
| 40 | |
| 41 | local owner=$(stat -c '%U' "${file_to_wipe}") |
| 42 | local group=$(stat -c '%G' "${file_to_wipe}") |
| 43 | local access_bits="$(stat -c '%a' "${file_to_wipe}")" |
| 44 | local context="$(ls -Z "${file_to_wipe}" | grep -o "u:object_r:[^ ]*")" |
| 45 | |
| 46 | if [ "${FRONT_CAM_CHANGED}" == "1" ] |
| 47 | then |
| 48 | sed -i "/${PREFERENCE_TO_WIPE_CACHE_FRONT}/d" "${file_to_wipe}" |
| 49 | sed -i "/${PREFERENCE_TO_WIPE_RES_FRONT}/d" "${file_to_wipe}" |
| 50 | fi |
| 51 | |
| 52 | if [ "${MAIN_CAM_CHANGED}" == "1" ] |
| 53 | then |
| 54 | sed -i "/${PREFERENCE_TO_WIPE_CACHE_MAIN}/d" "${file_to_wipe}" |
| 55 | sed -i "/${PREFERENCE_TO_WIPE_RES_MAIN}/d" "${file_to_wipe}" |
| 56 | fi |
| 57 | |
| 58 | chown -f ${owner} "${file_to_wipe}" |
| 59 | chgrp -f ${group} "${file_to_wipe}" |
| 60 | chmod "${access_bits}" "${file_to_wipe}" |
| 61 | chcon "${context}" "${file_to_wipe}" |
| 62 | } |
| 63 | |
| 64 | |
| 65 | for f in ${FILES_TO_WIPE}; do |
| 66 | for user in /data/user/*; do |
| 67 | if [[ -f "${user}/${f}" ]]; then |
| 68 | _remove_preferences "${user}/${f}" |
| 69 | fi |
| 70 | done |
| 71 | done |