Skip to content

Commit

Permalink
Add root permission check,make one only checkbox selectable and small…
Browse files Browse the repository at this point in the history
… layout fix
  • Loading branch information
fcaronte committed Apr 2, 2023
1 parent 205b559 commit aae4f31
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 41 deletions.
137 changes: 108 additions & 29 deletions app/src/main/java/com/example/kinginstaller/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.os.Bundle;
import android.os.Environment;
import android.provider.OpenableColumns;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -28,19 +29,20 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class MainActivity extends AppCompatActivity {

private static final int FILE_SELECT_CODE = 1;
private static final int PERMISSION_REQUEST_CODE = 2;
boolean oppoTrickEnabled;
boolean rootTrickEnabled;
boolean oppoTrickEnabled, rootTrickEnabled;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -62,20 +64,6 @@ public void onClick(View v) {
}
});

Button btnInstall = findViewById(R.id.installButton);
btnInstall.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
if (rootTrickEnabled) { installAsRoot(); }
else { installAsKing(); }
}
catch (Exception e) {
TextView tv = findViewById(R.id.textViewError);
tv.setText(e.toString());
}
}
});

TextView siteAnnexhack = findViewById(R.id.site_annexhack);
siteAnnexhack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Expand All @@ -96,31 +84,79 @@ public void onClick(View v) {
oppoTrickEnabled = oppoTrickStatus.getBoolean("oppo_trick_value",false);
CheckBox oppoTrick = (CheckBox) findViewById(R.id.checkBox1);
oppoTrick.setChecked(oppoTrickEnabled);
//MAKE ROOT TRICK DISABLED AS DEFAULT
SharedPreferences rootTrickStatus = getSharedPreferences("root_trick_value", Activity.MODE_PRIVATE);
rootTrickEnabled = rootTrickStatus.getBoolean("root_trick_value",false);
CheckBox rootTrick = (CheckBox) findViewById(R.id.checkBox2);
rootTrick.setChecked(rootTrickEnabled);
oppoTrick();

oppoTrick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
oppoTrickEnabled = !oppoTrickEnabled;
SharedPreferences.Editor editor = oppoTrickStatus.edit();
editor.putBoolean("oppo_trick_value", oppoTrickEnabled);
editor.apply();
SharedPreferences.Editor oppoEditor = oppoTrickStatus.edit();
oppoEditor.putBoolean("oppo_trick_value", oppoTrickEnabled);
oppoEditor.apply();
oppoTrick.setChecked(oppoTrickEnabled);
//Switch off root flags
SharedPreferences.Editor rootEditor = rootTrickStatus.edit();
rootEditor.putBoolean("root_trick_value", false);
rootEditor.apply();
rootTrick.setChecked(false);
oppoTrick();

Log.d("oppo button", "oppo value is " + oppoTrickStatus.getBoolean("oppo_trick_value", false));
Log.d("root button", "root value is " + rootTrickStatus.getBoolean("root_trick_value", false));
}
});

//MAKE ROOT TRICK DISABLED AS DEFAULT
SharedPreferences rootTrickStatus = getSharedPreferences("root_trick_value", Activity.MODE_PRIVATE);
rootTrickEnabled = rootTrickStatus.getBoolean("root_trick_value",false);
CheckBox rootTrick = (CheckBox) findViewById(R.id.checkBox2);
rootTrick.setChecked(rootTrickEnabled);
rootTrick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rootTrickEnabled = !rootTrickEnabled;
SharedPreferences.Editor editor = rootTrickStatus.edit();
editor.putBoolean("root_trick_value", rootTrickEnabled);
editor.apply();
rootTrick.setChecked(rootTrickEnabled);
isDeviceRooted();
if (!isDeviceRooted()) {
Toast.makeText(getBaseContext(), R.string.device_not_rooted, Toast.LENGTH_SHORT).show();
//Switch off root flags
SharedPreferences.Editor rootEditor = rootTrickStatus.edit();
rootEditor.putBoolean("root_trick_value", false);
rootEditor.apply();
rootTrick.setChecked(false);
} else {
rootTrickEnabled = !rootTrickEnabled;
SharedPreferences.Editor rootEditor = rootTrickStatus.edit();
rootEditor.putBoolean("root_trick_value", rootTrickEnabled);
rootEditor.apply();
rootTrick.setChecked(rootTrickEnabled);
//Switch off oppo flags
SharedPreferences.Editor oppoEditor = oppoTrickStatus.edit();
oppoEditor.putBoolean("oppo_trick_value", false);
oppoEditor.apply();
oppoTrick.setChecked(false);
oppoTrick();

}
Log.d("root check", "is phone rooted " + isDeviceRooted());
Log.d("oppo button", "oppo value is " + oppoTrickStatus.getBoolean("oppo_trick_value", false));
Log.d("root button", "root value is " + rootTrickStatus.getBoolean("root_trick_value", false));
}
});

