• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 android.compat.testing;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static com.google.common.truth.Truth.assertWithMessage;
21 
22 import com.google.common.collect.ImmutableList;
23 
24 /**
25  * For extracting and storing shared library information in CTS.
26  */
27 public final class SharedLibraryInfo {
28     static final String HELPER_APP_APK = "SharedLibraryInfoTestApp.apk";
29     static final String HELPER_APP_PACKAGE = "android.compat.testing.app";
30     static final String HELPER_APP_CLASS = HELPER_APP_PACKAGE + ".SharedLibraryInfoDeviceTest";
31 
32     public final String name;
33     public final String type;
34     public final String version;
35     public final ImmutableList<String> paths;
36 
SharedLibraryInfo(String name, String type, String version, ImmutableList<String> paths)37     private SharedLibraryInfo(String name, String type, String version,
38             ImmutableList<String> paths) {
39         this.name = name;
40         this.type = type;
41         this.version = version;
42         this.paths = paths;
43     }
44 
readFromLine(String line)45     private static SharedLibraryInfo readFromLine(String line) {
46         String[] words = line.split(" ");
47         assertWithMessage(
48                 "expected each line to be in the format: <name> <type> <version> <path>...")
49                 .that(words.length)
50                 .isAtLeast(4);
51         String libraryName = words[0];
52         String libraryType = words[1];
53         String libraryVersion = words[2];
54         ImmutableList.Builder<String> paths = ImmutableList.builder();
55         for (int i = 3; i < words.length; i++) {
56             String path = words[i];
57             paths.add(path);
58         }
59         return new SharedLibraryInfo(libraryName, libraryType, libraryVersion, paths.build());
60     }
61 
getSharedLibraryInfos(String sharedLibsTxtContent)62     static ImmutableList<SharedLibraryInfo> getSharedLibraryInfos(String sharedLibsTxtContent) {
63         ImmutableList.Builder<SharedLibraryInfo> libraries = ImmutableList.builder();
64         for (String line : sharedLibsTxtContent.split("\n")) {
65             libraries.add(readFromLine(line));
66         }
67         return libraries.build();
68     }
69 }
70