├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── themes.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── menu
│ │ │ └── menu_main.xml
│ │ ├── values-night
│ │ │ └── themes.xml
│ │ ├── layout
│ │ │ ├── content_main.xml
│ │ │ ├── fragment_second.xml
│ │ │ ├── fragment_first.xml
│ │ │ └── activity_main.xml
│ │ ├── navigation
│ │ │ └── nav_graph.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── superreflection
│ │ │ ├── DemoApplication.java
│ │ │ ├── FirstFragment.java
│ │ │ ├── SecondFragment.java
│ │ │ ├── test
│ │ │ └── HiddenApiTest.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── RePublic
├── .gitignore
├── consumer-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── cpp
│ │ ├── CMakeLists.txt
│ │ └── RePublic.cpp
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/RePublic/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/RePublic/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':RePublic'
2 | include ':app'
3 | rootProject.name = "RePublic"
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whulzz1993/RePublic/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePublic/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Aug 16 20:01:20 CST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SuperReflection
3 | Settings
4 |
5 | First Fragment
6 | Second Fragment
7 | Next
8 | Previous
9 |
10 | Hello first fragment
11 | Hello second fragment. Arg: %1$s
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/superreflection/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.superreflection;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.os.Build;
6 |
7 | public class DemoApplication extends Application {
8 |
9 | @Override
10 | protected void attachBaseContext(Context base) {
11 | super.attachBaseContext(base);
12 | }
13 |
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 | }
18 |
19 | public DemoApplication() {
20 | super();
21 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
22 | || (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1 && Build.VERSION.PREVIEW_SDK_INT > 0)) {
23 | System.loadLibrary("republic");
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/RePublic/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/RePublic/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | }
4 |
5 | android {
6 | compileSdkVersion 31
7 | buildToolsVersion "31.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 19
11 | targetSdkVersion 30
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | consumerProguardFiles "consumer-rules.pro"
16 |
17 | externalNativeBuild {
18 | cmake {
19 | arguments "-DANDROID_STL=c++_shared"
20 | }
21 | }
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_8
32 | targetCompatibility JavaVersion.VERSION_1_8
33 | }
34 | externalNativeBuild {
35 | cmake {
36 | path "src/main/cpp/CMakeLists.txt"
37 | version "3.10.2"
38 | }
39 | }
40 | }
41 |
42 | dependencies {
43 |
44 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.3"
8 |
9 | defaultConfig {
10 | applicationId "com.example.superreflection"
11 | minSdkVersion 19
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 | }
29 |
30 | dependencies {
31 |
32 | implementation 'androidx.appcompat:appcompat:1.3.0'
33 | implementation 'com.google.android.material:material:1.4.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
35 | implementation 'androidx.navigation:navigation-fragment:2.3.5'
36 | implementation 'androidx.navigation:navigation-ui:2.3.5'
37 |
38 | implementation project(path: ':RePublic')
39 | }
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
17 |
18 |
23 |
24 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/superreflection/FirstFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.superreflection;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.fragment.app.Fragment;
10 | import androidx.navigation.fragment.NavHostFragment;
11 |
12 | public class FirstFragment extends Fragment {
13 |
14 | @Override
15 | public View onCreateView(
16 | LayoutInflater inflater, ViewGroup container,
17 | Bundle savedInstanceState
18 | ) {
19 | // Inflate the layout for this fragment
20 | return inflater.inflate(R.layout.fragment_first, container, false);
21 | }
22 |
23 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
24 | super.onViewCreated(view, savedInstanceState);
25 |
26 | view.findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View view) {
29 | NavHostFragment.findNavController(FirstFragment.this)
30 | .navigate(R.id.action_FirstFragment_to_SecondFragment);
31 | }
32 | });
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/superreflection/SecondFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.superreflection;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.fragment.app.Fragment;
10 | import androidx.navigation.fragment.NavHostFragment;
11 |
12 | public class SecondFragment extends Fragment {
13 |
14 | @Override
15 | public View onCreateView(
16 | LayoutInflater inflater, ViewGroup container,
17 | Bundle savedInstanceState
18 | ) {
19 | // Inflate the layout for this fragment
20 | return inflater.inflate(R.layout.fragment_second, container, false);
21 | }
22 |
23 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
24 | super.onViewCreated(view, savedInstanceState);
25 |
26 | view.findViewById(R.id.button_second).setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View view) {
29 | NavHostFragment.findNavController(SecondFragment.this)
30 | .navigate(R.id.action_SecondFragment_to_FirstFragment);
31 | }
32 | });
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_first.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/superreflection/test/HiddenApiTest.java:
--------------------------------------------------------------------------------
1 | package com.example.superreflection.test;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.util.Log;
6 | import android.widget.Toast;
7 |
8 | import com.example.superreflection.MainActivity;
9 |
10 | import java.lang.reflect.Method;
11 |
12 | public class HiddenApiTest {
13 | private static final String TAG = "HiddenApiTest";
14 | public static void main(Context context) {
15 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
16 | || (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1 && Build.VERSION.PREVIEW_SDK_INT > 0)) {
17 | try {
18 | Class runtimeClass = Class.forName("dalvik.system.VMRuntime");
19 | Method nativeLoadMethod = runtimeClass.getDeclaredMethod("setTargetSdkVersionNative",
20 | new Class[] {int.class});
21 |
22 | Log.d("whulzz", "setTargetSdkVersionNative success!");
23 | Toast.makeText(context,
24 | "HiddenApiTest success",
25 | Toast.LENGTH_SHORT).show();
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | throw new RuntimeException();
29 | }
30 | } else {
31 | Log.d(TAG, "nothing todo");
32 | Toast.makeText(context,
33 | "HiddenApiTest nothing todo",
34 | Toast.LENGTH_SHORT).show();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/RePublic/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html
3 |
4 | # Sets the minimum version of CMake required to build the native library.
5 |
6 | cmake_minimum_required(VERSION 3.10.2)
7 |
8 | # Declares and names the project.
9 |
10 | project("core.republic")
11 | string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)
12 | if(cmake_build_type_lower STREQUAL "release")
13 | message(VERBOSE "begin build release")
14 | set(ENABLE_DEBUG OFF CACHE BOOL "" FORCE)
15 | else()
16 | message(VERBOSE "begin build debug")
17 | endif()
18 | if(ENABLE_DEBUG)
19 | add_definitions(-DDEBUG)
20 | endif()
21 |
22 | # Creates and names a library, sets it as either STATIC
23 | # or SHARED, and provides the relative paths to its source code.
24 | # You can define multiple libraries, and CMake builds them for you.
25 | # Gradle automatically packages shared libraries with your APK.
26 |
27 | set(sources
28 | RePublic.cpp
29 | )
30 |
31 | add_library(
32 | republic
33 | SHARED
34 | ${sources}
35 | )
36 | target_include_directories(republic PUBLIC
37 | include
38 | )
39 |
40 | # Searches for a specified prebuilt library and stores the path as a
41 | # variable. Because CMake includes system libraries in the search path by
42 | # default, you only need to specify the key of the public NDK library
43 | # you want to add. CMake verifies that the library exists before
44 | # completing its build.
45 |
46 | find_library(
47 | log-lib
48 | log )
49 |
50 | # Specifies libraries CMake should link to your target library. You
51 | # can link multiple libraries, such as libraries you define in this
52 | # build script, prebuilt third-party libraries, or system libraries.
53 |
54 | target_link_libraries(
55 | republic
56 | ${log-lib}
57 | )
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/superreflection/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.superreflection;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.example.superreflection.test.HiddenApiTest;
6 | import com.google.android.material.floatingactionbutton.FloatingActionButton;
7 | import com.google.android.material.snackbar.Snackbar;
8 |
9 | import androidx.appcompat.app.AppCompatActivity;
10 | import androidx.appcompat.widget.Toolbar;
11 |
12 | import android.view.View;
13 |
14 | import android.view.Menu;
15 | import android.view.MenuItem;
16 | import android.widget.Toast;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | Toolbar toolbar = findViewById(R.id.toolbar);
25 | setSupportActionBar(toolbar);
26 |
27 | FloatingActionButton fab = findViewById(R.id.fab);
28 | fab.setOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View view) {
31 | HiddenApiTest.main(MainActivity.this);
32 | }
33 | });
34 | }
35 |
36 | @Override
37 | public boolean onCreateOptionsMenu(Menu menu) {
38 | // Inflate the menu; this adds items to the action bar if it is present.
39 | getMenuInflater().inflate(R.menu.menu_main, menu);
40 | return true;
41 | }
42 |
43 | @Override
44 | public boolean onOptionsItemSelected(MenuItem item) {
45 | // Handle action bar item clicks here. The action bar will
46 | // automatically handle clicks on the Home/Up button, so long
47 | // as you specify a parent activity in AndroidManifest.xml.
48 | int id = item.getItemId();
49 |
50 | //noinspection SimplifiableIfStatement
51 | if (id == R.id.action_settings) {
52 | return true;
53 | }
54 |
55 | return super.onOptionsItemSelected(item);
56 | }
57 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/RePublic/src/main/cpp/RePublic.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by liuzhuangzhuang on 2021/8/16.
3 | //
4 | #define DEBUG
5 | #include
6 | #include
7 |
8 | #define LOG_TAG "republic"
9 | #define DEBUG
10 | #ifdef DEBUG
11 | #define ALOGD(fmt, args...) do {__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args);} while(0)
12 | #define ALOGI(fmt, args...) do {__android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##args);} while(0)
13 | #else
14 | #define ALOGD(fmt, args...) do {} while(0)
15 | #define ALOGI(fmt, args...) do {} while(0)
16 | #endif
17 | #define ALOGE(fmt, args...) do {__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args);} while(0)
18 |
19 | typedef union {
20 | JNIEnv* env;
21 | void* venv;
22 | } UnionJNIEnvToVoid;
23 |
24 | bool setApiBlacklistExemptions(JNIEnv* env) {
25 | jclass zygoteInitClass = env->FindClass("com/android/internal/os/ZygoteInit");
26 | if (zygoteInitClass == nullptr) {
27 | ALOGE("not found class");
28 | env->ExceptionClear();
29 | return false;
30 | }
31 |
32 | jmethodID setApiBlackListApiMethod =
33 | env->GetStaticMethodID(zygoteInitClass,
34 | "setApiBlacklistExemptions",
35 | "([Ljava/lang/String;)V");
36 | if (setApiBlackListApiMethod == nullptr) {
37 | env->ExceptionClear();
38 | setApiBlackListApiMethod =
39 | env->GetStaticMethodID(zygoteInitClass,
40 | "setApiDenylistExemptions",
41 | "([Ljava/lang/String;)V");
42 | }
43 |
44 | if (setApiBlackListApiMethod == nullptr) {
45 | ALOGE("not found method");
46 | #if !defined(DEBUG)
47 | env->ExceptionClear();
48 | #endif
49 | return false;
50 | }
51 |
52 | jclass stringCLass = env->FindClass("java/lang/String");
53 |
54 | jstring fakeStr = env->NewStringUTF("L");
55 |
56 | jobjectArray fakeArray = env->NewObjectArray(
57 | 1, stringCLass, NULL);
58 |
59 | env->SetObjectArrayElement(fakeArray, 0, fakeStr);
60 |
61 | env->CallStaticVoidMethod(zygoteInitClass,
62 | setApiBlackListApiMethod, fakeArray);
63 |
64 | env->DeleteLocalRef(fakeStr);
65 | env->DeleteLocalRef(fakeArray);
66 | ALOGD("fakeapi success!");
67 | return true;
68 | }
69 |
70 | jint JNI_OnLoad(JavaVM* vm, void* reserved) {
71 | UnionJNIEnvToVoid uenv;
72 | uenv.venv = NULL;
73 | jint result = -1;
74 | JNIEnv* env = NULL;
75 |
76 | ALOGD("JNI_OnLoad");
77 |
78 | if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK) {
79 | ALOGE("ERROR: GetEnv failed");
80 | goto bail;
81 | }
82 | env = uenv.env;
83 |
84 | if (!setApiBlacklistExemptions(env)) {
85 | ALOGE("failed");
86 | goto bail;
87 | }
88 | result = JNI_VERSION_1_6;
89 |
90 | bail:
91 | return result;
92 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 背景
2 |
3 | ## 非 SDK API 名单([谷歌官方](https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces))
4 |
5 | 随着每个 Android 版本的发布,会有更多非 SDK 接口受到限制。 我们知道这些限制会影响您的发布工作流,同时我们希望确保您拥有相关工具来检测非 SDK 接口的使用情况、有机会[向我们提供反馈](https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces#feature-request),并且有时间根据相应新政策做出规划和调整。
6 |
7 | 为最大程度地降低非 SDK 使用限制对开发工作流的影响,我们将非 SDK 接口分成了几个名单,这些名单界定了非 SDK 接口使用限制的严格程度(取决于应用的目标 API 级别)。下表介绍了这些名单:
8 |
9 | | 名单 | 说明 |
10 | | :---------------------------- | :----------------------------------------------------------- |
11 | | 屏蔽名单 (`blacklist`) | 无论应用的[目标 API 级别](https://developer.android.com/distribute/best-practices/develop/target-sdk)是什么,您都无法使用的非 SDK 接口。 如果您的应用尝试访问其中任何一个接口,系统就会[抛出错误](https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces#results-of-keeping-non-sdk)。 |
12 | | 有条件屏蔽 (`greylist-max-x`) | 从 Android 9(API 级别 28)开始,当有应用以该 API 级别为目标平台时,我们会在每个 API 级别分别限制某些非 SDK 接口。这些名单会以应用无法再访问该名单中的非 SDK 接口之前可以作为目标平台的最高 API 级别 (`max-target-x`) 进行标记。例如,在 Android Pie 中未被屏蔽、但现在已被 Android 10 屏蔽的非 SDK 接口会列入 `max-target-p` (`greylist-max-p`) 名单,其中的“p”表示 Pie 或 Android 9(API 级别 28)。如果您的应用尝试访问受目标 API 级别限制的接口,系统就会[将此 API 视为已列入屏蔽名单](https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces#results-of-keeping-non-sdk)。 |
13 | | 不支持 (`greylist`) | 当前不受限制且您的应用可以使用的非 SDK 接口。 但请注意,这些接口**不受支持**,可能会在未发出通知的情况下随时发生更改。预计这些接口在未来的 Android 版本中会被有条件地屏蔽,并列在 `max-target-x` 名单中。 |
14 | | SDK (`whitelist`) | 已在 Android 框架[软件包索引](https://developer.android.com/reference/packages)中正式记录、受支持并且可以自由使用的接口。 |
15 |
16 | 尽管您目前仍可以使用某些非 SDK 接口(取决于应用的目标 API 级别),但只要您使用任何非 SDK 方法或字段,终归存在导致应用出问题的显著风险。如果您的应用依赖于非 SDK 接口,建议您开始计划迁移到 SDK 接口或其他替代方案。如果您无法为应用中的功能找到无需使用非 SDK 接口的替代方案,我们建议您[请求添加新的公共 API](https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces#feature-request)。
17 |
18 | # 该git仓库目的:
19 |
20 | 绕开非SDK接口限制,访问hiddenapi接口
21 |
22 | ## 目前已有的方案参考:
23 |
24 | [Free reflection](https://github.com/tiann/FreeReflection)
25 | 缺点:classloader未来[可能受限](https://android-review.googlesource.com/c/platform/libcore/+/1666599)
26 |
27 | [RestrictionBypass](https://github.com/ChickenHook/RestrictionBypass)
28 | 缺点:pthread创建线程使caller为null的方案[将受限](https://android-review.googlesource.com/c/platform/art/+/1664304)
29 |
30 | # 核心实现:
31 |
32 | 1.系统framework代码中可以通过设置setHiddenApiExemptions,达到随意访问hiddenapi的目的
33 |
34 | 2.由于class VMRuntime被hide,可以在JNI_OnLoad中反射ZygoteInit;->setApiBlacklistExemptions
35 |
36 | ## 使用JNI_OnLoad的原因:
37 |
38 | ### JNI_OnLoad中调用env->FindClass流程:
39 |
40 | ```c++
41 | static jclass FindClass(JNIEnv* env, const char* name) {
42 | CHECK_NON_NULL_ARGUMENT(name);
43 | ...
44 | ...
45 | if (runtime->IsStarted()) {
46 | //关键的地方为GetClassLoader
47 | StackHandleScope<1> hs(soa.Self());
48 | Handle class_loader(hs.NewHandle(GetClassLoader(soa)));
49 | c = class_linker->FindClass(soa.Self(), descriptor.c_str(), class_loader);
50 | } else {
51 | c = class_linker->FindSystemClass(soa.Self(), descriptor.c_str());
52 | }
53 | return soa.AddLocalReference(c);
54 | }
55 | ```
56 |
57 |
58 |
59 | GetClassLoader函数:
60 |
61 | ```c++
62 | static ObjPtr GetClassLoader(const ScopedObjectAccess& soa)
63 | REQUIRES_SHARED(Locks::mutator_lock_) {
64 | ArtMethod* method = soa.Self()->GetCurrentMethod(nullptr);
65 | // If we are running Runtime.nativeLoad, use the overriding ClassLoader it set.
66 | if (method == jni::DecodeArtMethod(WellKnownClasses::java_lang_Runtime_nativeLoad)) {
67 | return soa.Decode(soa.Self()->GetClassLoaderOverride());
68 | }
69 | ```
70 |
71 | 由于JNI_OnLoad是通过java层Runtime;->nativeLoad调用过来的,所以GetClassLoader返回的是bootclassloader,该classLoader的domain为kCorePlatform,可以访问任何hiddenapi(包括blacklist),所以此处为系统的一个漏洞
72 |
73 | # 兼容性:
74 |
75 | android 9至android12-beta-4
76 |
77 | # 与freereflection比较
78 |
79 | | | RePublic | Free reflection |
80 | | -------------------------- | -------- | --------------- |
81 | | 使用setHiddenApiExemptions | 是 | 是 |
82 | | 是否使用了bootclassloader | 否 | 是 |
83 | | 元反射 | 否 | 是 |
84 | | 兼容安卓11/12 | 是 | 不太清楚 |
85 | | 第三方ROM兼容性得分 | 优秀 | 良好 |
86 |
87 |
88 | # RePublic文章参考
89 |
90 | [安卓hiddenapi访问绝技](https://bbs.pediy.com/thread-268936.htm)
91 |
92 |
93 |
94 | # License
95 |
96 | MIT License
97 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------