• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2025 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 /**
18  * Compatibility wrapper for [android.sysprop.BackportedFixesProperties].
19  */
20 @file:JvmName("BackportedFixesPropertiesCompat")
21 
22 package com.android.cts.backportedfixes.support
23 
24 private const val ALIAS_BITSET_PROP_NAME = "ro.build.backported_fixes.alias_bitset.long_list"
25 
26 // TODO: b/308461809 use androidx library when available
27 
28 /**
29  *
30  * BitSet where the index of the bits are aliases for known issues that are backported and fixed on
31  * the device.
32  *
33  * Encoded as a long array containing a little-endian representation of a sequence of bits
34  * as defined by [java.util.BitSet.valueOf].
35  *
36  * The list 10,9 means alias 1,4,64 and 67 are fixed on this device.
37  */
38 @get:JvmName("alias_bitset")
39 val alias_bitset: List<Long>
40     get() {
41         // TODO: b/308461809 - use BackportedFixesProperties.alias_bitset() when available.
42         return aliasBitset()
43     }
44 
aliasBitsetnull45 private fun aliasBitset(): List<Long> {
46     return parseLongListString(getAliasBitsetString())
47 }
48 
parseLongListStringnull49 private fun parseLongListString(s: String): List<Long> {
50     val list = buildList {
51         for (x in s.split(',')) {
52             try {
53                 val l = x.toLong()
54                 add(l)
55             } catch (_: NumberFormatException) {
56                 // Since the order matters, stop and just return what we have.
57                 break
58             }
59         }
60     }
61     return list
62 }
63 
getAliasBitsetStringnull64 private fun getAliasBitsetString(): String {
65     try {
66         val c = Class.forName("android.os.SystemProperties")
67         val get = c.getMethod("get", String::class.java, String::class.java)
68 
69         return get.invoke(c, ALIAS_BITSET_PROP_NAME, "") as String
70     } catch (e: Exception) {
71         return ""
72     }
73 }
74