Skip to content

Commit

Permalink
chore(android): remove aps-analytics.jar
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Nov 24, 2024
1 parent c5f2132 commit 0b83418
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/
package ti.modules.titanium.analytics;

import com.appcelerator.aps.APSAnalytics;

import org.appcelerator.titanium.util.APSAnalytics;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;

import com.appcelerator.aps.APSAnalytics;
import org.appcelerator.titanium.util.APSAnalytics;

@Kroll.module
public class AppModule extends KrollModule implements SensorEventListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.location.Location;
import android.location.LocationManager;

import com.appcelerator.aps.APSAnalytics;
import org.appcelerator.titanium.util.APSAnalytics;

public class TiLocation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import android.os.ParcelFileDescriptor;
import android.os.SystemClock;

import com.appcelerator.aps.APSAnalytics;
import com.appcelerator.aps.APSAnalyticsMeta;
import org.appcelerator.titanium.util.APSAnalytics;
import org.appcelerator.titanium.util.APSAnalyticsMeta;

import java.io.BufferedReader;
import java.io.File;
Expand Down
Binary file removed android/titanium/lib/aps-analytics.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

import androidx.annotation.NonNull;

import com.appcelerator.aps.APSAnalytics;
import com.appcelerator.aps.APSAnalyticsMeta;

import org.appcelerator.kroll.KrollApplication;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.KrollProxy;
Expand All @@ -36,6 +33,8 @@
import org.appcelerator.kroll.common.TiDeployData;
import org.appcelerator.kroll.common.TiMessenger;
import org.appcelerator.kroll.util.KrollAssetHelper;
import org.appcelerator.titanium.util.APSAnalytics;
import org.appcelerator.titanium.util.APSAnalyticsMeta;
import org.appcelerator.titanium.util.TiBlobLruCache;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiImageCache;
Expand Down Expand Up @@ -452,10 +451,6 @@ public void postAppInfo()
}

String buildType = this.appInfo.getBuildType();
if (buildType != null && !buildType.equals("")) {
APSAnalyticsMeta.setBuildType(buildType);
}

APSAnalyticsMeta.setAppId(this.appInfo.getId());
APSAnalyticsMeta.setAppName(this.appInfo.getName());
APSAnalyticsMeta.setAppVersion(this.appInfo.getVersion());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package org.appcelerator.titanium.util;

import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.provider.Settings.Secure;
import android.util.Log;

import androidx.annotation.NonNull;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

public final class APSAnalytics
{
private static final APSAnalytics INSTANCE = new APSAnalytics();
private static final Set<String> BAD_IDENTIFIERS =
new HashSet(Arrays.asList("9774d56d682e549c", "1234567890ABCDEF"));
private final AtomicReference<String> sessionId = new AtomicReference();
private SharedPreferences preferences;
private String app;
private String machineId;

private APSAnalytics()
{
}

public static APSAnalytics getInstance()
{
return INSTANCE;
}

public void initialize(@NonNull String app, @NonNull Context ctx)
{
Log.d("APSAnalytics", "Initialization started...");
synchronized (this)
{
try {
String packageName = ctx.getPackageName();
PackageManager packageManager = ctx.getPackageManager();
ApplicationInfo ai = packageManager.getApplicationInfo(packageName, 128);
PackageInfo pi = packageManager.getPackageInfo(packageName, 0);
if (ai != null && ai.metaData != null) {
String urlString = ai.metaData.getString("APSAnalyticsBaseURL");
if (urlString != null) {
APSAnalyticsMeta.setAnalyticsUrl(new URL(urlString));
}
}

if (pi != null && APSAnalyticsMeta.getAppVersion() == null) {
APSAnalyticsMeta.setAppVersion(pi.versionName);
}
} catch (PackageManager.NameNotFoundException | MalformedURLException var10) {
Exception e = var10;
Log.w("APSAnalytics", "Could not validate analytics URL:", e);
return;
}

this.app = app;
this.preferences = ctx.getSharedPreferences("titanium", 0);
if (this.machineId == null) {
this.setMachineId(ctx);
}

}
}

public boolean isInitialized()
{
return false;
}

public String getCurrentSessionId()
{
return this.sessionId.get();
}

public String getMachineId()
{
return this.machineId;
}

public void setMachineId(@NonNull Context ctx)
{
ContentResolver resolver = ctx.getContentResolver();
this.machineId = Secure.getString(resolver, "android_id");
if (this.machineId == null || BAD_IDENTIFIERS.contains(this.machineId)) {
this.machineId = UUID.randomUUID().toString();
}
}

public boolean isOptedOut()
{
return this.preferences.getBoolean("_APS_isOptedOut", false);
}

public void setOptedOut(boolean value)
{
this.preferences.edit().putBoolean("_APS_isOptedOut", value).apply();
}

public int getCacheSize()
{
return this.preferences.getInt("_APS_cacheSize", 28000);
}

public void setCacheSize(int value)
{
this.preferences.edit().putInt("_APS_cacheSize", value).apply();
}
}
Loading

0 comments on commit 0b83418

Please sign in to comment.