package com.umeng.commonsdk.statistics.common; import android.content.Context; import android.content.SharedPreferences; import android.text.TextUtils; import com.umeng.commonsdk.framework.UMFrUtils; import com.umeng.commonsdk.statistics.internal.PreferenceWrapper; import java.io.File; import java.io.FilenameFilter; import java.util.Arrays; import java.util.Locale; /* compiled from: StoreHelper */ public final class d { private static d a = null; private static Context b = null; private static String c = null; private static final String e = "mobclick_agent_user_"; private static final String f = "mobclick_agent_header_"; private static final String g = "mobclick_agent_cached_"; private a d; /* compiled from: StoreHelper */ public interface b { void a(File file); boolean b(File file); void c(File file); } public d(Context context) { this.d = new a(context); } public static synchronized d a(Context context) { d dVar; synchronized (d.class) { b = context.getApplicationContext(); c = context.getPackageName(); if (a == null) { a = new d(context); } dVar = a; } return dVar; } public void a(int i) { SharedPreferences sharedPreferences = PreferenceWrapper.getDefault(b); if (sharedPreferences != null) { sharedPreferences.edit().putInt("vt", i).commit(); } } public int a() { SharedPreferences sharedPreferences = PreferenceWrapper.getDefault(b); if (sharedPreferences != null) { return sharedPreferences.getInt("vt", 0); } return 0; } public String b() { SharedPreferences sharedPreferences = PreferenceWrapper.getDefault(b); if (sharedPreferences != null) { return sharedPreferences.getString("st", null); } return null; } public void a(String str) { SharedPreferences sharedPreferences = PreferenceWrapper.getDefault(b); if (sharedPreferences != null) { sharedPreferences.edit().putString("st", str).commit(); } } public boolean c() { return UMFrUtils.envelopeFileNumber(b) > 0; } /* compiled from: StoreHelper */ public static class a { private final int a; private File b; private FilenameFilter c; public a(Context context) { this(context, ".um"); } public a(Context context, String str) { this.a = 10; this.c = new FilenameFilter() { /* class com.umeng.commonsdk.statistics.common.d.a.AnonymousClass1 */ public boolean accept(File file, String str) { return str.startsWith("um"); } }; File file = new File(context.getFilesDir(), str); this.b = file; if (!file.exists() || !this.b.isDirectory()) { this.b.mkdir(); } } public boolean a() { File[] listFiles = this.b.listFiles(); return listFiles != null && listFiles.length > 0; } public void a(b bVar) { File file; File[] listFiles = this.b.listFiles(this.c); if (listFiles != null && listFiles.length >= 10) { Arrays.sort(listFiles); int length = listFiles.length - 10; for (int i = 0; i < length; i++) { listFiles[i].delete(); } } if (listFiles != null && listFiles.length > 0) { bVar.a(this.b); int length2 = listFiles.length; for (int i2 = 0; i2 < length2; i2++) { try { if (bVar.b(listFiles[i2])) { file = listFiles[i2]; file.delete(); } } catch (Throwable unused) { file = listFiles[i2]; } } bVar.c(this.b); } } public void a(byte[] bArr) { if (bArr != null && bArr.length != 0) { try { HelperUtils.writeFile(new File(this.b, String.format(Locale.US, "um_cache_%d.env", Long.valueOf(System.currentTimeMillis()))), bArr); } catch (Exception unused) { } } } public void b() { File[] listFiles = this.b.listFiles(this.c); if (listFiles != null && listFiles.length > 0) { for (File file : listFiles) { file.delete(); } } } public int c() { File[] listFiles = this.b.listFiles(this.c); if (listFiles == null || listFiles.length <= 0) { return 0; } return listFiles.length; } } private SharedPreferences f() { Context context = b; return context.getSharedPreferences(e + c, 0); } public void a(String str, String str2) { if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) { SharedPreferences.Editor edit = f().edit(); edit.putString("au_p", str); edit.putString("au_u", str2); edit.commit(); } } public String[] d() { try { SharedPreferences f2 = f(); String string = f2.getString("au_p", null); String string2 = f2.getString("au_u", null); if (!(string == null || string2 == null)) { return new String[]{string, string2}; } } catch (Exception unused) { } return null; } public void e() { f().edit().remove("au_p").remove("au_u").commit(); } }