AppIndexingService.java
11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
package com.bitstrips.imoji.firebase;
import android.app.IntentService;
import android.app.job.JobParameters;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import com.bitstrips.imoji.InjectorApplication;
import com.bitstrips.imoji.behaviour.BehaviourHelper;
import com.bitstrips.imoji.firebase.models.IndexableSticker;
import com.bitstrips.imoji.firebase.models.IndexableStickerPack;
import com.bitstrips.imoji.manager.AppIndexingManager;
import com.bitstrips.imoji.manager.StickerPacksManager;
import com.bitstrips.imoji.models.AvatarInfo;
import com.bitstrips.imoji.models.StickerPacks;
import com.bitstrips.imoji.monouser.oauth2.OAuth2Manager;
import com.bitstrips.imoji.util.AuthorizationException;
import com.bitstrips.imoji.util.AvatarInfoUtils;
import com.bitstrips.imoji.util.FileUtil;
import com.bitstrips.imoji.util.PreferenceTimer;
import com.bitstrips.imoji.util.PreferenceUtils;
import com.crashlytics.android.Crashlytics;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class AppIndexingService
extends IntentService
{
private static final int DEFAULT_INDEX_BATCH_SIZE = 400;
private static final String INDEXED_STICKERS_CACHE_FILE = "firebase_indexed_stickers";
private static final String INDEXED_STICKER_PACKS_CACHE_FILE = "firebase_indexed_sticker_packs";
public static final String INTENT_FLAG_FORCE_FLUSH_FIREBASE = "forceFlushFirebase";
public static final String INTENT_FLAG_FORCE_REQUEST_AVATAR_INFO = "forceRequestAvatarInfo";
public static final String INTENT_FLAG_FORCE_REQUEST_STICKER_PACKS = "forceRequestStickerPacks";
public static final String INTENT_FLAG_INDEX_REASON = "reason";
public static final String INTENT_FLAG_JOB_PARAMS = "jobParams";
public static final String INTENT_FLAG_MESSENGER = "messenger";
private static final String LOG_TAG = "AppIndexingService";
private static final int SCHEDULED_INDEX_BATCH_SIZE = 200;
private static final long SHOULD_UPDATE_STICKERS_INTERVAL = TimeUnit.HOURS.toMillis(1L);
public static final String UPDATE_INDEX_REASON_APP_OPEN = "app_open";
public static final String UPDATE_INDEX_REASON_LOCALE_CHANGED = "locale_changed";
public static final String UPDATE_INDEX_REASON_SCHEDULED = "scheduled";
public static final String UPDATE_INDEX_REASON_STICKERS_CHANGED = "stickers_changed";
public static final String UPDATE_INDEX_REASON_THIRD_PARTY_OPEN = "third_party_open";
@Inject
AppIndexingManager mAppIndexingManager;
@Inject
AvatarInfoUtils mAvatarInfoUtils;
@Inject
BehaviourHelper mBehaviourHelper;
@Inject
FileUtil mFileUtil;
@Inject
OAuth2Manager mOAuth2Manager;
@Inject
PreferenceUtils mPreferenceUtils;
@Inject
StickerPacksManager mStickerPacksManager;
public AppIndexingService()
{
super("AppIndexingService");
}
private void clearAllIndexables()
{
long l = System.currentTimeMillis();
clearCachedIndexableUrls();
FirebaseUtils.clearFirebaseSync();
Log.i("AppIndexingService", MessageFormat.format("Successfully removed all app index - {0}ms", new Object[] { Long.valueOf(System.currentTimeMillis() - l) }));
}
private void clearCachedIndexableUrls()
{
this.mFileUtil.saveGsonToFile("firebase_indexed_sticker_packs", null);
this.mFileUtil.saveGsonToFile("firebase_indexed_stickers", null);
}
private void clearLastSuccessfulUpdateTimer()
{
this.mPreferenceUtils.getTimer(2131231266).setTimestamp(0L);
}
private String getAvatarId(boolean paramBoolean)
{
String str = this.mPreferenceUtils.getString(2131231175, null);
if (!paramBoolean) {}
for (;;)
{
return str;
try
{
Object localObject = this.mAvatarInfoUtils.getLatestAvatarInfoSync();
if (localObject != null)
{
localObject = ((AvatarInfo)localObject).getId();
return (String)localObject;
}
}
catch (AuthorizationException localAuthorizationException)
{
return null;
}
catch (Exception localException)
{
Log.e("AppIndexingService", "Avatar info fetching failed", localException);
}
}
return localAuthorizationException;
}
private Map<String, IndexableSticker> getCachedStickerMap()
{
IndexableSticker[] arrayOfIndexableSticker = (IndexableSticker[])this.mFileUtil.readGsonFromFile("firebase_indexed_stickers", IndexableSticker[].class);
HashMap localHashMap = new HashMap();
if ((arrayOfIndexableSticker == null) || (arrayOfIndexableSticker.length == 0)) {
return localHashMap;
}
int j = arrayOfIndexableSticker.length;
int i = 0;
while (i < j)
{
IndexableSticker localIndexableSticker = arrayOfIndexableSticker[i];
localHashMap.put(localIndexableSticker.getGeneratedUrl(), localIndexableSticker);
i += 1;
}
return localHashMap;
}
private Map<String, IndexableStickerPack> getCachedStickerPackMap()
{
IndexableStickerPack[] arrayOfIndexableStickerPack = (IndexableStickerPack[])this.mFileUtil.readGsonFromFile("firebase_indexed_sticker_packs", IndexableStickerPack[].class);
HashMap localHashMap = new HashMap();
if ((arrayOfIndexableStickerPack == null) || (arrayOfIndexableStickerPack.length == 0)) {
return localHashMap;
}
int j = arrayOfIndexableStickerPack.length;
int i = 0;
while (i < j)
{
IndexableStickerPack localIndexableStickerPack = arrayOfIndexableStickerPack[i];
localHashMap.put(localIndexableStickerPack.getUrl(), localIndexableStickerPack);
i += 1;
}
return localHashMap;
}
private static int getIndexingMaxBatchSize(String paramString)
{
if ("scheduled".equals(paramString)) {
return 200;
}
return 400;
}
private void setLastSuccessfulUpdateTimer(String paramString)
{
if (!"scheduled".equals(paramString)) {
this.mPreferenceUtils.getTimer(2131231266).setTimestamp(System.currentTimeMillis());
}
}
private void updateFirebaseStickerPacks(StickerPacks paramStickerPacks, String paramString, Map<String, IndexableStickerPack> paramMap, int paramInt)
{
long l = System.currentTimeMillis();
paramStickerPacks = AppIndexablesFactory.generateIndexableStickerPacks(paramStickerPacks.get(), paramString, paramMap);
FirebaseUtils.batchUpdateFirebaseSync(paramStickerPacks.getIndexableUrlsToRemove(), paramStickerPacks.getIndexablesToUpdate(), paramInt);
Log.i("AppIndexingService", MessageFormat.format("Successfully updated app index - sticker packs - {0}ms", new Object[] { Long.valueOf(System.currentTimeMillis() - l) }));
this.mFileUtil.saveGsonToFile("firebase_indexed_sticker_packs", paramStickerPacks.getSerializables().toArray());
}
private void updateFirebaseStickers(StickerPacks paramStickerPacks, String paramString, Map<String, IndexableSticker> paramMap, int paramInt)
{
long l = System.currentTimeMillis();
paramStickerPacks = AppIndexablesFactory.generateIndexableStickers(paramStickerPacks.get(), paramString, paramMap);
FirebaseUtils.batchUpdateFirebaseSync(paramStickerPacks.getIndexableUrlsToRemove(), paramStickerPacks.getIndexablesToUpdate(), paramInt);
Log.i("AppIndexingService", MessageFormat.format("Successfully updated app index - stickers - {0}ms", new Object[] { Long.valueOf(System.currentTimeMillis() - l) }));
this.mFileUtil.saveGsonToFile("firebase_indexed_stickers", paramStickerPacks.getSerializables().toArray());
}
private boolean updateIndex(boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, int paramInt)
{
try
{
String str = getAvatarId(paramBoolean1);
if (TextUtils.isEmpty(str))
{
Log.w("AppIndexingService", "User is not logged in. Stop indexing..");
return true;
}
}
catch (Exception localException1)
{
Log.e("AppIndexingService", "Avatar info fetching failed", localException1);
Crashlytics.logException(localException1);
return false;
}
Map localMap1 = getCachedStickerPackMap();
Map localMap2 = getCachedStickerMap();
StickerPacks localStickerPacks;
try
{
localStickerPacks = this.mStickerPacksManager.updateStickerPacksIfNecessarySync(paramBoolean2, SHOULD_UPDATE_STICKERS_INTERVAL);
if (localStickerPacks == null) {
return false;
}
}
catch (Exception localException2)
{
Log.e("AppIndexingService", "Sticker packs fetching failed", localException2);
Crashlytics.logException(localException2);
return false;
}
if (!paramBoolean3) {}
try
{
if ((localMap1.isEmpty()) || (localMap2.isEmpty())) {
clearAllIndexables();
}
updateFirebaseStickerPacks(localStickerPacks, localException2, localMap1, paramInt);
updateFirebaseStickers(localStickerPacks, localException2, localMap2, paramInt);
return true;
}
catch (Exception localException3)
{
clearCachedIndexableUrls();
clearLastSuccessfulUpdateTimer();
Log.e("AppIndexingService", "Templates update failed", localException3);
Crashlytics.logException(localException3);
}
return false;
}
public void onCreate()
{
super.onCreate();
((InjectorApplication)getApplication()).inject(this);
}
protected void onHandleIntent(Intent paramIntent)
{
if (paramIntent == null) {
return;
}
boolean bool1 = paramIntent.getBooleanExtra("forceRequestAvatarInfo", false);
boolean bool2 = paramIntent.getBooleanExtra("forceRequestStickerPacks", false);
boolean bool3 = paramIntent.getBooleanExtra("forceFlushFirebase", false);
Object localObject = paramIntent.getStringExtra("reason");
Messenger localMessenger = (Messenger)paramIntent.getParcelableExtra("messenger");
if (((bool1) || (this.mBehaviourHelper.isTokenRefreshForced())) && (this.mOAuth2Manager.isUserLoggedIn())) {
this.mOAuth2Manager.syncRefreshToken(this.mBehaviourHelper.isTokenRefreshForced());
}
if (updateIndex(bool1, bool2, bool3, getIndexingMaxBatchSize((String)localObject)))
{
setLastSuccessfulUpdateTimer((String)localObject);
this.mAppIndexingManager.notifyFirebaseIndexCompleteOnMainThread();
}
for (int i = 1;; i = 0)
{
this.mAppIndexingManager.setIsUpdatingIndex(false);
if ((Build.VERSION.SDK_INT < 21) || (localMessenger == null)) {
break;
}
paramIntent = (JobParameters)paramIntent.getParcelableExtra("jobParams");
localObject = Message.obtain();
((Message)localObject).what = 100;
((Message)localObject).arg1 = i;
((Message)localObject).obj = paramIntent;
try
{
localMessenger.send((Message)localObject);
return;
}
catch (RemoteException paramIntent)
{
Log.e("AppIndexingService", "Couldn't send message to finish job!", paramIntent);
return;
}
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/firebase/AppIndexingService.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/