Button btnInstall = findViewById(R.id.installButton);
btnInstall.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SharedPreferences oppoTrickStatus = getSharedPreferences("oppo_trick_value", Activity.MODE_PRIVATE);
oppoTrickEnabled = oppoTrickStatus.getBoolean("oppo_trick_value",false);
SharedPreferences rootTrickStatus = getSharedPreferences("root_trick_value", Activity.MODE_PRIVATE);
rootTrickEnabled = rootTrickStatus.getBoolean("root_trick_value",false);
try {
if (rootTrickEnabled) { installAsRoot(); }
else installAsKing();
}
catch (Exception e) {
TextView tv = findViewById(R.id.textViewError);
tv.setText(e.toString());
}
}
});

Expand All @@ -142,6 +178,11 @@ public void onClick(View v) {

public void oppoTrick() {
//MAKE OPPO TRICK DISABLED AS DEFAULT AND AVOID HAVE AN UNUSEFUL FAKE INSTALLER
SharedPreferences oppoTrickStatus = getSharedPreferences("oppo_trick_value", Activity.MODE_PRIVATE);
oppoTrickEnabled = oppoTrickStatus.getBoolean("oppo_trick_value",false);
//MAKE ROOT TRICK DISABLED AS DEFAULT
SharedPreferences rootTrickStatus = getSharedPreferences("root_trick_value", Activity.MODE_PRIVATE);
rootTrickEnabled = rootTrickStatus.getBoolean("root_trick_value",false);
PackageManager pm = getApplicationContext().getPackageManager();
if (oppoTrickEnabled) {
ComponentName oppoTrickFlagged =
Expand All @@ -158,6 +199,12 @@ public void oppoTrick() {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
SharedPreferences.Editor oppoEditor = oppoTrickStatus.edit();
oppoEditor.putBoolean("oppo_trick_value", oppoTrickEnabled);
oppoEditor.apply();
SharedPreferences.Editor rootEditor = rootTrickStatus.edit();
rootEditor.putBoolean("root_trick_value", rootTrickEnabled);
rootEditor.apply();
}

@Override
Expand Down Expand Up @@ -415,4 +462,36 @@ public static String readStream(InputStream is) throws IOException {
}
return byteArrayOutputStream.toString("UTF-8");
}
public static boolean isDeviceRooted() {
return checkRootMethod1() || checkRootMethod2() ||
checkRootMethod3();
}
private static boolean checkRootMethod1() {
String buildTags = android.os.Build.TAGS;
return buildTags != null && buildTags.contains("test-keys");
}
private static boolean checkRootMethod2() {
String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su",
"/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
"/system/bin/failsafe/su", "/data/local/su" };
for (String path : paths) {
if (new File(path).exists()) return true;
}
return false;
}
private static boolean checkRootMethod3() {
Process process = null;
try {
process = Runtime.getRuntime().exec(new String[] {
"/system/xbin/which", "su" });
BufferedReader in = new BufferedReader(new
InputStreamReader(process.getInputStream()));
if (in.readLine() != null) return true;
return false;
} catch (Throwable t) {
return false;
} finally {
if (process != null) process.destroy();
}
}
}
14 changes: 12 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
android:id="@+id/selectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="2"
android:text="@string/select_file" />

<EditText
Expand All @@ -61,12 +62,12 @@
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="46dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:lines="1"
android:lines="2"
android:text="@string/info_manager"
android:textSize="12sp" />

Expand All @@ -77,6 +78,7 @@
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_gravity="center_horizontal"
android:lines="2"
android:text="@string/oppo_trick" />

<CheckBox
Expand All @@ -86,25 +88,33 @@
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_gravity="center_horizontal"
android:lines="2"
android:text="@string/root_trick" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="2"
android:orientation="horizontal">

<Button
android:id="@+id/installButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_weight="10"
android:layout_gravity="center_vertical|center_horizontal"
android:lines="2"
android:text="@string/install_as_king" />

