6.0.0 - 部分插件及工具版本更新
This commit is contained in:
@@ -2,19 +2,29 @@ package com.stardust.app
|
||||
|
||||
import android.app.AppOpsManager
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.KITKAT)
|
||||
fun Context.isOpPermissionGranted(permission: String): Boolean {
|
||||
val appOps = getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
|
||||
val mode = appOps.checkOpNoThrow(permission, android.os.Process.myUid(), packageName)
|
||||
|
||||
return if (mode == AppOpsManager.MODE_DEFAULT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
checkCallingOrSelfPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
return try {
|
||||
val packageManager: PackageManager = this.packageManager
|
||||
val applicationInfo: ApplicationInfo = packageManager.getApplicationInfo(this.packageName, 0)
|
||||
val appOpsManager: AppOpsManager = this.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
|
||||
val mode = if (Build.VERSION.SDK_INT >= 29 /* Build.VERSION_CODES.Q */) {
|
||||
appOpsManager.unsafeCheckOpNoThrow(permission, applicationInfo.uid, applicationInfo.packageName)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
appOpsManager.checkOpNoThrow(permission, applicationInfo.uid, applicationInfo.packageName)
|
||||
}
|
||||
mode == AppOpsManager.MODE_ALLOWED
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isUsageStatsPermissionGranted(): Boolean {
|
||||
return this.isOpPermissionGranted(AppOpsManager.OPSTR_GET_USAGE_STATS)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.stardust.app;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
@@ -20,9 +21,9 @@ public class FragmentPagerAdapterBuilder {
|
||||
void OnInstantiate(int pos, Fragment fragment);
|
||||
}
|
||||
|
||||
private List<Fragment> mFragments = new ArrayList<>();
|
||||
private List<String> mTitles = new ArrayList<>();
|
||||
private FragmentActivity mActivity;
|
||||
private final List<Fragment> mFragments = new ArrayList<>();
|
||||
private final List<String> mTitles = new ArrayList<>();
|
||||
private final FragmentActivity mActivity;
|
||||
|
||||
public FragmentPagerAdapterBuilder(FragmentActivity activity) {
|
||||
mActivity = activity;
|
||||
@@ -59,15 +60,16 @@ public class FragmentPagerAdapterBuilder {
|
||||
|
||||
public abstract static class StoredFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private SparseArray<Fragment> mStoredFragments = new SparseArray<>();
|
||||
private final SparseArray<Fragment> mStoredFragments = new SparseArray<>();
|
||||
private OnFragmentInstantiateListener mOnFragmentInstantiateListener;
|
||||
|
||||
public StoredFragmentPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
||||
Fragment fragment = (Fragment) super.instantiateItem(container, position);
|
||||
mStoredFragments.put(position, fragment);
|
||||
if(mOnFragmentInstantiateListener != null){
|
||||
@@ -78,7 +80,7 @@ public class FragmentPagerAdapterBuilder {
|
||||
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
mStoredFragments.remove(position);
|
||||
super.destroyItem(container, position, object);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.stardust.pio;
|
||||
|
||||
import android.app.NativeActivity;
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.util.Func1;
|
||||
|
||||
@@ -14,15 +12,12 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/1.
|
||||
@@ -30,8 +25,6 @@ import java.util.Locale;
|
||||
|
||||
public class PFiles {
|
||||
|
||||
private static final String TAG = "PFiles";
|
||||
|
||||
static final int DEFAULT_BUFFER_SIZE = 8192;
|
||||
static final String DEFAULT_ENCODING = Charset.defaultCharset().name();
|
||||
|
||||
@@ -313,16 +306,8 @@ public class PFiles {
|
||||
String fullAssetsPath = join(assetsDir, file);
|
||||
String[] children = manager.list(fullAssetsPath);
|
||||
if (children == null || children.length == 0) {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = manager.open(fullAssetsPath);
|
||||
try (InputStream stream = manager.open(fullAssetsPath)) {
|
||||
copyStream(stream, join(toDir, file));
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
copyAssetDir(manager, fullAssetsPath, join(toDir, file), children);
|
||||
@@ -460,12 +445,7 @@ public class PFiles {
|
||||
|
||||
public static String[] listDir(String path, final Func1<String, Boolean> filter) {
|
||||
final File file = new File(path);
|
||||
return wrapNonNull(file.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return filter.call(name);
|
||||
}
|
||||
}));
|
||||
return wrapNonNull(file.list((dir, name) -> filter.call(name)));
|
||||
}
|
||||
|
||||
public static boolean isFile(String path) {
|
||||
@@ -478,7 +458,7 @@ public class PFiles {
|
||||
|
||||
public static boolean isEmptyDir(String path) {
|
||||
File file = new File(path);
|
||||
return file.isDirectory() && file.list().length == 0;
|
||||
return file.isDirectory() && Objects.requireNonNull(file.list()).length == 0;
|
||||
}
|
||||
|
||||
public static String join(String base, String... paths) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.content.pm.ServiceInfo;
|
||||
import android.content.pm.Signature;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
@@ -19,6 +20,8 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import kotlin.text.Regex;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/5.
|
||||
*/
|
||||
@@ -26,8 +29,7 @@ import java.util.zip.ZipFile;
|
||||
public class DeveloperUtils {
|
||||
|
||||
private static final String PACKAGE_NAME = "org.autojs.autojs";
|
||||
private static final String SIGNATURE = "nPNPcy4Lk/eP6fLvZitP0VPbHdFCbKua77m59vis5fA=";
|
||||
private static final String LOG_TAG = "DeveloperUtils";
|
||||
private static final Regex SIGNATURE_REX = new Regex(".*(CbKua77m59vis|N7YkpKxKjsPWe).*");
|
||||
private static final ExecutorService sExecutor = UnderuseExecutors.getExecutor();
|
||||
private static final String SALT = "let\nlife\nbe\nbeautiful\nlike\nsummer\nflowers\nand\ndeath\nlike\nautumn\nleaves\n.";
|
||||
|
||||
@@ -80,7 +82,7 @@ public class DeveloperUtils {
|
||||
if (sha.endsWith("\n")) {
|
||||
sha = sha.substring(0, sha.length() - 1);
|
||||
}
|
||||
return SIGNATURE.equals(sha);
|
||||
return SIGNATURE_REX.matches(sha);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +152,7 @@ public class DeveloperUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyApk(Activity activity, final int crcRes) {
|
||||
public static void verifyApk(Activity activity) {
|
||||
final WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
|
||||
sExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
@@ -160,13 +162,7 @@ public class DeveloperUtils {
|
||||
return;
|
||||
if (!checkSignature(a)) {
|
||||
a.finish();
|
||||
return;
|
||||
}
|
||||
//long[] crc = readCrc(a.getString(crcRes));
|
||||
//if (!checkDexFile(a, crc)) {
|
||||
//a.finish();
|
||||
//}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,13 +8,41 @@ import android.util.SparseArray;
|
||||
import com.stardust.BuildConfig;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
|
||||
public final class ResourceMonitor {
|
||||
|
||||
private static final String LOG_TAG = "ResourceMonitor";
|
||||
|
||||
private static final ConcurrentHashMap<Class<?>, SparseArray<Exception>> mResources = new ConcurrentHashMap<>();
|
||||
// @Reference to TonyJiangWJ/Auto.js on Nov 22, 2021
|
||||
private static class LockedResource {
|
||||
private ReentrantLock lock;
|
||||
private SparseArray<Exception> resource;
|
||||
|
||||
public LockedResource() {
|
||||
this.resource = new SparseArray<>();
|
||||
this.lock = new ReentrantLock();
|
||||
}
|
||||
|
||||
public ReentrantLock getLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void setLock(ReentrantLock lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
public SparseArray<Exception> getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void setResource(SparseArray<Exception> resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<Class<?>, LockedResource> mResources = new ConcurrentHashMap<>();
|
||||
private static Handler sHandler;
|
||||
private static boolean sEnabled = BuildConfig.DEBUG;
|
||||
private static ExceptionCreator sExceptionCreator;
|
||||
@@ -32,9 +60,9 @@ public final class ResourceMonitor {
|
||||
if (!sEnabled) {
|
||||
return;
|
||||
}
|
||||
SparseArray<Exception> map = mResources.get(resource.getClass());
|
||||
LockedResource map = mResources.get(resource.getClass());
|
||||
if (map == null) {
|
||||
map = new SparseArray<>();
|
||||
map = new LockedResource();
|
||||
mResources.put(resource.getClass(), map);
|
||||
}
|
||||
int resourceId = resource.getResourceId();
|
||||
@@ -45,16 +73,20 @@ public final class ResourceMonitor {
|
||||
} else {
|
||||
exception = sExceptionCreator.create(resource);
|
||||
}
|
||||
map.put(resourceId, exception);
|
||||
map.getLock().lock();
|
||||
map.getResource().put(resourceId, exception);
|
||||
map.getLock().unlock();
|
||||
}
|
||||
|
||||
public static void onClose(ResourceMonitor.Resource resource) {
|
||||
if (!sEnabled) {
|
||||
return;
|
||||
}
|
||||
SparseArray map = mResources.get(resource.getClass());
|
||||
LockedResource map = mResources.get(resource.getClass());
|
||||
if (map != null) {
|
||||
map.remove(resource.getResourceId());
|
||||
map.getLock().lock();
|
||||
map.getResource().remove(resource.getResourceId());
|
||||
map.getLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +94,16 @@ public final class ResourceMonitor {
|
||||
if (!sEnabled) {
|
||||
return;
|
||||
}
|
||||
SparseArray<Exception> map = mResources.get(resource.getClass());
|
||||
LockedResource map = mResources.get(resource.getClass());
|
||||
if (map != null) {
|
||||
int indexOfKey = map.indexOfKey(resource.getResourceId());
|
||||
if (indexOfKey >= 0) {
|
||||
final Exception exception = map.valueAt(indexOfKey);
|
||||
map.removeAt(indexOfKey);
|
||||
map.getLock().lock();
|
||||
int indexOfKey = map.getResource().indexOfKey(resource.getResourceId());
|
||||
if (indexOfKey < 0) {
|
||||
map.getLock().unlock();
|
||||
} else {
|
||||
final Exception exception = map.getResource().valueAt(indexOfKey);
|
||||
map.getResource().removeAt(indexOfKey);
|
||||
map.getLock().unlock();
|
||||
if (sHandler == null) {
|
||||
sHandler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
@@ -3,9 +3,15 @@ package com.stardust.util;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.content.ContextWrapper;
|
||||
import android.graphics.Rect;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/24.
|
||||
@@ -19,7 +25,7 @@ public class ViewUtil {
|
||||
}
|
||||
|
||||
// FIXME: 2018/1/23 not working in some devices (https://github.com/hyb1996/Auto.js/issues/268)
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
public static int getStatusBarHeightLegacy(Context context) {
|
||||
int result = 0;
|
||||
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
@@ -28,6 +34,36 @@ public class ViewUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
Rect rectangle = new Rect();
|
||||
Window window = getWindowForContext(context);
|
||||
if (window == null) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, context.getResources().getDisplayMetrics());
|
||||
}
|
||||
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
|
||||
return rectangle.top;
|
||||
}
|
||||
|
||||
public static int getTitleBarHeight(Context context) {
|
||||
Window window = getWindowForContext(context);
|
||||
int contentViewTop = 0;
|
||||
if (window != null) {
|
||||
contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
|
||||
}
|
||||
return contentViewTop - getStatusBarHeight(context);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Window getWindowForContext(Context context) {
|
||||
if (context instanceof Activity) {
|
||||
return ((Activity) context).getWindow();
|
||||
}
|
||||
if (context instanceof ContextWrapper) {
|
||||
return getWindowForContext(((ContextWrapper) context).getBaseContext());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getScreenHeight(Activity activity) {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
|
||||
Reference in New Issue
Block a user