prompt_and_wipe_data
boot-recovery
recovery
--prompt_and_wipe_data
--reason=prepareUserData failed for system user
--locale=zh_CN_#Hans
Directory not empty
Failed to set encryption policy of /data/system_ce/0 to 74382dd49925a380 v1 modes 1/4 flags 0x0: Directory not empty
ls : drwx------ 4 system system u:object_r:system_data_file:s0 4096 2024-10-08 10:24 shortcut_service
different encryption policy
Failed to set encryption policy of /data/media/0 to 988b3fcf0502e7b3 v1 modes 1/4 flags 0x0: The directory already has a different encryption policy.
recovery
console
--- a/etc/init.rc
+++ b/etc/init.rc
@@ -81,6 +81,13 @@ service adbd /system/bin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
socket adbd stream 660 system system
seclabel u:r:adbd:s0
+service console /system/bin/sh
+ console
+ user root
+ group root shell log readproc
+ seclabel u:r:shell:s0
+ setenv HOSTNAME console
+
service fastbootd /system/bin/fastbootd
disabled
group system
reason
recovery --wipe_data --reason=wipe_data_via_recovery
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -801,8 +801,10 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri
std::string option = OPTIONS[option_index].name;
if (option == "install_with_fuse") {
install_with_fuse = true;
- } else if (option == "locale" || option == "fastboot" || option == "reason") {
+ } else if (option == "locale" || option == "fastboot") {
// Handled in recovery_main.cpp
+ } else if (option == "reason") {
+ reason = optarg;
} else if (option == "prompt_and_wipe_data") {
should_prompt_and_wipe_data = true;
} else if (option == "rescue") {
init
console
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -1192,8 +1192,8 @@ service ueventd /system/bin/ueventd
service console /system/bin/sh
class core
console
- disabled
- user shell
+ #disabled
+ user root
group shell log readproc
seclabel u:r:shell:s0
setenv HOSTNAME console
sys.powerctl
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -744,6 +744,9 @@ uint32_t HandlePropertySet(const std::string& name, const std::string& value,
*error = "Userspace reboot is not supported by this device";
return PROP_ERROR_INVALID_VALUE;
}
+ if (strstr(process_cmdline.c_str(), "system_server")) {
+ return PROP_ERROR_INVALID_VALUE;
+ }
}
// If a process other than init is writing a non-empty value, it means that process is
log time
for logcat -vmonotonic
AlarmManagerService
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -1547,7 +1547,7 @@ public class AlarmManagerService extends SystemService {
/// M: For handling non-wakeup alarms while WFD is connected
registerWFDStatusChangeReciever();
///@}
- mInjector.setKernelTime(systemBuildTime);
+ //mInjector.setKernelTime(systemBuildTime);
}
// Determine SysUI's uid
threadtime
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -312,7 +312,7 @@ android_log_formatFromString(const char* formatString) {
else if (!strcmp(formatString, "tag")) format = FORMAT_TAG;
else if (!strcmp(formatString, "thread")) format = FORMAT_THREAD;
else if (!strcmp(formatString, "raw")) format = FORMAT_RAW;
- else if (!strcmp(formatString, "time")) format = FORMAT_TIME;
+ else if (!strcmp(formatString, "time")) format = FORMAT_THREADTIME;
else if (!strcmp(formatString, "threadtime")) format = FORMAT_THREADTIME;
else if (!strcmp(formatString, "long")) format = FORMAT_LONG;
else if (!strcmp(formatString, "color")) format = FORMAT_MODIFIER_COLOR;
backtrace
try {
throw new NullPointerException("zzz");
} catch (Exception e) {
Log.e(TAG, "zzz", e);
}
StorageManagerService
services/core/java/com/android/server/StorageManagerService.java
prepareUserStorageInternal
prepareUserStorage
ShortcutService
保存信息,默认延时3秒。保存信息在finishUserUnlocking之前发生就会出现prompt_and_wipe_data问题。
services/core/java/com/android/server/pm/ShortcutService.java
injectUserDataPath
189 @VisibleForTesting
190 static final int DEFAULT_SAVE_DELAY_MS = 3000;
191
192 @VisibleForTesting
193 static final String FILENAME_BASE_STATE = "shortcut_service.xml";
194
195 @VisibleForTesting
196 static final String DIRECTORY_PER_USER = "shortcut_service";
4829 @VisibleForTesting
4830 File injectUserDataPath(@UserIdInt int userId) {
4831 return new File(Environment.getDataSystemCeDirectory(userId), DIRECTORY_PER_USER);
4832 }
BroadcastReceiver
mPackageMonitor
481 // We need to set a priority, so let's just not use PackageMonitor for now.
482 // TODO Refactor PackageMonitor to support priorities.
483 final IntentFilter packageFilter = new IntentFilter();
484 packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
485 packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
486 packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
487 packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
488 packageFilter.addDataScheme("package");
489 packageFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
490 mContext.registerReceiverAsUser(mPackageMonitor, UserHandle.ALL,
491 packageFilter, null, mHandler);
492
493 final IntentFilter preferedActivityFilter = new IntentFilter();
494 preferedActivityFilter.addAction(Intent.ACTION_PREFERRED_ACTIVITY_CHANGED);
495 preferedActivityFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
496 mContext.registerReceiverAsUser(mPackageMonitor, UserHandle.ALL,
497 preferedActivityFilter, null, mHandler);
backtrace
24.642 754 754 D ShortcutService: Scheduling to save for -10000
28.254 754 842 I ShortcutService: BroadcastReceiver Intent { act=android.intent.action.ACTION_PREFERRED_ACTIVITY_CHANGED flg=0x4000010 (has extras) }
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutService.packageShortcutsChanged(ShortcutService.java:1686)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutPackage.rescanPackageIfNeeded(ShortcutPackage.java:1074)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutUser.rescanPackageIfNeeded(ShortcutUser.java:326)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutService.lambda$rescanUpdatedPackagesLocked$12$ShortcutService(ShortcutService.java:3562)
28.591 754 842 E ShortcutService: at com.android.server.pm.-$$Lambda$ShortcutService$ErhAH9ktbNmekJprGoLIQXZuBOc.accept(Unknown Source:8)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutService.forUpdatedPackages(ShortcutService.java:3831)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutService.rescanUpdatedPackagesLocked(ShortcutService.java:3559)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutService.checkPackageChanges(ShortcutService.java:3540)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutService.getUserShortcutsLocked(ShortcutService.java:1259)
28.591 754 842 E ShortcutService: at com.android.server.pm.ShortcutService$5.onReceive(ShortcutService.java:3442)
28.591 754 842 E ShortcutService: at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1574)
28.591 754 842 E ShortcutService: at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
28.591 754 842 E ShortcutService: at android.os.Handler.handleCallback(Handler.java:938)
28.591 754 842 E ShortcutService: at android.os.Handler.dispatchMessage(Handler.java:99)
28.591 754 842 E ShortcutService: at android.os.Looper.loop(Looper.java:223)
28.591 754 842 E ShortcutService: at android.os.HandlerThread.run(HandlerThread.java:67)
28.591 754 842 D ShortcutService: Scheduling to save for 0
28.719 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.injectUserDataPath(ShortcutService.java:4832)
28.719 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.getUserFile(ShortcutService.java:986)
28.719 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.loadUserLocked(ShortcutService.java:1047)
28.719 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.getUserShortcutsLocked(ShortcutService.java:1252)
28.719 757 842 E ShortcutService: at com.android.server.pm.ShortcutService$5.onReceive(ShortcutService.java:3436)
28.719 757 842 E ShortcutService: at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1574)
28.719 757 842 E ShortcutService: at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
28.719 757 842 E ShortcutService: at android.os.Handler.handleCallback(Handler.java:938)
28.719 757 842 E ShortcutService: at android.os.Handler.dispatchMessage(Handler.java:99)
28.719 757 842 E ShortcutService: at android.os.Looper.loop(Looper.java:223)
28.719 757 842 E ShortcutService: at android.os.HandlerThread.run(HandlerThread.java:67)
saveDirtyInfo
packageShortcutsChanged
scheduleSaveInner
mHandler.postDelayed
32.188 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.injectUserDataPath(ShortcutService.java:4832)
32.188 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.getUserFile(ShortcutService.java:986)
32.188 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.saveUserLocked(ShortcutService.java:991)
32.188 757 842 E ShortcutService: at com.android.server.pm.ShortcutService.saveDirtyInfo(ShortcutService.java:1141)
32.188 757 842 E ShortcutService: at com.android.server.pm.-$$Lambda$jZzCUQd1whVIqs_s1XMLbFqTP_E.run(Unknown Source:2)
32.188 757 842 E ShortcutService: at android.os.Handler.handleCallback(Handler.java:938)
32.188 757 842 E ShortcutService: at android.os.Handler.dispatchMessage(Handler.java:99)
32.188 757 842 E ShortcutService: at android.os.Looper.loop(Looper.java:223)
32.188 757 842 E ShortcutService: at android.os.HandlerThread.run(HandlerThread.java:67)
dumpsys shortcut
SAVE_DELAY
--- a/services/core/java/com/android/server/pm/ShortcutService.java
+++ b/services/core/java/com/android/server/pm/ShortcutService.java
@@ -187,7 +187,7 @@ public class ShortcutService extends IShortcutService.Stub {
static final int DEFAULT_ICON_PERSIST_QUALITY = 100;
@VisibleForTesting
- static final int DEFAULT_SAVE_DELAY_MS = 3000;
+ static final int DEFAULT_SAVE_DELAY_MS = 6000;
@VisibleForTesting
static final String FILENAME_BASE_STATE = "shortcut_service.xml";
libfscrypt
fscrypt_is_native
88 bool fscrypt_is_native() {
89 char value[PROPERTY_VALUE_MAX];
90 property_get("ro.crypto.type", value, "none");
91 return !strcmp(value, "file");
92 }
log_ls
97 static void log_ls(const char* dirname) {
98 std::array<const char*, 3> argv = {"ls", "-laZ", dirname};
99 int status = 0;
100 auto res =
101 logwrap_fork_execvp(argv.size(), argv.data(), &status, false, LOG_ALOG, false, nullptr);
102 if (res != 0) {
103 PLOG(ERROR) << argv[0] << " " << argv[1] << " " << argv[2] << "failed";
104 return;
105 }
106 if (!WIFEXITED(status)) {
107 LOG(ERROR) << argv[0] << " " << argv[1] << " " << argv[2]
108 << " did not exit normally, status: " << status;
109 return;
110 }
111 if (WEXITSTATUS(status) != 0) {
112 LOG(ERROR) << argv[0] << " " << argv[1] << " " << argv[2]
113 << " returned failure: " << WEXITSTATUS(status);
114 return;
115 }
116 }
FSCRYPT_MODE
53 static const auto contents_modes = std::vector<ModeLookupEntry>{
54 {"aes-256-xts"s, FSCRYPT_MODE_AES_256_XTS},
55 {"software"s, FSCRYPT_MODE_AES_256_XTS},
56 {"adiantum"s, FSCRYPT_MODE_ADIANTUM},
57 {"ice"s, FSCRYPT_MODE_PRIVATE},
58 };
59
60 static const auto filenames_modes = std::vector<ModeLookupEntry>{
61 {"aes-256-cts"s, FSCRYPT_MODE_AES_256_CTS},
62 {"aes-256-heh"s, FSCRYPT_MODE_AES_256_HEH},
63 {"adiantum"s, FSCRYPT_MODE_ADIANTUM},
64 };
Failed to set encryption policy of
331 // FS_IOC_SET_ENCRYPTION_POLICY will set the policy if the directory is
332 // unencrypted; otherwise it will verify that the existing policy matches.
333 // Setting the policy will fail if the directory is already nonempty.
334 if (ioctl(fd, FS_IOC_SET_ENCRYPTION_POLICY, &kern_policy) != 0) {
335 std::string reason;
336 switch (errno) {
337 case EEXIST:
338 reason = "The directory already has a different encryption policy.";
339 break;
340 default:
341 reason = strerror(errno);
342 break;
343 }
344 LOG(ERROR) << "Failed to set encryption policy of " << directory << " to "
345 << PolicyDebugString(policy) << ": " << reason;
346 if (errno == ENOTEMPTY) {
347 log_ls(directory.c_str());
348 }
349 return false;
350 }
PolicyDebugString
271 static std::string PolicyDebugString(const EncryptionPolicy& policy) {
272 std::stringstream ss;
273 std::string ref_hex;
274 BytesToHex(policy.key_raw_ref, &ref_hex);
275 ss << ref_hex;
276 ss << " v" << policy.options.version;
277 ss << " modes " << policy.options.contents_mode << "/" << policy.options.filenames_mode;
278 ss << std::hex << " flags 0x" << policy.options.flags;
279 return ss.str();
280 }
vold
FsCrypt.cpp
get_volume_file_encryption_options
ro.crypto.volume.contents_mode
ro.crypto.volume.filenames_mode
ro.crypto.volume.options
fscrypt_init_user0
Failed to prepare user 0 storage
VoldNativeService::initUser0
vold:initUser0:START
fscrypt_init_user0
vold:initUser0:END, rtn =%d
vold_prepare_subdirs.cpp
vold_prepare_subdirs
fscrypt_prepare_user_storage
818 bool fscrypt_prepare_user_storage(const std::string& volume_uuid, userid_t user_id, int serial,
819 int flags) {
820 LOG(DEBUG) << "zzz fscrypt_prepare_user_storage for volume " << escape_empty(volume_uuid)
821 << ", user " << user_id << ", serial " << serial << ", flags " << flags;
822
fs_pprepare_dir
system/core/libcutils/fs.cpp
fs_prepare_dir
fs_prepare_path_impl
lstat
ENOENT mkdir(open close)
chmod
chown
/proc/bootprof
write_file_bootprof
vold
system/vold/Utils.cpp
1885 int write_file_bootprof(const char* content) {
1886 const char* path = "/proc/bootprof";
1887 int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY|O_CREAT|O_NOFOLLOW|O_CLOEXEC, 0600));
1888 if (fd == -1) {
1889 PLOG(ERROR) << __FUNCTION__ << ": Failed to open " << path;
1890 return -1;
1891 }
1892 int result = android::base::WriteStringToFd(content, fd) ? 0 : -1;
1893 if (result == -1) {
1894 PLOG(ERROR) << __FUNCTION__ << ": Failed to write " << path;
1895 }
1896 close(fd);
1897 return result;
1898 }
bootProf
SurfaceFlinger
frameworks/native/services/surfaceflinger/mediatek/SurfaceFlinger.cpp
addBootEvent
Zygote
frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
Runtime
frameworks/base/core/jni/AndroidRuntime.cpp
adb
should_drop_privileges
65 static bool should_drop_privileges() {
66 // The properties that affect `adb root` and `adb unroot` are ro.secure and
67 // ro.debuggable. In this context the names don't make the expected behavior
68 // particularly obvious.
69 //
70 // ro.debuggable:
71 // Allowed to become root, but not necessarily the default. Set to 1 on
72 // eng and userdebug builds.
73 //
74 // ro.secure:
75 // Drop privileges by default. Set to 1 on userdebug and user builds.
76 bool ro_secure = android::base::GetBoolProperty("ro.secure", true);
77 //bool ro_debuggable = __android_log_is_debuggable();
78
79 // Drop privileges if ro.secure is set...
80 bool drop = ro_secure;
81
82 // ... except "adb root" lets you keep privileges in a debuggable build.
83 std::string prop = android::base::GetProperty("service.adb.root", "");
84 bool adb_root = (prop == "1");
85 bool adb_unroot = (prop == "0");
86 if (adb_root) {
87 drop = false;
88 }
89 // ... and "adb unroot" lets you explicitly drop privileges.
90 if (adb_unroot) {
91 drop = true;
92 }
93
94 return drop;
95 }
restart_root_service
31 void restart_root_service(unique_fd fd) {
32 if (getuid() == 0) {
33 WriteFdExactly(fd.get(), "adbd is already running as root\n");
34 return;
35 }
36 if (!__android_log_is_debuggable()) {
37 WriteFdExactly(fd.get(), "adbd cannot run as root in production builds\n");
38 return;
39 }
40
41 LOG(INFO) << "adbd restarting as root";
42 android::base::SetProperty("service.adb.root", "1");
43 WriteFdExactly(fd.get(), "restarting adbd as root\n");
44 }
root
setprop service.adb.root 1
adb usb
unroot
adb unroot