@@ -20,14 +20,13 @@ import java.net.URL
2020interface DeviceInfo {
2121 val codename: String
2222 val blBlock: String
23- val bdev: String
24- val pbdev: String
2523 val metaonsd: Boolean
2624 val postInstallScript: Boolean
2725 val havedtbo: Boolean
2826 fun isInstalled (logic : DeviceLogic ): Boolean
2927 @SuppressLint(" PrivateApi" )
3028 fun isBooted (logic : DeviceLogic ): Boolean {
29+ // TODO migrate all modern BL to one of these three variants
3130 try {
3231 val c = Class .forName(" android.os.SystemProperties" )
3332 val getBoolean: Method = c.getMethod(
@@ -48,7 +47,11 @@ interface DeviceInfo {
4847 fun getAbmSettings (logic : DeviceLogic ): String?
4948}
5049
50+ fun DeviceInfo.asMetaOnSdDeviceInfo () = this as MetaOnSdDeviceInfo
51+
5152abstract class MetaOnSdDeviceInfo : DeviceInfo {
53+ abstract val bdev: String
54+ abstract val pbdev: String
5255 override val metaonsd = true
5356 override fun isInstalled (logic : DeviceLogic ): Boolean {
5457 return SuFile .open(bdev).exists() && SDUtils .generateMeta(this )?.let { meta ->
@@ -84,7 +87,7 @@ abstract class SdLessDeviceInfo : DeviceInfo {
8487 }
8588}
8689
87- class JsonDeviceInfo (
90+ class JsonMetaOnSdDeviceInfo (
8891 override val codename : String ,
8992 override val blBlock : String ,
9093 override val bdev : String ,
@@ -93,6 +96,13 @@ class JsonDeviceInfo(
9396 override val havedtbo : Boolean
9497) : MetaOnSdDeviceInfo()
9598
99+ class JsonSdLessDeviceInfo (
100+ override val codename : String ,
101+ override val blBlock : String ,
102+ override val postInstallScript : Boolean ,
103+ override val havedtbo : Boolean
104+ ) : SdLessDeviceInfo()
105+
96106class JsonDeviceInfoFactory (private val ctx : Context ) {
97107 suspend fun get (codename : String ): DeviceInfo ? {
98108 return try {
@@ -124,16 +134,23 @@ class JsonDeviceInfoFactory(private val ctx: Context) {
124134 File (ctx.filesDir, " abm_dd_cache.json" ).writeText(newRoot.toString())
125135 }
126136 }
127- if (! json.getBoolean(" metaOnSd" ))
128- throw IllegalArgumentException (" sd less currently not implemented" )
129- JsonDeviceInfo (
130- json.getString(" codename" ),
131- json.getString(" blBlock" ),
132- json.getString(" sdBlock" ),
133- json.getString(" sdBlockP" ),
134- json.getBoolean(" postInstallScript" ),
135- json.getBoolean(" haveDtbo" )
136- )
137+ if (json.getBoolean(" metaOnSd" )) {
138+ JsonMetaOnSdDeviceInfo (
139+ json.getString(" codename" ),
140+ json.getString(" blBlock" ),
141+ json.getString(" sdBlock" ),
142+ json.getString(" sdBlockP" ),
143+ json.getBoolean(" postInstallScript" ),
144+ json.getBoolean(" haveDtbo" )
145+ )
146+ } else {
147+ JsonSdLessDeviceInfo (
148+ json.getString(" codename" ),
149+ json.getString(" blBlock" ),
150+ json.getBoolean(" postInstallScript" ),
151+ json.getBoolean(" haveDtbo" )
152+ )
153+ }
137154 }
138155 } catch (e: Exception ) {
139156 Log .e(" ABM device info" , Log .getStackTraceString(e))
0 commit comments