use of io.github.muntashirakon.AppManager.ssaid.SsaidSettings in project AppManager by MuntashirAkon.
the class BackupOp method backupExtras.
private void backupExtras() throws BackupException {
PseudoRules rules = new PseudoRules(mPackageName, mUserId);
Path miscFile;
try {
miscFile = mBackupFile.getMiscFile(CryptoUtils.MODE_NO_ENCRYPTION);
} catch (IOException e) {
throw new BackupException("Couldn't get misc.am.tsv", e);
}
// Backup permissions
@NonNull String[] permissions = ArrayUtils.defeatNullable(mPackageInfo.requestedPermissions);
int[] permissionFlags = mPackageInfo.requestedPermissionsFlags;
List<OpEntry> opEntries = new ArrayList<>();
try {
List<PackageOps> packageOpsList = new AppOpsService().getOpsForPackage(mPackageInfo.applicationInfo.uid, mPackageName, null);
if (packageOpsList.size() == 1)
opEntries.addAll(packageOpsList.get(0).getOps());
} catch (Exception ignore) {
}
PermissionInfo info;
int basePermissionType;
int protectionLevels;
for (int i = 0; i < permissions.length; ++i) {
try {
info = mPm.getPermissionInfo(permissions[i], 0);
basePermissionType = PermissionInfoCompat.getProtection(info);
protectionLevels = PermissionInfoCompat.getProtectionFlags(info);
if (basePermissionType != PermissionInfo.PROTECTION_DANGEROUS && (protectionLevels & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) == 0) {
// Don't include permissions that are neither dangerous nor development
continue;
}
boolean isGranted = (permissionFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;
int permFlags = PermissionCompat.getPermissionFlags(info.name, mPackageName, mUserId);
rules.setPermission(permissions[i], isGranted, permFlags);
} catch (PackageManager.NameNotFoundException | RemoteException ignore) {
}
}
// Backup app ops
for (OpEntry entry : opEntries) {
rules.setAppOp(entry.getOp(), entry.getMode());
}
// Backup MagiskHide data
Collection<String> magiskHiddenProcesses = MagiskHide.getProcesses(mPackageName);
for (String processName : magiskHiddenProcesses) {
rules.setMagiskHide(processName, true);
}
// Backup Magisk DenyList data
Collection<String> magiskDeniedProcesses = MagiskDenyList.getProcesses(mPackageName);
for (String processName : magiskDeniedProcesses) {
rules.setMagiskDenyList(processName, true);
}
// Backup allowed notification listeners aka BIND_NOTIFICATION_LISTENER_SERVICE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
INotificationManager notificationManager = INotificationManager.Stub.asInterface(ProxyBinder.getService(Context.NOTIFICATION_SERVICE));
try {
List<ComponentName> notificationComponents;
if (LocalServer.isAMServiceAlive()) {
notificationComponents = notificationManager.getEnabledNotificationListeners(mUserId);
} else
notificationComponents = Collections.emptyList();
List<String> componentsForThisPkg = new ArrayList<>();
for (ComponentName componentName : notificationComponents) {
if (mPackageName.equals(componentName.getPackageName())) {
componentsForThisPkg.add(componentName.getClassName());
}
}
for (String component : componentsForThisPkg) {
rules.setNotificationListener(component, true);
}
} catch (RemoteException ignore) {
}
}
// Backup battery optimization
String targetString = "user," + mPackageName + "," + mApplicationInfo.uid;
Runner.Result result = Runner.runCommand(new String[] { "dumpsys", "deviceidle", "whitelist" });
if (result.isSuccessful() && result.getOutput().contains(targetString)) {
rules.setBatteryOptimization(false);
}
// Backup net policy
int policies = NetworkPolicyManagerCompat.getUidPolicy(mApplicationInfo.uid);
if (policies > 0) {
// Store only if there is a policy
rules.setNetPolicy(policies);
}
// Backup URI grants
List<UriManager.UriGrant> uriGrants = new UriManager().getGrantedUris(mPackageName);
if (uriGrants != null) {
for (UriManager.UriGrant uriGrant : uriGrants) {
if (uriGrant.targetUserId == mUserId) {
rules.setUriGrant(uriGrant);
}
}
}
// Backup SSAID
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
String ssaid = new SsaidSettings(mPackageName, mApplicationInfo.uid).getSsaid();
if (ssaid != null)
rules.setSsaid(ssaid);
} catch (IOException e) {
// Ignore exception
Log.e(TAG, e);
}
}
rules.commitExternal(miscFile);
if (!miscFile.exists())
return;
try {
encrypt(new Path[] { miscFile });
// Overwrite with the new file
miscFile = mBackupFile.getMiscFile(mMetadata.crypto);
// Store checksum
mChecksum.add(miscFile.getName(), DigestUtils.getHexDigest(mMetadata.checksumAlgo, miscFile));
} catch (IOException e) {
throw new BackupException("Couldn't get misc.am.tsv for generating checksum", e);
}
}
use of io.github.muntashirakon.AppManager.ssaid.SsaidSettings in project AppManager by MuntashirAkon.
the class RestoreOp method restoreExtras.
private synchronized void restoreExtras() throws BackupException {
if (!isInstalled) {
throw new BackupException("Misc restore is requested but the app isn't installed.");
}
PseudoRules rules = new PseudoRules(packageName, userHandle);
// Backward compatibility for restoring permissions
loadMiscRules(rules);
// Apply rules
List<RuleEntry> entries = rules.getAll();
AppOpsService appOpsService = new AppOpsService();
INotificationManager notificationManager = INotificationManager.Stub.asInterface(ProxyBinder.getService(Context.NOTIFICATION_SERVICE));
boolean magiskHideAvailable = MagiskHide.available();
for (RuleEntry entry : entries) {
try {
switch(entry.type) {
case APP_OP:
appOpsService.setMode(Integer.parseInt(entry.name), packageInfo.applicationInfo.uid, packageName, ((AppOpRule) entry).getMode());
break;
case NET_POLICY:
NetworkPolicyManagerCompat.setUidPolicy(packageInfo.applicationInfo.uid, ((NetPolicyRule) entry).getPolicies());
break;
case PERMISSION:
{
PermissionRule permissionRule = (PermissionRule) entry;
Permission permission = permissionRule.getPermission(true);
permission.setAppOpAllowed(permission.getAppOp() != OP_NONE && appOpsService.checkOperation(permission.getAppOp(), packageInfo.applicationInfo.uid, packageName) == AppOpsManager.MODE_ALLOWED);
if (permissionRule.isGranted()) {
PermUtils.grantPermission(packageInfo, permission, appOpsService, true, true);
} else {
PermUtils.revokePermission(packageInfo, permission, appOpsService, true);
}
break;
}
case BATTERY_OPT:
Runner.runCommand(new String[] { "dumpsys", "deviceidle", "whitelist", "+" + packageName });
break;
case MAGISK_HIDE:
{
MagiskHideRule magiskHideRule = (MagiskHideRule) entry;
if (magiskHideAvailable) {
if (magiskHideRule.isHidden()) {
MagiskHide.add(packageName, magiskHideRule.getProcessName());
} else {
MagiskHide.remove(packageName, magiskHideRule.getProcessName());
}
} else {
// Fall-back to Magisk DenyList
if (magiskHideRule.isHidden()) {
MagiskDenyList.add(packageName, magiskHideRule.getProcessName());
} else {
MagiskDenyList.remove(packageName, magiskHideRule.getProcessName());
}
}
break;
}
case MAGISK_DENY_LIST:
{
MagiskDenyListRule magiskDenyListRule = (MagiskDenyListRule) entry;
if (magiskDenyListRule.isDenied()) {
MagiskDenyList.add(packageName, magiskDenyListRule.getProcessName());
} else {
MagiskDenyList.remove(packageName, magiskDenyListRule.getProcessName());
}
break;
}
case NOTIFICATION:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
notificationManager.setNotificationListenerAccessGrantedForUser(new ComponentName(packageName, entry.name), userHandle, true);
}
break;
case URI_GRANT:
UriManager.UriGrant uriGrant = ((UriGrantRule) entry).getUriGrant();
UriManager.UriGrant newUriGrant = new UriManager.UriGrant(uriGrant.sourceUserId, userHandle, uriGrant.userHandle, uriGrant.sourcePkg, uriGrant.targetPkg, uriGrant.uri, uriGrant.prefix, uriGrant.modeFlags, uriGrant.createdTime);
UriManager uriManager = new UriManager();
uriManager.grantUri(newUriGrant);
uriManager.writeGrantedUriPermissions();
break;
case SSAID:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
new SsaidSettings(packageName, packageInfo.applicationInfo.uid).setSsaid(((SsaidRule) entry).getSsaid());
}
break;
}
} catch (Throwable e) {
// There are several reason restoring these things go wrong, especially when
// downgrading from an Android to another. It's better to simply suppress these
// exceptions instead of causing a failure or worse, a crash
Log.e(TAG, e);
}
}
}
use of io.github.muntashirakon.AppManager.ssaid.SsaidSettings in project AppManager by MuntashirAkon.
the class AppInfoFragment method setupTagCloud.
@UiThread
private void setupTagCloud(AppInfoViewModel.TagCloud tagCloud) {
mTagCloud.removeAllViews();
if (mainModel == null)
return;
// Add tracker chip
if (!tagCloud.trackerComponents.isEmpty()) {
CharSequence[] trackerComponentNames = new CharSequence[tagCloud.trackerComponents.size()];
for (int i = 0; i < trackerComponentNames.length; ++i) {
ComponentRule rule = tagCloud.trackerComponents.get(i);
trackerComponentNames[i] = rule.isBlocked() ? getColoredText(rule.name, ContextCompat.getColor(mActivity, R.color.stopped)) : rule.name;
}
addChip(getResources().getQuantityString(R.plurals.no_of_trackers, tagCloud.trackerComponents.size(), tagCloud.trackerComponents.size()), tagCloud.areAllTrackersBlocked ? R.color.stopped : R.color.tracker).setOnClickListener(v -> {
if (!isExternalApk && isRootEnabled) {
new SearchableMultiChoiceDialogBuilder<>(mActivity, tagCloud.trackerComponents, trackerComponentNames).setTitle(R.string.trackers).setSelections(tagCloud.trackerComponents).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.block, (dialog, which, selectedItems) -> {
showProgressIndicator(true);
executor.submit(() -> {
mainModel.addRules(selectedItems, true);
runOnUiThread(() -> {
if (isDetached())
return;
showProgressIndicator(false);
displayShortToast(R.string.done);
});
});
}).setNeutralButton(R.string.unblock, (dialog, which, selectedItems) -> {
showProgressIndicator(true);
executor.submit(() -> {
mainModel.removeRules(selectedItems, true);
runOnUiThread(() -> {
if (isDetached())
return;
showProgressIndicator(false);
displayShortToast(R.string.done);
});
});
}).show();
} else {
new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.trackers).setItems(trackerComponentNames, null).setNegativeButton(R.string.close, null).show();
}
});
}
if (tagCloud.isSystemApp) {
if (tagCloud.isSystemlessPath) {
addChip(R.string.systemless_app);
} else
addChip(R.string.system_app);
if (tagCloud.isUpdatedSystemApp) {
addChip(R.string.updated_app);
}
} else if (!mainModel.getIsExternalApk())
addChip(R.string.user_app);
if (tagCloud.splitCount > 0) {
addChip(getResources().getQuantityString(R.plurals.no_of_splits, tagCloud.splitCount, tagCloud.splitCount)).setOnClickListener(v -> {
try (ApkFile apkFile = ApkFile.getInstance(mainModel.getApkFileKey())) {
// Display a list of apks
List<ApkFile.Entry> apkEntries = apkFile.getEntries();
CharSequence[] entryNames = new CharSequence[tagCloud.splitCount];
for (int i = 0; i < tagCloud.splitCount; ++i) {
entryNames[i] = apkEntries.get(i + 1).toLocalizedString(mActivity);
}
new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.splits).setItems(entryNames, null).setNegativeButton(R.string.close, null).show();
}
});
}
if (tagCloud.isDebuggable) {
addChip(R.string.debuggable);
}
if (tagCloud.isTestOnly) {
addChip(R.string.test_only);
}
if (!tagCloud.hasCode) {
addChip(R.string.no_code);
}
if (tagCloud.hasRequestedLargeHeap) {
addChip(R.string.requested_large_heap, R.color.tracker);
}
if (tagCloud.runningServices.size() > 0) {
addChip(R.string.running, R.color.running).setOnClickListener(v -> {
mProgressIndicator.show();
executor.submit(() -> {
CharSequence[] runningServices = new CharSequence[tagCloud.runningServices.size()];
for (int i = 0; i < runningServices.length; ++i) {
runningServices[i] = new SpannableStringBuilder().append(getTitleText(mActivity, tagCloud.runningServices.get(i).service.getShortClassName())).append("\n").append(getSmallerText(new SpannableStringBuilder().append(getStyledKeyValue(mActivity, R.string.process_name, tagCloud.runningServices.get(i).process)).append("\n").append(getStyledKeyValue(mActivity, R.string.pid, String.valueOf(tagCloud.runningServices.get(i).pid)))));
}
DialogTitleBuilder titleBuilder = new DialogTitleBuilder(mActivity).setTitle(R.string.running_services);
if (PermissionUtils.hasDumpPermission() && FeatureController.isLogViewerEnabled()) {
titleBuilder.setSubtitle(R.string.running_services_logcat_hint);
}
runOnUiThread(() -> {
mProgressIndicator.hide();
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(mActivity).setCustomTitle(titleBuilder.build()).setItems(runningServices, (dialog, which) -> {
if (!FeatureController.isLogViewerEnabled())
return;
Intent logViewerIntent = new Intent(mActivity.getApplicationContext(), LogViewerActivity.class).setAction(LogViewerActivity.ACTION_LAUNCH).putExtra(LogViewerActivity.EXTRA_FILTER, SearchCriteria.PID_KEYWORD + tagCloud.runningServices.get(which).pid).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(logViewerIntent);
}).setNeutralButton(R.string.force_stop, (dialog, which) -> 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);
}
})).setNegativeButton(R.string.close, null);
builder.show();
});
});
});
}
if (tagCloud.isForceStopped) {
addChip(R.string.stopped, R.color.stopped);
}
if (!tagCloud.isAppEnabled) {
addChip(R.string.disabled_app, R.color.disabled_user);
}
if (tagCloud.isAppSuspended) {
addChip(R.string.suspended, R.color.stopped);
}
if (tagCloud.isAppHidden) {
addChip(R.string.hidden, R.color.disabled_user);
}
magiskHiddenProcesses = tagCloud.magiskHiddenProcesses;
if (tagCloud.isMagiskHideEnabled) {
addChip(R.string.magisk_hide_enabled).setOnClickListener(v -> displayMagiskHideDialog());
}
magiskDeniedProcesses = tagCloud.magiskDeniedProcesses;
if (tagCloud.isMagiskDenyListEnabled) {
addChip(R.string.magisk_denylist).setOnClickListener(v -> displayMagiskDenyListDialog());
}
if (tagCloud.hasKeyStoreItems) {
Chip chip;
if (tagCloud.hasMasterKeyInKeyStore) {
chip = addChip(R.string.keystore, R.color.tracker);
} else
chip = addChip(R.string.keystore);
chip.setOnClickListener(view -> new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.keystore).setItems(KeyStoreUtils.getKeyStoreFiles(mApplicationInfo.uid, mainModel.getUserHandle()).toArray(new String[0]), null).setNegativeButton(R.string.close, null).show());
}
if (tagCloud.backups.length > 0) {
CharSequence[] backupNames = new CharSequence[tagCloud.backups.length];
for (int i = 0; i < tagCloud.backups.length; ++i) {
backupNames[i] = tagCloud.backups[i].toLocalizedString(mActivity);
}
addChip(R.string.backup).setOnClickListener(v -> new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.backup).setItems(backupNames, null).setNegativeButton(R.string.close, null).show());
}
if (!tagCloud.isBatteryOptimized) {
addChip(R.string.no_battery_optimization, R.color.red_orange).setOnClickListener(v -> new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.battery_optimization).setMessage(R.string.enable_battery_optimization).setNegativeButton(R.string.no, null).setPositiveButton(R.string.yes, (dialog, which) -> {
Runner.runCommand(new String[] { "dumpsys", "deviceidle", "whitelist", "-" + mPackageName });
refreshDetails();
}).show());
}
if (tagCloud.netPolicies > 0) {
String[] readablePolicies = NetworkPolicyManagerCompat.getReadablePolicies(mActivity, tagCloud.netPolicies).values().toArray(new String[0]);
addChip(R.string.has_net_policy).setOnClickListener(v -> new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.net_policy).setItems(readablePolicies, null).setNegativeButton(R.string.ok, null).show());
}
if (tagCloud.ssaid != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
addChip(R.string.ssaid, R.color.red_orange).setOnClickListener(v -> {
View view = getLayoutInflater().inflate(R.layout.dialog_ssaid_info, null);
AlertDialog alertDialog = new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.ssaid).setView(view).setPositiveButton(R.string.apply, null).setNegativeButton(R.string.close, null).setNeutralButton(R.string.reset_to_default, null).create();
TextInputEditText ssaidHolder = view.findViewById(R.id.ssaid);
TextInputLayout ssaidInputLayout = view.findViewById(android.R.id.text1);
AtomicReference<Button> applyButton = new AtomicReference<>();
AtomicReference<Button> resetButton = new AtomicReference<>();
AtomicReference<String> ssaid = new AtomicReference<>(tagCloud.ssaid);
alertDialog.setOnShowListener(dialog -> {
applyButton.set(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE));
resetButton.set(alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
applyButton.get().setVisibility(View.GONE);
applyButton.get().setOnClickListener(v2 -> executor.submit(() -> {
try {
SsaidSettings ssaidSettings = new SsaidSettings(mPackageName, mApplicationInfo.uid);
if (ssaidSettings.setSsaid(ssaid.get())) {
model.loadTagCloud();
runOnUiThread(() -> displayLongToast(R.string.restart_to_reflect_changes));
} else {
runOnUiThread(() -> displayLongToast(R.string.failed_to_change_ssaid));
}
alertDialog.dismiss();
} catch (IOException ignore) {
}
}));
resetButton.get().setVisibility(View.GONE);
resetButton.get().setOnClickListener(v2 -> {
ssaid.set(tagCloud.ssaid);
ssaidHolder.setText(ssaid.get());
resetButton.get().setVisibility(View.GONE);
applyButton.get().setVisibility(View.GONE);
});
});
ssaidHolder.setText(tagCloud.ssaid);
ssaidHolder.setTypeface(Typeface.MONOSPACE);
ssaidHolder.setOnClickListener(v2 -> {
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("SSAID", ssaid.get());
clipboard.setPrimaryClip(clip);
displayShortToast(R.string.copied_to_clipboard);
});
ssaidInputLayout.setEndIconOnClickListener(v2 -> {
ssaid.set(SsaidSettings.generateSsaid(mPackageName));
ssaidHolder.setText(ssaid.get());
if (!tagCloud.ssaid.equals(ssaid.get())) {
if (resetButton.get() != null) {
resetButton.get().setVisibility(View.VISIBLE);
}
if (applyButton.get() != null) {
applyButton.get().setVisibility(View.VISIBLE);
}
}
});
alertDialog.show();
});
}
if (tagCloud.uriGrants != null) {
addChip(R.string.saf).setOnClickListener(v -> {
CharSequence[] uriGrants = new CharSequence[tagCloud.uriGrants.size()];
for (int i = 0; i < tagCloud.uriGrants.size(); ++i) {
uriGrants[i] = tagCloud.uriGrants.get(i).uri.toString();
}
new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.saf).setItems(uriGrants, null).setNegativeButton(R.string.close, null).show();
});
}
if (tagCloud.usesPlayAppSigning) {
addChip(R.string.uses_play_app_signing, R.color.disabled_user).setOnClickListener(v -> new MaterialAlertDialogBuilder(mActivity).setTitle(R.string.uses_play_app_signing).setMessage(R.string.uses_play_app_signing_description).setNegativeButton(R.string.close, null).show());
}
}
use of io.github.muntashirakon.AppManager.ssaid.SsaidSettings in project AppManager by MuntashirAkon.
the class AppInfoViewModel method loadTagCloud.
@WorkerThread
public void loadTagCloud() {
if (mainModel == null)
return;
PackageInfo packageInfo = mainModel.getPackageInfo();
if (packageInfo == null)
return;
String packageName = packageInfo.packageName;
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
TagCloud tagCloud = new TagCloud();
try {
HashMap<String, RuleType> trackerComponents = ComponentUtils.getTrackerComponentsForPackageInfo(packageInfo);
tagCloud.trackerComponents = new ArrayList<>(trackerComponents.size());
for (String component : trackerComponents.keySet()) {
ComponentRule componentRule = mainModel.getComponentRule(component);
if (componentRule == null) {
componentRule = new ComponentRule(packageName, component, trackerComponents.get(component), AppPref.getDefaultComponentStatus());
}
tagCloud.trackerComponents.add(componentRule);
tagCloud.areAllTrackersBlocked &= componentRule.isBlocked();
}
tagCloud.isSystemApp = (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
tagCloud.isSystemlessPath = !mainModel.getIsExternalApk() && Ops.isRoot() && MagiskUtils.isSystemlessPath(PackageUtils.getHiddenCodePathOrDefault(packageName, applicationInfo.publicSourceDir));
tagCloud.isUpdatedSystemApp = (applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
tagCloud.splitCount = mainModel.getSplitCount();
tagCloud.isDebuggable = (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
tagCloud.isTestOnly = (applicationInfo.flags & ApplicationInfo.FLAG_TEST_ONLY) != 0;
tagCloud.hasCode = (applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0;
tagCloud.hasRequestedLargeHeap = (applicationInfo.flags & ApplicationInfo.FLAG_LARGE_HEAP) != 0;
tagCloud.runningServices = ActivityManagerCompat.getRunningServices(packageName, mainModel.getUserHandle());
tagCloud.isForceStopped = (applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0;
tagCloud.isAppEnabled = applicationInfo.enabled;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
tagCloud.isAppSuspended = (applicationInfo.flags & ApplicationInfo.FLAG_SUSPENDED) != 0;
}
int privateFlags = ApplicationInfoCompat.getPrivateFlags(applicationInfo);
tagCloud.isAppHidden = (privateFlags & ApplicationInfoCompat.PRIVATE_FLAG_HIDDEN) != 0;
tagCloud.magiskHiddenProcesses = new ArrayList<>(MagiskHide.getProcesses(packageInfo));
boolean magiskHideEnabled = false;
for (MagiskProcess magiskProcess : tagCloud.magiskHiddenProcesses) {
magiskHideEnabled |= magiskProcess.isEnabled();
for (ActivityManager.RunningServiceInfo info : tagCloud.runningServices) {
if (info.process.startsWith(magiskProcess.name)) {
magiskProcess.setRunning(true);
}
}
}
tagCloud.isMagiskHideEnabled = !mainModel.getIsExternalApk() && magiskHideEnabled;
tagCloud.magiskDeniedProcesses = new ArrayList<>(MagiskDenyList.getProcesses(packageInfo));
boolean magiskDenyListEnabled = false;
for (MagiskProcess magiskProcess : tagCloud.magiskDeniedProcesses) {
magiskDenyListEnabled |= magiskProcess.isEnabled();
for (ActivityManager.RunningServiceInfo info : tagCloud.runningServices) {
if (info.process.startsWith(magiskProcess.name)) {
magiskProcess.setRunning(true);
}
}
}
tagCloud.isMagiskDenyListEnabled = !mainModel.getIsExternalApk() && magiskDenyListEnabled;
tagCloud.hasKeyStoreItems = KeyStoreUtils.hasKeyStore(applicationInfo.uid);
tagCloud.hasMasterKeyInKeyStore = KeyStoreUtils.hasMasterKey(applicationInfo.uid);
tagCloud.usesPlayAppSigning = PackageUtils.usesPlayAppSigning(applicationInfo);
try {
tagCloud.backups = MetadataManager.getMetadata(packageName);
} catch (IOException e) {
tagCloud.backups = ArrayUtils.emptyArray(MetadataManager.Metadata.class);
}
if (!mainModel.getIsExternalApk() && PermissionUtils.hasDumpPermission()) {
String targetString = "user," + packageName + "," + applicationInfo.uid;
Runner.Result result = Runner.runCommand(new String[] { "dumpsys", "deviceidle", "whitelist" });
tagCloud.isBatteryOptimized = !result.isSuccessful() || !result.getOutput().contains(targetString);
} else {
tagCloud.isBatteryOptimized = true;
}
if (!mainModel.getIsExternalApk() && LocalServer.isAMServiceAlive()) {
tagCloud.netPolicies = NetworkPolicyManagerCompat.getUidPolicy(applicationInfo.uid);
} else {
tagCloud.netPolicies = 0;
}
if (Ops.isRoot() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
tagCloud.ssaid = new SsaidSettings(packageName, applicationInfo.uid).getSsaid();
if (TextUtils.isEmpty(tagCloud.ssaid))
tagCloud.ssaid = null;
} catch (IOException ignore) {
}
}
if (Ops.isRoot()) {
List<UriManager.UriGrant> uriGrants = new UriManager().getGrantedUris(packageName);
if (uriGrants != null) {
Iterator<UriManager.UriGrant> uriGrantIterator = uriGrants.listIterator();
UriManager.UriGrant uriGrant;
while (uriGrantIterator.hasNext()) {
uriGrant = uriGrantIterator.next();
if (uriGrant.targetUserId != mainModel.getUserHandle()) {
uriGrantIterator.remove();
}
}
tagCloud.uriGrants = uriGrants;
}
}
} catch (Throwable th) {
// Unknown behaviour
throw new RuntimeException(th);
} finally {
this.tagCloud.postValue(tagCloud);
}
}
Aggregations