Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shizuku support again. #6

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<queries>
<package android:name="com.instagram.android" />
<package android:name="com.instafel.android" />
<package android:name="moe.shizuku.privileged.api" />
</queries>

<application
Expand All @@ -27,6 +28,14 @@
android:theme="@style/Theme.InstafelUpdater"
tools:targetApi="34">

<provider
android:name="rikka.shizuku.ShizukuProvider"
android:authorities="${applicationId}.shizuku"
android:multiprocess="false"
android:enabled="true"
android:exported="true"
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />

<activity
android:name=".SetupActivity"
android:exported="false" />
Expand Down
70 changes: 61 additions & 9 deletions app/src/main/java/me/mamiiblt/instafel/updater/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
import me.mamiiblt.instafel.updater.utils.LocalizationUtils;
import me.mamiiblt.instafel.updater.utils.LogUtils;
import me.mamiiblt.instafel.updater.utils.RootManager;
import me.mamiiblt.instafel.updater.utils.Utils;
import rikka.shizuku.Shizuku;

public class MainActivity extends AppCompatActivity {

private TextView titleView;
private final Shizuku.OnRequestPermissionResultListener REQUEST_PERMISSION_RESULT_LISTENER = this::onRequestPermissionsResult;

SharedPreferences prefsApp;
SharedPreferences.Editor prefsEditor;
LogUtils logUtils;
Expand All @@ -54,6 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (!prefsApp.getBoolean("init", false)) {
prefsEditor.putString("checker_arch", "NULL");
prefsEditor.putString("checker_type", "NULL");
prefsEditor.putString("checker_method", "NULL");
prefsEditor.putBoolean("root_request_complete", false);
prefsEditor.putBoolean("init", true);
prefsEditor.apply();
Expand All @@ -67,7 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Base_Theme_InstafelUpdater);
}

if (prefsApp.getString("checker_arch", "NULL").equals("NULL") || prefsApp.getString("checker_type", "NULL").equals("NULL")) {
if (prefsApp.getString("checker_arch", "NULL").equals("NULL")) {
Intent intent = new Intent(MainActivity.this, SetupActivity.class);
startActivity(intent);
finish();
Expand Down Expand Up @@ -121,28 +126,75 @@ public void onDestinationChanged(@NonNull NavController controller, @NonNull Nav
}
}

private void onRequestPermissionsResult(int requestCode, int grantResult) {
if (requestCode == 100) {
boolean granted = grantResult == PackageManager.PERMISSION_GRANTED;
if (granted) {
recreate();
logUtils.w("Shizuku permission is granted.");

if (Utils.getBatteryRestrictionStatus(this)) {
Utils.showBatteryDialog(this);
}
} else {
logUtils.w("Shizuku permission is rejected.");
Utils.showDialog(this, this.getString(R.string.permission_rejected), this.getString(R.string.perm_rejected_desc));
}
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 105) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (RootManager.isDeviceRooted()) {
if (RootManager.requestRootPermission()) {
Toast.makeText(MainActivity.this, "Root access granted", Toast.LENGTH_SHORT).show();
if (Utils.getMethod(MainActivity.this) == 1) {
if (RootManager.isDeviceRooted()) {
if (RootManager.requestRootPermission()) {
Toast.makeText(MainActivity.this, "Root access granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Root access rejected, please allow from manager.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(MainActivity.this, "Root access rejected, please allow from manager.", Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "SU binary doesn't found in device, please root your device.", Toast.LENGTH_SHORT).show();
}
prefsEditor.putBoolean("root_request_complete", true);
prefsEditor.apply();
recreate();
} else {
Toast.makeText(MainActivity.this, "SU binary doesn't found in device, please root your device.", Toast.LENGTH_SHORT).show();
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (Utils.isShizukuInstalled(MainActivity.this)) {
if (Shizuku.pingBinder()) {
Shizuku.addRequestPermissionResultListener(REQUEST_PERMISSION_RESULT_LISTENER);
if (!Utils.hasShizukuPermission()) {
logUtils.w("Shizuku permission is not granted, requesting permission.");
Shizuku.requestPermission(100);
}
} else {
Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.please_start_shizuku), Toast.LENGTH_SHORT).show();
Utils.openShizuku(MainActivity.this);
}
} else {
Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.please_install_shizuku), Toast.LENGTH_SHORT).show();
Utils.openPlayStore(MainActivity.this);
}

} else {
Toast.makeText(this, "Please allow notification permission from App Info", Toast.LENGTH_SHORT).show();
finish();
}
}
prefsEditor.putBoolean("root_request_complete", true);
prefsEditor.apply();
recreate();
} else {
Toast.makeText(this, "Please allow notification permission from App Info", Toast.LENGTH_SHORT).show();
finish();
}
}

}

