Skip to content

Commit

Permalink
Merge pull request #144 from adobe/staging-v2.x
Browse files Browse the repository at this point in the history
Merge `staging v2.x` into `main-v2.x` for Assurance 2.2.2
  • Loading branch information
prudrabhat authored Oct 29, 2024
2 parents d3b79f1 + 3d59e63 commit 9bb78bd
Show file tree
Hide file tree
Showing 11 changed files with 733 additions and 259 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

orbs:
android: circleci/[email protected]
android: circleci/android@2.4.0

workflows:
version: 2
Expand All @@ -15,7 +15,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: 2022.01.1
tag: 2024.01.1

steps:
- checkout
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: 2022.01.1
tag: 2024.01.1

steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish package to the Maven Central Repository
on:
push:
branches:
- main
- main-v2.x
jobs:
publish:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish package to the Maven Central Staging Repository
on:
push:
branches:
- staging
- staging-v2.x
jobs:
publish:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion code/assurance/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ dependencies {
testImplementation 'com.google.code.gson:gson:2.8.5'
testImplementation 'org.mockito:mockito-core:4.5.1'
testImplementation 'org.mockito.kotlin:mockito-kotlin:3.2.0'
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation 'org.mockito:mockito-inline:4.5.1'
testImplementation 'net.sf.kxml:kxml2:2.3.0@jar'
testImplementation 'org.json:json:20171018'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation 'org.robolectric:robolectric:4.12.2'

androidTestImplementation "androidx.test:core:1.4.0"
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Assurance {

public static final Class<? extends Extension> EXTENSION = AssuranceExtension.class;
public static final String LOG_TAG = "Assurance";
public static final String EXTENSION_VERSION = "2.2.1";
public static final String EXTENSION_VERSION = "2.2.2";
public static final String EXTENSION_NAME = "com.adobe.assurance";
public static final String EXTENSION_FRIENDLY_NAME = "Assurance";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public void run() {
if (value.isEmpty()) {
uploadFailure(
callback,
"Uploading Blob failed, Invalid BlobId"
+ " returned from the fileStorage server");
"Uploading Blob failed, Invalid BlobId returned"
+ " from the fileStorage server");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.location.LocationManager;
Expand All @@ -25,27 +27,39 @@
import android.os.PowerManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.ActivityCompat;
import com.adobe.marketing.mobile.Assurance;
import com.adobe.marketing.mobile.services.ServiceProvider;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

final class AssuranceClientInfo {

private static final String VALUE_UNKNOWN = "Unknown";
private static final String MANIFEST_FILE_NAME = "AndroidManifest.xml";
private static final String EVENT_TYPE_CONNECT = "connect";
private static final String KEY_MANIFEST = "manifest";
private static final String KEY_PACKAGE = "package";
private static final String FALLBACK_KEY_VERSION_NAME = "versionName";
private static final String FALLBACK_KEY_VERSION_CODE = "versionCode";
private static final String FALLBACK_KEY_APPLICATION = "application";
private static final String FALLBACK_KEY_APPLICATION_NAME = "name";

private final JSONObject manifestData;

AssuranceClientInfo() {
// parse the manifest file and store it in a JSONObject for later use as this does not
// change
// during the lifetime of the application
manifestData = AssuranceIOUtils.parseXMLResourceFileToJson(MANIFEST_FILE_NAME);
final JSONObject parsedManifest =
AssuranceIOUtils.parseXMLResourceFileToJson(MANIFEST_FILE_NAME);
final boolean isValid = validateManifestData(parsedManifest);
manifestData = isValid ? parsedManifest : getFallbackManifestData();
}

/**
Expand Down Expand Up @@ -363,4 +377,79 @@ private boolean isPowerSaveModeEnabled() {

return powerManager.isPowerSaveMode();
}

/**
* Checks that the manifest data provided is associated with the current application.
*
* @param manifestData the manifest data JSONObject to validate
* @return true if the manifest data is valid, false otherwise
*/
@VisibleForTesting
boolean validateManifestData(final JSONObject manifestData) {
if (manifestData == null) {
return false;
}
final JSONObject manifest = manifestData.optJSONObject(KEY_MANIFEST);
if (manifest == null) {
return false;
}

final String parsedPackageName = manifest.optString(KEY_PACKAGE, "");
final Application app =
ServiceProvider.getInstance().getAppContextService().getApplication();
return (app != null && parsedPackageName.equals(app.getPackageName()));
}

/**
* Returns a curated JSONObject with fallback manifest data. This is typically is to be used
* when the manifest data parsed is invalid (i.e not associated with the application)
*
* <p>The fallback manifest data has the following structure: { "manifest": { "package":
* "com.mygroup.myapp", "versionName": "1.0", "versionCode": "1", "application": { "name":
* "MyAppName" } } }
*
* @return a JSONObject with fallback manifest data
*/
@VisibleForTesting
JSONObject getFallbackManifestData() {
final Application app =
ServiceProvider.getInstance().getAppContextService().getApplication();
final JSONObject result = new JSONObject();
final JSONObject manifestJson = new JSONObject();
if (app == null) {
return manifestJson;
}

try {
final String appPackageName = app.getPackageName();
manifestJson.put(KEY_PACKAGE, appPackageName);

final PackageManager pm = app.getApplicationContext().getPackageManager();
try {
final PackageInfo packageInfo =
pm.getPackageInfo(appPackageName, PackageManager.GET_PERMISSIONS);
final String versionName = packageInfo.versionName;
final String versionCode = String.valueOf(packageInfo.versionCode);
manifestJson.put(FALLBACK_KEY_VERSION_NAME, versionName);
manifestJson.put(FALLBACK_KEY_VERSION_CODE, versionCode);

} catch (PackageManager.NameNotFoundException e) {
Log.d(Assurance.LOG_TAG, "Failed to get package info for " + appPackageName);
}

final ApplicationInfo appInfo = app.getApplicationInfo();
if (appInfo != null) {
final String applicationName = appInfo.name;
final JSONObject applicationJson = new JSONObject();
applicationJson.put(FALLBACK_KEY_APPLICATION_NAME, applicationName);
manifestJson.put(FALLBACK_KEY_APPLICATION, applicationJson);
}

result.put(KEY_MANIFEST, manifestJson);
} catch (JSONException e) {
Log.d(Assurance.LOG_TAG, "Failed to put version details into fallbackManifestData");
}

return result;
}
}
Loading

0 comments on commit 9bb78bd

Please sign in to comment.