1 /*
2  * Copyright (C) 2016 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 package com.android.compatibility.common.util;
17 
18 /**
19  * Utility class for handling device ABIs
20  */
21 public class AbiUtils {
22 
23     /**
24      * Creates a unique id from the given ABI and name.
25      * @param abi The ABI to use.
26      * @param name The name to use.
27      * @return a string which uniquely identifies a run.
28      */
createId(String abi, String name)29     public static String createId(String abi, String name) {
30         return String.format("%s %s", abi, name);
31     }
32 
33     /**
34      * @return the abi portion of the test id.
35      *         e.g. armeabi-v7a android.mytest = armeabi-v7a
36      */
parseAbi(String id)37     public static String parseAbi(String id) {
38         return parseId(id)[0];
39     }
40 
41     /**
42      * Parses a unique id into the ABI and name.
43      * @param id The id to parse.
44      * @return a string array containing the ABI and name.
45      */
parseId(String id)46     public static String[] parseId(String id) {
47         if (id == null || !id.contains(" ")) {
48             return new String[] {"", ""};
49         }
50         return id.split(" ");
51     }
52 
53     /**
54      * @return the test name portion of the test id.
55      *         e.g. armeabi-v7a android.mytest = android.mytest
56      */
parseTestName(String id)57     public static String parseTestName(String id) {
58         return parseId(id)[1];
59     }
60 
61 }
62