@Override
protected void onDestroy() {
super.onDestroy();
Shizuku.removeRequestPermissionResultListener(REQUEST_PERMISSION_RESULT_LISTENER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {

RadioGroup radioGroupArch = findViewById(R.id.architecture_radio_group);
RadioGroup radioGroupInstallType = findViewById(R.id.install_type_radio_group);
RadioGroup radioGroupIMethod = findViewById(R.id.method_radio_group);
radioGroupArch.setOnCheckedChangeListener((group, checkedId) -> {
if (checkedId == R.id.radio_arm64) {
editor.putString("checker_arch", "arm64-v8a (64-bit)");
Expand All @@ -66,11 +67,20 @@ protected void onCreate(Bundle savedInstanceState) {
}
editor.apply();
});

radioGroupIMethod.setOnCheckedChangeListener((group, checkedId) -> {
if (checkedId == R.id.radio_root) {
editor.putString("checker_method", "root");
} else if (checkedId == R.id.radio_shizuku) {
editor.putString("checker_method", "shi");
}
editor.apply();
});
}

public void next(View view) {

if (!preferences.getString("checker_arch", "NULL").equals("NULL") && !preferences.getString("checker_type", "MULL").equals("NULL")) {
if (!preferences.getString("checker_method", "NULL").equals("NULL") && !preferences.getString("checker_arch", "NULL").equals("NULL") && !preferences.getString("checker_type", "MULL").equals("NULL")) {

// set app preferences too
editor.putString("checker_interval", "4 hour");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ public void onCreate(Bundle savedInstanceState) {
}

}
private TextView viewRootStatus, viewArchitecture, viewIType, viewStatus, viewBatteryStatus;
private TextView viewStatusDesc, viewStatusTitle, viewArchitecture, viewIType, viewStatus, viewBatteryStatus;
private Button viewStartBtn, viewStopBtn;
private FloatingActionButton viewFab;
private SharedPreferences sharedPreferences;
public String STRING_UNAUTHORIZED, STRING_STOPPED, STRING_RESTRICTED, STRING_NOT_FOUND, STRING_UNRESTICTED;
public String STRING_AUTHORIZED, STRING_NOT_INSTALLED, STRING_START_SERVICE, STRING_UNAUTHORIZED, STRING_STOPPED, STRING_RESTRICTED, STRING_NOT_FOUND, STRING_UNRESTICTED;
private LogUtils logUtils;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_info, container, false);
viewRootStatus = view.findViewById(R.id.statusTextView);
viewStatusTitle = view.findViewById(R.id.viewStatusTitle);
viewStatusDesc = view.findViewById(R.id.statusTextView);
viewArchitecture = view.findViewById(R.id.statusTextView2);
viewIType = view.findViewById(R.id.statusTextView3);
viewStatus = view.findViewById(R.id.statusTextView4);
Expand All @@ -84,6 +85,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
logUtils = new LogUtils(getActivity());

Context ctx = getContext();
STRING_AUTHORIZED = ctx.getString(R.string.authorized);
STRING_NOT_INSTALLED = ctx.getString(R.string.not_installed);
STRING_START_SERVICE = ctx.getString(R.string.start_service);
STRING_UNAUTHORIZED = ctx.getString(R.string.unauthorized);
STRING_NOT_FOUND = ctx.getString(R.string.not_found);
STRING_STOPPED = ctx.getString(R.string.stopped);
Expand All @@ -108,28 +112,63 @@ public void onClick(View view) {
viewBatteryStatus.setText(STRING_UNRESTICTED);
}

if (sharedPreferences.getBoolean("root_request_complete", false)) {
if (RootManager.isDeviceRooted()) {
CommandOutput commandOutput = RootManager.execSuCommands("su -v", "su -V");
if (commandOutput.getExitCode() == 0) {
rootStatus = true;
String[] outputParts = commandOutput.getLog().trim().split("\n");
viewRootStatus.setText("✔ " + outputParts[0].trim() + " (" + outputParts[1].trim() + ")");
if (Utils.getMethod(getContext()) == 1) {
viewStatusTitle.setText(this.getString(R.string.root_status));
if (sharedPreferences.getBoolean("root_request_complete", false)) {
if (RootManager.isDeviceRooted()) {
CommandOutput commandOutput = RootManager.execSuCommands("su -v", "su -V");
if (commandOutput.getExitCode() == 0) {
rootStatus = true;
String[] outputParts = commandOutput.getLog().trim().split("\n");
viewStatusDesc.setText("✔ " + outputParts[0].trim() + " (" + outputParts[1].trim() + ")");
} else {
rootStatus = false;
viewStatusDesc.setText(STRING_UNAUTHORIZED);
view.findViewById(R.id.root_status).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RootManager.requestRootPermission();
}
});
}
} else {
rootStatus = false;
viewRootStatus.setText(STRING_UNAUTHORIZED);
view.findViewById(R.id.root_status).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RootManager.requestRootPermission();
}
});
viewStatusDesc.setText(STRING_NOT_FOUND);
}
} else {
viewRootStatus.setText(STRING_NOT_FOUND);
viewStatusDesc.setText(this.getString(R.string.checking));
}
} else {
viewRootStatus.setText(this.getString(R.string.checking));
viewStatusTitle.setText(this.getString(R.string.shiuku_status));
if (Utils.isShizukuInstalled(getActivity())) {
if (Shizuku.pingBinder()) {
if (Utils.hasShizukuPermission()) {
viewStatusDesc.setText(STRING_AUTHORIZED);
} else {
viewStatusDesc.setText(STRING_UNAUTHORIZED);
view.findViewById(R.id.root_status).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Utils.hasShizukuPermission()) {
viewStatusDesc.setText(STRING_AUTHORIZED);
} else {
Shizuku.requestPermission(100);
}
}
});
}
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_start_shizuku), Toast.LENGTH_SHORT).show();
viewStatusDesc.setText(STRING_START_SERVICE);
}
} else {
viewStatusDesc.setText(STRING_NOT_INSTALLED);
view.findViewById(R.id.root_status).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Utils.openPlayStore(getActivity());
}
});
}
}

