Skip to content

Commit

Permalink
fix: lint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Nov 20, 2023
1 parent fc72289 commit 64aba30
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,22 @@ public void notifyListeners(final String id, final JSObject res) {
return;
}
final CapConfig config = CapConfig.loadDefault(this.getActivity());
this.implementation.appId = InternalUtils.getPackageName(getContext().getPackageManager(), getContext().getPackageName());
this.implementation.appId = config.getString("appId", this.implementation.appId);
this.implementation.appId =
InternalUtils.getPackageName(
getContext().getPackageManager(),
getContext().getPackageName()
);
this.implementation.appId =
config.getString("appId", this.implementation.appId);
this.implementation.appId =
this.getConfig().getString("appId", this.implementation.appId);
if (this.implementation.appId == null || "".equals(this.implementation.appId)) {
if (
this.implementation.appId == null || "".equals(this.implementation.appId)
) {
// crash the app
throw new RuntimeException("appId is missing in capacitor.config.json or plugin config, and cannot be retrieved from the native app, please add it globally or in the plugin config");
throw new RuntimeException(
"appId is missing in capacitor.config.json or plugin config, and cannot be retrieved from the native app, please add it globally or in the plugin config"
);
}
Log.i(CapacitorUpdater.TAG, "appId: " + implementation.appId);
this.implementation.privateKey =
Expand Down
50 changes: 29 additions & 21 deletions android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,37 @@

public class InternalUtils {

public static String getPackageName(PackageManager pm, String packageName) {
try {
PackageInfo pinfo = getPackageInfoInternal(pm, packageName, 0);
return (pinfo != null) ? pinfo.packageName : null;
} catch (PackageManager.NameNotFoundException e) {
// Exception is handled internally, and null is returned to indicate the package name could not be retrieved
return null;
}
public static String getPackageName(PackageManager pm, String packageName) {
try {
PackageInfo pinfo = getPackageInfoInternal(pm, packageName, 0);
return (pinfo != null) ? pinfo.packageName : null;
} catch (PackageManager.NameNotFoundException e) {
// Exception is handled internally, and null is returned to indicate the package name could not be retrieved
return null;
}
}

private static PackageInfo getPackageInfoInternal(PackageManager pm, String packageName, long flags)
throws PackageManager.NameNotFoundException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
return pm.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags));
} else {
return getPackageInfoLegacy(pm, packageName, (int) flags);
}
private static PackageInfo getPackageInfoInternal(
PackageManager pm,
String packageName,
long flags
) throws PackageManager.NameNotFoundException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
return pm.getPackageInfo(
packageName,
PackageManager.PackageInfoFlags.of(flags)
);
} else {
return getPackageInfoLegacy(pm, packageName, (int) flags);
}
}

@SuppressWarnings("deprecation")
private static PackageInfo getPackageInfoLegacy(PackageManager pm, String packageName, int flags)
throws PackageManager.NameNotFoundException {
return pm.getPackageInfo(packageName, flags);
}
@SuppressWarnings("deprecation")
private static PackageInfo getPackageInfoLegacy(
PackageManager pm,
String packageName,
int flags
) throws PackageManager.NameNotFoundException {
return pm.getPackageInfo(packageName, flags);
}
}

0 comments on commit 64aba30

Please sign in to comment.