-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make content provider authorities dynamic
- Loading branch information
Sascha Roth
committed
May 2, 2020
1 parent
aafc767
commit 588e961
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...onbypass/src/androidTest/java/org/chickenhook/restrictionbypass/ReflectionHelperTest.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,16 @@ | ||
package org.chickenhook.restrictionbypass; | ||
|
||
import org.chickenhook.restrictionbypass.helpers.Reflection; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertSame; | ||
|
||
public class ReflectionHelperTest { | ||
|
||
Object reflectiveField = new Object(); | ||
|
||
@Test | ||
public void getReflective() throws Exception { | ||
assertSame(Reflection.getReflective(this, "reflectiveField"), reflectiveField); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
restrictionbypass/src/main/java/org/chickenhook/restrictionbypass/helpers/Reflection.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,21 @@ | ||
package org.chickenhook.restrictionbypass.helpers; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class Reflection { | ||
|
||
public static @Nullable | ||
<T> T getReflective(@NonNull Object obj, @NonNull String field) throws NoSuchFieldException, IllegalAccessException { | ||
return getReflective(obj, obj.getClass(), field); | ||
} | ||
|
||
public static @Nullable | ||
<T> T getReflective(@Nullable Object obj, @NonNull Class<?> cls, @NonNull String field) throws NoSuchFieldException, IllegalAccessException { | ||
Field f = cls.getDeclaredField(field); | ||
f.setAccessible(true); | ||
return (T) f.get(obj); | ||
} | ||
} |