• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/bash
2
3export RESTART=false
4
5if [ -z "${ANDROID_BUILD_TOP}" ]
6then
7   echo "ANDROID_BUILD_TOP not set"
8   exit 1
9fi
10
11function enable_android_feature() {
12  FEATURE=$1
13
14  echo -n "Checking if device has feature ${FEATURE}..."
15
16  if adb shell pm list features | grep "feature:${FEATURE}" > /dev/null
17  then
18    echo "yep"
19    return
20  fi
21
22  echo "not yet, let's fix that"
23
24  FROM="${ANDROID_BUILD_TOP}/frameworks/native/data/etc/${FEATURE}.xml"
25  TO="/vendor/etc/permissions/${FEATURE}.xml"
26
27  echo -n "..Checking if ${TO} exists..."
28  if adb shell ls ${TO} > /dev/null 2>&1
29  then
30    echo "it does"
31  else
32    echo "not yet"
33    echo -n "....Pushing $FROM to $TO"
34    if ! adb push $FROM $TO > /dev/null
35    then
36      echo "FAILED"
37      exit 1
38    else
39      echo "done"
40      RESTART=true
41    fi
42  fi
43
44  # Feature might have been explicitly disabled, in which case it needs to be commented out
45
46  XML_FILE=android.hardware.type.automotive.xml
47  GREP_REGEX="^ *<unavailable-feature name=.*${FEATURE}.*>\$"
48
49  for DIR in  "system" "vendor"
50  do
51    FULL_FILE=/${DIR}/etc/permissions/${XML_FILE}
52
53    echo -n "..Checking if ${FEATURE} is explicitly disabled on ${FULL_FILE}..."
54
55    if adb shell egrep "\"${GREP_REGEX}\"" ${FULL_FILE} > /dev/null
56    then
57      echo yep
58      BKP_FILE=/tmp/${XML_FILE}.$$
59
60      echo "....Creating backup file (${BKP_FILE})"
61      adb pull ${FULL_FILE} ${BKP_FILE} > /dev/null || exit 1
62      MODIFIED_FILE=/tmp/${XML_FILE}.$$.commented_out
63
64      echo "....Commenting that line out (on ${MODIFIED_FILE})"
65      # TODO: figure out how to re-use GREP_REGEX above - sed need to quote the (group) with \
66      sed "s/^ *\(<unavailable-feature name=.*${FEATURE}.*>*\)\$/<\!-- \1 -->/g" < ${BKP_FILE} > ${MODIFIED_FILE}
67
68      echo "....Replacing ${FULL_FILE}"
69      adb push ${MODIFIED_FILE} ${FULL_FILE} > /dev/null
70      RESTART=true
71    else
72      echo nope
73    fi
74  done
75}
76
77function enable_car_feature() {
78  FEATURE=$1
79
80  echo -n "Checking if car feature ${FEATURE} is enabled..."
81  if adb shell dumpsys car_service --services CarFeatureController | grep mEnabledFeatures | grep ${FEATURE} > /dev/null
82  then
83    echo yep
84    return
85  fi
86  echo nope, enabling it
87  if ! adb shell cmd car_service enable-feature ${FEATURE}
88  then
89    echo FAILED
90    exit 1
91  fi
92  RESTART=true
93}
94
95enable_android_feature android.software.device_admin
96enable_android_feature android.software.managed_users
97enable_car_feature experimental_car_user_service
98
99if ${RESTART}
100then
101  echo "Restarting system (run the command again afterwards to make sure it worked)"
102  adb shell stop && adb shell start
103else
104  echo "Good news, everyone! Everything is ready, no need to restart!"
105fi
106