Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ANRs issue when opt in and remove residual image files left from the legacy SDK versions #807

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.os.SystemClock;
import android.util.DisplayMetrics;

import com.mixpanel.android.util.Base64Coder;
import com.mixpanel.android.util.HttpService;
import com.mixpanel.android.util.LegacyVersionUtils;
import com.mixpanel.android.util.MPLog;
import com.mixpanel.android.util.RemoteService;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -139,6 +140,13 @@ public void updateEventProperties(final UpdateEventsPropertiesDescription update
mWorker.runMessage(m);
}

public void removeResidualImageFiles(File fileOrDirectory) {
final Message m = Message.obtain();
m.what = REMOVE_RESIDUAL_IMAGE_FILES;
m.obj = fileOrDirectory;
mWorker.runMessage(m);
}

public void hardKill() {
final Message m = Message.obtain();
m.what = KILL_WORKER;
Expand Down Expand Up @@ -424,6 +432,9 @@ public void handleMessage(Message msg) {
mHandler = null;
Looper.myLooper().quit();
}
} else if (msg.what == REMOVE_RESIDUAL_IMAGE_FILES) {
final File file = (File) msg.obj;
LegacyVersionUtils.removeLegacyResidualImageFiles(file);
} else {
MPLog.e(LOGTAG, "Unexpected message received by Mixpanel worker: " + msg);
}
Expand Down Expand Up @@ -689,6 +700,7 @@ public long getTrackEngageRetryAfter() {
private static final int EMPTY_QUEUES = 6; // Remove any local (and pending to be flushed) events or people/group updates from the db
private static final int CLEAR_ANONYMOUS_UPDATES = 7; // Remove anonymous people updates from DB
private static final int REWRITE_EVENT_PROPERTIES = 8; // Update or add properties to existing queued events
private static final int REMOVE_RESIDUAL_IMAGE_FILES = 9; // Remove residual image files left from the legacy SDK versions

private static final String LOGTAG = "MixpanelAPI.Messages";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;

import com.mixpanel.android.util.LegacyVersionUtils;
import com.mixpanel.android.util.MPLog;

import org.json.JSONArray;
Expand Down Expand Up @@ -199,7 +197,7 @@ public class MixpanelAPI {
}

if (mConfig.getRemoveLegacyResidualFiles()) {
LegacyVersionUtils.removeLegacyResidualImageFiles(new File(mContext.getApplicationInfo().dataDir));
mMessages.removeResidualImageFiles(new File(mContext.getApplicationInfo().dataDir));
}
}

Expand Down