updateUI();
Expand All @@ -138,12 +177,38 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
if (!Utils.getBatteryRestrictionStatus(getActivity())) {
if (rootStatus) {
logUtils.w(getContext().getString(R.string.upd_started));
UpdateWorkHelper.scheduleWork(getActivity());
updateUI();
if (Utils.getMethod(getContext()) == 1) {
if (rootStatus) {
logUtils.w(getContext().getString(R.string.upd_started));
UpdateWorkHelper.scheduleWork(getActivity());
updateUI();
} else {
Toast.makeText(ctx, getString(R.string.please_install_root), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(ctx, getString(R.string.please_install_root), Toast.LENGTH_SHORT).show();
if (!Utils.getBatteryRestrictionStatus(getActivity())) {
if (Utils.isShizukuInstalled(getActivity())) {
if (Shizuku.pingBinder()) {
if (Utils.hasShizukuPermission()) {
logUtils.w(getContext().getString(R.string.upd_started));
UpdateWorkHelper.scheduleWork(getActivity());
updateUI();
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_give_permission), Toast.LENGTH_SHORT).show();
Utils.openShizuku(ctx);
}
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_start_shizuku), Toast.LENGTH_SHORT).show();
Utils.openShizuku(ctx);
}
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_install_shizuku), Toast.LENGTH_SHORT).show();
Utils.openPlayStore(ctx);
}
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_allow_unrestiracted), Toast.LENGTH_SHORT).show();
Utils.showBatteryDialog(ctx);
}
}
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_allow_unrestiracted), Toast.LENGTH_SHORT).show();
Expand Down
Loading
Loading