2021-08-03 07:33:18 +00:00
|
|
|
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) {
|
2021-08-09 22:51:56 +00:00
|
|
|
this.sharedPreferences = context.getSharedPreferences(PREFS_NAME, 0);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
2021-08-09 22:51:56 +00:00
|
|
|
if (str.equals(PREFS_KEY_RAW_REFERRERS)) {
|
|
|
|
remove(PREFS_KEY_RAW_REFERRERS);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
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() {
|
2021-08-09 22:51:56 +00:00
|
|
|
return getLong(PREFS_KEY_DEEPLINK_CLICK_TIME, -1);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized String getDeeplinkUrl() {
|
2021-08-09 22:51:56 +00:00
|
|
|
return getString(PREFS_KEY_DEEPLINK_URL);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized boolean getDisableThirdPartySharing() {
|
2021-08-09 22:51:56 +00:00
|
|
|
return getBoolean(PREFS_KEY_DISABLE_THIRD_PARTY_SHARING, false);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized boolean getGdprForgetMe() {
|
2021-08-09 22:51:56 +00:00
|
|
|
return getBoolean(PREFS_KEY_GDPR_FORGET_ME, false);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized boolean getInstallTracked() {
|
2021-08-09 22:51:56 +00:00
|
|
|
return getBoolean(PREFS_KEY_INSTALL_TRACKED, false);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized String getPushToken() {
|
2021-08-09 22:51:56 +00:00
|
|
|
return getString(PREFS_KEY_PUSH_TOKEN);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2021-08-09 22:51:56 +00:00
|
|
|
String string = getString(PREFS_KEY_RAW_REFERRERS);
|
2021-08-03 07:33:18 +00:00
|
|
|
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() {
|
2021-08-09 22:51:56 +00:00
|
|
|
remove(PREFS_KEY_DEEPLINK_URL);
|
|
|
|
remove(PREFS_KEY_DEEPLINK_CLICK_TIME);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void removeDisableThirdPartySharing() {
|
2021-08-09 22:51:56 +00:00
|
|
|
remove(PREFS_KEY_DISABLE_THIRD_PARTY_SHARING);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void removeGdprForgetMe() {
|
2021-08-09 22:51:56 +00:00
|
|
|
remove(PREFS_KEY_GDPR_FORGET_ME);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void removePushToken() {
|
2021-08-09 22:51:56 +00:00
|
|
|
remove(PREFS_KEY_PUSH_TOKEN);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-09 22:51:56 +00:00
|
|
|
saveString(PREFS_KEY_RAW_REFERRERS, jSONArray.toString());
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void saveDeeplink(Uri uri, long j) {
|
|
|
|
if (uri != null) {
|
2021-08-09 22:51:56 +00:00
|
|
|
saveString(PREFS_KEY_DEEPLINK_URL, uri.toString());
|
|
|
|
saveLong(PREFS_KEY_DEEPLINK_CLICK_TIME, j);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void savePushToken(String str) {
|
2021-08-09 22:51:56 +00:00
|
|
|
saveString(PREFS_KEY_PUSH_TOKEN, str);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 {
|
2021-08-09 22:51:56 +00:00
|
|
|
saveString(PREFS_KEY_RAW_REFERRERS, jSONArray.toString());
|
2021-08-03 07:33:18 +00:00
|
|
|
} catch (Throwable unused) {
|
2021-08-09 22:51:56 +00:00
|
|
|
remove(PREFS_KEY_RAW_REFERRERS);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void setDisableThirdPartySharing() {
|
2021-08-09 22:51:56 +00:00
|
|
|
saveBoolean(PREFS_KEY_DISABLE_THIRD_PARTY_SHARING, true);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void setGdprForgetMe() {
|
2021-08-09 22:51:56 +00:00
|
|
|
saveBoolean(PREFS_KEY_GDPR_FORGET_ME, true);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void setInstallTracked() {
|
2021-08-09 22:51:56 +00:00
|
|
|
saveBoolean(PREFS_KEY_INSTALL_TRACKED, true);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|