-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix215' into fix191_cat_keywords
- Loading branch information
Showing
21 changed files
with
219 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
> | ||
|
||
<application | ||
android:icon="@android:drawable/sym_def_app_icon" | ||
android:allowBackup="false" | ||
tools:ignore="DataExtractionRules" | ||
> | ||
<!-- lint:DataExtractionRules not necessary for this test app. --> | ||
</application> | ||
|
||
</manifest> |
8 changes: 7 additions & 1 deletion
8
android/src/androidTest/java/net/twisterrob/inventory/android/InventoryJUnitRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package net.twisterrob.inventory.android; | ||
|
||
import android.os.Bundle; | ||
|
||
import net.twisterrob.android.test.junit.AndroidJUnitRunner; | ||
import net.twisterrob.inventory.android.hacks.ViewCompatHacks; | ||
|
||
public class InventoryJUnitRunner extends AndroidJUnitRunner { | ||
// Empty for now, useful for quick debugging. | ||
@Override public void onCreate(Bundle arguments) { | ||
super.onCreate(arguments); | ||
ViewCompatHacks.patchFor293190504(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ndroidTest/java/net/twisterrob/inventory/android/hacks/DeferredWeakHashMapFor293190504.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package net.twisterrob.inventory.android.hacks | ||
|
||
import java.util.LinkedList | ||
import java.util.WeakHashMap | ||
import kotlin.collections.MutableMap.MutableEntry | ||
|
||
private typealias Change<K, V> = DeferredWeakHashMapFor293190504<K, V>.() -> Unit | ||
|
||
/** | ||
* See https://issuetracker.google.com/issues/293190504 | ||
* | ||
* This is a workaround for not allowing concurrent modifications | ||
* to [androidx.core.view.ViewCompat.AccessibilityPaneVisibilityManager]'s internal state. | ||
* | ||
* Any structure-modifying changes made to the map while iterating | ||
* is deferred until the iteration is over. | ||
* | ||
* This prevents the nested `put` call in `checkPaneVisibility` | ||
* from cleaning up the weak queue mid-iteration. | ||
*/ | ||
internal class DeferredWeakHashMapFor293190504<K, V> : WeakHashMap<K, V>() { | ||
@Volatile | ||
private var locked = false | ||
private val changes: MutableList<Change<K, V>> = LinkedList() | ||
|
||
override fun put(key: K, value: V): V? { | ||
return if (!locked) { | ||
super.put(key, value) | ||
} else { | ||
changes.add { put(key, value) } | ||
// Should be super.get(key), but reads also mutate the map because it's weak. | ||
null | ||
} | ||
} | ||
|
||
override fun remove(key: K?): V? { | ||
return if (!locked) { | ||
super.remove(key) | ||
} else { | ||
changes.add { remove(key) } | ||
// Should be super.get(key), but reads also mutate the map because it's weak. | ||
null | ||
} | ||
} | ||
|
||
override val entries: MutableSet<MutableEntry<K, V>> | ||
get() = DeferringEntrySet(super.entries) | ||
|
||
private inner class DeferringEntrySet( | ||
private val backingSet: MutableSet<MutableEntry<K, V>> | ||
) : MutableSet<MutableEntry<K, V>> by backingSet { | ||
|
||
override fun iterator(): MutableIterator<MutableEntry<K, V>> { | ||
check(!locked) { "Already iterating, only one supported." } | ||
locked = true | ||
val iterator = backingSet.iterator() | ||
return object : MutableIterator<MutableEntry<K, V>> by iterator { | ||
override fun hasNext(): Boolean { | ||
val hasNext = iterator.hasNext() | ||
// Assuming a for(:) loop will not do anything after this. | ||
if (!hasNext) { | ||
locked = false | ||
changes.removeAll { | ||
this@DeferredWeakHashMapFor293190504.it() | ||
return@removeAll true | ||
} | ||
} | ||
return hasNext | ||
} | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
android/src/androidTest/java/net/twisterrob/inventory/android/hacks/ViewCompatHacks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.twisterrob.inventory.android.hacks; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class ViewCompatHacks { | ||
/** | ||
* Replace the {@link java.util.WeakHashMap} in {@link androidx.core.view.ViewCompat} with a | ||
* {@link DeferredWeakHashMapFor293190504} to prevent concurrent modification. | ||
* | ||
* @see <a href="https://issuetracker.google.com/issues/293190504">Issue</a> | ||
* @see <a href="https://github.com/TWiStErRob/net.twisterrob.inventory/issues/302">Issue</a> | ||
*/ | ||
public static void patchFor293190504() { | ||
try { | ||
Field sAccessibilityPaneVisibilityManager = Class | ||
.forName("androidx.core.view.ViewCompat") | ||
.getDeclaredField("sAccessibilityPaneVisibilityManager"); | ||
sAccessibilityPaneVisibilityManager.setAccessible(true); | ||
Field mPanesToVisible = Class | ||
.forName("androidx.core.view.ViewCompat$AccessibilityPaneVisibilityManager") | ||
.getDeclaredField("mPanesToVisible"); | ||
mPanesToVisible.setAccessible(true); | ||
|
||
Object target = sAccessibilityPaneVisibilityManager.get(null); | ||
mPanesToVisible.set(target, new DeferredWeakHashMapFor293190504<>()); | ||
} catch (NoSuchFieldException | ClassNotFoundException | IllegalAccessException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.