diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index db17f56..ea2db33 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -13,6 +13,7 @@
+
+
+
diff --git a/app/src/main/java/me/mamiiblt/instafel/updater/MainActivity.java b/app/src/main/java/me/mamiiblt/instafel/updater/MainActivity.java
index 162b8e2..6865738 100644
--- a/app/src/main/java/me/mamiiblt/instafel/updater/MainActivity.java
+++ b/app/src/main/java/me/mamiiblt/instafel/updater/MainActivity.java
@@ -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;
@@ -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();
@@ -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();
@@ -121,23 +126,64 @@ 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();
@@ -145,4 +191,10 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ Shizuku.removeRequestPermissionResultListener(REQUEST_PERMISSION_RESULT_LISTENER);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/me/mamiiblt/instafel/updater/SetupActivity.java b/app/src/main/java/me/mamiiblt/instafel/updater/SetupActivity.java
index fd74d35..d8abf1c 100644
--- a/app/src/main/java/me/mamiiblt/instafel/updater/SetupActivity.java
+++ b/app/src/main/java/me/mamiiblt/instafel/updater/SetupActivity.java
@@ -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)");
@@ -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");
diff --git a/app/src/main/java/me/mamiiblt/instafel/updater/fragments/InfoFragment.java b/app/src/main/java/me/mamiiblt/instafel/updater/fragments/InfoFragment.java
index ec1d210..7eedd66 100644
--- a/app/src/main/java/me/mamiiblt/instafel/updater/fragments/InfoFragment.java
+++ b/app/src/main/java/me/mamiiblt/instafel/updater/fragments/InfoFragment.java
@@ -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);
@@ -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);
@@ -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();
@@ -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();
diff --git a/app/src/main/java/me/mamiiblt/instafel/updater/update/InstafelUpdateService.java b/app/src/main/java/me/mamiiblt/instafel/updater/update/InstafelUpdateService.java
index 68c14e1..384873d 100644
--- a/app/src/main/java/me/mamiiblt/instafel/updater/update/InstafelUpdateService.java
+++ b/app/src/main/java/me/mamiiblt/instafel/updater/update/InstafelUpdateService.java
@@ -26,6 +26,8 @@
import me.mamiiblt.instafel.updater.utils.CommandOutput;
import me.mamiiblt.instafel.updater.utils.LogUtils;
import me.mamiiblt.instafel.updater.utils.RootManager;
+import me.mamiiblt.instafel.updater.utils.ShizukuInstaller;
+import me.mamiiblt.instafel.updater.utils.Utils;
public class InstafelUpdateService extends Service {
@@ -38,7 +40,6 @@ public class InstafelUpdateService extends Service {
private Context ctx;
private LogUtils logUtils;
private String version;
- private boolean advanced_userservice_mode, disable_priority_error_log;
NotificationManager notificationManager;
NotificationCompat.Builder notificationBuilder;
@@ -58,13 +59,15 @@ public int onStartCommand(Intent intent, int flags, int startId) {
createNotificationChannel();
startForeground(NOTIFICATION_ID, notifyWaitingAPI());
version = intent.getStringExtra("version");
- disable_priority_error_log = intent.getBooleanExtra("disable_error_log", false);
downloadFile(intent.getStringExtra("file_url"));
}
- return START_STICKY;
+ return START_NOT_STICKY;
}
private void downloadFile(String fileUrl) {
+ if (Utils.getMethod(ctx) != 1) {
+ ShizukuInstaller.ensureUserService(ctx);
+ }
this.df = new DecimalFormat("#.##");
try {
@@ -118,6 +121,9 @@ private void downloadFile(String fileUrl) {
errorOccured = true;
} finally {
if (!errorOccured) {
+ if (Utils.getMethod(ctx) != 1) {
+ ShizukuInstaller.ensureUserService(ctx);
+ }
updateApp(ifl_update_file);
}
}
@@ -167,24 +173,26 @@ private void updateApp(File ifl_update_file) {
logUtils.w("Download complete, installation is started.");
new Thread(() -> {
try {
- logUtils.w("Installing update");
- CommandOutput commandOutput = RootManager.execSuCommands(
- "cp " + ifl_update_file.getAbsolutePath() + " /data/local/tmp/INSTAFEL_UPDATE.apk",
- "pm install /data/local/tmp/INSTAFEL_UPDATE.apk",
- "rm /data/local/tmp/INSTAFEL_UPDATE.apk"
- );
-
- if (commandOutput.getExitCode() == 0 && commandOutput.getLog().contains("Success")) {
- logUtils.w("Update installed.");
- recreateFilesDir();
- notifyUpdateInstalled();
- logUtils.w("Instafel succesfully updated.");
+
+ if (Utils.getMethod(ctx) == 1) {
+ installApk(ifl_update_file, true);
} else {
- logUtils.w("Update installation failed.");
- notifyError("An error occurred when installing update (RESULT_FAILED)");
- logUtils.w("exitCode: " + commandOutput.getExitCode());
- logUtils.w("output: " + commandOutput.getLog());
- logUtils.w("errOutput: " + commandOutput.getErrorLog());
+ if (ShizukuInstaller.isShizukuSupported()) {
+ if (Utils.hasShizukuPermission()) {
+ for (int i = 0; i < 5; i++) {
+ if (ShizukuInstaller.ensureUserService(ctx)) {
+ i = 10;
+ } else {
+ i++;
+ }
+ }
+ installApk(ifl_update_file, false);
+ } else {
+ logUtils.w("Shizuku permission is not granted for Install.");
+ }
+ } else {
+ logUtils.w("Shizuku is not supported.");
+ }
}
} catch (Exception e) {
logUtils.w("Installation method crashed.");
@@ -196,6 +204,47 @@ private void updateApp(File ifl_update_file) {
}).start();
}
+ private void installApk(File ifl_update_file, boolean status) {
+ if (status) {
+ logUtils.w("Installing update");
+ CommandOutput commandOutput = RootManager.execSuCommands(
+ "cp " + ifl_update_file.getAbsolutePath() + " /data/local/tmp/INSTAFEL_UPDATE.apk",
+ "pm install /data/local/tmp/INSTAFEL_UPDATE.apk",
+ "rm /data/local/tmp/INSTAFEL_UPDATE.apk"
+ );
+
+ if (commandOutput.getExitCode() == 0 && commandOutput.getLog().contains("Success")) {
+ logUtils.w("Update installed.");
+ recreateFilesDir();
+ notifyUpdateInstalled();
+ logUtils.w("Instafel succesfully updated.");
+ } else {
+ logUtils.w("Update installation failed.");
+ notifyError("An error occurred when installing update (RESULT_FAILED)");
+ logUtils.w("exitCode: " + commandOutput.getExitCode());
+ logUtils.w("output: " + commandOutput.getLog());
+ logUtils.w("errOutput: " + commandOutput.getErrorLog());
+ }
+ } else {
+ logUtils.w("Shizuku permission is valid, triggering UserService again, " + ShizukuInstaller.ensureUserService(ctx));
+ logUtils.w("Copying downloaded apk file to temp.");
+ ShizukuInstaller.runCommand(ctx, "cp " + ifl_update_file + " /data/local/tmp/INSTAFEL_UPDATE.apk");
+ logUtils.w("Installing update");
+ String updateLog = ShizukuInstaller.runCommand(ctx, "pm install /data/local/tmp/INSTAFEL_UPDATE.apk");
+ if (updateLog.trim().equals("Success")) {
+ logUtils.w("Update installed.");
+ ShizukuInstaller.runCommand(ctx, "rm -r /data/local/tmp/INSTAFEL_UPDATE.apk");
+ recreateFilesDir();
+ logUtils.w("Downloaded apk & temp apk removed");
+ notifyUpdateInstalled();
+ logUtils.w("Instafel succesfully updated.");
+ } else {
+ logUtils.w("Update installation failed.");
+ notifyError("An error occurred when installing update (RESULT_FAILED)");
+ }
+ }
+ }
+
private void notifyStatus(int prog, String finalFormattedDownloadedSize) {
notificationBuilder
.setContentTitle(ctx.getString(R.string.n1_downloading))
diff --git a/app/src/main/java/me/mamiiblt/instafel/updater/update/UpdateWork.java b/app/src/main/java/me/mamiiblt/instafel/updater/update/UpdateWork.java
index 38abd1d..8d2db9e 100644
--- a/app/src/main/java/me/mamiiblt/instafel/updater/update/UpdateWork.java
+++ b/app/src/main/java/me/mamiiblt/instafel/updater/update/UpdateWork.java
@@ -33,6 +33,7 @@
import me.mamiiblt.instafel.updater.utils.AppPreferences;
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 okhttp3.OkHttpClient;
import okhttp3.Request;
@@ -44,15 +45,8 @@ public class UpdateWork extends Worker {
private static final int NOTIFICATION_ID = 1;
private AppPreferences appPreferences;
private Context ctx;
- private double currentDownloadedSizeMegabyte;
- private long fileSize;
- private String formattedFileSize;
- private DecimalFormat df;
- private NotificationCompat.Builder notificationBuilder;
- private int notificationId = 105;
private String uVersion;
private LogUtils logUtils;
- private NotificationManager notificationManager;
private LocalizationUtils localizationUtils;
public UpdateWork(Context ctx, WorkerParameters params) {
@@ -67,8 +61,6 @@ public Result doWork() {
ctx = getApplicationContext();
logUtils.w("");
logUtils.w("Work is running.");
- notificationBuilder = new NotificationCompat.Builder(ctx, CHANNEL_ID);
- notificationManager = ctx.getSystemService(NotificationManager.class);
localizationUtils = new LocalizationUtils(getApplicationContext());
// Update locale
@@ -200,6 +192,10 @@ public Result doWork() {
}
}
+ if (Utils.getMethod(ctx) != 1) {
+ ShizukuInstaller.ensureUserService(ctx);
+ }
+
String b_download_url = null;
if (appPreferences.isUseInstafelApi()) {
if (type.equals("uc")) {
@@ -224,7 +220,6 @@ public Result doWork() {
Intent fgServiceIntent = new Intent(ctx, InstafelUpdateService.class);
fgServiceIntent.putExtra("file_url", b_download_url);
fgServiceIntent.putExtra("version", uVersion);
- fgServiceIntent.putExtra("disable_error_log", appPreferences.isDisable_error_notifications());
ctx.startService(fgServiceIntent);
} else {
sendError("Updater can't found update asset!", true, null);
diff --git a/app/src/main/java/me/mamiiblt/instafel/updater/utils/ShizukuInstaller.java b/app/src/main/java/me/mamiiblt/instafel/updater/utils/ShizukuInstaller.java
new file mode 100644
index 0000000..caf5e2c
--- /dev/null
+++ b/app/src/main/java/me/mamiiblt/instafel/updater/utils/ShizukuInstaller.java
@@ -0,0 +1,79 @@
+package me.mamiiblt.instafel.updater.utils;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+
+import androidx.core.app.NotificationCompat;
+
+import java.io.File;
+
+import me.mamiiblt.instafel.updater.BuildConfig;
+import me.mamiiblt.instafel.updater.IUserService;
+import me.mamiiblt.instafel.updater.services.UserService;
+import rikka.shizuku.Shizuku;
+
+public class ShizukuInstaller {
+
+ private static IUserService mUserService = null;
+
+ public static boolean isShizukuSupported() {
+ return Shizuku.pingBinder() && Shizuku.getVersion() >= 11 && !Shizuku.isPreV11();
+ }
+
+ public static boolean ensureUserService(Context ctx) {
+ if (mUserService != null) {
+ return true;
+ }
+
+ Shizuku.UserServiceArgs mUserServiceArgs = new Shizuku.UserServiceArgs(new ComponentName(BuildConfig.APPLICATION_ID, UserService.class.getName()))
+ .daemon(false)
+ .processNameSuffix("service")
+ .debuggable(BuildConfig.DEBUG)
+ .version(BuildConfig.VERSION_CODE);
+ Shizuku.bindUserService(mUserServiceArgs, mServiceConnection);
+
+ return false;
+ }
+
+ public static boolean userServiceIsAvailable() {
+ if (mUserService != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private static final ServiceConnection mServiceConnection = new ServiceConnection() {
+
+ @Override
+ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
+ if (iBinder == null || !iBinder.pingBinder()) {
+ return;
+ }
+
+ mUserService = IUserService.Stub.asInterface(iBinder);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName componentName) {
+
+ }
+ };
+
+ public static String runCommand(Context ctx, String command) {
+ if (ensureUserService(ctx)) {
+ try {
+ return mUserService.executeShellCommand(command);
+ } catch (RemoteException ignored) {
+ ignored.printStackTrace();
+ }
+ } else {
+ Log.v("IFL", "ensureUserService is false");
+ }
+ return "";
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/me/mamiiblt/instafel/updater/utils/Utils.java b/app/src/main/java/me/mamiiblt/instafel/updater/utils/Utils.java
index e312d4f..3be94a9 100644
--- a/app/src/main/java/me/mamiiblt/instafel/updater/utils/Utils.java
+++ b/app/src/main/java/me/mamiiblt/instafel/updater/utils/Utils.java
@@ -5,6 +5,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
@@ -15,6 +16,8 @@
import android.provider.Settings;
import android.util.Log;
+import androidx.preference.PreferenceManager;
+
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.List;
@@ -24,6 +27,30 @@
import rikka.shizuku.Shizuku;
public class Utils {
+
+ public static boolean status = false;
+
+ public static boolean hasShizukuPermission() {
+ if (Shizuku.isPreV11()) {
+ return false;
+ }
+
+ return Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED;
+ }
+
+ public static boolean isShizukuInstalled(Activity activity) {
+ if (getAppVersionCode(activity, "moe.shizuku.privileged.api").equals("NOT_INSTALLED")) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public static void openShizuku(Context ctx) {
+ Intent intent = ctx.getPackageManager().getLaunchIntentForPackage("moe.shizuku.privileged.api");
+ ctx.startActivity(intent);
+ }
+
public static void showBatteryDialog(Context ctx) {
if (Utils.getBatteryRestrictionStatus(ctx)) {
new MaterialAlertDialogBuilder(ctx)
@@ -35,6 +62,15 @@ public static void showBatteryDialog(Context ctx) {
}
}
+ public static int getMethod(Context ctx) {
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
+ if (sharedPreferences.getString("checker_method", "shizuku").equals("root")) {
+ return 1;
+ } else {
+ return 2;
+ }
+ }
+
public static void showAppInfoDialog(Context ctx) {
new MaterialAlertDialogBuilder(ctx)
.setTitle(ctx.getString(R.string.about_app))
@@ -81,4 +117,19 @@ public static String getAppVersionCode(Context ctx, String packageName) {
return "NOT_INSTALLED";
}
}
+
+ public static void openPlayStore(Context ctx) {
+ Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=moe.shizuku.privileged.api"));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ ctx.startActivity(intent);
+ }
+
+ public static void showDialog(Context ctx, String title, String message) {
+ new MaterialAlertDialogBuilder(ctx)
+ .setTitle(title)
+ .setMessage(message)
+ .setNegativeButton(android.R.string.yes, null)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .show();
+ }
}
diff --git a/app/src/main/res/layout/activity_setup.xml b/app/src/main/res/layout/activity_setup.xml
index 9cecf85..fb51db9 100644
--- a/app/src/main/res/layout/activity_setup.xml
+++ b/app/src/main/res/layout/activity_setup.xml
@@ -27,19 +27,20 @@
android:id="@+id/architecture_radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:orientation="vertical">
+ android:orientation="horizontal">
+ android:layout_marginRight="20dp"
+ android:text="arm64-v8a"/>
+ android:text="armeabi-v7a"/>
+ android:orientation="horizontal">
+
+
+
+
+
+
+
+
+