version:1.3
fix: update:sos界面拨打所有电话
This commit is contained in:
@@ -13,14 +13,24 @@ import android.util.Log;
|
||||
|
||||
import com.uiui.os.BuildConfig;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class APKUtils {
|
||||
private static String[] excludePackageName = {BuildConfig.APPLICATION_ID};
|
||||
private static HashSet<String> excludePackageName = new HashSet<String>() {{
|
||||
this.add(BuildConfig.APPLICATION_ID);
|
||||
this.add("org.chromium.browser");
|
||||
this.add("com.sprd.sprdnote");
|
||||
this.add("com.android.deskclock");
|
||||
this.add("com.alldocube.store");
|
||||
}};
|
||||
private static String TAG = APKUtils.class.getSimpleName();
|
||||
|
||||
|
||||
public static ArrayList<ApplicationInfo> queryFilterAppInfo(Context context) {
|
||||
@@ -37,6 +47,7 @@ public class APKUtils {
|
||||
List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);
|
||||
Set<String> allowPackages = new HashSet();
|
||||
for (ResolveInfo resolveInfo : resolveinfoList) {
|
||||
Log.i(TAG, "queryFilterAppInfo: " + resolveInfo.activityInfo.packageName);
|
||||
allowPackages.add(resolveInfo.activityInfo.packageName);
|
||||
}
|
||||
|
||||
@@ -48,11 +59,28 @@ public class APKUtils {
|
||||
// if(app.uid > 10000){//通过uid排除系统应用,在一些手机上效果不好
|
||||
// applicationInfos.add(app);
|
||||
// }
|
||||
if (allowPackages.contains(app.packageName) && !Arrays.asList(excludePackageName).contains(app.packageName)) {
|
||||
if (allowPackages.contains(app.packageName) && !excludePackageName.contains(app.packageName)) {
|
||||
// if (allowPackages.contains(app.packageName)) {
|
||||
applicationInfos.add(app);
|
||||
}
|
||||
}
|
||||
applicationInfos.sort(new Comparator<ApplicationInfo>() {
|
||||
@Override
|
||||
public int compare(ApplicationInfo o1, ApplicationInfo o2) {
|
||||
return Collator.getInstance(Locale.CHINESE).compare(o1.loadLabel(pm).toString(),o2.loadLabel(pm).toString());
|
||||
// return o1.loadLabel(pm).toString().compareTo(o2.loadLabel(pm).toString());
|
||||
}
|
||||
});
|
||||
applicationInfos.sort(new Comparator<ApplicationInfo>() {
|
||||
@Override
|
||||
public int compare(ApplicationInfo o1, ApplicationInfo o2) {
|
||||
if ((o1.flags & ApplicationInfo.FLAG_SYSTEM) <= (o2.flags & ApplicationInfo.FLAG_SYSTEM)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
return applicationInfos;
|
||||
}
|
||||
|
||||
@@ -180,4 +208,15 @@ public class APKUtils {
|
||||
return versionName;
|
||||
}
|
||||
|
||||
public static String getAppNameByPackage(Context context, String pkg) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
try {
|
||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(pkg, PackageManager.GET_META_DATA);
|
||||
String packageName = packageManager.getApplicationLabel(applicationInfo).toString();
|
||||
return packageName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
169
app/src/main/java/com/uiui/os/utils/AppUsedTimeUtils.java
Normal file
169
app/src/main/java/com/uiui/os/utils/AppUsedTimeUtils.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package com.uiui.os.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class AppUsedTimeUtils {
|
||||
private static final String TAG = AppUsedTimeUtils.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static AppUsedTimeUtils sInstance;
|
||||
private Context mContext;
|
||||
|
||||
private SimpleDateFormat ruleSDF = new SimpleDateFormat("HH:mm:ss");
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private AppTimeinfo appTimeinfo;
|
||||
|
||||
private AppUsedTimeUtils(Context context) {
|
||||
this.mContext = context;
|
||||
appTimeinfo = getAppTimeinfo();
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AppUsedTimeUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static AppUsedTimeUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init TimeUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private static String normalStartTime = "8:00:00";
|
||||
private static String unusualStartTime = "22:00:00";
|
||||
|
||||
static class AppTimeinfo implements Serializable {
|
||||
private static final long serialVersionUID = 5373751133823666192L;
|
||||
|
||||
AppTimeinfo() {
|
||||
this.appPackageName = "";
|
||||
this.endTime = 0;
|
||||
this.startTime = 0;
|
||||
}
|
||||
|
||||
private String appPackageName;
|
||||
private long endTime;
|
||||
private long startTime;
|
||||
|
||||
public String getAppPackageName() {
|
||||
return appPackageName;
|
||||
}
|
||||
|
||||
public void setAppPackageName(String appPackageName) {
|
||||
this.appPackageName = appPackageName;
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(long endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public void setAppPackageName(String name) {
|
||||
appTimeinfo.setAppPackageName(name);
|
||||
setAppTimeinfo();
|
||||
}
|
||||
|
||||
synchronized public String getAppPackageName() {
|
||||
return appTimeinfo.getAppPackageName();
|
||||
}
|
||||
|
||||
synchronized public void setStartTime(long time) {
|
||||
appTimeinfo.setStartTime(time);
|
||||
setAppTimeinfo();
|
||||
}
|
||||
|
||||
synchronized public long getStartTime() {
|
||||
return appTimeinfo.getStartTime();
|
||||
}
|
||||
|
||||
synchronized public void setEndTime(long time) {
|
||||
appTimeinfo.setEndTime(time);
|
||||
setAppTimeinfo();
|
||||
}
|
||||
|
||||
synchronized public long getEndTime() {
|
||||
return appTimeinfo.getEndTime();
|
||||
}
|
||||
|
||||
synchronized private AppTimeinfo getAppTimeinfo() {
|
||||
String jsonString = Settings.System.getString(mContext.getContentResolver(), "runningAppInfo");
|
||||
if (TextUtils.isEmpty(jsonString)) {
|
||||
return new AppTimeinfo();
|
||||
}
|
||||
Log.e(TAG, "getAppTimeinfo: " + jsonString);
|
||||
Type type = new TypeToken<AppTimeinfo>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
AppTimeinfo appTimeinfo = gson.fromJson(jsonString, type);
|
||||
return appTimeinfo;
|
||||
}
|
||||
|
||||
synchronized private void setAppTimeinfo() {
|
||||
String jsonString = JsonParser.parseString(appTimeinfo.toString()).getAsJsonObject().toString();
|
||||
Settings.System.putString(mContext.getContentResolver(), "runningAppInfo", jsonString);
|
||||
}
|
||||
|
||||
private static final long DAY_TIME = 1000 * 60 * 60 * 24;
|
||||
|
||||
public boolean isNormalTime() {
|
||||
long nowTime = System.currentTimeMillis();
|
||||
String nowTimeString = ruleSDF.format(new Date(nowTime)); // 时间戳转换日期
|
||||
try {
|
||||
Date startDate = ruleSDF.parse(normalStartTime);
|
||||
Date endDate = ruleSDF.parse(unusualStartTime);
|
||||
Date now = ruleSDF.parse(nowTimeString);
|
||||
Log.e(TAG, "isScreenshot: startDate = " + startDate);
|
||||
Log.e(TAG, "isScreenshot: endDate = " + endDate);
|
||||
Log.e(TAG, "isScreenshot: now = " + now);
|
||||
if (startDate.getTime() <= now.getTime() && now.getTime() <= endDate.getTime()) {
|
||||
return true;
|
||||
} else if (endDate.getTime() < now.getTime() && now.getTime() <= startDate.getTime() + DAY_TIME) {
|
||||
return false;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "isScreenshot: " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class IconUtils {
|
||||
this.add("com.android.dialer");//电话
|
||||
this.add("com.android.gallery3d");//图库
|
||||
this.add("com.android.mms.ui");//信息
|
||||
this.add("com.android.messaging");//信息
|
||||
this.add("com.android.music");//音乐
|
||||
this.add("com.android.providers.downloads.ui");//下载
|
||||
this.add("com.android.quicksearchbox");//搜索
|
||||
@@ -45,6 +46,7 @@ public class IconUtils {
|
||||
this.add("com_android_dialer");
|
||||
this.add("com_android_gallery3d_app");
|
||||
this.add("com_android_mms_ui");
|
||||
this.add("com_android_mms_ui");
|
||||
this.add("com_android_music");
|
||||
this.add("com_android_providers_downloads_ui");
|
||||
this.add("com_android_quicksearchbox");
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package com.uiui.os.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class TimeUtils {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static TimeUtils sInstance;
|
||||
private Context mContext;
|
||||
|
||||
private SimpleDateFormat ruleSDF = new SimpleDateFormat("HH:mm:ss");
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private String TAG = TimeUtils.class.getSimpleName();
|
||||
|
||||
private TimeUtils(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new TimeUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static TimeUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init TimeUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private static String normalStartTime = "8:00:00";
|
||||
private static String unusualStartTime = "22:00:00";
|
||||
|
||||
private String appPackageName;
|
||||
private long endTime = 0;
|
||||
private long startTime = 0;
|
||||
|
||||
public void setAppPackageName(String name) {
|
||||
this.appPackageName = name;
|
||||
}
|
||||
|
||||
public String getAppPackageName() {
|
||||
return appPackageName;
|
||||
}
|
||||
|
||||
public void setStartTime(long time) {
|
||||
this.startTime = time;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setEndTime(long time) {
|
||||
this.endTime = time;
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
private static final long DAY_TIME = 1000 * 60 * 60 * 24;
|
||||
|
||||
public boolean isNormalTime() {
|
||||
long nowTime = System.currentTimeMillis();
|
||||
String nowTimeString = ruleSDF.format(new Date(nowTime)); // 时间戳转换日期
|
||||
try {
|
||||
Date startDate = ruleSDF.parse(normalStartTime);
|
||||
Date endDate = ruleSDF.parse(unusualStartTime);
|
||||
Date now = ruleSDF.parse(nowTimeString);
|
||||
Log.e(TAG, "isScreenshot: startDate = " + startDate);
|
||||
Log.e(TAG, "isScreenshot: endDate = " + endDate);
|
||||
Log.e(TAG, "isScreenshot: now = " + now);
|
||||
if (startDate.getTime() <= now.getTime() && now.getTime() <= endDate.getTime()) {
|
||||
return true;
|
||||
} else if (endDate.getTime() < now.getTime() && now.getTime() <= startDate.getTime() + DAY_TIME) {
|
||||
return false;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "isScreenshot: " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user