Skip to content

Commit

Permalink
fix: latest reco from android studio
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Mar 19, 2024
1 parent f21b851 commit dd07eee
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package ee.forgr.capacitor_updater;

import com.getcapacitor.JSObject;
Expand Down
16 changes: 4 additions & 12 deletions android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public static byte[] decryptRSA(byte[] source, PrivateKey privateKey)
PSource.PSpecified.DEFAULT
);
cipher.init(Cipher.DECRYPT_MODE, privateKey, oaepParams);
byte[] decryptedBytes = cipher.doFinal(source);
return decryptedBytes;
return cipher.doFinal(source);
}

public static byte[] decryptAES(byte[] cipherText, SecretKey key, byte[] iv) {
Expand All @@ -53,8 +52,7 @@ public static byte[] decryptAES(byte[] cipherText, SecretKey key, byte[] iv) {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES");
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec);
byte[] decryptedText = cipher.doFinal(cipherText);
return decryptedText;
return cipher.doFinal(cipherText);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -63,13 +61,7 @@ public static byte[] decryptAES(byte[] cipherText, SecretKey key, byte[] iv) {

public static SecretKey byteToSessionKey(byte[] sessionKey) {
// rebuild key using SecretKeySpec
SecretKey originalKey = new SecretKeySpec(
sessionKey,
0,
sessionKey.length,
"AES"
);
return originalKey;
return new SecretKeySpec(sessionKey, 0, sessionKey.length, "AES");
}

private static PrivateKey readPkcs8PrivateKey(byte[] pkcs8Bytes)
Expand Down Expand Up @@ -137,7 +129,7 @@ public static PrivateKey stringToPrivateKey(String private_key)
throws GeneralSecurityException {
// Base64 decode the result

String pkcs1Pem = private_key.toString();
String pkcs1Pem = private_key;
pkcs1Pem = pkcs1Pem.replace("-----BEGIN RSA PRIVATE KEY-----", "");
pkcs1Pem = pkcs1Pem.replace("-----END RSA PRIVATE KEY-----", "");
pkcs1Pem = pkcs1Pem.replace("\\n", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package ee.forgr.capacitor_updater;

import androidx.annotation.NonNull;
import com.google.gson.annotations.SerializedName;
import java.util.Objects;

Expand Down Expand Up @@ -41,8 +42,7 @@ public void setValue(String value) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DelayCondition)) return false;
DelayCondition that = (DelayCondition) o;
if (!(o instanceof DelayCondition that)) return false;
return (
getKind() == that.getKind() && Objects.equals(getValue(), that.getValue())
);
Expand All @@ -53,6 +53,7 @@ public int hashCode() {
return Objects.hash(getKind(), getValue());
}

@NonNull
@Override
public String toString() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Objects;

public class DownloadService extends IntentService {

Expand Down Expand Up @@ -44,6 +45,7 @@ private int calcTotalPercent(
// Will be called asynchronously by OS.
@Override
protected void onHandleIntent(Intent intent) {
assert intent != null;
String url = intent.getStringExtra(URL);
String id = intent.getStringExtra(ID);
String documentsDir = intent.getStringExtra(DOCDIR);
Expand All @@ -60,8 +62,9 @@ protected void onHandleIntent(Intent intent) {
final InputStream is = u.openStream();
final DataInputStream dis = new DataInputStream(is)
) {
assert dest != null;
final File target = new File(documentsDir, dest);
target.getParentFile().mkdirs();
Objects.requireNonNull(target.getParentFile()).mkdirs();
target.createNewFile();
try (final FileOutputStream fos = new FileOutputStream(target)) {
final long totalLength = connection.getContentLength();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class InternalUtils {

public static String getPackageName(PackageManager pm, String packageName) {
try {
PackageInfo pinfo = getPackageInfoInternal(pm, packageName, 0);
return (pinfo != null) ? pinfo.packageName : null;
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;
Expand Down

0 comments on commit dd07eee

Please sign in to comment.