Skip to content

Commit

Permalink
added reflection helper
Browse files Browse the repository at this point in the history
make content provider authorities dynamic
  • Loading branch information
Sascha Roth committed May 2, 2020
1 parent aafc767 commit 588e961
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
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);
}
}
2 changes: 1 addition & 1 deletion restrictionbypass/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<application>
<provider
android:name=".BypassProvider"
android:authorities="org.chickenhook.restrictionbypass"
android:authorities="${applicationId}.restrictionbypass"
android:enabled="true"
android:exported="false"></provider>
</application>
Expand Down
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);
}
}

0 comments on commit 588e961

Please sign in to comment.