配置为本地开发用,同时修复资源回收的bug

This commit is contained in:
TonyJiangWJ 2019-12-16 10:51:37 +08:00
parent dbd71b8c0a
commit 84faf16a9d
10 changed files with 232 additions and 60 deletions

View File

@ -1,12 +1,6 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="RIGHT_MARGIN" value="100" />
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="android" withSubpackages="true" static="false" />
@ -30,38 +24,7 @@
</value>
</option>
</JavaCodeStyleSettings>
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
<XML>
<option name="XML_KEEP_LINE_BREAKS" value="false" />
<option name="XML_ALIGN_ATTRIBUTES" value="false" />
<option name="XML_SPACE_INSIDE_EMPTY_TAG" value="true" />
</XML>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>

View File

@ -1,7 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>

View File

@ -81,7 +81,10 @@ android {
buildConfigField "String", "CHANNEL", '"coolapk"'
}
}
// TensorFlow
aaptOptions {
noCompress "tflite"
}
}
@ -95,6 +98,9 @@ repositories {
}
dependencies {
// TensorFlow-lite
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1-alpha01', {
exclude group: 'com.android.support', module: 'support-annotations'
})

View File

@ -0,0 +1,7 @@
package org.autojs.autojs.tensorflow;
public class Demo {
public String getDemoResult() {
return "Hello Demo.";
}
}

View File

@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":455,"versionName":"4.1.0 Alpha5","enabled":true,"outputFile":"commonRelease-4.1.0 Alpha5.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.1.0 Alpha5.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"FULL_SPLIT","splits":[{"filterType":"ABI","value":"armeabi-v7a"}],"versionCode":461,"versionName":"4.1.1 Alpha2","enabled":true,"filterName":"armeabi-v7a","outputFile":"app-common-armeabi-v7a-release.apk","fullName":"commonArmeabi-v7aRelease","baseName":"common-armeabi-v7a-release"},"path":"app-common-armeabi-v7a-release.apk","properties":{}},{"outputType":{"type":"APK"},"apkInfo":{"type":"FULL_SPLIT","splits":[{"filterType":"ABI","value":"x86"}],"versionCode":461,"versionName":"4.1.1 Alpha2","enabled":true,"filterName":"x86","outputFile":"app-common-x86-release.apk","fullName":"commonX86Release","baseName":"common-x86-release"},"path":"app-common-x86-release.apk","properties":{}}]

View File

@ -8,13 +8,45 @@ 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<>();
private static class LockedResource {
private ReentrantLock lock;
private SparseArray<Exception> resource;
public LockedResource() {
this.resource = new SparseArray<>();
this.lock = new ReentrantLock();
}
public LockedResource(SparseArray<Exception> resource) {
this.resource = resource;
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 +64,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 +77,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 +98,14 @@ 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());
map.getLock().lock();
int indexOfKey = map.getResource().indexOfKey(resource.getResourceId());
if (indexOfKey >= 0) {
final Exception exception = map.valueAt(indexOfKey);
map.removeAt(indexOfKey);
final Exception exception = map.getResource().valueAt(indexOfKey);
map.getResource().removeAt(indexOfKey);
map.getLock().unlock();
if (sHandler == null) {
sHandler = new Handler(Looper.getMainLooper());
}
@ -84,6 +122,7 @@ public final class ResourceMonitor {
}
});
}
}
}

View File