<Button
android:id="@+id/resetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_weight="10"
android:layout_gravity="center_vertical|center_horizontal"
android:lines="2"
android:text="@string/reset_default" />
</LinearLayout>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/menu/user_info_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_search"
android:title="@string/source_code_ax"/>
android:title="@string/source_code_annexhack"/>
<item
android:id="@+id/action_search2"
android:title="@string/source_code_fc"/>
android:title="@string/source_code_fcaronte"/>
<item
android:id="@+id/action_search3"
android:title="@string/source_code_rikj000"/>
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
<string name="info_uninstall">Se l\'app è già installata,\n conviene prima disinstallarla</string>
<string name="install_as_king">Installa come un king</string>
<string name="info_manager">(se ottieni come errore NON ESISTE, usa un gestore file alternativo per scegliere il file)</string>
<string name="jen94">Grazie jen94! Updated by fcaronte &amp; Rikj000</string>
<string name="jen94">Grazie jen94! Aggiornato da fcaronte &amp; Rikj000</string>
<string name="oppo_trick">Attiva se usi un telefono Oppo, Realme o OnePlus</string>
<string name="source_code_ax">Codice Sorgente annexhack</string>
<string name="source_code_fc">Codice Sorgente fcaronte</string>
<string name="source_code_annexhack">Codice Sorgente Annexhack</string>
<string name="source_code_fcaronte">Codice Sorgente Fcaronte</string>
<string name="source_code_rikj000">Codice Sorgente Rikj000</string>
<string name="select_a_file">Prima scegli un file</string>
<string name="file_error">Errore: il file non esiste</string>
<string name="reset_default">Resetta Default</string>
<string name="reset_default_description">Usa il tasto \"Resetta Default\" per aprire l\'installatore pacchetto di Google e poterlo resettare se lo hai impostato per sbaglio come default e non esce più il popup. Dopo aver cliccato il tasto di reset, cerca \"Cancella Preferenze Predefinite\" PS se quando clicchi non succede nulla e da errore, è perché il tuo telefono usa un altro \"Installatore Pacchetto\" e quindi dovrai cercarlo manualmente dalle impostazioni del telefono</string>
<string name="root_trick">Attivare se si utilizza un telefono rootato (LineageOS)</string>
<string name="device_not_rooted">Non posso attivarlo, il dispositivo non ha Root</string>
</resources>
7 changes: 4 additions & 3 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<string name="info_uninstall">Если приложение уже установлено,\n сначала удалите его!</string>
<string name="install_as_king">Установить</string>
<string name="info_manager">(Если вы получили ошибку NOT EXISTS, используйте другой файловый менеджер для выбора файла)</string>
<string name="jen94">Спасибо jen94! Updated by fcaronte &amp; Rikj000</string>
<string name="jen94">Спасибо jen94! Обновлено fcaronte &amp; Rikj000</string>
<string name="oppo_trick">Включить, если вы используете телефон Oppo, Realme или OnePlus</string>
<string name="source_code_ax">annexhack Исходный код</string>
<string name="source_code_fc">fcaronte Исходный код</string>
<string name="source_code_annexhack">Annexhack Исходный код</string>
<string name="source_code_fcaronte">Fcaronte Исходный код</string>
<string name="source_code_rikj000">Rikj000 Исходный код</string>
<string name="select_a_file">Выбрать файл</string>
<string name="file_error">Ошибка: файл не существует</string>
<string name="reset_default">Сбросить значение по умолчанию</string>
<string name="reset_default_description">Используйте кнопку \"Сбросить значение по умолчанию\", чтобы открыть Google PackageInstaller по умолчанию, если вы неправильно установили значение по умолчанию и всплывающее окно больше не будет отображаться. После нажатия кнопки \"Сбросить настройки по умолчанию\" найдите \"Очистить настройки по умолчанию\" PS если кнопка выдает ошибку, это потому, что ваш телефон использует другой PackageInstaller, и поэтому вам нужно вручную выполнить поиск в настройках вашего телефона</string>
<string name="root_trick">Включить, если вы используете рутированный (LineageOS) телефон</string>
<string name="device_not_rooted">Невозможно включить, устройство не рутировано</string>
</resources>
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
<string name="info_manager">If you got NOT EXISTS error use custom file manager to select file</string>
<string name="jen94">Thanks jen94! Updated by fcaronte &amp; Rikj000</string>
<string name="oppo_trick">Enable if you use Oppo, Realme or OnePlus phone</string>
<string name="source_code_ax">annexhack Source code</string>
<string name="source_code_fc">fcaronte Source code</string>
<string name="source_code_annexhack">Annexhack Source code</string>
<string name="source_code_fcaronte">Fcaronte Source code</string>
<string name="source_code_rikj000">Rikj000 Source code</string>
<string name="select_a_file">Please select a file first</string>
<string name="file_error">Error: file not exists</string>
<string name="reset_default">Reset Default</string>
<string name="reset_default_description">Use \"Reset Default\" button to open default Google PackageInstaller\nif you wrongly set as default and popup won\'t show anymore.\n\nAfter touch \"Reset Default\" button,\nsearch for \"Clear Default Preference\" PS.\n\nIf the button gives an error,\nit is because your phone use a different PackageInstaller\nand so you need to manually search on your phone setting.</string>
<string name="root_trick">Enable if you use rooted (LineageOS) phone</string>
<string name="device_not_rooted">Can\'t enable, device is not Rooted</string>
</resources>

0 comments on commit aae4f31

Please sign in to comment.