183 lines
4.5 KiB
Java
183 lines
4.5 KiB
Java
package com.baidu.uaq.agent.android;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import java.util.concurrent.locks.Lock;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONTokener;
|
|
|
|
/* compiled from: SavedState.java */
|
|
/* loaded from: classes.dex */
|
|
public class f {
|
|
private static final com.baidu.uaq.agent.android.logging.a f = com.baidu.uaq.agent.android.logging.b.a();
|
|
private static final UAQ g = UAQ.getInstance();
|
|
private final SharedPreferences a;
|
|
private SharedPreferences.Editor b;
|
|
private final Lock c = new ReentrantLock();
|
|
private com.baidu.uaq.agent.android.harvest.bean.b d = new com.baidu.uaq.agent.android.harvest.bean.b();
|
|
private long e;
|
|
|
|
@SuppressLint({"CommitPrefEdits"})
|
|
public f(Context context) {
|
|
this.a = context.getSharedPreferences("com.baidu.uaq.android.agent.v2_" + context.getPackageName(), 0);
|
|
f();
|
|
c();
|
|
d();
|
|
g();
|
|
}
|
|
|
|
private void f() {
|
|
com.baidu.uaq.agent.android.harvest.bean.b h = h();
|
|
if (h == null) {
|
|
return;
|
|
}
|
|
this.d.a(h.e());
|
|
this.d.b(h.f());
|
|
}
|
|
|
|
private void g() {
|
|
if (!d("lastUpdateTimestamp")) {
|
|
c(System.currentTimeMillis());
|
|
}
|
|
k();
|
|
}
|
|
|
|
private com.baidu.uaq.agent.android.harvest.bean.b h() {
|
|
JSONArray jSONArray;
|
|
int[] iArr = new int[2];
|
|
String c = c("dataToken");
|
|
if (c == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
jSONArray = (JSONArray) new JSONTokener(c).nextValue();
|
|
} catch (JSONException e) {
|
|
f.a("Caught error while getDataToken: ", e);
|
|
}
|
|
if (jSONArray == null) {
|
|
return null;
|
|
}
|
|
iArr[0] = jSONArray.getInt(0);
|
|
iArr[1] = jSONArray.getInt(1);
|
|
return new com.baidu.uaq.agent.android.harvest.bean.b(iArr[0], iArr[1]);
|
|
}
|
|
|
|
private long i() {
|
|
return b("dataReportPeriod");
|
|
}
|
|
|
|
private long j() {
|
|
return b("dataReportLimit");
|
|
}
|
|
|
|
private long k() {
|
|
return b("lastUpdateTimestamp");
|
|
}
|
|
|
|
public void a(long j) {
|
|
f.d("!! saving dataReportPeriod: " + j);
|
|
a("dataReportPeriod", j);
|
|
}
|
|
|
|
public long b() {
|
|
return this.e;
|
|
}
|
|
|
|
public final void c() {
|
|
if (d("dataReportPeriod")) {
|
|
this.e = i();
|
|
}
|
|
}
|
|
|
|
public final void d() {
|
|
if (!d("dataReportLimit")) {
|
|
b(g.getConfig().getDataReportLimit());
|
|
}
|
|
j();
|
|
}
|
|
|
|
public String e() {
|
|
return c("appToken");
|
|
}
|
|
|
|
public void b(long j) {
|
|
f.d("!! saving dataReportLimit: " + j);
|
|
a("dataReportLimit", j);
|
|
}
|
|
|
|
public void a(String str) {
|
|
a("appToken", str);
|
|
}
|
|
|
|
public void c(long j) {
|
|
f.d("!! saving lastUpdateTimestamp: " + j);
|
|
a("lastUpdateTimestamp", j);
|
|
}
|
|
|
|
private void a(String str, String str2) {
|
|
this.c.lock();
|
|
try {
|
|
try {
|
|
if (this.b == null) {
|
|
this.b = this.a.edit();
|
|
}
|
|
this.b.putString(str, str2);
|
|
this.b.apply();
|
|
} catch (Exception e) {
|
|
f.a("Caught error while SavedState save: ", e);
|
|
}
|
|
} finally {
|
|
this.c.unlock();
|
|
}
|
|
}
|
|
|
|
private long b(String str) {
|
|
return this.a.getLong(str, 0L);
|
|
}
|
|
|
|
private boolean d(String str) {
|
|
return this.a.contains(str);
|
|
}
|
|
|
|
private String c(String str) {
|
|
return this.a.getString(str, null);
|
|
}
|
|
|
|
private void a(String str, long j) {
|
|
this.c.lock();
|
|
try {
|
|
try {
|
|
if (this.b == null) {
|
|
this.b = this.a.edit();
|
|
}
|
|
this.b.putLong(str, j);
|
|
this.b.apply();
|
|
} catch (Exception e) {
|
|
f.a("Caught error while SavedState save: ", e);
|
|
}
|
|
} finally {
|
|
this.c.unlock();
|
|
}
|
|
}
|
|
|
|
public void a() {
|
|
this.c.lock();
|
|
try {
|
|
try {
|
|
if (this.b == null) {
|
|
this.b = this.a.edit();
|
|
}
|
|
this.b.clear();
|
|
this.b.apply();
|
|
} catch (Exception e) {
|
|
f.a("Caught error while clear SavedState: ", e);
|
|
}
|
|
} finally {
|
|
this.c.unlock();
|
|
}
|
|
}
|
|
}
|