1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wm.flicker 18 19 import com.android.compatibility.common.util.SystemUtil 20 import com.android.server.wm.flicker.FlickerRunResult.Companion.RunStatus 21 import java.nio.file.Path 22 23 object Utils { renameFilenull24 fun renameFile(src: Path, dst: Path) { 25 SystemUtil.runShellCommand("mv $src $dst") 26 } 27 copyFilenull28 fun copyFile(src: Path, dst: Path) { 29 SystemUtil.runShellCommand("cp $src $dst") 30 SystemUtil.runShellCommand("chmod a+r $dst") 31 } 32 moveFilenull33 fun moveFile(src: Path, dst: Path) { 34 // Move the file to the output directory 35 // Note: Due to b/141386109, certain devices do not allow moving the files between 36 // directories with different encryption policies, so manually copy and then 37 // remove the original file 38 // Moreover, the copied trace file may end up with different permissions, resulting 39 // in b/162072200, to prevent this, ensure the files are readable after copying 40 copyFile(src, dst) 41 SystemUtil.runShellCommand("rm $src") 42 } 43 addStatusToFileNamenull44 fun addStatusToFileName(traceFile: Path, status: RunStatus) { 45 val newFileName = "${status.prefix}_${traceFile.fileName}" 46 val dst = traceFile.resolveSibling(newFileName) 47 renameFile(traceFile, dst) 48 } 49 } 50