1#!/bin/bash 2 3# 4# Copyright (C) 2023 The Android Open Source Project 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18read -p "This script will be deleting the current Health Connect Database on your device and flash it with the latest 19 code. Do you want to continue y/n:" input 20 21if [ "$input" != "y" ] && [ "$input" != "Y" ]; then 22 if [ "$input" = "n" ] || [ "$input" = "N" ]; then 23 exit 24 else 25 echo "Not a valid input, exiting." 26 exit 27 fi 28fi 29 30# Building the HealthFitness module 31cd ~ || exit 32cd $ANDROID_BUILD_TOP || exit 33source build/envsetup.sh 34lunch bluejay 35cd packages/modules/HealthFitness || exit 36m com.google.android.healthfitness 37 38if [ $? -ne 0 ]; then 39 echo "Operation failed. Error occurred during healthfitness module build" 40fi 41 42# Removing previously installed database from device 43adb root 44adb shell rm /data/system_ce/0/healthconnect/healthconnect.db 45if [ $? -ne 0 ]; then 46 echo "Operation failed. Error occurred during removal of database" 47fi 48 49# Installing the database version of currently build module 50cd ~ || exit 51adb root 52adb install $OUT/system/apex/com.google.android.healthfitness.apex 53adb reboot 54adb wait-for-device 55 56# Building the CtsHealthFitnessDeviceTestCases module 57cd ~ || exit 58cd $ANDROID_BUILD_TOP || exit 59atest CtsHealthFitnessDeviceTestCases -b 60if [ $? -ne 0 ]; then 61 echo "Operation failed. Error occurred during CtsHealthFitnessDeviceTestCases module build" 62fi 63 64# Storing the database version in a variable 65sleep 10s 66adb root 67version=$( 68 adb shell <<EOF 69cd ~; 70sqlite3 /data/system_ce/0/healthconnect/healthconnect.db 71PRAGMA user_version; 72.exit 73EOF 74) || { 75 echo "Waited but the new database was not created. Run the script again and please unlock your device after it reboots." 76 exit 77} 78 79#saving the build apex file in resources 80source_apex_file="$OUT/system/apex/com.google.android.healthfitness.apex" 81required_apex_file_name="HeathConnectVersion_$version.apex" 82destination_apex_resource="$ANDROID_BUILD_TOP/packages/modules/HealthFitness/tests/cts/hostsidetests/healthconnect/host/res/HealthConnectApexFiles/$required_apex_file_name" 83cp "$source_apex_file" "$destination_apex_resource" 84if [ $? -eq 0 ]; then 85 echo "File '$source_apex_file' have been saved to resources '$destination_apex_resource'" 86else 87 echo "Failed to save file '$source_apex_file'." 88fi 89 90#saving the build cts-apk file in resources 91source_apk_file="$OUT/testcases/CtsHealthFitnessDeviceTestCases" 92required_apk_file_name="HealthConnectCTS_$version.apk" 93destination_apk_resource="$ANDROID_BUILD_TOP/packages/modules/HealthFitness/tests/cts/hostsidetests/healthconnect/host/res/HealthConnectCtsApkFiles/$required_apk_file_name" 94cp -r "$source_apk_file" "$destination_apk_resource" 95if [ $? -eq 0 ]; then 96 echo "File '$source_apk_file' have been saved to resources '$destination_apk_resource'" 97else 98 echo "Failed to save file '$source_apk_file'." 99fi 100