Skip to content

Commit

Permalink
[Refactor] Assign name in the AppDetails*Item constructors
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Aug 19, 2024
1 parent 89a761a commit 44b9b85
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,9 @@ public class AppDetailsViewModel extends AndroidViewModel {

public AppDetailsViewModel(@NonNull Application application) {
super(application);
try {
mPackageManager = application.getPackageManager();
mReceiver = new PackageIntentReceiver(this);
mWaitForBlocker = true;
} catch (Throwable th) {
Log.e(TAG, th);
throw new RuntimeException("Could not instantiate AppDetailsViewModel", th);
}
mPackageManager = application.getPackageManager();
mReceiver = new PackageIntentReceiver(this);
mWaitForBlocker = true;
}

@GuardedBy("blockerLocker")
Expand Down Expand Up @@ -1170,7 +1165,6 @@ private void loadActivities() {
SelfPermissions.checkSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS);
for (ActivityInfo activityInfo : packageInfo.activities) {
AppDetailsActivityItem componentItem = new AppDetailsActivityItem(activityInfo);
componentItem.name = activityInfo.name;
componentItem.label = getComponentLabel(activityInfo, appLabel);
synchronized (mBlockerLocker) {
if (!mExternalApk) {
Expand Down Expand Up @@ -1214,7 +1208,6 @@ private void loadServices() {
CharSequence appLabel = packageInfo.applicationInfo.loadLabel(mPackageManager);
for (ServiceInfo serviceInfo : packageInfo.services) {
AppDetailsServiceItem serviceItem = new AppDetailsServiceItem(serviceInfo);
serviceItem.name = serviceInfo.name;
serviceItem.label = getComponentLabel(serviceInfo, appLabel);
synchronized (mBlockerLocker) {
if (!mExternalApk) {
Expand Down Expand Up @@ -1259,7 +1252,6 @@ private void loadReceivers() {
CharSequence appLabel = packageInfo.applicationInfo.loadLabel(mPackageManager);
for (ActivityInfo activityInfo : packageInfo.receivers) {
AppDetailsComponentItem componentItem = new AppDetailsComponentItem(activityInfo);
componentItem.name = activityInfo.name;
componentItem.label = getComponentLabel(activityInfo, appLabel);
synchronized (mBlockerLocker) {
if (!mExternalApk) {
Expand Down Expand Up @@ -1293,7 +1285,6 @@ private void loadProviders() {
CharSequence appLabel = packageInfo.applicationInfo.loadLabel(mPackageManager);
for (ProviderInfo providerInfo : packageInfo.providers) {
AppDetailsComponentItem componentItem = new AppDetailsComponentItem(providerInfo);
componentItem.name = providerInfo.name;
componentItem.label = getComponentLabel(providerInfo, appLabel);
synchronized (mBlockerLocker) {
if (!mExternalApk) {
Expand Down Expand Up @@ -1458,7 +1449,6 @@ private void loadAppOps() {
} else {
appDetailsItem = new AppDetailsAppOpItem(entry);
}
appDetailsItem.name = entry.getName();
mAppOpItems.add(appDetailsItem);
}
// Add other ops
Expand All @@ -1481,7 +1471,6 @@ private void loadAppOps() {
} else {
appDetailsItem = new AppDetailsAppOpItem(op);
}
appDetailsItem.name = AppOpsManagerCompat.opToName(op);
mAppOpItems.add(appDetailsItem);
}
} catch (Throwable e) {
Expand Down Expand Up @@ -1610,7 +1599,6 @@ private void loadPermissions() {
if (packageInfo.permissions != null) {
for (PermissionInfo permissionInfo : packageInfo.permissions) {
AppDetailsDefinedPermissionItem appDetailsItem = new AppDetailsDefinedPermissionItem(permissionInfo, false);
appDetailsItem.name = permissionInfo.name;
mPermissionItems.add(appDetailsItem);
visitedPerms.add(permissionInfo.name);
}
Expand All @@ -1627,7 +1615,6 @@ private void loadPermissions() {
permissionInfo.name = activityInfo.permission;
}
AppDetailsDefinedPermissionItem appDetailsItem = new AppDetailsDefinedPermissionItem(permissionInfo, true);
appDetailsItem.name = permissionInfo.name;
mPermissionItems.add(appDetailsItem);
visitedPerms.add(permissionInfo.name);
} catch (RemoteException e) {
Expand All @@ -1648,7 +1635,6 @@ private void loadPermissions() {
permissionInfo.name = serviceInfo.permission;
}
AppDetailsDefinedPermissionItem appDetailsItem = new AppDetailsDefinedPermissionItem(permissionInfo, true);
appDetailsItem.name = permissionInfo.name;
mPermissionItems.add(appDetailsItem);
visitedPerms.add(permissionInfo.name);
} catch (RemoteException e) {
Expand All @@ -1669,7 +1655,6 @@ private void loadPermissions() {
permissionInfo.name = providerInfo.readPermission;
}
AppDetailsDefinedPermissionItem appDetailsItem = new AppDetailsDefinedPermissionItem(permissionInfo, true);
appDetailsItem.name = permissionInfo.name;
mPermissionItems.add(appDetailsItem);
visitedPerms.add(permissionInfo.name);
} catch (RemoteException e) {
Expand All @@ -1686,7 +1671,6 @@ private void loadPermissions() {
permissionInfo.name = providerInfo.writePermission;
}
AppDetailsDefinedPermissionItem appDetailsItem = new AppDetailsDefinedPermissionItem(permissionInfo, true);
appDetailsItem.name = permissionInfo.name;
mPermissionItems.add(appDetailsItem);
visitedPerms.add(permissionInfo.name);
} catch (RemoteException e) {
Expand All @@ -1707,7 +1691,6 @@ private void loadPermissions() {
permissionInfo.name = activityInfo.permission;
}
AppDetailsDefinedPermissionItem appDetailsItem = new AppDetailsDefinedPermissionItem(permissionInfo, true);
appDetailsItem.name = permissionInfo.name;
mPermissionItems.add(appDetailsItem);
visitedPerms.add(permissionInfo.name);
} catch (RemoteException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import androidx.core.content.pm.PermissionInfoCompat;

import java.util.List;
import java.util.Objects;

import io.github.muntashirakon.AppManager.compat.AppOpsManagerCompat;
import io.github.muntashirakon.AppManager.compat.ManifestCompat;
Expand Down Expand Up @@ -41,11 +42,13 @@ public class AppDetailsAppOpItem extends AppDetailsItem<Integer> {

public AppDetailsAppOpItem(@NonNull AppOpsManagerCompat.OpEntry opEntry) {
this(opEntry.getOp());
name = opEntry.getName();
mOpEntry = opEntry;
}

public AppDetailsAppOpItem(int op) {
super(op);
name = AppOpsManagerCompat.opToName(op);
mOpEntry = null;
permissionInfo = null;
permission = null;
Expand All @@ -57,6 +60,7 @@ public AppDetailsAppOpItem(int op) {
public AppDetailsAppOpItem(@NonNull AppOpsManagerCompat.OpEntry opEntry, @NonNull PermissionInfo permissionInfo,
boolean isGranted, int permissionFlags, boolean appContainsPermission) {
super(opEntry.getOp());
name = opEntry.getName();
mOpEntry = opEntry;
this.permissionInfo = permissionInfo;
this.appContainsPermission = appContainsPermission;
Expand All @@ -75,6 +79,7 @@ public AppDetailsAppOpItem(@NonNull AppOpsManagerCompat.OpEntry opEntry, @NonNul
public AppDetailsAppOpItem(int op, @NonNull PermissionInfo permissionInfo,
boolean isGranted, int permissionFlags, boolean appContainsPermission) {
super(op);
name = AppOpsManagerCompat.opToName(op);
mOpEntry = null;
this.permissionInfo = permissionInfo;
this.appContainsPermission = appContainsPermission;
Expand Down Expand Up @@ -220,4 +225,18 @@ public void invalidate(@NonNull AppOpsManagerCompat appOpsManager, @NonNull Pack
throw new PermissionException(e);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AppDetailsAppOpItem)) return false;
if (!super.equals(o)) return false;
AppDetailsAppOpItem that = (AppDetailsAppOpItem) o;
return Objects.equals(mainItem, that.mainItem);
}

@Override
public int hashCode() {
return Objects.hash(mainItem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class AppDetailsComponentItem extends AppDetailsItem<ComponentInfo> {

public AppDetailsComponentItem(@NonNull ComponentInfo componentInfo) {
super(componentInfo);
name = componentInfo.name;
mIsDisabled = !componentInfo.isEnabled();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class AppDetailsDefinedPermissionItem extends AppDetailsItem<PermissionIn

public AppDetailsDefinedPermissionItem(@NonNull PermissionInfo permissionInfo, boolean isExternal) {
super(permissionInfo);
name = permissionInfo.name;
this.isExternal = isExternal;
}
}

0 comments on commit 44b9b85

Please sign in to comment.