android 12 修改File.java 不生效的问题
2022-06-25 本文已影响0人
gale_小米
.客户需求调整内存大小的数值,之前再11上改过是生效的。
1.系统设置里面的数值修改
Index: libcore/ojluni/src/main/java/java/io/File.java
===================================================================
@@ -37,6 +37,9 @@
import java.nio.file.FileSystems;
import sun.security.action.GetPropertyAction;
+import java.lang.StackTraceElement;
+import java.lang.Thread;
+
// Android-added: Info about UTF-8 usage in filenames.
/**
* An abstract representation of file and directory pathnames.
@@ -1780,7 +1783,20 @@
if (isInvalid()) {
return 0L;
}
- return fs.getSpace(this, FileSystem.SPACE_TOTAL);
+ long GB_64 = 60*1000*1000*1001L;
+ StackTraceElement[] stacks = Thread.currentThread().getStackTrace();
+ for(StackTraceElement s: stacks){
+ if(s.getClassName().contains("com.inkwired")){
+ GB_64 = 64*1024*1024*1024L;
+ break;
+ }
+ }
+ long mFakeTotal = fs.getSpace(this, FileSystem.SPACE_TOTAL);
+ long GB_25 = 20*1024*1024*1024L;
+ if(mFakeTotal>GB_25 && mFakeTotal<GB_64 && ( path.contains("/data") || path.contains("storage/emulated"))){
+ mFakeTotal = GB_64;
+ }
+ return mFakeTotal;
}
/**
@@ -1865,7 +1881,12 @@
if (isInvalid()) {
return 0L;
}
- return fs.getSpace(this, FileSystem.SPACE_USABLE);
+ long mFakeTotal = fs.getSpace(this, FileSystem.SPACE_TOTAL);
+ long userable=fs.getSpace(this, FileSystem.SPACE_USABLE);
+ long realuser=mFakeTotal-userable;
+ long mytotal=getTotalSpace();
+ return mytotal-realuser;
+ //return fs.getSpace(this, FileSystem.SPACE_USABLE);
}
2.第三方应用调用
/* -- Temporary files -- */
Index: frameworks/base/core/java/android/os/StatFs.java
===================================================================
@@ -21,6 +21,10 @@
import android.system.Os;
import android.system.StructStatVfs;
+import android.util.Log;
+
+import java.lang.StackTraceElement;
+import java.lang.Thread;
/**
* Retrieve overall information about the space on a filesystem. This is a
* wrapper for Unix statvfs().
@@ -28,6 +32,7 @@
public class StatFs {
@UnsupportedAppUsage
private StructStatVfs mStat;
+ private static final String TAG = "StatFs";
/**
* Construct a new StatFs for looking at the stats of the filesystem at
@@ -47,8 +52,32 @@
* @throws IllegalArgumentException if the file system access fails
*/
private static StructStatVfs doStat(String path) {
- try {
- return Os.statvfs(path);
+ try {
+ StructStatVfs mStatVfs = Os.statvfs(path);
+ long GB_64=60*1000*1000*1001L;
+ StackTraceElement[] stacks = Thread.currentThread().getStackTrace();
+ for(StackTraceElement s: stacks){
+ if (s.getClassName().contains("com.finalwire") && path.contains("storage")){
+ return mStatVfs;
+ } else if(s.getClassName().contains("com.finalwire")&& !path.contains("storage")){
+ GB_64 = 64*1024*1024*1024L;
+ break;
+ }
+ //Log.i(TAG,"----------StackTraceElement------GB_64--"+GB_64+"----"+s.getMethodName()+"--------"+s.getClassName());
+ }
+
+ long mFakeTotal = mStatVfs.f_blocks * mStatVfs.f_frsize;
+ long GB_25 = 20*1024*1024*1024L;
+ long avail=mStatVfs.f_bavail * mStatVfs.f_frsize;
+ long usered=mFakeTotal-avail;
+ long my_zaival=(GB_64-usered)/mStatVfs.f_frsize;
+ if(mFakeTotal>GB_25 && mFakeTotal<GB_64 && ( path.contains("/data") || path.contains("storage/emulated"))){
+ mFakeTotal = GB_64;
+ StructStatVfs mStatVfs2 = new StructStatVfs(mStatVfs.f_bsize, mStatVfs.f_frsize, mFakeTotal/mStatVfs.f_frsize, mStatVfs.f_bfree, my_zaival,
+ mStatVfs.f_files, mStatVfs.f_ffree, mStatVfs.f_favail, mStatVfs.f_fsid, mStatVfs.f_flag, mStatVfs.f_namemax);
+ return mStatVfs2;
+ }
+ return mStatVfs;
} catch (ErrnoException e) {
throw new IllegalArgumentException("Invalid path: " + path, e);
}
3.连接电脑显示
Index: frameworks/av/media/mtp/MtpStorage.cpp
===================================================================
@@ -65,6 +65,9 @@
return -1;
mMaxCapacity = (uint64_t)stat.f_blocks * (uint64_t)stat.f_bsize;
}
+ if(!mRemovable){
+ mMaxCapacity=(uint64_t)64*1024*1024*1024;
+ }
return mMaxCapacity;
}
@@ -72,7 +75,12 @@
struct statfs stat;
if (statfs(getPath(), &stat))
return -1;
- return (uint64_t)stat.f_bavail * (uint64_t)stat.f_bsize;
+ //return (uint64_t)stat.f_bavail * (uint64_t)stat.f_bsize;
+ if(!mRemovable){
+ return (uint64_t)64*1024*1024*1024-((uint64_t)stat.f_blocks * (uint64_t)stat.f_bsize - (uint64_t)stat.f_bavail * (uint64_t)stat.f_bsize);
+ }else{
+ return (uint64_t)stat.f_bavail * (uint64_t)stat.f_bsize;
+ }
}
const char* MtpStorage::getDescription() const {
但是在Android 12上File.java文件修改不生效的
libcore\ojluni\src\main\java\java\io\File.java
直接修改这个文件发现修改不生效,那么很大可能就是没有编译,如是直接新增了一个测试方法,
public long getTotalSpace2() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("getFileSystemAttributes"));
sm.checkRead(path);
}
if (isInvalid()) {
return 0L;
}
return GB_64;
}
有报错,那就说明文件已经被编译了,那么问题就是代码被编译了,但是没有被引用;
libcore/ojluni/src/main/java/java/util/AbstractSequentialList.java:242: warning: Method java.util.AbstractSequentialList.listIterator has changed 'abstract' qualifier [ChangedAbstract]
[ 30% 1410/4674] //libcore:art.module.public.api.stubs.source check current API
FAILED: out/soong/.intermediates/libcore/art.module.public.api.stubs.source/android_common/metalava/check_current_api.timestamp
( true && diff -u -F '{ *$' libcore/api/current.txt out/soong/.intermediates/libcore/art.module.public.api.stubs.source/android_common/metalava/art.module.public.api.stubs.source_api.txt && diff -u -F '{ *$' libcore/api/removed.txt out/soong/.intermediates/libcore/art.module.public.api.stubs.source/android_common/metalava/art.module.public.api.stubs.source_removed.txt && touch out/soong/.intermediates/libcore/art.module.public.api.stubs.source/android_common/metalava/check_current_api.timestamp ) || ( echo -e "\n******************************\nYou have tried to change the API from what has been previously approved.\n\nTo make these errors go away, you have two choices:\n 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n to the new methods, etc. shown in the above diff.\n\n 2. You can update current.txt and/or removed.txt by executing the following command:\n m art.module.public.api.stubs.source-update-current-api\n\n To submit the revised current.txt to the main Android repository,\n you will need approval.\n******************************\n" ; exit 38 ) # hash of input list: f41cb0b11921a65a9aee36669b12258d2f9af38cbe4c3f73dbe991055e23c9ae
--- libcore/api/current.txt 2022-05-26 21:58:01.678639210 +0800
+++ out/soong/.intermediates/libcore/art.module.public.api.stubs.source/android_common/metalava/art.module.public.api.stubs.source_api.txt 2022-06-24 15:18:48.545468984 +0800
@@ -1490,6 +1490,7 @@ public class File implements java.lang.C
method @Nullable public java.io.File getParentFile();
method @NonNull public String getPath();
method public long getTotalSpace();
+ method public long getTotalSpace1();
method public long getUsableSpace();
method public boolean isAbsolute();
method public boolean isDirectory();
-e
******************************
You have tried to change the API from what has been previously approved.
To make these errors go away, you have two choices:
1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)
to the new methods, etc. shown in the above diff.
2. You can update current.txt and/or removed.txt by executing the following command:
m art.module.public.api.stubs.source-update-current-api
To submit the revised current.txt to the main Android repository,
you will need approval.
******************************
[ 30% 1416/4674] //frameworks/base:test-api-stubs-docs-non-updatable metalava merged
frameworks/base/core/java/android/os/PackageTagsList.java:111: info: Method can be invoked as a "in" operator from Kotlin: `contains` (this is usually desirable; just make sure it makes sense for this type of object) [KotlinOperator]
15:19:49 ninja failed with: exit status 1
#### failed to build some targets (08:35 (mm:ss)) ####
1.那就去查找Android.mk、Android.bp grep "File.java" * -Rn
openjdk_java_files.bp:37: "ojluni/src/main/java/java/io/File.java",
openjdk_java_files.bp:81: "ojluni/src/main/java/java/io/RandomAccessFile.java",
打开搜索到的文件libcore/openjdk_java_files.bp
filegroup {//文件组
name: "openjdk_javadoc_files",
srcs: [
...
"ojluni/src/main/java/java/io/File.java",
...
],
path: "ojluni/src/main/java",//路径
}
然后搜索openjdk_javadoc_files ,JavaLibrary.bp
// OpenJDK source is not annotated with @hide so we need this separate
// filegroup for just the parts that contribute to the API.
filegroup {
name: "core_oj_api_files",
srcs: [":openjdk_javadoc_files"],
}
// The source files that go into core-oj.
filegroup {
name: "core_oj_java_files",
visibility: [
"//libcore:__subpackages__",
],
srcs: [":openjdk_java_files"],
}
// Contains the parts of core library associated with OpenJDK.
java_library {
name: "core-oj",
visibility: [
"//art/build/apex",
"//art/build/sdk",
"//external/wycheproof",
"//libcore/benchmarks",
"//packages/modules/ArtPrebuilt",
],
apex_available: [
"com.android.art",
"com.android.art.debug",
],
defaults: ["libcore_java_defaults"],
installable: true,
hostdex: true,
srcs: [":core_oj_java_files"],
java_resources: core_resources,
sdk_version: "none",
system_modules: "core-all-system-modules",
patch_module: "java.base",
jacoco: {
exclude_filter: [
"java.lang.Class",
"java.lang.Long",
"java.lang.Number",
"java.lang.Object",
"java.lang.String",
"java.lang.invoke.MethodHandle",
"java.lang.ref.Reference",
"java.lang.reflect.Proxy",
"java.util.AbstractMap",
"java.util.HashMap",
"java.util.HashMap$Node",
"java.util.Map",
],
},
notice: "ojluni/NOTICE",
hiddenapi_additional_annotations: [
"core-oj-hiddenapi-annotations",
],
}
.find . -name "core-oj.jar"
./prebuilts/module_sdk/art/current/sdk/java/core-oj.jar
./out/soong/H20_EEA/dex_artjars_input/core-oj.jar
./out/soong/.intermediates/vendor/partner_modules/ArtPrebuilt/com.google.android.art.deapexer/android_common/deapexer/javalib/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/dex-withres/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/withres/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/dex-withres-aligned/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/res/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/javac/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/turbine/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/turbine-combined/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/aligned/core-oj.jar
./out/soong/.intermediates/libcore/core-oj/android_common_apex31/dex/core-oj.jar
./out/soong/.intermediates/art/build/apex/com.android.art/android_common_com.android.art_image/image.apex/javalib/core-oj.jar
./out/soong/.intermediates/art/build/boot/art-bootclasspath-fragment/android_common_apex31/hiddenapi-modular/encoded/unaligned/core-oj.jar
./out/soong/.intermediates/art/build/boot/art-bootclasspath-fragment/android_common_apex31/hiddenapi-modular/encoded/core-oj.jar
./out/target/product/H20_EEA/apex/com.android.art/javalib/core-oj.jar
从上面的搜索信息来看是在art里面
//art/build/apex/Android.bp
// Core Java libraries.
libcore_java_libs = [
"core-oj",
"core-libart",
"okhttp",
"bouncycastle",
"apache-xml",
]
// Default values shared by device ART APEXes.
apex_defaults {
name: "com.android.art-device-defaults",
defaults: ["com.android.art-defaults"],
compile_multilib: "both",
manifest: "manifest-art.json",
bootclasspath_fragments: ["art-bootclasspath-fragment"],
compat_configs: ["libcore-platform-compat-config"],
java_libs: libcore_java_libs,
native_shared_libs: art_runtime_base_native_shared_libs +
art_runtime_base_native_device_only_shared_libs +
libcore_native_shared_libs,
multilib: {
both: {
binaries: art_runtime_base_binaries_both +
art_runtime_base_binaries_both_on_device_first_on_host,
},
first: {
binaries: art_runtime_base_binaries_first_on_device_first_on_host +
art_tools_common_binaries +
art_tools_device_only_binaries,
},
},
key: "com.android.art.key",
required: [
"com.android.i18n",
],
prebuilts: [
"art-linker-config",
"current_sdkinfo",
],
// ART APEXes depend on bouncycastle which is disabled for PDK builds.
// Since the dependency is disabled, ART APEXes can't be built either.
// Disable the APEXes too. See b/157267166.
product_variables: {
pdk: {
enabled: false,
},
},
min_sdk_version: "S",
// Indicates that pre-installed version of this apex can be compressed.
// Whether it actually will be compressed is controlled on per-device basis.
compressible: true,
}
// Release version of the ART APEX module (not containing debug
// variants nor tools), included in user builds. Also used for
// storage-constrained devices in userdebug and eng builds.
art_apex {
name: "com.android.art",
defaults: ["com.android.art-device-defaults"],
certificate: ":com.android.art.certificate",
}
先尝试在device 下面 检索一下 grep "com.android.art" * -Rn
grep: generic/trusty/.git/hooks: No such file or directory
generic/trusty/qemu_trusty_base.mk:30: com.android.art \
grep: generic/mini-emulator-x86_64/.git/description: No such file or directory
PRODUCT_PACKAGES += \
...
com.android.art \
...
那么大概应该是类似安装包的资源文件,去系统目录下面查看一下,确实有apex这个文件,并且目录下面还有这个资源,那么基本可以判断com.android.art 是被com.google.android.art 替换了,所以才导致修改的资源文件没有生效
/system/apex/com.google.android.art.capex
然后从上述的(.find . -name "core-oj.jar")资源是有看到类似的文件
./out/soong/.intermediates/vendor/partner_modules/ArtPrebuilt/com.google.android.art.deapexer/android_common/deapexer/javalib/core-oj.jar
那么进入vendor/partner_modules/ArtPrebuilt查看一下是否有对应的资源,打开Android.bp查看一下
module_apex_set {
name: "com.google.android.art",
apex_name: "com.android.art",
owner: "google",
// Override both AOSP APEX variants, to ensure only com.google.android.art
// is installed regardless which APEX the logic in runtime_libart.mk has
// picked.
overrides: [
"com.android.art",
"com.android.art.debug",
],
filename: "com.google.android.art.apex",
set: "com.google.android.art.apks",
prefer: true,
soong_config_variables: {
module_build_from_source: {
prefer: false
}
},
// Make fragment related files from the apex file available for use by the
// build when using prebuilts, e.g. for running the boot jars package check
// and hidden API flag validation among other uses.
exported_bootclasspath_fragments: ["art-bootclasspath-fragment"],
}
然后向上逐级检索\vendor\partner_modules,再build/mainline_modules_s.mk中找到相关配置
vendor/partner_modules$ grep "com.google.android.art" * -Rn
Binary file ArtPrebuilt/com.google.android.art_compressed.apks matches
ArtPrebuilt/LICENSE:4:/system/apex/com.google.android.art.apex
ArtPrebuilt/Android.bp:43: name: "com.google.android.art",
ArtPrebuilt/Android.bp:46: // Override both AOSP APEX variants, to ensure only com.google.android.art
ArtPrebuilt/Android.bp:53: filename: "com.google.android.art.apex",
ArtPrebuilt/Android.bp:54: set: "com.google.android.art.apks",
ArtPrebuilt/Android.bp:68: name: "com.google.android.art_compressed",
ArtPrebuilt/Android.bp:71: // Override both AOSP APEX variants, to ensure only com.google.android.art
ArtPrebuilt/Android.bp:78:// filename: "com.google.android.art.capex",
ArtPrebuilt/Android.bp:79: set: "com.google.android.art_compressed.apks",
build/mainline_modules_s.mk:55:# com.google.android.art \
build/mainline_modules_s.mk:87:# com.google.android.art_compressed
build/mainline_modules_s.mk:90:# com.google.android.art
然后注释掉这里,重新编译测试确认ok
# Art
# MAINLINE_COMPRESS_APEX_ART ?= true
# ifeq ($(MAINLINE_COMPRESS_APEX_ART),true)
# PRODUCT_PACKAGES += \
# com.google.android.art_compressed
# else
# PRODUCT_PACKAGES += \
# com.google.android.art
# endif