@ -0,0 +1,163 @@
package com.stardust.util;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.SparseArray;
import com.stardust.BuildConfig;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
public final class ResourceMonitorFixed {
private static final String LOG_TAG = "ResourceMonitor";
private static class LockedResource {
private ReentrantLock lock;
private SparseArray<Exception> resource;
public LockedResource() {
this.resource = new SparseArray<>();
this.lock = new ReentrantLock();
}
public LockedResource(SparseArray<Exception> resource) {
this.resource = resource;
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;
private static UnclosedResourceDetectedHandler sUnclosedResourceDetectedHandler;
public static void setExceptionCreator(ExceptionCreator exceptionCreator) {
sExceptionCreator = exceptionCreator;
}
public static void setUnclosedResourceDetectedHandler(UnclosedResourceDetectedHandler unclosedResourceDetectedHandler) {
sUnclosedResourceDetectedHandler = unclosedResourceDetectedHandler;
}
public static void onOpen(ResourceMonitorFixed.Resource resource) {
if (!sEnabled) {
return;
}
LockedResource map = mResources.get(resource.getClass());
if (map == null) {
map = new LockedResource();
mResources.put(resource.getClass(), map);
}
int resourceId = resource.getResourceId();
Exception exception;
if (sExceptionCreator == null) {
exception = new ResourceMonitorFixed.UnclosedResourceException(resource);
exception.fillInStackTrace();
} else {
exception = sExceptionCreator.create(resource);
}
map.getLock().lock();
map.getResource().put(resourceId, exception);
map.getLock().unlock();
}
public static void onClose(ResourceMonitorFixed.Resource resource) {
if (!sEnabled) {
return;
}
LockedResource map = mResources.get(resource.getClass());
if (map != null) {
map.getLock().lock();
map.getResource().remove(resource.getResourceId());
map.getLock().unlock();
}
}
public static void onFinalize(ResourceMonitorFixed.Resource resource) {
if (!sEnabled) {
return;
}
LockedResource map = mResources.get(resource.getClass());
if (map != null) {
map.getLock().lock();
int indexOfKey = map.getResource().indexOfKey(resource.getResourceId());
if (indexOfKey >= 0) {
final Exception exception = map.getResource().valueAt(indexOfKey);
map.getResource().removeAt(indexOfKey);
map.getLock().unlock();
if (sHandler == null) {
sHandler = new Handler(Looper.getMainLooper());
}
sHandler.post(new Runnable() {
public final void run() {
UnclosedResourceDetectedException detectedException = new UnclosedResourceDetectedException(exception);
detectedException.fillInStackTrace();
Log.w(LOG_TAG, "UnclosedResourceDetected", detectedException);
if (sUnclosedResourceDetectedHandler != null) {
sUnclosedResourceDetectedHandler.onUnclosedResourceDetected(detectedException);
} else {
throw detectedException;
}
}
});
}
}
}
public static boolean isEnabled() {
return sEnabled;
}
public static void setEnabled(boolean mEnabled) {
ResourceMonitorFixed.sEnabled = mEnabled;
}
public static final class UnclosedResourceException extends RuntimeException {
public UnclosedResourceException(Resource resource) {
super("id = " + resource.getResourceId() + ", resource = " + resource);
}
}
public static final class UnclosedResourceDetectedException extends RuntimeException {
public UnclosedResourceDetectedException(Throwable cause) {
super(cause);
}
}
public interface Resource {
int getResourceId();
}
public interface ExceptionCreator {
Exception create(Resource resource);
}
public interface UnclosedResourceDetectedHandler {
void onUnclosedResourceDetected(UnclosedResourceDetectedException detectedException);
}
}

View File

@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"FULL_SPLIT","splits":[{"filterType":"ABI","value":"armeabi-v7a"}],"versionCode":461,"versionName":"4.1.1 Alpha2","enabled":true,"filterName":"armeabi-v7a","outputFile":"app-coolapk-armeabi-v7a-release.apk","fullName":"coolapkArmeabi-v7aRelease","baseName":"coolapk-armeabi-v7a-release"},"path":"app-coolapk-armeabi-v7a-release.apk","properties":{}},{"outputType":{"type":"APK"},"apkInfo":{"type":"FULL_SPLIT","splits":[{"filterType":"ABI","value":"x86"}],"versionCode":461,"versionName":"4.1.1 Alpha2","enabled":true,"filterName":"x86","outputFile":"app-coolapk-x86-release.apk","fullName":"coolapkX86Release","baseName":"coolapk-x86-release"},"path":"app-coolapk-x86-release.apk","properties":{}}]

View File

@ -13,10 +13,10 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Mon Jan 23 10:16:46 CST 2017
#systemProp.https.proxyPort=1080
#systemProp.http.proxyHost=127.0.0.1
org.gradle.jvmargs=-Xms8192m -Xmx8192m -Dfile.encoding=UTF-8
#systemProp.https.proxyHost=127.0.0.1
#systemProp.http.proxyPort=1080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
android.useAndroidX=true
android.enableJetifier=true