Loading play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt +63 −36 Original line number Diff line number Diff line Loading @@ -67,19 +67,29 @@ object ProfileManager { PROFILE_AUTO -> false PROFILE_REAL -> false PROFILE_NATIVE -> true else -> getProfileXml(context, profile)?.use { var next = it.next() else -> { val parser = getProfileXml(context, profile) if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { XmlPullParser.START_TAG -> when (parser.name) { "profile" -> { return@use it.getAttributeBooleanValue(null, "auto", false) return@runCatching parser.getAttributeBooleanValue(null, "auto", false) } } } next = it.next() next = parser.next() } } finally { parser.close() } false } else { false } } } == true } }.getOrDefault(false) Loading @@ -90,20 +100,25 @@ object ProfileManager { if (profileResId == 0) return realData val resultData = mutableMapOf<String, String>() resultData.putAll(realData) getProfileXml(context, profile)?.use { var next = it.next() val parser = getProfileXml(context, profile) if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { XmlPullParser.START_TAG -> when (parser.name) { "data" -> { val key = it.getAttributeValue(null, "key") val value = it.getAttributeValue(null, "value") val key = parser.getAttributeValue(null, "key") val value = parser.getAttributeValue(null, "value") resultData[key] = value Log.d(TAG, "Overwrite from profile: $key = $value") } } } next = it.next() next = parser.next() } } finally { parser.close() } } return resultData Loading Loading @@ -151,15 +166,20 @@ object ProfileManager { // From profile try { getProfileXml(context, profile)?.use { var next = it.next() val parser = getProfileXml(context, profile) if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { "serial" -> return it.getAttributeValue(null, "template") XmlPullParser.START_TAG -> when (parser.name) { "serial" -> return parser.getAttributeValue(null, "template") } } next = parser.next() } next = it.next() } finally { parser.close() } } } catch (e: Exception) { Loading Loading @@ -274,19 +294,26 @@ object ProfileManager { fun getProfileName(context: Context, profile: String): String? = getProfileName { getProfileXml(context, profile) } private fun getProfileName(parserCreator: () -> XmlResourceParser?): String? = parserCreator()?.use { var next = it.next() private fun getProfileName(parserCreator: () -> XmlResourceParser?): String? { val parser = parserCreator() if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { XmlPullParser.START_TAG -> when (parser.name) { "profile" -> { return@use it.getAttributeValue(null, "name") return parser.getAttributeValue(null, "name") } } } next = parser.next() } } finally { parser.close() } next = it.next() } null return null } fun setProfile(context: Context, profile: String?) { Loading Loading
play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt +63 −36 Original line number Diff line number Diff line Loading @@ -67,19 +67,29 @@ object ProfileManager { PROFILE_AUTO -> false PROFILE_REAL -> false PROFILE_NATIVE -> true else -> getProfileXml(context, profile)?.use { var next = it.next() else -> { val parser = getProfileXml(context, profile) if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { XmlPullParser.START_TAG -> when (parser.name) { "profile" -> { return@use it.getAttributeBooleanValue(null, "auto", false) return@runCatching parser.getAttributeBooleanValue(null, "auto", false) } } } next = it.next() next = parser.next() } } finally { parser.close() } false } else { false } } } == true } }.getOrDefault(false) Loading @@ -90,20 +100,25 @@ object ProfileManager { if (profileResId == 0) return realData val resultData = mutableMapOf<String, String>() resultData.putAll(realData) getProfileXml(context, profile)?.use { var next = it.next() val parser = getProfileXml(context, profile) if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { XmlPullParser.START_TAG -> when (parser.name) { "data" -> { val key = it.getAttributeValue(null, "key") val value = it.getAttributeValue(null, "value") val key = parser.getAttributeValue(null, "key") val value = parser.getAttributeValue(null, "value") resultData[key] = value Log.d(TAG, "Overwrite from profile: $key = $value") } } } next = it.next() next = parser.next() } } finally { parser.close() } } return resultData Loading Loading @@ -151,15 +166,20 @@ object ProfileManager { // From profile try { getProfileXml(context, profile)?.use { var next = it.next() val parser = getProfileXml(context, profile) if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { "serial" -> return it.getAttributeValue(null, "template") XmlPullParser.START_TAG -> when (parser.name) { "serial" -> return parser.getAttributeValue(null, "template") } } next = parser.next() } next = it.next() } finally { parser.close() } } } catch (e: Exception) { Loading Loading @@ -274,19 +294,26 @@ object ProfileManager { fun getProfileName(context: Context, profile: String): String? = getProfileName { getProfileXml(context, profile) } private fun getProfileName(parserCreator: () -> XmlResourceParser?): String? = parserCreator()?.use { var next = it.next() private fun getProfileName(parserCreator: () -> XmlResourceParser?): String? { val parser = parserCreator() if (parser != null) { try { var next = parser.next() while (next != XmlPullParser.END_DOCUMENT) { when (next) { XmlPullParser.START_TAG -> when (it.name) { XmlPullParser.START_TAG -> when (parser.name) { "profile" -> { return@use it.getAttributeValue(null, "name") return parser.getAttributeValue(null, "name") } } } next = parser.next() } } finally { parser.close() } next = it.next() } null return null } fun setProfile(context: Context, profile: String?) { Loading