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

Root support added (Magisk & KernelSU) and Shizuku support is completely removed. #5

Merged
merged 1 commit into from
Dec 22, 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
6 changes: 6 additions & 0 deletions .idea/AndroidProjectSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

<application
Expand All @@ -28,14 +27,6 @@
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
Binary file modified app/src/main/iflu_icon-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 39 additions & 69 deletions app/src/main/java/me/mamiiblt/instafel/updater/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@

import me.mamiiblt.instafel.updater.utils.LocalizationUtils;
import me.mamiiblt.instafel.updater.utils.LogUtils;
import me.mamiiblt.instafel.updater.utils.ShizukuInstaller;
import me.mamiiblt.instafel.updater.utils.Utils;
import rikka.shizuku.Shizuku;
import me.mamiiblt.instafel.updater.utils.RootManager;

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 @@ -58,6 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (!prefsApp.getBoolean("init", false)) {
prefsEditor.putString("checker_arch", "NULL");
prefsEditor.putString("checker_type", "NULL");
prefsEditor.putBoolean("root_request_complete", false);
prefsEditor.putBoolean("init", true);
prefsEditor.apply();
}
Expand All @@ -70,21 +67,22 @@ protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Base_Theme_InstafelUpdater);
}

EdgeToEdge.enable(this);

setContentView(R.layout.activity_main);

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, 0);
return insets;
});

if (prefsApp.getString("checker_arch", "NULL").equals("NULL") || prefsApp.getString("checker_type", "NULL").equals("NULL")) {
Intent intent = new Intent(MainActivity.this, SetupActivity.class);
startActivity(intent);
finish();
} else {

EdgeToEdge.enable(this);

setContentView(R.layout.activity_main);

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, 0);
return insets;
});

if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
new MaterialAlertDialogBuilder(this)
Expand All @@ -101,43 +99,25 @@ public void onClick(DialogInterface dialog, int which) {
}
}

}

titleView = findViewById(R.id.title);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupWithNavController(bottomNavigationView, navController);

Context ctx = getApplicationContext();

navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
if (destination.getId() == R.id.nav_info) {
titleView.setText(ctx.getString(R.string.status));
} else if (destination.getId() == R.id.nav_logs) {
titleView.setText(ctx.getString(R.string.logs));
} else if (destination.getId() == R.id.nav_settings) {
titleView.setText(ctx.getString(R.string.settings));
}
}
});
}

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);
titleView = findViewById(R.id.title);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupWithNavController(bottomNavigationView, navController);

Context ctx = getApplicationContext();

navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
if (destination.getId() == R.id.nav_info) {
titleView.setText(ctx.getString(R.string.status));
} else if (destination.getId() == R.id.nav_logs) {
titleView.setText(ctx.getString(R.string.logs));
} else if (destination.getId() == R.id.nav_settings) {
titleView.setText(ctx.getString(R.string.settings));
}
}
} else {
logUtils.w("Shizuku permission is rejected.");
Utils.showDialog(this, this.getString(R.string.permission_rejected), this.getString(R.string.perm_rejected_desc));
}
});
}
}

Expand All @@ -146,33 +126,23 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 105) {
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);
}
if (RootManager.isDeviceRooted()) {
if (RootManager.requestRootPermission()) {
Toast.makeText(MainActivity.this, "Root access granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.please_start_shizuku), Toast.LENGTH_SHORT).show();
Utils.openShizuku(MainActivity.this);
Toast.makeText(MainActivity.this, "Root access rejected, please allow from manager.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.please_install_shizuku), Toast.LENGTH_SHORT).show();
Utils.openPlayStore(MainActivity.this);
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(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 @@ -13,6 +13,7 @@
import androidx.preference.PreferenceManager;

import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -25,15 +26,18 @@

import me.mamiiblt.instafel.updater.MainActivity;
import me.mamiiblt.instafel.updater.update.UpdateWorkHelper;
import me.mamiiblt.instafel.updater.utils.CommandOutput;
import me.mamiiblt.instafel.updater.utils.LogUtils;
import me.mamiiblt.instafel.updater.R;
import me.mamiiblt.instafel.updater.utils.RootManager;
import me.mamiiblt.instafel.updater.utils.Utils;
import rikka.shizuku.Shizuku;

public class InfoFragment extends Fragment {

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private static boolean rootStatus = false;

private String mParam1;
private String mParam2;
Expand All @@ -59,17 +63,17 @@ public void onCreate(Bundle savedInstanceState) {
}

}
private TextView viewShizukuStatus, viewArchitecture, viewIType, viewStatus, viewBatteryStatus;
private TextView viewRootStatus, viewArchitecture, viewIType, viewStatus, viewBatteryStatus;
private Button viewStartBtn, viewStopBtn;
private FloatingActionButton viewFab;
private SharedPreferences sharedPreferences;
public String STRING_AUTHORIZED, STRING_UNAUTHORIZED, STRING_STOPPED, STRING_NOT_INSTALLED, STRING_START_SERVICE, STRING_RESTRICTED, STRING_UNRESTICTED;
public String 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);
viewShizukuStatus = view.findViewById(R.id.statusTextView);
viewRootStatus = 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 @@ -80,11 +84,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_UNAUTHORIZED = ctx.getString(R.string.unauthorized);
STRING_NOT_FOUND = ctx.getString(R.string.not_found);
STRING_STOPPED = ctx.getString(R.string.stopped);
STRING_NOT_INSTALLED = ctx.getString(R.string.not_installed);
STRING_START_SERVICE = ctx.getString(R.string.start_service);
STRING_RESTRICTED = ctx.getString(R.string.battery_restiricted);
STRING_UNRESTICTED = ctx.getString(R.string.battery_unrestiricted);

Expand All @@ -106,35 +108,28 @@ public void onClick(View view) {
viewBatteryStatus.setText(STRING_UNRESTICTED);
}

if (Utils.isShizukuInstalled(getActivity())) {
if (Shizuku.pingBinder()) {
if (Utils.hasShizukuPermission()) {
viewShizukuStatus.setText(STRING_AUTHORIZED);
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() + ")");
} else {
viewShizukuStatus.setText(STRING_UNAUTHORIZED);
view.findViewById(R.id.shizuku_status).setOnClickListener(new View.OnClickListener() {
rootStatus = false;
viewRootStatus.setText(STRING_UNAUTHORIZED);
view.findViewById(R.id.root_status).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Utils.hasShizukuPermission()) {
viewShizukuStatus.setText(STRING_AUTHORIZED);
} else {
Shizuku.requestPermission(100);
}
RootManager.requestRootPermission();
}
});
}
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_start_shizuku), Toast.LENGTH_SHORT).show();
viewShizukuStatus.setText(STRING_START_SERVICE);
viewRootStatus.setText(STRING_NOT_FOUND);
}
} else {
viewShizukuStatus.setText(STRING_NOT_INSTALLED);
view.findViewById(R.id.shizuku_status).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Utils.openPlayStore(getActivity());
}
});
viewRootStatus.setText(this.getString(R.string.checking));
}

updateUI();
Expand All @@ -143,23 +138,12 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
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);
}
if (rootStatus) {
logUtils.w(getContext().getString(R.string.upd_started));
UpdateWorkHelper.scheduleWork(getActivity());
updateUI();
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_install_shizuku), Toast.LENGTH_SHORT).show();
Utils.openPlayStore(ctx);
Toast.makeText(ctx, getString(R.string.please_install_root), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(ctx, ctx.getString(R.string.please_allow_unrestiracted), Toast.LENGTH_SHORT).show();
Expand Down
Loading
Loading