use of io.github.muntashirakon.AppManager.utils.UIUtils.displayLongToast in project AppManager by MuntashirAkon.
the class AppInfoFragment method setHorizontalActions.
private void setHorizontalActions() {
mHorizontalLayout.removeAllViews();
if (mainModel != null && !mainModel.getIsExternalApk()) {
// Set open
final Intent launchIntentForPackage = mPackageManager.getLaunchIntentForPackage(mPackageName);
if (launchIntentForPackage != null) {
addToHorizontalLayout(R.string.launch_app, R.drawable.ic_open_in_new_black_24dp).setOnClickListener(v -> {
try {
startActivity(launchIntentForPackage);
} catch (Throwable th) {
UIUtils.displayLongToast(th.getLocalizedMessage());
}
});
}
// Set disable
if (isRootEnabled || isAdbEnabled) {
if (mApplicationInfo.enabled) {
addToHorizontalLayout(R.string.disable, R.drawable.ic_block_black_24dp).setOnClickListener(v -> {
if (BuildConfig.APPLICATION_ID.equals(mPackageName)) {
new MaterialAlertDialogBuilder(mActivity).setMessage(R.string.are_you_sure).setPositiveButton(R.string.yes, (d, w) -> disable()).setNegativeButton(R.string.no, null).show();
} else
disable();
});
}
}
// Set uninstall
addToHorizontalLayout(R.string.uninstall, R.drawable.ic_trash_can_outline).setOnClickListener(v -> {
final boolean isSystemApp = (mApplicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
if (Ops.isPrivileged()) {
ScrollableDialogBuilder builder = new ScrollableDialogBuilder(mActivity, isSystemApp ? R.string.uninstall_system_app_message : R.string.uninstall_app_message).setCheckboxLabel(R.string.keep_data_and_app_signing_signatures).setTitle(mPackageLabel).setPositiveButton(R.string.uninstall, (dialog, which, keepData) -> executor.submit(() -> {
try {
PackageInstallerCompat.uninstall(mPackageName, mainModel.getUserHandle(), keepData);
runOnUiThread(() -> {
displayLongToast(R.string.uninstalled_successfully, mPackageLabel);
mActivity.finish();
});
} catch (Exception e) {
Log.e(TAG, e);
runOnUiThread(() -> displayLongToast(R.string.failed_to_uninstall, mPackageLabel));
}
})).setNegativeButton(R.string.cancel, (dialog, which, keepData) -> {
if (dialog != null)
dialog.cancel();
});
if ((mApplicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
builder.setNeutralButton(R.string.uninstall_updates, (dialog, which, keepData) -> executor.submit(() -> {
Runner.Result result = RunnerUtils.uninstallPackageUpdate(mPackageName, mainModel.getUserHandle(), keepData);
if (result.isSuccessful()) {
runOnUiThread(() -> displayLongToast(R.string.update_uninstalled_successfully, mPackageLabel));
} else {
runOnUiThread(() -> displayLongToast(R.string.failed_to_uninstall_updates, mPackageLabel));
}
}));
}
builder.show();
} else {
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE);
uninstallIntent.setData(Uri.parse("package:" + mPackageName));
startActivity(uninstallIntent);
}
});
// Enable/disable app (root/ADB only)
if (isRootEnabled || isAdbEnabled) {
if (!mApplicationInfo.enabled) {
// Enable app
addToHorizontalLayout(R.string.enable, R.drawable.ic_baseline_get_app_24).setOnClickListener(v -> {
try {
PackageManagerCompat.setApplicationEnabledSetting(mPackageName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0, mainModel.getUserHandle());
} catch (RemoteException | SecurityException e) {
Log.e(TAG, e);
displayLongToast(R.string.failed_to_enable, mPackageLabel);
}
});
}
}
if (isAdbEnabled || isRootEnabled || ServiceHelper.checkIfServiceIsRunning(mActivity, NoRootAccessibilityService.class)) {
// Force stop
if ((mApplicationInfo.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
addToHorizontalLayout(R.string.force_stop, R.drawable.ic_baseline_power_settings_new_24).setOnClickListener(v -> {
if (isAdbEnabled || isRootEnabled) {
executor.submit(() -> {
try {
PackageManagerCompat.forceStopPackage(mPackageName, mainModel.getUserHandle());
runOnUiThread(this::refreshDetails);
} catch (RemoteException | SecurityException e) {
Log.e(TAG, e);
displayLongToast(R.string.failed_to_stop, mPackageLabel);
}
});
} else {
// Use accessibility
AccessibilityMultiplexer.getInstance().enableForceStop(true);
activityLauncher.launch(IntentUtils.getAppDetailsSettings(mPackageName), result -> {
AccessibilityMultiplexer.getInstance().enableForceStop(false);
refreshDetails();
});
}
});
}
// Clear data
addToHorizontalLayout(R.string.clear_data, R.drawable.ic_trash_can_outline).setOnClickListener(v -> new MaterialAlertDialogBuilder(mActivity).setTitle(mPackageLabel).setMessage(R.string.clear_data_message).setPositiveButton(R.string.clear, (dialog, which) -> {
if (isAdbEnabled || isRootEnabled) {
executor.submit(() -> {
if (PackageManagerCompat.clearApplicationUserData(mPackageName, mainModel.getUserHandle())) {
runOnUiThread(this::refreshDetails);
}
});
} else {
// Use accessibility
AccessibilityMultiplexer.getInstance().enableNavigateToStorageAndCache(true);
AccessibilityMultiplexer.getInstance().enableClearData(true);
activityLauncher.launch(IntentUtils.getAppDetailsSettings(mPackageName), result -> {
AccessibilityMultiplexer.getInstance().enableNavigateToStorageAndCache(true);
AccessibilityMultiplexer.getInstance().enableClearData(false);
refreshDetails();
});
}
}).setNegativeButton(R.string.cancel, null).show());
// Clear cache
addToHorizontalLayout(R.string.clear_cache, R.drawable.ic_trash_can_outline).setOnClickListener(v -> {
if (isAdbEnabled || isRootEnabled) {
executor.submit(() -> {
if (PackageManagerCompat.deleteApplicationCacheFilesAsUser(mPackageName, mainModel.getUserHandle())) {
runOnUiThread(this::refreshDetails);
}
});
} else {
// Use accessibility
AccessibilityMultiplexer.getInstance().enableNavigateToStorageAndCache(true);
AccessibilityMultiplexer.getInstance().enableClearCache(true);
activityLauncher.launch(IntentUtils.getAppDetailsSettings(mPackageName), result -> {
AccessibilityMultiplexer.getInstance().enableNavigateToStorageAndCache(false);
AccessibilityMultiplexer.getInstance().enableClearCache(false);
refreshDetails();
});
}
});
} else {
// Display Android settings button
addToHorizontalLayout(R.string.view_in_settings, R.drawable.ic_baseline_settings_24).setOnClickListener(v -> startActivity(IntentUtils.getAppDetailsSettings(mPackageName)));
}
} else if (FeatureController.isInstallerEnabled()) {
if (mInstalledPackageInfo == null) {
// App not installed
addToHorizontalLayout(R.string.install, R.drawable.ic_baseline_get_app_24).setOnClickListener(v -> install());
} else {
// App is installed
long installedVersionCode = PackageInfoCompat.getLongVersionCode(mInstalledPackageInfo);
long thisVersionCode = PackageInfoCompat.getLongVersionCode(mPackageInfo);
if (installedVersionCode < thisVersionCode) {
// Needs update
addToHorizontalLayout(R.string.whats_new, R.drawable.ic_information_variant).setOnClickListener(v -> {
Bundle args = new Bundle();
args.putParcelable(WhatsNewDialogFragment.ARG_NEW_PKG_INFO, mPackageInfo);
args.putParcelable(WhatsNewDialogFragment.ARG_OLD_PKG_INFO, mInstalledPackageInfo);
WhatsNewDialogFragment dialogFragment = new WhatsNewDialogFragment();
dialogFragment.setArguments(args);
dialogFragment.show(mActivity.getSupportFragmentManager(), WhatsNewDialogFragment.TAG);
});
addToHorizontalLayout(R.string.update, R.drawable.ic_baseline_get_app_24).setOnClickListener(v -> install());
} else if (installedVersionCode == thisVersionCode) {
// Needs reinstall
addToHorizontalLayout(R.string.reinstall, R.drawable.ic_baseline_get_app_24).setOnClickListener(v -> install());
} else {
// Needs downgrade
if (Ops.isPrivileged()) {
addToHorizontalLayout(R.string.downgrade, R.drawable.ic_baseline_get_app_24).setOnClickListener(v -> install());
}
}
}
}
// Set manifest
if (FeatureController.isManifestEnabled()) {
addToHorizontalLayout(R.string.manifest, R.drawable.ic_package_variant).setOnClickListener(v -> {
Intent intent = new Intent(mActivity, ManifestViewerActivity.class);
startActivityForSplit(intent);
});
}
// Set scanner
if (FeatureController.isScannerEnabled()) {
addToHorizontalLayout(R.string.scanner, R.drawable.ic_baseline_security_24).setOnClickListener(v -> {
Intent intent = new Intent(mActivity, ScannerActivity.class);
intent.putExtra(ScannerActivity.EXTRA_IS_EXTERNAL, isExternalApk);
startActivityForSplit(intent);
});
}
// Root only features
if (!mainModel.getIsExternalApk()) {
// Shared prefs (root only)
final List<ProxyFile> sharedPrefs = new ArrayList<>();
ProxyFile[] tmpPaths = getSharedPrefs(mApplicationInfo.dataDir);
if (tmpPaths != null)
sharedPrefs.addAll(Arrays.asList(tmpPaths));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
tmpPaths = getSharedPrefs(mApplicationInfo.deviceProtectedDataDir);
if (tmpPaths != null)
sharedPrefs.addAll(Arrays.asList(tmpPaths));
}
if (!sharedPrefs.isEmpty()) {
CharSequence[] sharedPrefNames = new CharSequence[sharedPrefs.size()];
for (int i = 0; i < sharedPrefs.size(); ++i) {
sharedPrefNames[i] = sharedPrefs.get(i).getName();
}
addToHorizontalLayout(R.string.shared_prefs, R.drawable.ic_view_list_black_24dp).setOnClickListener(v -> new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.shared_prefs).setItems(sharedPrefNames, (dialog, which) -> {
Intent intent = new Intent(mActivity, SharedPrefsActivity.class);
intent.putExtra(SharedPrefsActivity.EXTRA_PREF_LOCATION, sharedPrefs.get(which).getAbsolutePath());
intent.putExtra(SharedPrefsActivity.EXTRA_PREF_LABEL, mPackageLabel);
startActivity(intent);
}).setNegativeButton(R.string.ok, null).show());
}
// Databases (root only)
final List<ProxyFile> databases = new ArrayList<>();
tmpPaths = getDatabases(mApplicationInfo.dataDir);
if (tmpPaths != null)
databases.addAll(Arrays.asList(tmpPaths));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
tmpPaths = getDatabases(mApplicationInfo.deviceProtectedDataDir);
if (tmpPaths != null)
databases.addAll(Arrays.asList(tmpPaths));
}
if (!databases.isEmpty()) {
CharSequence[] databases2 = new CharSequence[databases.size()];
for (int i = 0; i < databases.size(); ++i) {
databases2[i] = databases.get(i).getName();
}
addToHorizontalLayout(R.string.databases, R.drawable.ic_database).setOnClickListener(v -> new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.databases).setItems(databases2, (dialog, i) -> {
// TODO: 7/7/21 VACUUM the database before opening it
Context ctx = AppManager.getContext();
Path dbPath = new Path(ctx, databases.get(i));
Intent openFile = new Intent(Intent.ACTION_VIEW);
openFile.setDataAndType(FmProvider.getContentUri(dbPath), "application/vnd.sqlite3");
openFile.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (openFile.resolveActivityInfo(ctx.getPackageManager(), 0) != null) {
ctx.startActivity(openFile);
}
}).setNegativeButton(R.string.ok, null).show());
}
}
// End root only features
// Set F-Droid
Intent fdroid_intent = new Intent(Intent.ACTION_VIEW);
fdroid_intent.setData(Uri.parse("https://f-droid.org/packages/" + mPackageName));
List<ResolveInfo> resolvedActivities = mPackageManager.queryIntentActivities(fdroid_intent, 0);
if (resolvedActivities.size() > 0) {
addToHorizontalLayout(R.string.fdroid, R.drawable.ic_frost_fdroid_black_24dp).setOnClickListener(v -> {
try {
startActivity(fdroid_intent);
} catch (Exception ignored) {
}
});
}
// Set Aurora Store
try {
PackageInfo auroraInfo = mPackageManager.getPackageInfo(PACKAGE_NAME_AURORA_STORE, 0);
if (PackageInfoCompat.getLongVersionCode(auroraInfo) == 36L || !auroraInfo.applicationInfo.enabled) {
// Aurora Store is disabled or the installed version has promotional apps
throw new PackageManager.NameNotFoundException();
}
addToHorizontalLayout(R.string.store, R.drawable.ic_frost_aurorastore_black_24dp).setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage(PACKAGE_NAME_AURORA_STORE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + mPackageName));
try {
startActivity(intent);
} catch (Exception ignored) {
}
});
} catch (PackageManager.NameNotFoundException ignored) {
}
View v = mHorizontalLayout.getChildAt(0);
if (v != null)
v.requestFocus();
}
Aggregations