Skip to content

Commit

Permalink
Update APSAnalytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Apr 19, 2018
1 parent dddaa72 commit 1f078d2
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.util.Log;

import com.appcelerator.aps.APSAnalytics;
import com.appcelerator.aps.APSAnalyticsEvent;

@Kroll.module
public class AnalyticsModule extends KrollModule
Expand Down Expand Up @@ -61,16 +60,16 @@ public void navEvent(String from, String to, @Kroll.argument(optional = true) St
event = "";
}
if (data instanceof HashMap) {
analytics.sendAppNavEvent(from, to, event, TiConvert.toJSON(data));
analytics.sendAppNavEvent(from, to, TiConvert.toJSON(data));

} else if (data != null) {
try {
analytics.sendAppNavEvent(from, to, event, new JSONObject(data.toString()));
analytics.sendAppNavEvent(from, to, new JSONObject(data.toString()));
} catch (JSONException e) {
Log.e(TAG, "Cannot convert data into JSON");
}
} else {
analytics.sendAppNavEvent(from, to, event, null);
analytics.sendAppNavEvent(from, to, null);
}
} else {
Log.e(
Expand Down Expand Up @@ -190,29 +189,7 @@ public String getLastEvent()
// clang-format on
{
if (TiApplication.getInstance().isAnalyticsEnabled()) {
TiPlatformHelper platformHelper = TiPlatformHelper.getInstance();
APSAnalyticsEvent event = platformHelper.getLastEvent();
if (event != null) {
try {
JSONObject json = new JSONObject();
json.put("ver", platformHelper.getDBVersion());
json.put("id", platformHelper.getLastEventID());
json.put("event", event.getEventType());
json.put("ts", event.getEventTimestamp());
json.put("mid", event.getEventMid());
json.put("sid", event.getEventSid());
json.put("aguid", event.getEventAppGuid());
json.put("seq", event.getEventSeq());
if (event.mustExpandPayload()) {
json.put("data", new JSONObject(event.getEventPayload()));
} else {
json.put("data", event.getEventPayload());
}
return json.toString();
} catch (JSONException e) {
Log.e(TAG, "Error generating last event.", e);
}
}
return analytics.getLastEvent().toString();
} else {
Log.e(
TAG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;

import com.appcelerator.aps.APSAnalytics;

@Kroll.module
public class AppModule extends KrollModule implements SensorEventListener
{
Expand Down Expand Up @@ -168,7 +170,7 @@ public String getDeployType()
public String getSessionId()
// clang-format on
{
return TiPlatformHelper.getInstance().getSessionId();
return APSAnalytics.getInstance().getCurrentSessionId();
}

// clang-format off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.analytics.TiAnalyticsEventFactory;
import org.appcelerator.titanium.util.TiConvert;
import org.json.JSONException;
import org.json.JSONObject;

import ti.modules.titanium.geolocation.TiLocation.GeocodeResponseHandler;
import ti.modules.titanium.geolocation.android.AndroidModule;
Expand All @@ -38,11 +39,8 @@
import android.location.Location;
import android.location.LocationProvider;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
* GeolocationModule exposes all common methods and properties relating to geolocation behavior
Expand Down Expand Up @@ -649,7 +647,21 @@ public void getCurrentHeading(final KrollFunction listener)
public String getLastGeolocation()
// clang-format on
{
return TiAnalyticsEventFactory.locationToJSONString(lastLocation);
JSONObject result = new JSONObject();

try {
result.put("latitude", lastLocation.getLatitude());
result.put("longitude", lastLocation.getLongitude());
result.put("altitude", lastLocation.getAltitude());
result.put("accuracy", lastLocation.getAccuracy());
result.put("heading", lastLocation.getBearing());
result.put("speed", lastLocation.getSpeed());
result.put("timestamp", lastLocation.getTime());
} catch (JSONException e) {
// safe to return empty object
}

return result.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.appcelerator.kroll.common.TiMessenger;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.analytics.TiAnalyticsEventFactory;
import org.appcelerator.titanium.util.TiPlatformHelper;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -54,7 +53,6 @@ public class TiLocation implements Handler.Callback
private String appGuid;
private String sessionId;
private String countryCode;
private long lastAnalyticsTimestamp = 0;
private List<String> knownProviders;
private Handler runtimeHandler;

Expand All @@ -66,9 +64,9 @@ public TiLocation()
{
locationManager = (LocationManager) TiApplication.getInstance().getSystemService(Context.LOCATION_SERVICE);
knownProviders = locationManager.getAllProviders();
mobileId = TiPlatformHelper.getInstance().getMobileId();
mobileId = APSAnalytics.getInstance().getMachineId();
appGuid = TiApplication.getInstance().getAppInfo().getGUID();
sessionId = TiPlatformHelper.getInstance().getSessionId();
sessionId = APSAnalytics.getInstance().getCurrentSessionId();
countryCode = Locale.getDefault().getCountry();
runtimeHandler = new Handler(TiMessenger.getRuntimeMessenger().getLooper(), this);
}
Expand Down Expand Up @@ -146,10 +144,8 @@ public Location getLastKnownLocation()

public void doAnalytics(Location location)
{
long locationTime = location.getTime();
TiApplication application = TiApplication.getInstance();
if ((locationTime - lastAnalyticsTimestamp > TiAnalyticsEventFactory.MAX_GEO_ANALYTICS_FREQUENCY)
&& application.isAnalyticsEnabled() && !application.isAnalyticsFiltered("ti.geo")) {
if (application.isAnalyticsEnabled() && !application.isAnalyticsFiltered("ti.geo")) {
APSAnalytics.getInstance().sendAppGeoEvent(location);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.net.Uri;
import android.os.Build;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Display;
Expand Down Expand Up @@ -218,7 +219,7 @@ protected void measureVideo(int videoWidth, int videoHeight, int widthMeasureSpe
}
}
}
String model = TiPlatformHelper.getInstance().getModel();
String model = Build.MODEL;
if (model != null && model.equals("SPH-P100")) {
Activity activity = (Activity) getContext();
Display d = activity.getWindowManager().getDefaultDisplay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;

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

import java.util.UUID;

@Kroll.module
public class PlatformModule extends KrollModule
Expand Down Expand Up @@ -61,7 +70,7 @@ public PlatformModule()
public String getName()
// clang-format on
{
return TiPlatformHelper.getInstance().getName();
return "android";
}

// clang-format off
Expand All @@ -70,7 +79,7 @@ public String getName()
public String getOsname()
// clang-format on
{
return TiPlatformHelper.getInstance().getName();
return "android";
}

// clang-format off
Expand Down Expand Up @@ -101,7 +110,7 @@ public DisplayCapsProxy getDisplayCaps()
public int getProcessorCount()
// clang-format on
{
return TiPlatformHelper.getInstance().getProcessorCount();
return Runtime.getRuntime().availableProcessors();
}

// clang-format off
Expand All @@ -110,7 +119,7 @@ public int getProcessorCount()
public String getUsername()
// clang-format on
{
return TiPlatformHelper.getInstance().getUsername();
return Build.USER;
}

// clang-format off
Expand All @@ -119,7 +128,7 @@ public String getUsername()
public String getVersion()
// clang-format on
{
return TiPlatformHelper.getInstance().getVersion();
return APSAnalyticsMeta.getAppVersion();
}

// clang-format off
Expand All @@ -128,7 +137,7 @@ public String getVersion()
public double getAvailableMemory()
// clang-format on
{
return TiPlatformHelper.getInstance().getAvailableMemory();
return Runtime.getRuntime().freeMemory();
}

// clang-format off
Expand All @@ -137,7 +146,7 @@ public double getAvailableMemory()
public String getModel()
// clang-format on
{
return TiPlatformHelper.getInstance().getModel();
return Build.MODEL;
}

// clang-format off
Expand All @@ -146,7 +155,7 @@ public String getModel()
public String getManufacturer()
// clang-format on
{
return TiPlatformHelper.getInstance().getManufacturer();
return Build.MANUFACTURER;
}

// clang-format off
Expand All @@ -155,7 +164,7 @@ public String getManufacturer()
public String getOstype()
// clang-format on
{
return TiPlatformHelper.getInstance().getOstype();
return "32bit";
}

// clang-format off
Expand All @@ -164,7 +173,7 @@ public String getOstype()
public String getArchitecture()
// clang-format on
{
return TiPlatformHelper.getInstance().getArchitecture();
return APSAnalyticsMeta.getArchitecture();
}

// clang-format off
Expand Down Expand Up @@ -198,7 +207,7 @@ public boolean is24HourTimeFormat()
@Kroll.method
public String createUUID()
{
return TiPlatformHelper.getInstance().createUUID();
return UUID.randomUUID().toString();
}

@Kroll.method
Expand Down Expand Up @@ -228,7 +237,44 @@ public boolean openURL(String url)
public String getMacaddress()
// clang-format on
{
return TiPlatformHelper.getInstance().getMacaddress();
// String macaddr = null;
// TiApplication tiApp = TiApplication.getInstance();
//
// if (tiApp.checkCallingOrSelfPermission(Manifest.permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED) {
// WifiManager wm = (WifiManager) tiApp.getSystemService(Context.WIFI_SERVICE);
// if (wm != null) {
// WifiInfo wi = wm.getConnectionInfo();
// if (wi != null) {
// macaddr = wi.getMacAddress();
// Log.d(TAG, "Found mac address " + macaddr);
// } else {
// Log.d(TAG, "Mo WifiInfo, enabling Wifi to get mac address");
// if (!wm.isWifiEnabled()) {
// if (wm.setWifiEnabled(true)) {
// if ((wi = wm.getConnectionInfo()) != null) {
// macaddr = wi.getMacAddress();
// } else {
// Log.d(TAG, "Still no WifiInfo, assuming no mac address");
// }
// Log.d(TAG, "Disabling wifi because we enabled it.");
// wm.setWifiEnabled(false);
// } else {
// Log.d(TAG, "Enabling wifi failed, assuming no mac address");
// }
// } else {
// Log.d(TAG, "Wifi already enabled, assuming no mac address");
// }
// }
// }
// } else {
// Log.w(TAG, "Must have android.permission.ACCESS_WIFI_STATE to get mac address.");
// }
//
// if (macaddr == null) {
// macaddr = getId(); // just make it the unique ID if not found
// }

return null;
}

// clang-format off
Expand All @@ -237,7 +283,7 @@ public String getMacaddress()
public String getId()
// clang-format on
{
return TiPlatformHelper.getInstance().getMobileId();
return APSAnalytics.getInstance().getMachineId();
}

// clang-format off
Expand Down
Binary file modified android/titanium/lib/aps-analytics.jar
Binary file not shown.

0 comments on commit 1f078d2

Please sign in to comment.