Skip to content

Commit

Permalink
Add Oppo, Realme and OnePlus trick and a clear default button
Browse files Browse the repository at this point in the history
  • Loading branch information
fcaronte committed Mar 5, 2023
1 parent f95e2cc commit 68b70ef
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<activity-alias android:name=".OppoTrick"
android:targetActivity=".MainActivity"
android:exported="true"
android:enabled="true">
android:enabled="false">
<intent-filter android:label="@string/installer_trick">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.INSTALL_PACKAGE"/>
Expand Down
78 changes: 58 additions & 20 deletions app/src/main/java/com/example/kinginstaller/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
import androidx.core.content.FileProvider;

import android.Manifest;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.OpenableColumns;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -28,13 +32,14 @@
import java.io.InputStream;

import static android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION;
import static android.service.notification.Condition.SCHEME;

public class MainActivity extends AppCompatActivity {

private static final int FILE_SELECT_CODE = 1;
private static final int PERMISSION_REQUEST_CODE = 2;
boolean oppo_trick;

boolean oppo_trick = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -68,16 +73,6 @@ public void onClick(View v) {
}
}
});
/*
//TEST TO MAKE OPPO TRICK DISABLED AS DEFAULT AND AVOID HAVE AN UNUSEFUL FAKE INSTALLER
CheckBox oppoTrick = findViewById(R.id.checkBox);
oppoTrick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
oppo_trick = true;
}
});
*/

TextView siteAnnexhack = findViewById(R.id.site_annexhack);
siteAnnexhack.setOnClickListener(new View.OnClickListener() {
Expand All @@ -93,8 +88,58 @@ public void onClick(View v) {
}
}
});

//MAKE OPPO TRICK DISABLED AS DEFAULT AND AVOID HAVE AN UNUSEFUL FAKE INSTALLER
SharedPreferences oppoTrickStatus = getSharedPreferences("oppo_trick_value", Activity.MODE_PRIVATE);
oppo_trick = oppoTrickStatus.getBoolean("oppo_trick_value",false);
CheckBox oppoTrick = (CheckBox) findViewById(R.id.checkBox);
oppoTrick.setChecked(oppo_trick);
oppoTrick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
oppo_trick = !oppo_trick;
SharedPreferences.Editor editor = oppoTrickStatus.edit();
editor.putBoolean("oppo_trick_value", oppo_trick);
editor.apply();
oppoTrick.setChecked(oppo_trick);
OppoTrick();
}
});
//RESET BUTTON TO OPEN DEFAULT PACKAGE INSTALLER TO CAN CLEAR AS DEFAULT SETTING
Button resetButton = findViewById(R.id.resetButton);
resetButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + "com.google.android.packageinstaller"));
startActivity(intent);
} catch (Exception e) {
TextView tv = findViewById(R.id.textViewError);
tv.setText(e.toString());
}
}
});
}

public void OppoTrick() {
//MAKE OPPO TRICK DISABLED AS DEFAULT AND AVOID HAVE AN UNUSEFUL FAKE INSTALLER
PackageManager pm = getApplicationContext().getPackageManager();
if (oppo_trick) {
ComponentName oppoTrickFlagged =
new ComponentName(getPackageName(), getPackageName() + ".OppoTrick");
pm.setComponentEnabledSetting(
oppoTrickFlagged,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
} else {
ComponentName oppoTrickFlagged =
new ComponentName(getPackageName(), getPackageName() + ".OppoTrick");
pm.setComponentEnabledSetting(
oppoTrickFlagged,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand All @@ -119,12 +164,12 @@ private void installAsKing() {
EditText et = findViewById(R.id.pathTextEdit);
String filepath = et.getText().toString();
if (filepath.length() == 0) {
Toast.makeText(this, "Please select a file first", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.select_a_file, Toast.LENGTH_SHORT).show();
return;
}
File myFile = new File(filepath);
if (!myFile.exists()) {
Toast.makeText(this, "Error: file not exists", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.file_error, Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
Expand All @@ -137,13 +182,6 @@ private void installAsKing() {
et.setText("");
TextView tv = findViewById(R.id.textViewError);
tv.setText("");
/*
//TEST TO MAKE OPPO TRICK DISABLED AS DEFAULT AND AVOID HAVE AN UNUSEFUL FAKE INSTALLER
if (oppo_trick) {
ComponentName oppoTrickFlagged = new ComponentName(getPackageName(), getPackageName()+".OppoTrick");
intent.setComponent(oppoTrickFlagged);
}
*/
startActivity(intent);
} catch (Exception e) {
TextView tv = findViewById(R.id.textViewError);
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,36 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/install_as_king" />
<!--

<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="5dp"
android:layout_gravity="center_horizontal"
android:text="@string/oppo_trick" />
-->

<Button
android:id="@+id/resetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset_default" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="10dp"
android:fontFamily="casual"
android:gravity="center"
android:lines="6"
android:text="@string/reset_default_description"
android:textSize="12sp" />
<TextView
android:id="@+id/textViewError"
android:layout_width="match_parent"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<string name="jen94">Grazie jen94!, mod by fcaronte</string>
<string name="oppo_trick">Attiva se usi un telefono Oppo, Realme o OnePlus</string>
<string name="source_code">Codice Sorgente</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>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
<string name="jen94">Спасибо jen94!, mod by fcaronte</string>
<string name="oppo_trick">Enable if you use Oppo, Realme or OnePlus phone</string>
<string name="source_code">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 if you wrongly set as default and popup won\'t show anymore. After touch \"Reset Default\" button, search for \"Clear Default Preference\" PS if button give an error is because your phone use a different PackageInstaller and so you need to manually search on your phone setting</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
<string name="jen94">Thanks jen94!, mod by fcaronte</string>
<string name="oppo_trick">Enable if you use Oppo, Realme or OnePlus phone</string>
<string name="source_code">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 if you wrongly set as default and popup won\'t show anymore. After touch \"Reset Default\" button, search for \"Clear Default Preference\" PS if button give an error is because your phone use a different PackageInstaller and so you need to manually search on your phone setting</string>
</resources>

0 comments on commit 68b70ef

Please sign in to comment.