blob: 5e11643798176a05566c091d7847ff84a405ca6e [file] [log] [blame]
Vivekbalachandar M7af3d832020-02-12 15:56:09 +05301#!/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
18set -e
19set -u
20
21readonly 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"
25readonly PREFERENCE_TO_WIPE_CACHE_FRONT="CachedSupportedPictureSizes_Build_Camera1"
26readonly PREFERENCE_TO_WIPE_RES_FRONT="pref_camera_picturesize_front_key"
27readonly PREFERENCE_TO_WIPE_CACHE_MAIN="CachedSupportedPictureSizes_Build_Camera0"
28readonly PREFERENCE_TO_WIPE_RES_MAIN="pref_camera_picturesize_back_key"
29
30readonly FRONT_CAM_CHANGED_PROPERTY="fp2.cam.front.changed"
31readonly MAIN_CAM_CHANGED_PROPERTY="fp2.cam.main.changed"
32
33readonly FRONT_CAM_CHANGED="$(getprop "${FRONT_CAM_CHANGED_PROPERTY}")"
34readonly MAIN_CAM_CHANGED="$(getprop "${MAIN_CAM_CHANGED_PROPERTY}")"
35
36
37# Precondition: file_to_wipe exists
38function _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
65for 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
71done