253 lines
8.6 KiB
Java
253 lines
8.6 KiB
Java
package com.adjust.sdk;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.net.Uri;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
public class SharedPreferencesManager {
|
|
private static final int INDEX_CLICK_TIME = 1;
|
|
private static final int INDEX_IS_SENDING = 2;
|
|
private static final int INDEX_RAW_REFERRER = 0;
|
|
private static final String PREFS_KEY_DEEPLINK_CLICK_TIME = "deeplink_click_time";
|
|
private static final String PREFS_KEY_DEEPLINK_URL = "deeplink_url";
|
|
private static final String PREFS_KEY_DISABLE_THIRD_PARTY_SHARING = "disable_third_party_sharing";
|
|
private static final String PREFS_KEY_GDPR_FORGET_ME = "gdpr_forget_me";
|
|
private static final String PREFS_KEY_INSTALL_TRACKED = "install_tracked";
|
|
private static final String PREFS_KEY_PUSH_TOKEN = "push_token";
|
|
private static final String PREFS_KEY_RAW_REFERRERS = "raw_referrers";
|
|
private static final String PREFS_NAME = "adjust_preferences";
|
|
private static final int REFERRERS_COUNT = 10;
|
|
private final SharedPreferences sharedPreferences;
|
|
|
|
public SharedPreferencesManager(Context context) {
|
|
this.sharedPreferences = context.getSharedPreferences("adjust_preferences", 0);
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:10:0x000d, code lost:
|
|
return r3;
|
|
*/
|
|
/* JADX WARNING: Exception block dominator not found, dom blocks: [] */
|
|
private synchronized boolean getBoolean(String str, boolean z2) {
|
|
return this.sharedPreferences.getBoolean(str, z2);
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:10:0x000d, code lost:
|
|
return r3;
|
|
*/
|
|
/* JADX WARNING: Exception block dominator not found, dom blocks: [] */
|
|
private synchronized long getLong(String str, long j) {
|
|
return this.sharedPreferences.getLong(str, j);
|
|
}
|
|
|
|
/* JADX WARNING: Exception block dominator not found, dom blocks: [] */
|
|
private synchronized int getRawReferrerIndex(String str, long j) {
|
|
JSONArray rawReferrerArray = getRawReferrerArray();
|
|
for (int i = 0; i < rawReferrerArray.length(); i++) {
|
|
JSONArray jSONArray = rawReferrerArray.getJSONArray(i);
|
|
String optString = jSONArray.optString(0, null);
|
|
if (optString != null) {
|
|
if (optString.equals(str)) {
|
|
if (jSONArray.optLong(1, -1) == j) {
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private synchronized String getString(String str) {
|
|
try {
|
|
} catch (ClassCastException unused) {
|
|
return null;
|
|
} catch (Throwable unused2) {
|
|
if (str.equals("raw_referrers")) {
|
|
remove("raw_referrers");
|
|
}
|
|
return null;
|
|
}
|
|
return this.sharedPreferences.getString(str, null);
|
|
}
|
|
|
|
private synchronized void remove(String str) {
|
|
this.sharedPreferences.edit().remove(str).apply();
|
|
}
|
|
|
|
private synchronized void saveBoolean(String str, boolean z2) {
|
|
this.sharedPreferences.edit().putBoolean(str, z2).apply();
|
|
}
|
|
|
|
private synchronized void saveInteger(String str, int i) {
|
|
this.sharedPreferences.edit().putInt(str, i).apply();
|
|
}
|
|
|
|
private synchronized void saveLong(String str, long j) {
|
|
this.sharedPreferences.edit().putLong(str, j).apply();
|
|
}
|
|
|
|
private synchronized void saveString(String str, String str2) {
|
|
this.sharedPreferences.edit().putString(str, str2).apply();
|
|
}
|
|
|
|
public synchronized void clear() {
|
|
this.sharedPreferences.edit().clear().apply();
|
|
}
|
|
|
|
public synchronized long getDeeplinkClickTime() {
|
|
return getLong("deeplink_click_time", -1);
|
|
}
|
|
|
|
public synchronized String getDeeplinkUrl() {
|
|
return getString("deeplink_url");
|
|
}
|
|
|
|
public synchronized boolean getDisableThirdPartySharing() {
|
|
return getBoolean("disable_third_party_sharing", false);
|
|
}
|
|
|
|
public synchronized boolean getGdprForgetMe() {
|
|
return getBoolean("gdpr_forget_me", false);
|
|
}
|
|
|
|
public synchronized boolean getInstallTracked() {
|
|
return getBoolean("install_tracked", false);
|
|
}
|
|
|
|
public synchronized String getPushToken() {
|
|
return getString("push_token");
|
|
}
|
|
|
|
public synchronized JSONArray getRawReferrer(String str, long j) {
|
|
int rawReferrerIndex = getRawReferrerIndex(str, j);
|
|
if (rawReferrerIndex >= 0) {
|
|
try {
|
|
return getRawReferrerArray().getJSONArray(rawReferrerIndex);
|
|
} catch (JSONException unused) {
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public synchronized JSONArray getRawReferrerArray() {
|
|
String string = getString("raw_referrers");
|
|
if (string != null) {
|
|
JSONArray jSONArray = new JSONArray(string);
|
|
if (jSONArray.length() > 10) {
|
|
JSONArray jSONArray2 = new JSONArray();
|
|
for (int i = 0; i < 10; i++) {
|
|
jSONArray2.put(jSONArray.get(i));
|
|
}
|
|
saveRawReferrerArray(jSONArray2);
|
|
return jSONArray2;
|
|
}
|
|
try {
|
|
return new JSONArray(string);
|
|
} catch (JSONException unused) {
|
|
}
|
|
}
|
|
return new JSONArray();
|
|
}
|
|
|
|
public synchronized void removeDeeplink() {
|
|
remove("deeplink_url");
|
|
remove("deeplink_click_time");
|
|
}
|
|
|
|
public synchronized void removeDisableThirdPartySharing() {
|
|
remove("disable_third_party_sharing");
|
|
}
|
|
|
|
public synchronized void removeGdprForgetMe() {
|
|
remove("gdpr_forget_me");
|
|
}
|
|
|
|
public synchronized void removePushToken() {
|
|
remove("push_token");
|
|
}
|
|
|
|
public synchronized void removeRawReferrer(String str, long j) {
|
|
if (str != null) {
|
|
if (str.length() != 0) {
|
|
int rawReferrerIndex = getRawReferrerIndex(str, j);
|
|
if (rawReferrerIndex >= 0) {
|
|
JSONArray rawReferrerArray = getRawReferrerArray();
|
|
JSONArray jSONArray = new JSONArray();
|
|
for (int i = 0; i < rawReferrerArray.length(); i++) {
|
|
if (i != rawReferrerIndex) {
|
|
try {
|
|
jSONArray.put(rawReferrerArray.getJSONArray(i));
|
|
} catch (JSONException unused) {
|
|
}
|
|
}
|
|
}
|
|
saveString("raw_referrers", jSONArray.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public synchronized void saveDeeplink(Uri uri, long j) {
|
|
if (uri != null) {
|
|
saveString("deeplink_url", uri.toString());
|
|
saveLong("deeplink_click_time", j);
|
|
}
|
|
}
|
|
|
|
public synchronized void savePushToken(String str) {
|
|
saveString("push_token", str);
|
|
}
|
|
|
|
/* JADX WARNING: Exception block dominator not found, dom blocks: [] */
|
|
public synchronized void saveRawReferrer(String str, long j) {
|
|
if (getRawReferrer(str, j) == null) {
|
|
JSONArray rawReferrerArray = getRawReferrerArray();
|
|
if (rawReferrerArray.length() != 10) {
|
|
JSONArray jSONArray = new JSONArray();
|
|
jSONArray.put(0, str);
|
|
jSONArray.put(1, j);
|
|
jSONArray.put(2, 0);
|
|
rawReferrerArray.put(jSONArray);
|
|
saveRawReferrerArray(rawReferrerArray);
|
|
}
|
|
}
|
|
}
|
|
|
|
public synchronized void saveRawReferrerArray(JSONArray jSONArray) {
|
|
try {
|
|
saveString("raw_referrers", jSONArray.toString());
|
|
} catch (Throwable unused) {
|
|
remove("raw_referrers");
|
|
}
|
|
return;
|
|
}
|
|
|
|
public synchronized void setDisableThirdPartySharing() {
|
|
saveBoolean("disable_third_party_sharing", true);
|
|
}
|
|
|
|
public synchronized void setGdprForgetMe() {
|
|
saveBoolean("gdpr_forget_me", true);
|
|
}
|
|
|
|
public synchronized void setInstallTracked() {
|
|
saveBoolean("install_tracked", true);
|
|
}
|
|
|
|
/* JADX WARNING: Exception block dominator not found, dom blocks: [] */
|
|
public synchronized void setSendingReferrersAsNotSent() {
|
|
JSONArray rawReferrerArray = getRawReferrerArray();
|
|
boolean z2 = false;
|
|
for (int i = 0; i < rawReferrerArray.length(); i++) {
|
|
JSONArray jSONArray = rawReferrerArray.getJSONArray(i);
|
|
if (jSONArray.optInt(2, -1) == 1) {
|
|
jSONArray.put(2, 0);
|
|
z2 = true;
|
|
}
|
|
}
|
|
if (z2) {
|
|
saveRawReferrerArray(rawReferrerArray);
|
|
}
|
|
}
|
|
}
|