2021-06-27 20:44:35 +00:00
|
|
|
package androidx.appcompat.widget;
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.database.DataSetObservable;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Xml;
|
2021-12-21 23:37:30 +00:00
|
|
|
import b.d.b.a.a;
|
2021-08-09 22:50:01 +00:00
|
|
|
import com.adjust.sdk.Constants;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
import org.xmlpull.v1.XmlSerializer;
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public class ActivityChooserModel extends DataSetObservable {
|
|
|
|
public static final String ATTRIBUTE_ACTIVITY = "activity";
|
|
|
|
public static final String ATTRIBUTE_TIME = "time";
|
|
|
|
public static final String ATTRIBUTE_WEIGHT = "weight";
|
|
|
|
public static final boolean DEBUG = false;
|
|
|
|
private static final int DEFAULT_ACTIVITY_INFLATION = 5;
|
|
|
|
private static final float DEFAULT_HISTORICAL_RECORD_WEIGHT = 1.0f;
|
|
|
|
public static final String DEFAULT_HISTORY_FILE_NAME = "activity_choser_model_history.xml";
|
|
|
|
public static final int DEFAULT_HISTORY_MAX_LENGTH = 50;
|
|
|
|
private static final String HISTORY_FILE_EXTENSION = ".xml";
|
|
|
|
private static final int INVALID_INDEX = -1;
|
|
|
|
public static final String TAG_HISTORICAL_RECORD = "historical-record";
|
|
|
|
public static final String TAG_HISTORICAL_RECORDS = "historical-records";
|
|
|
|
private OnChooseActivityListener mActivityChoserModelPolicy;
|
|
|
|
public final Context mContext;
|
|
|
|
public final String mHistoryFileName;
|
|
|
|
private Intent mIntent;
|
2022-03-02 20:59:20 +00:00
|
|
|
public static final String LOG_TAG = ActivityChooserModel.class.getSimpleName();
|
|
|
|
private static final Object sRegistryLock = new Object();
|
|
|
|
private static final Map<String, ActivityChooserModel> sDataModelRegistry = new HashMap();
|
|
|
|
private final Object mInstanceLock = new Object();
|
|
|
|
private final List<ActivityResolveInfo> mActivities = new ArrayList();
|
|
|
|
private final List<HistoricalRecord> mHistoricalRecords = new ArrayList();
|
|
|
|
private ActivitySorter mActivitySorter = new DefaultSorter();
|
|
|
|
private int mHistoryMaxSize = 50;
|
|
|
|
public boolean mCanReadHistoricalData = true;
|
2021-06-27 20:44:35 +00:00
|
|
|
private boolean mReadShareHistoryCalled = false;
|
2022-03-02 20:59:20 +00:00
|
|
|
private boolean mHistoricalRecordsChanged = true;
|
2021-06-27 20:44:35 +00:00
|
|
|
private boolean mReloadActivities = false;
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public interface ActivityChooserModelClient {
|
|
|
|
void setActivityChooserModel(ActivityChooserModel activityChooserModel);
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public static final class ActivityResolveInfo implements Comparable<ActivityResolveInfo> {
|
|
|
|
public final ResolveInfo resolveInfo;
|
|
|
|
public float weight;
|
|
|
|
|
|
|
|
public ActivityResolveInfo(ResolveInfo resolveInfo) {
|
|
|
|
this.resolveInfo = resolveInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int compareTo(ActivityResolveInfo activityResolveInfo) {
|
|
|
|
return Float.floatToIntBits(activityResolveInfo.weight) - Float.floatToIntBits(this.weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return obj != null && ActivityResolveInfo.class == obj.getClass() && Float.floatToIntBits(this.weight) == Float.floatToIntBits(((ActivityResolveInfo) obj).weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int hashCode() {
|
|
|
|
return Float.floatToIntBits(this.weight) + 31;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
2022-03-22 15:40:06 +00:00
|
|
|
StringBuilder W = a.W("[", "resolveInfo:");
|
|
|
|
W.append(this.resolveInfo.toString());
|
|
|
|
W.append("; weight:");
|
|
|
|
W.append(new BigDecimal(this.weight));
|
|
|
|
W.append("]");
|
|
|
|
return W.toString();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public interface ActivitySorter {
|
|
|
|
void sort(Intent intent, List<ActivityResolveInfo> list, List<HistoricalRecord> list2);
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public static final class DefaultSorter implements ActivitySorter {
|
|
|
|
private static final float WEIGHT_DECAY_COEFFICIENT = 0.95f;
|
|
|
|
private final Map<ComponentName, ActivityResolveInfo> mPackageNameToActivityMap = new HashMap();
|
|
|
|
|
|
|
|
@Override // androidx.appcompat.widget.ActivityChooserModel.ActivitySorter
|
|
|
|
public void sort(Intent intent, List<ActivityResolveInfo> list, List<HistoricalRecord> list2) {
|
|
|
|
Map<ComponentName, ActivityResolveInfo> map = this.mPackageNameToActivityMap;
|
|
|
|
map.clear();
|
|
|
|
int size = list.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
ActivityResolveInfo activityResolveInfo = list.get(i);
|
|
|
|
activityResolveInfo.weight = 0.0f;
|
|
|
|
ActivityInfo activityInfo = activityResolveInfo.resolveInfo.activityInfo;
|
|
|
|
map.put(new ComponentName(activityInfo.packageName, activityInfo.name), activityResolveInfo);
|
|
|
|
}
|
|
|
|
float f = 1.0f;
|
|
|
|
for (int size2 = list2.size() - 1; size2 >= 0; size2--) {
|
|
|
|
HistoricalRecord historicalRecord = list2.get(size2);
|
|
|
|
ActivityResolveInfo activityResolveInfo2 = map.get(historicalRecord.activity);
|
|
|
|
if (activityResolveInfo2 != null) {
|
|
|
|
activityResolveInfo2.weight = (historicalRecord.weight * f) + activityResolveInfo2.weight;
|
2021-08-09 22:50:01 +00:00
|
|
|
f *= WEIGHT_DECAY_COEFFICIENT;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Collections.sort(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public static final class HistoricalRecord {
|
|
|
|
public final ComponentName activity;
|
|
|
|
public final long time;
|
|
|
|
public final float weight;
|
|
|
|
|
|
|
|
public HistoricalRecord(ComponentName componentName, long j, float f) {
|
|
|
|
this.activity = componentName;
|
|
|
|
this.time = j;
|
|
|
|
this.weight = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HistoricalRecord(String str, long j, float f) {
|
|
|
|
this(ComponentName.unflattenFromString(str), j, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (obj == null || HistoricalRecord.class != obj.getClass()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
HistoricalRecord historicalRecord = (HistoricalRecord) obj;
|
|
|
|
ComponentName componentName = this.activity;
|
|
|
|
if (componentName == null) {
|
|
|
|
if (historicalRecord.activity != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!componentName.equals(historicalRecord.activity)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.time == historicalRecord.time && Float.floatToIntBits(this.weight) == Float.floatToIntBits(historicalRecord.weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int hashCode() {
|
|
|
|
ComponentName componentName = this.activity;
|
|
|
|
int hashCode = componentName == null ? 0 : componentName.hashCode();
|
|
|
|
long j = this.time;
|
|
|
|
return Float.floatToIntBits(this.weight) + ((((hashCode + 31) * 31) + ((int) (j ^ (j >>> 32)))) * 31);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
2022-03-22 15:40:06 +00:00
|
|
|
StringBuilder W = a.W("[", "; activity:");
|
|
|
|
W.append(this.activity);
|
|
|
|
W.append("; time:");
|
|
|
|
W.append(this.time);
|
|
|
|
W.append("; weight:");
|
|
|
|
W.append(new BigDecimal(this.weight));
|
|
|
|
W.append("]");
|
|
|
|
return W.toString();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public interface OnChooseActivityListener {
|
|
|
|
boolean onChooseActivity(ActivityChooserModel activityChooserModel, Intent intent);
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public final class PersistHistoryAsyncTask extends AsyncTask<Object, Void, Void> {
|
|
|
|
public PersistHistoryAsyncTask() {
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:10:0x006d, code lost:
|
2021-06-27 20:44:35 +00:00
|
|
|
if (r15 != null) goto L_0x006f;
|
|
|
|
*/
|
2022-03-02 20:59:20 +00:00
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:11:0x006f, code lost:
|
2021-06-27 20:44:35 +00:00
|
|
|
r15.close();
|
|
|
|
*/
|
2022-03-02 20:59:20 +00:00
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:16:0x0092, code lost:
|
2021-06-27 20:44:35 +00:00
|
|
|
if (r15 == null) goto L_0x00d5;
|
|
|
|
*/
|
2022-03-02 20:59:20 +00:00
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:20:0x00b2, code lost:
|
2021-06-27 20:44:35 +00:00
|
|
|
if (r15 == null) goto L_0x00d5;
|
|
|
|
*/
|
2022-03-02 20:59:20 +00:00
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:24:0x00d2, code lost:
|
2021-06-27 20:44:35 +00:00
|
|
|
if (r15 == null) goto L_0x00d5;
|
|
|
|
*/
|
2022-03-02 20:59:20 +00:00
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:25:0x00d5, code lost:
|
|
|
|
return null;
|
|
|
|
*/
|
2021-06-27 20:44:35 +00:00
|
|
|
@Override // android.os.AsyncTask
|
2022-03-02 20:59:20 +00:00
|
|
|
/*
|
|
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
|
|
*/
|
2021-06-27 20:44:35 +00:00
|
|
|
public Void doInBackground(Object... objArr) {
|
|
|
|
List list = (List) objArr[0];
|
|
|
|
String str = (String) objArr[1];
|
|
|
|
try {
|
|
|
|
FileOutputStream openFileOutput = ActivityChooserModel.this.mContext.openFileOutput(str, 0);
|
|
|
|
XmlSerializer newSerializer = Xml.newSerializer();
|
|
|
|
try {
|
2022-03-02 20:59:20 +00:00
|
|
|
try {
|
|
|
|
try {
|
|
|
|
newSerializer.setOutput(openFileOutput, null);
|
|
|
|
newSerializer.startDocument(Constants.ENCODING, Boolean.TRUE);
|
|
|
|
newSerializer.startTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORDS);
|
|
|
|
int size = list.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
HistoricalRecord historicalRecord = (HistoricalRecord) list.remove(0);
|
|
|
|
newSerializer.startTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORD);
|
|
|
|
newSerializer.attribute(null, ActivityChooserModel.ATTRIBUTE_ACTIVITY, historicalRecord.activity.flattenToString());
|
|
|
|
newSerializer.attribute(null, "time", String.valueOf(historicalRecord.time));
|
|
|
|
newSerializer.attribute(null, ActivityChooserModel.ATTRIBUTE_WEIGHT, String.valueOf(historicalRecord.weight));
|
|
|
|
newSerializer.endTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORD);
|
|
|
|
}
|
|
|
|
newSerializer.endTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORDS);
|
|
|
|
newSerializer.endDocument();
|
|
|
|
ActivityChooserModel.this.mCanReadHistoricalData = true;
|
|
|
|
} catch (Throwable th) {
|
|
|
|
ActivityChooserModel.this.mCanReadHistoricalData = true;
|
|
|
|
if (openFileOutput != null) {
|
|
|
|
try {
|
|
|
|
openFileOutput.close();
|
|
|
|
} catch (IOException unused) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw th;
|
|
|
|
}
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
String str2 = ActivityChooserModel.LOG_TAG;
|
|
|
|
Log.e(str2, "Error writing historical record file: " + ActivityChooserModel.this.mHistoryFileName, e);
|
|
|
|
ActivityChooserModel.this.mCanReadHistoricalData = true;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
} catch (IOException e2) {
|
2021-06-27 20:44:35 +00:00
|
|
|
String str3 = ActivityChooserModel.LOG_TAG;
|
|
|
|
Log.e(str3, "Error writing historical record file: " + ActivityChooserModel.this.mHistoryFileName, e2);
|
|
|
|
ActivityChooserModel.this.mCanReadHistoricalData = true;
|
2022-03-02 20:59:20 +00:00
|
|
|
} catch (IllegalArgumentException e3) {
|
2021-06-27 20:44:35 +00:00
|
|
|
String str4 = ActivityChooserModel.LOG_TAG;
|
|
|
|
Log.e(str4, "Error writing historical record file: " + ActivityChooserModel.this.mHistoryFileName, e3);
|
|
|
|
ActivityChooserModel.this.mCanReadHistoricalData = true;
|
|
|
|
}
|
|
|
|
} catch (FileNotFoundException e4) {
|
|
|
|
String str5 = ActivityChooserModel.LOG_TAG;
|
|
|
|
Log.e(str5, "Error writing historical record file: " + str, e4);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private ActivityChooserModel(Context context, String str) {
|
|
|
|
this.mContext = context.getApplicationContext();
|
2021-08-09 22:50:01 +00:00
|
|
|
if (TextUtils.isEmpty(str) || str.endsWith(HISTORY_FILE_EXTENSION)) {
|
2021-06-27 20:44:35 +00:00
|
|
|
this.mHistoryFileName = str;
|
|
|
|
} else {
|
2021-11-08 18:25:28 +00:00
|
|
|
this.mHistoryFileName = a.v(str, HISTORY_FILE_EXTENSION);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean addHistoricalRecord(HistoricalRecord historicalRecord) {
|
|
|
|
boolean add = this.mHistoricalRecords.add(historicalRecord);
|
|
|
|
if (add) {
|
|
|
|
this.mHistoricalRecordsChanged = true;
|
|
|
|
pruneExcessiveHistoricalRecordsIfNeeded();
|
|
|
|
persistHistoricalDataIfNeeded();
|
|
|
|
sortActivitiesIfNeeded();
|
|
|
|
notifyChanged();
|
|
|
|
}
|
|
|
|
return add;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ensureConsistentState() {
|
|
|
|
boolean loadActivitiesIfNeeded = loadActivitiesIfNeeded() | readHistoricalDataIfNeeded();
|
|
|
|
pruneExcessiveHistoricalRecordsIfNeeded();
|
|
|
|
if (loadActivitiesIfNeeded) {
|
|
|
|
sortActivitiesIfNeeded();
|
|
|
|
notifyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ActivityChooserModel get(Context context, String str) {
|
|
|
|
ActivityChooserModel activityChooserModel;
|
|
|
|
synchronized (sRegistryLock) {
|
|
|
|
Map<String, ActivityChooserModel> map = sDataModelRegistry;
|
|
|
|
activityChooserModel = map.get(str);
|
|
|
|
if (activityChooserModel == null) {
|
|
|
|
activityChooserModel = new ActivityChooserModel(context, str);
|
|
|
|
map.put(str, activityChooserModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return activityChooserModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean loadActivitiesIfNeeded() {
|
|
|
|
if (!this.mReloadActivities || this.mIntent == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.mReloadActivities = false;
|
|
|
|
this.mActivities.clear();
|
|
|
|
List<ResolveInfo> queryIntentActivities = this.mContext.getPackageManager().queryIntentActivities(this.mIntent, 0);
|
|
|
|
int size = queryIntentActivities.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
this.mActivities.add(new ActivityResolveInfo(queryIntentActivities.get(i)));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void persistHistoricalDataIfNeeded() {
|
|
|
|
if (!this.mReadShareHistoryCalled) {
|
|
|
|
throw new IllegalStateException("No preceding call to #readHistoricalData");
|
|
|
|
} else if (this.mHistoricalRecordsChanged) {
|
|
|
|
this.mHistoricalRecordsChanged = false;
|
|
|
|
if (!TextUtils.isEmpty(this.mHistoryFileName)) {
|
|
|
|
new PersistHistoryAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new ArrayList(this.mHistoricalRecords), this.mHistoryFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pruneExcessiveHistoricalRecordsIfNeeded() {
|
|
|
|
int size = this.mHistoricalRecords.size() - this.mHistoryMaxSize;
|
|
|
|
if (size > 0) {
|
|
|
|
this.mHistoricalRecordsChanged = true;
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
this.mHistoricalRecords.remove(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean readHistoricalDataIfNeeded() {
|
|
|
|
if (!this.mCanReadHistoricalData || !this.mHistoricalRecordsChanged || TextUtils.isEmpty(this.mHistoryFileName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.mCanReadHistoricalData = false;
|
|
|
|
this.mReadShareHistoryCalled = true;
|
|
|
|
readHistoricalDataImpl();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void readHistoricalDataImpl() {
|
2022-03-02 20:59:20 +00:00
|
|
|
FileInputStream fileInputStream;
|
|
|
|
XmlPullParser newPullParser;
|
2021-06-27 20:44:35 +00:00
|
|
|
try {
|
|
|
|
try {
|
2022-03-02 20:59:20 +00:00
|
|
|
fileInputStream = this.mContext.openFileInput(this.mHistoryFileName);
|
|
|
|
try {
|
|
|
|
newPullParser = Xml.newPullParser();
|
|
|
|
newPullParser.setInput(fileInputStream, Constants.ENCODING);
|
|
|
|
for (int i = 0; i != 1 && i != 2; i = newPullParser.next()) {
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
String str = LOG_TAG;
|
|
|
|
Log.e(str, "Error reading historical recrod file: " + this.mHistoryFileName, e);
|
|
|
|
if (fileInputStream == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (XmlPullParserException e2) {
|
|
|
|
String str2 = LOG_TAG;
|
|
|
|
Log.e(str2, "Error reading historical recrod file: " + this.mHistoryFileName, e2);
|
|
|
|
if (fileInputStream == null) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2021-08-09 22:50:01 +00:00
|
|
|
if (TAG_HISTORICAL_RECORDS.equals(newPullParser.getName())) {
|
2021-06-27 20:44:35 +00:00
|
|
|
List<HistoricalRecord> list = this.mHistoricalRecords;
|
|
|
|
list.clear();
|
|
|
|
while (true) {
|
|
|
|
int next = newPullParser.next();
|
|
|
|
if (next == 1) {
|
2022-03-02 20:59:20 +00:00
|
|
|
if (fileInputStream == null) {
|
2021-06-27 20:44:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (!(next == 3 || next == 4)) {
|
2021-08-09 22:50:01 +00:00
|
|
|
if (TAG_HISTORICAL_RECORD.equals(newPullParser.getName())) {
|
|
|
|
list.add(new HistoricalRecord(newPullParser.getAttributeValue(null, ATTRIBUTE_ACTIVITY), Long.parseLong(newPullParser.getAttributeValue(null, "time")), Float.parseFloat(newPullParser.getAttributeValue(null, ATTRIBUTE_WEIGHT))));
|
2021-06-27 20:44:35 +00:00
|
|
|
} else {
|
|
|
|
throw new XmlPullParserException("Share records file not well-formed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new XmlPullParserException("Share records file does not start with historical-records tag.");
|
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
} catch (FileNotFoundException unused) {
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (fileInputStream != null) {
|
|
|
|
try {
|
|
|
|
fileInputStream.close();
|
|
|
|
} catch (IOException unused2) {
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean sortActivitiesIfNeeded() {
|
|
|
|
if (this.mActivitySorter == null || this.mIntent == null || this.mActivities.isEmpty() || this.mHistoricalRecords.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.mActivitySorter.sort(this.mIntent, this.mActivities, Collections.unmodifiableList(this.mHistoricalRecords));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Intent chooseActivity(int i) {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
if (this.mIntent == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
ensureConsistentState();
|
|
|
|
ActivityInfo activityInfo = this.mActivities.get(i).resolveInfo.activityInfo;
|
|
|
|
ComponentName componentName = new ComponentName(activityInfo.packageName, activityInfo.name);
|
|
|
|
Intent intent = new Intent(this.mIntent);
|
|
|
|
intent.setComponent(componentName);
|
|
|
|
if (this.mActivityChoserModelPolicy != null) {
|
|
|
|
if (this.mActivityChoserModelPolicy.onChooseActivity(this, new Intent(intent))) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addHistoricalRecord(new HistoricalRecord(componentName, System.currentTimeMillis(), 1.0f));
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResolveInfo getActivity(int i) {
|
|
|
|
ResolveInfo resolveInfo;
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
ensureConsistentState();
|
|
|
|
resolveInfo = this.mActivities.get(i).resolveInfo;
|
|
|
|
}
|
|
|
|
return resolveInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getActivityCount() {
|
|
|
|
int size;
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
ensureConsistentState();
|
|
|
|
size = this.mActivities.size();
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getActivityIndex(ResolveInfo resolveInfo) {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
ensureConsistentState();
|
|
|
|
List<ActivityResolveInfo> list = this.mActivities;
|
|
|
|
int size = list.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
if (list.get(i).resolveInfo == resolveInfo) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResolveInfo getDefaultActivity() {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
ensureConsistentState();
|
|
|
|
if (this.mActivities.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this.mActivities.get(0).resolveInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHistoryMaxSize() {
|
|
|
|
int i;
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
i = this.mHistoryMaxSize;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHistorySize() {
|
|
|
|
int size;
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
ensureConsistentState();
|
|
|
|
size = this.mHistoricalRecords.size();
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Intent getIntent() {
|
|
|
|
Intent intent;
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
intent = this.mIntent;
|
|
|
|
}
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setActivitySorter(ActivitySorter activitySorter) {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
if (this.mActivitySorter != activitySorter) {
|
|
|
|
this.mActivitySorter = activitySorter;
|
|
|
|
if (sortActivitiesIfNeeded()) {
|
|
|
|
notifyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultActivity(int i) {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
ensureConsistentState();
|
|
|
|
ActivityResolveInfo activityResolveInfo = this.mActivities.get(i);
|
|
|
|
ActivityResolveInfo activityResolveInfo2 = this.mActivities.get(0);
|
|
|
|
float f = activityResolveInfo2 != null ? (activityResolveInfo2.weight - activityResolveInfo.weight) + 5.0f : 1.0f;
|
|
|
|
ActivityInfo activityInfo = activityResolveInfo.resolveInfo.activityInfo;
|
|
|
|
addHistoricalRecord(new HistoricalRecord(new ComponentName(activityInfo.packageName, activityInfo.name), System.currentTimeMillis(), f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHistoryMaxSize(int i) {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
if (this.mHistoryMaxSize != i) {
|
|
|
|
this.mHistoryMaxSize = i;
|
|
|
|
pruneExcessiveHistoricalRecordsIfNeeded();
|
|
|
|
if (sortActivitiesIfNeeded()) {
|
|
|
|
notifyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIntent(Intent intent) {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
if (this.mIntent != intent) {
|
|
|
|
this.mIntent = intent;
|
|
|
|
this.mReloadActivities = true;
|
|
|
|
ensureConsistentState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnChooseActivityListener(OnChooseActivityListener onChooseActivityListener) {
|
|
|
|
synchronized (this.mInstanceLock) {
|
|
|
|
this.mActivityChoserModelPolicy = onChooseActivityListener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|