[app] Uninstall app with binder
This commit is contained in:
parent
d6ea773aa8
commit
46c15c0961
|
|
@ -24,7 +24,6 @@
|
|||
package="io.github.lsposed.manager">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
|
||||
|
||||
<queries>
|
||||
|
|
|
|||
|
|
@ -249,4 +249,13 @@ public class ConfigManager {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean uninstallPackage(String packageName) {
|
||||
try {
|
||||
return LSPosedManagerServiceClient.uninstallPackage(packageName);
|
||||
} catch (RemoteException | NullPointerException e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,4 +159,9 @@ public class LSPosedManagerServiceClient {
|
|||
ensureService();
|
||||
service.reboot(confirm, reason, wait);
|
||||
}
|
||||
|
||||
public static boolean uninstallPackage(String packageName) throws RemoteException, NullPointerException {
|
||||
ensureService();
|
||||
return service.uninstallPackage(packageName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import android.graphics.drawable.Drawable;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
|
|
@ -42,10 +44,13 @@ import android.view.ViewGroup;
|
|||
import android.widget.Filter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
|
|
@ -69,11 +74,18 @@ import static android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
|
|||
|
||||
public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleListener {
|
||||
|
||||
private static final Handler uninstallHandler;
|
||||
private PackageManager pm;
|
||||
private ModuleUtil moduleUtil;
|
||||
private ModuleAdapter adapter = null;
|
||||
private String selectedPackageName;
|
||||
|
||||
static {
|
||||
HandlerThread uninstallThread = new HandlerThread("uninstall");
|
||||
uninstallThread.start();
|
||||
uninstallHandler = new Handler(uninstallThread.getLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
moduleUtil = ModuleUtil.getInstance();
|
||||
|
|
@ -147,7 +159,23 @@ public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleLi
|
|||
startActivity(new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", module.packageName, null)));
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_uninstall) {
|
||||
startActivity(new Intent(Intent.ACTION_UNINSTALL_PACKAGE, Uri.fromParts("package", module.packageName, null)));
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(module.getAppName())
|
||||
.setMessage(R.string.module_uninstall_message)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) ->
|
||||
uninstallHandler.post(() -> {
|
||||
boolean success = ConfigManager.uninstallPackage(module.packageName);
|
||||
runOnUiThread(() -> {
|
||||
String text = success ? getString(R.string.module_uninstalled, module.getAppName()) : getString(R.string.module_uninstall_failed);
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
Snackbar.make(binding.snackbar, text, Snackbar.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(ModulesActivity.this, text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}))
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_repo) {
|
||||
Intent intent = new Intent();
|
||||
|
|
|
|||
|
|
@ -78,6 +78,9 @@
|
|||
<string name="module_uninstall">Uninstall</string>
|
||||
<string name="module_settings">Module settings</string>
|
||||
<string name="view_in_repo">View in Repo</string>
|
||||
<string name="module_uninstall_message">Do you want to uninstall this module?</string>
|
||||
<string name="module_uninstalled">Uninstalled %1$s</string>
|
||||
<string name="module_uninstall_failed">Uninstall unsuccessful</string>
|
||||
|
||||
<!-- AppListActivity -->
|
||||
<string name="compile_speed">Re-optimize</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue