• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #pragma once
18 
19 #include "adb_unique_fd.h"
20 #include "fastdeploy/proto/ApkEntry.pb.h"
21 
22 /**
23  * Helper class that mirrors the PatchUtils from deploy agent.
24  */
25 class PatchUtils {
26   public:
27     /**
28      * This function takes the dump of Central Directly and builds the APKMetaData required by the
29      * patching algorithm. The if this function has an error a string is printed to the terminal and
30      * exit(1) is called.
31      */
32     static com::android::fastdeploy::APKMetaData GetDeviceAPKMetaData(
33             const com::android::fastdeploy::APKDump& apk_dump);
34     /**
35      * This function takes a local APK file and builds the APKMetaData required by the patching
36      * algorithm. The if this function has an error a string is printed to the terminal and exit(1)
37      * is called.
38      */
39     static com::android::fastdeploy::APKMetaData GetHostAPKMetaData(const char* file);
40     /**
41      * Writes a fixed signature string to the header of the patch.
42      */
43     static void WriteSignature(android::base::borrowed_fd output);
44     /**
45      * Writes an int64 to the |output| reversing the bytes.
46      */
47     static void WriteLong(int64_t value, android::base::borrowed_fd output);
48     /**
49      * Writes string to the |output|.
50      */
51     static void WriteString(const std::string& value, android::base::borrowed_fd output);
52     /**
53      * Copy |amount| of data from |input| to |output|.
54      */
55     static void Pipe(android::base::borrowed_fd input, android::base::borrowed_fd output,
56                      size_t amount);
57 };
58