Loading cmds/dumpstate/dumpstate.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -2171,7 +2171,7 @@ static void PrepareToWriteToFile() { } if (ds.options_->do_screenshot) { ds.screenshot_path_ = ds.GetPath(ds.CalledByApi() ? "-tmp.png" : ".png"); ds.screenshot_path_ = ds.GetPath(ds.CalledByApi() ? "-png.tmp" : ".png"); } ds.tmp_path_ = ds.GetPath(".tmp"); ds.log_path_ = ds.GetPath("-dumpstate_log-" + std::to_string(ds.pid_) + ".txt"); Loading @@ -2190,7 +2190,7 @@ static void PrepareToWriteToFile() { ds.tmp_path_.c_str(), ds.screenshot_path_.c_str()); if (ds.options_->do_zip_file) { ds.path_ = ds.GetPath(ds.CalledByApi() ? "-tmp.zip" : ".zip"); ds.path_ = ds.GetPath(ds.CalledByApi() ? "-zip.tmp" : ".zip"); MYLOGD("Creating initial .zip file (%s)\n", ds.path_.c_str()); create_parent_dirs(ds.path_.c_str()); ds.zip_file.reset(fopen(ds.path_.c_str(), "wb")); Loading cmds/installd/otapreopt.cpp +15 −118 Original line number Diff line number Diff line Loading @@ -138,10 +138,10 @@ class OTAPreoptService { return 4; } PrepareEnvironment(); PrepareEnvironmentVariables(); if (!PrepareBootImage(/* force */ false)) { LOG(ERROR) << "Failed preparing boot image."; if (!EnsureBootImageAndDalvikCache()) { LOG(ERROR) << "Bad boot image."; return 5; } Loading Loading @@ -302,7 +302,7 @@ private: return parameters_.ReadArguments(argc, const_cast<const char**>(argv)); } void PrepareEnvironment() { void PrepareEnvironmentVariables() { environ_.push_back(StringPrintf("BOOTCLASSPATH=%s", boot_classpath_.c_str())); environ_.push_back(StringPrintf("ANDROID_DATA=%s", GetOTADataDirectory().c_str())); environ_.push_back(StringPrintf("ANDROID_ROOT=%s", android_root_.c_str())); Loading @@ -312,9 +312,8 @@ private: } } // Ensure that we have the right boot image. The first time any app is // compiled, we'll try to generate it. bool PrepareBootImage(bool force) const { // Ensure that we have the right boot image and cache file structures. bool EnsureBootImageAndDalvikCache() const { if (parameters_.instruction_set == nullptr) { LOG(ERROR) << "Instruction set missing."; return false; Loading @@ -340,34 +339,19 @@ private: } } // Check whether we have files in /data. // TODO: check that the files are correct wrt/ jars. std::string art_path = isa_path + "/system@framework@boot.art"; std::string oat_path = isa_path + "/system@framework@boot.oat"; bool cleared = false; if (access(art_path.c_str(), F_OK) == 0 && access(oat_path.c_str(), F_OK) == 0) { // Files exist, assume everything is alright if not forced. Otherwise clean up. if (!force) { return true; } // Clear cached artifacts. ClearDirectory(isa_path); cleared = true; } // Check whether we have an image in /system. // Check whether we have a boot image. // TODO: check that the files are correct wrt/ jars. std::string preopted_boot_art_path = StringPrintf("/system/framework/%s/boot.art", isa); if (access(preopted_boot_art_path.c_str(), F_OK) == 0) { // Note: we ignore |force| here. return true; } if (!cleared) { ClearDirectory(isa_path); std::string preopted_boot_art_path = StringPrintf("/apex/com.android.art/javalib/%s/boot.art", isa); if (access(preopted_boot_art_path.c_str(), F_OK) != 0) { PLOG(ERROR) << "Bad access() to " << preopted_boot_art_path; return false; } return Dex2oatBootImage(boot_classpath_, art_path, oat_path, isa); return true; } static bool CreatePath(const std::string& path) { Loading Loading @@ -432,77 +416,6 @@ private: CHECK_EQ(0, closedir(c_dir)) << "Unable to close directory."; } bool Dex2oatBootImage(const std::string& boot_cp, const std::string& art_path, const std::string& oat_path, const char* isa) const { // This needs to be kept in sync with ART, see art/runtime/gc/space/image_space.cc. std::vector<std::string> cmd; cmd.push_back(kDex2oatPath); cmd.push_back(StringPrintf("--image=%s", art_path.c_str())); for (const std::string& boot_part : Split(boot_cp, ":")) { cmd.push_back(StringPrintf("--dex-file=%s", boot_part.c_str())); } cmd.push_back(StringPrintf("--oat-file=%s", oat_path.c_str())); int32_t base_offset = ChooseRelocationOffsetDelta( art::imagevalues::GetImageMinBaseAddressDelta(), art::imagevalues::GetImageMaxBaseAddressDelta()); cmd.push_back(StringPrintf("--base=0x%x", art::imagevalues::GetImageBaseAddress() + base_offset)); cmd.push_back(StringPrintf("--instruction-set=%s", isa)); // These things are pushed by AndroidRuntime, see frameworks/base/core/jni/AndroidRuntime.cpp. AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xms", "-Xms", true, cmd); AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xmx", "-Xmx", true, cmd); AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-filter", "--compiler-filter=", false, cmd); cmd.push_back("--profile-file=/system/etc/boot-image.prof"); // TODO: Compiled-classes. const std::string* extra_opts = system_properties_.GetProperty("dalvik.vm.image-dex2oat-flags"); if (extra_opts != nullptr) { std::vector<std::string> extra_vals = Split(*extra_opts, " "); cmd.insert(cmd.end(), extra_vals.begin(), extra_vals.end()); } // TODO: Should we lower this? It's usually set close to max, because // normally there's not much else going on at boot. AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-threads", "-j", false, cmd); AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-cpu-set", "--cpu-set=", false, cmd); AddCompilerOptionFromSystemProperty( StringPrintf("dalvik.vm.isa.%s.variant", isa).c_str(), "--instruction-set-variant=", false, cmd); AddCompilerOptionFromSystemProperty( StringPrintf("dalvik.vm.isa.%s.features", isa).c_str(), "--instruction-set-features=", false, cmd); std::string error_msg; bool result = Exec(cmd, &error_msg); if (!result) { LOG(ERROR) << "Could not generate boot image: " << error_msg; } return result; } static const char* ParseNull(const char* arg) { return (strcmp(arg, "!") == 0) ? nullptr : arg; } Loading Loading @@ -592,22 +505,6 @@ private: return 0; } // If the dexopt failed, we may have a stale boot image from a previous OTA run. // Then regenerate and retry. if (WEXITSTATUS(dexopt_result) == static_cast<int>(::art::dex2oat::ReturnCode::kCreateRuntime)) { if (!PrepareBootImage(/* force */ true)) { LOG(ERROR) << "Forced boot image creating failed. Original error return was " << dexopt_result; return dexopt_result; } int dexopt_result_boot_image_retry = Dexopt(); if (dexopt_result_boot_image_retry == 0) { return 0; } } // If this was a profile-guided run, we may have profile version issues. Try to downgrade, // if possible. if ((parameters_.dexopt_flags & DEXOPT_PROFILE_GUIDED) == 0) { Loading libs/binder/ActivityManager.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,15 @@ int32_t ActivityManager::getUidProcessState(const uid_t uid, const String16& cal return PROCESS_STATE_UNKNOWN; } bool ActivityManager::isUidActiveOrForeground(const uid_t uid, const String16& callingPackage) { sp<IActivityManager> service = getService(); if (service != nullptr) { return service->isUidActiveOrForeground(uid, callingPackage); } return false; } status_t ActivityManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipient) { sp<IActivityManager> service = getService(); if (service != nullptr) { Loading libs/binder/IActivityManager.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,18 @@ public: } return reply.readInt32(); } virtual bool isUidActiveOrForeground(const uid_t uid, const String16& callingPackage) { Parcel data, reply; data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor()); data.writeInt32(uid); data.writeString16(callingPackage); remote()->transact(IS_UID_ACTIVE_OR_FOREGROUND_TRANSACTION, data, &reply); // fail on exception if (reply.readExceptionCode() != 0) return false; return reply.readInt32() == 1; } }; // ------------------------------------------------------------------------------------ Loading libs/binder/include/binder/ActivityManager.h +19 −19 Original line number Diff line number Diff line Loading @@ -46,25 +46,24 @@ public: PROCESS_STATE_PERSISTENT = 0, PROCESS_STATE_PERSISTENT_UI = 1, PROCESS_STATE_TOP = 2, PROCESS_STATE_FOREGROUND_SERVICE_LOCATION = 3, PROCESS_STATE_BOUND_TOP = 4, PROCESS_STATE_FOREGROUND_SERVICE = 5, PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 6, PROCESS_STATE_IMPORTANT_FOREGROUND = 7, PROCESS_STATE_IMPORTANT_BACKGROUND = 8, PROCESS_STATE_TRANSIENT_BACKGROUND = 9, PROCESS_STATE_BACKUP = 10, PROCESS_STATE_SERVICE = 11, PROCESS_STATE_RECEIVER = 12, PROCESS_STATE_TOP_SLEEPING = 13, PROCESS_STATE_HEAVY_WEIGHT = 14, PROCESS_STATE_HOME = 15, PROCESS_STATE_LAST_ACTIVITY = 16, PROCESS_STATE_CACHED_ACTIVITY = 17, PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 18, PROCESS_STATE_CACHED_RECENT = 19, PROCESS_STATE_CACHED_EMPTY = 20, PROCESS_STATE_NONEXISTENT = 21, PROCESS_STATE_BOUND_TOP = 3, PROCESS_STATE_FOREGROUND_SERVICE = 4, PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 5, PROCESS_STATE_IMPORTANT_FOREGROUND = 6, PROCESS_STATE_IMPORTANT_BACKGROUND = 7, PROCESS_STATE_TRANSIENT_BACKGROUND = 8, PROCESS_STATE_BACKUP = 9, PROCESS_STATE_SERVICE = 10, PROCESS_STATE_RECEIVER = 11, PROCESS_STATE_TOP_SLEEPING = 12, PROCESS_STATE_HEAVY_WEIGHT = 13, PROCESS_STATE_HOME = 14, PROCESS_STATE_LAST_ACTIVITY = 15, PROCESS_STATE_CACHED_ACTIVITY = 16, PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 17, PROCESS_STATE_CACHED_RECENT = 18, PROCESS_STATE_CACHED_EMPTY = 19, PROCESS_STATE_NONEXISTENT = 20, }; ActivityManager(); Loading @@ -77,6 +76,7 @@ public: void unregisterUidObserver(const sp<IUidObserver>& observer); bool isUidActive(const uid_t uid, const String16& callingPackage); int getUidProcessState(const uid_t uid, const String16& callingPackage); bool isUidActiveOrForeground(const uid_t uid, const String16& callingPackage); status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient); Loading Loading
cmds/dumpstate/dumpstate.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -2171,7 +2171,7 @@ static void PrepareToWriteToFile() { } if (ds.options_->do_screenshot) { ds.screenshot_path_ = ds.GetPath(ds.CalledByApi() ? "-tmp.png" : ".png"); ds.screenshot_path_ = ds.GetPath(ds.CalledByApi() ? "-png.tmp" : ".png"); } ds.tmp_path_ = ds.GetPath(".tmp"); ds.log_path_ = ds.GetPath("-dumpstate_log-" + std::to_string(ds.pid_) + ".txt"); Loading @@ -2190,7 +2190,7 @@ static void PrepareToWriteToFile() { ds.tmp_path_.c_str(), ds.screenshot_path_.c_str()); if (ds.options_->do_zip_file) { ds.path_ = ds.GetPath(ds.CalledByApi() ? "-tmp.zip" : ".zip"); ds.path_ = ds.GetPath(ds.CalledByApi() ? "-zip.tmp" : ".zip"); MYLOGD("Creating initial .zip file (%s)\n", ds.path_.c_str()); create_parent_dirs(ds.path_.c_str()); ds.zip_file.reset(fopen(ds.path_.c_str(), "wb")); Loading
cmds/installd/otapreopt.cpp +15 −118 Original line number Diff line number Diff line Loading @@ -138,10 +138,10 @@ class OTAPreoptService { return 4; } PrepareEnvironment(); PrepareEnvironmentVariables(); if (!PrepareBootImage(/* force */ false)) { LOG(ERROR) << "Failed preparing boot image."; if (!EnsureBootImageAndDalvikCache()) { LOG(ERROR) << "Bad boot image."; return 5; } Loading Loading @@ -302,7 +302,7 @@ private: return parameters_.ReadArguments(argc, const_cast<const char**>(argv)); } void PrepareEnvironment() { void PrepareEnvironmentVariables() { environ_.push_back(StringPrintf("BOOTCLASSPATH=%s", boot_classpath_.c_str())); environ_.push_back(StringPrintf("ANDROID_DATA=%s", GetOTADataDirectory().c_str())); environ_.push_back(StringPrintf("ANDROID_ROOT=%s", android_root_.c_str())); Loading @@ -312,9 +312,8 @@ private: } } // Ensure that we have the right boot image. The first time any app is // compiled, we'll try to generate it. bool PrepareBootImage(bool force) const { // Ensure that we have the right boot image and cache file structures. bool EnsureBootImageAndDalvikCache() const { if (parameters_.instruction_set == nullptr) { LOG(ERROR) << "Instruction set missing."; return false; Loading @@ -340,34 +339,19 @@ private: } } // Check whether we have files in /data. // TODO: check that the files are correct wrt/ jars. std::string art_path = isa_path + "/system@framework@boot.art"; std::string oat_path = isa_path + "/system@framework@boot.oat"; bool cleared = false; if (access(art_path.c_str(), F_OK) == 0 && access(oat_path.c_str(), F_OK) == 0) { // Files exist, assume everything is alright if not forced. Otherwise clean up. if (!force) { return true; } // Clear cached artifacts. ClearDirectory(isa_path); cleared = true; } // Check whether we have an image in /system. // Check whether we have a boot image. // TODO: check that the files are correct wrt/ jars. std::string preopted_boot_art_path = StringPrintf("/system/framework/%s/boot.art", isa); if (access(preopted_boot_art_path.c_str(), F_OK) == 0) { // Note: we ignore |force| here. return true; } if (!cleared) { ClearDirectory(isa_path); std::string preopted_boot_art_path = StringPrintf("/apex/com.android.art/javalib/%s/boot.art", isa); if (access(preopted_boot_art_path.c_str(), F_OK) != 0) { PLOG(ERROR) << "Bad access() to " << preopted_boot_art_path; return false; } return Dex2oatBootImage(boot_classpath_, art_path, oat_path, isa); return true; } static bool CreatePath(const std::string& path) { Loading Loading @@ -432,77 +416,6 @@ private: CHECK_EQ(0, closedir(c_dir)) << "Unable to close directory."; } bool Dex2oatBootImage(const std::string& boot_cp, const std::string& art_path, const std::string& oat_path, const char* isa) const { // This needs to be kept in sync with ART, see art/runtime/gc/space/image_space.cc. std::vector<std::string> cmd; cmd.push_back(kDex2oatPath); cmd.push_back(StringPrintf("--image=%s", art_path.c_str())); for (const std::string& boot_part : Split(boot_cp, ":")) { cmd.push_back(StringPrintf("--dex-file=%s", boot_part.c_str())); } cmd.push_back(StringPrintf("--oat-file=%s", oat_path.c_str())); int32_t base_offset = ChooseRelocationOffsetDelta( art::imagevalues::GetImageMinBaseAddressDelta(), art::imagevalues::GetImageMaxBaseAddressDelta()); cmd.push_back(StringPrintf("--base=0x%x", art::imagevalues::GetImageBaseAddress() + base_offset)); cmd.push_back(StringPrintf("--instruction-set=%s", isa)); // These things are pushed by AndroidRuntime, see frameworks/base/core/jni/AndroidRuntime.cpp. AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xms", "-Xms", true, cmd); AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-Xmx", "-Xmx", true, cmd); AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-filter", "--compiler-filter=", false, cmd); cmd.push_back("--profile-file=/system/etc/boot-image.prof"); // TODO: Compiled-classes. const std::string* extra_opts = system_properties_.GetProperty("dalvik.vm.image-dex2oat-flags"); if (extra_opts != nullptr) { std::vector<std::string> extra_vals = Split(*extra_opts, " "); cmd.insert(cmd.end(), extra_vals.begin(), extra_vals.end()); } // TODO: Should we lower this? It's usually set close to max, because // normally there's not much else going on at boot. AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-threads", "-j", false, cmd); AddCompilerOptionFromSystemProperty("dalvik.vm.image-dex2oat-cpu-set", "--cpu-set=", false, cmd); AddCompilerOptionFromSystemProperty( StringPrintf("dalvik.vm.isa.%s.variant", isa).c_str(), "--instruction-set-variant=", false, cmd); AddCompilerOptionFromSystemProperty( StringPrintf("dalvik.vm.isa.%s.features", isa).c_str(), "--instruction-set-features=", false, cmd); std::string error_msg; bool result = Exec(cmd, &error_msg); if (!result) { LOG(ERROR) << "Could not generate boot image: " << error_msg; } return result; } static const char* ParseNull(const char* arg) { return (strcmp(arg, "!") == 0) ? nullptr : arg; } Loading Loading @@ -592,22 +505,6 @@ private: return 0; } // If the dexopt failed, we may have a stale boot image from a previous OTA run. // Then regenerate and retry. if (WEXITSTATUS(dexopt_result) == static_cast<int>(::art::dex2oat::ReturnCode::kCreateRuntime)) { if (!PrepareBootImage(/* force */ true)) { LOG(ERROR) << "Forced boot image creating failed. Original error return was " << dexopt_result; return dexopt_result; } int dexopt_result_boot_image_retry = Dexopt(); if (dexopt_result_boot_image_retry == 0) { return 0; } } // If this was a profile-guided run, we may have profile version issues. Try to downgrade, // if possible. if ((parameters_.dexopt_flags & DEXOPT_PROFILE_GUIDED) == 0) { Loading
libs/binder/ActivityManager.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,15 @@ int32_t ActivityManager::getUidProcessState(const uid_t uid, const String16& cal return PROCESS_STATE_UNKNOWN; } bool ActivityManager::isUidActiveOrForeground(const uid_t uid, const String16& callingPackage) { sp<IActivityManager> service = getService(); if (service != nullptr) { return service->isUidActiveOrForeground(uid, callingPackage); } return false; } status_t ActivityManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipient) { sp<IActivityManager> service = getService(); if (service != nullptr) { Loading
libs/binder/IActivityManager.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,18 @@ public: } return reply.readInt32(); } virtual bool isUidActiveOrForeground(const uid_t uid, const String16& callingPackage) { Parcel data, reply; data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor()); data.writeInt32(uid); data.writeString16(callingPackage); remote()->transact(IS_UID_ACTIVE_OR_FOREGROUND_TRANSACTION, data, &reply); // fail on exception if (reply.readExceptionCode() != 0) return false; return reply.readInt32() == 1; } }; // ------------------------------------------------------------------------------------ Loading
libs/binder/include/binder/ActivityManager.h +19 −19 Original line number Diff line number Diff line Loading @@ -46,25 +46,24 @@ public: PROCESS_STATE_PERSISTENT = 0, PROCESS_STATE_PERSISTENT_UI = 1, PROCESS_STATE_TOP = 2, PROCESS_STATE_FOREGROUND_SERVICE_LOCATION = 3, PROCESS_STATE_BOUND_TOP = 4, PROCESS_STATE_FOREGROUND_SERVICE = 5, PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 6, PROCESS_STATE_IMPORTANT_FOREGROUND = 7, PROCESS_STATE_IMPORTANT_BACKGROUND = 8, PROCESS_STATE_TRANSIENT_BACKGROUND = 9, PROCESS_STATE_BACKUP = 10, PROCESS_STATE_SERVICE = 11, PROCESS_STATE_RECEIVER = 12, PROCESS_STATE_TOP_SLEEPING = 13, PROCESS_STATE_HEAVY_WEIGHT = 14, PROCESS_STATE_HOME = 15, PROCESS_STATE_LAST_ACTIVITY = 16, PROCESS_STATE_CACHED_ACTIVITY = 17, PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 18, PROCESS_STATE_CACHED_RECENT = 19, PROCESS_STATE_CACHED_EMPTY = 20, PROCESS_STATE_NONEXISTENT = 21, PROCESS_STATE_BOUND_TOP = 3, PROCESS_STATE_FOREGROUND_SERVICE = 4, PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 5, PROCESS_STATE_IMPORTANT_FOREGROUND = 6, PROCESS_STATE_IMPORTANT_BACKGROUND = 7, PROCESS_STATE_TRANSIENT_BACKGROUND = 8, PROCESS_STATE_BACKUP = 9, PROCESS_STATE_SERVICE = 10, PROCESS_STATE_RECEIVER = 11, PROCESS_STATE_TOP_SLEEPING = 12, PROCESS_STATE_HEAVY_WEIGHT = 13, PROCESS_STATE_HOME = 14, PROCESS_STATE_LAST_ACTIVITY = 15, PROCESS_STATE_CACHED_ACTIVITY = 16, PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 17, PROCESS_STATE_CACHED_RECENT = 18, PROCESS_STATE_CACHED_EMPTY = 19, PROCESS_STATE_NONEXISTENT = 20, }; ActivityManager(); Loading @@ -77,6 +76,7 @@ public: void unregisterUidObserver(const sp<IUidObserver>& observer); bool isUidActive(const uid_t uid, const String16& callingPackage); int getUidProcessState(const uid_t uid, const String16& callingPackage); bool isUidActiveOrForeground(const uid_t uid, const String16& callingPackage); status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient); Loading