3535#include < vintf/constants.h>
3636#endif // !VENDORSERVICEMANAGER
3737
38+ #include " NameUtil.h"
39+
3840using ::android::binder::Status;
3941using ::android::internal::Stability;
4042
@@ -84,6 +86,10 @@ static bool forEachManifest(const std::function<bool(const ManifestWithDescripti
8486 return false ;
8587}
8688
89+ static std::string getNativeInstanceName (const vintf::ManifestInstance& instance) {
90+ return instance.package () + " /" + instance.instance ();
91+ }
92+
8793struct AidlName {
8894 std::string package;
8995 std::string iface;
@@ -105,7 +111,26 @@ struct AidlName {
105111 }
106112};
107113
114+ static std::string getAidlInstanceName (const vintf::ManifestInstance& instance) {
115+ return instance.package () + " ." + instance.interface () + " /" + instance.instance ();
116+ }
117+
108118static bool isVintfDeclared (const std::string& name) {
119+ NativeName nname;
120+ if (NativeName::fill (name, &nname)) {
121+ bool found = forEachManifest ([&](const ManifestWithDescription& mwd) {
122+ if (mwd.manifest ->hasNativeInstance (nname.package , nname.instance )) {
123+ ALOGI (" Found %s in %s VINTF manifest." , name.c_str (), mwd.description );
124+ return true ; // break
125+ }
126+ return false ; // continue
127+ });
128+ if (!found) {
129+ ALOGI (" Could not find %s in the VINTF manifest." , name.c_str ());
130+ }
131+ return found;
132+ }
133+
109134 AidlName aname;
110135 if (!AidlName::fill (name, &aname)) return false ;
111136
@@ -144,6 +169,24 @@ static bool isVintfDeclared(const std::string& name) {
144169}
145170
146171static std::optional<std::string> getVintfUpdatableApex (const std::string& name) {
172+ NativeName nname;
173+ if (NativeName::fill (name, &nname)) {
174+ std::optional<std::string> updatableViaApex;
175+
176+ forEachManifest ([&](const ManifestWithDescription& mwd) {
177+ bool cont = mwd.manifest ->forEachInstance ([&](const auto & manifestInstance) {
178+ if (manifestInstance.format () != vintf::HalFormat::NATIVE) return true ;
179+ if (manifestInstance.package () != nname.package ) return true ;
180+ if (manifestInstance.instance () != nname.instance ) return true ;
181+ updatableViaApex = manifestInstance.updatableViaApex ();
182+ return false ; // break (libvintf uses opposite convention)
183+ });
184+ return !cont;
185+ });
186+
187+ return updatableViaApex;
188+ }
189+
147190 AidlName aname;
148191 if (!AidlName::fill (name, &aname)) return std::nullopt ;
149192
@@ -164,24 +207,25 @@ static std::optional<std::string> getVintfUpdatableApex(const std::string& name)
164207 return updatableViaApex;
165208}
166209
167- static std::vector<std::string> getVintfUpdatableInstances (const std::string& apexName) {
168- std::vector<std::string> instances ;
210+ static std::vector<std::string> getVintfUpdatableNames (const std::string& apexName) {
211+ std::vector<std::string> names ;
169212
170213 forEachManifest ([&](const ManifestWithDescription& mwd) {
171214 mwd.manifest ->forEachInstance ([&](const auto & manifestInstance) {
172- if (manifestInstance.format () == vintf::HalFormat::AIDL &&
173- manifestInstance.updatableViaApex ().has_value () &&
215+ if (manifestInstance.updatableViaApex ().has_value () &&
174216 manifestInstance.updatableViaApex ().value () == apexName) {
175- std::string aname = manifestInstance.package () + " ." +
176- manifestInstance.interface () + " /" + manifestInstance.instance ();
177- instances.push_back (aname);
217+ if (manifestInstance.format () == vintf::HalFormat::NATIVE) {
218+ names.push_back (getNativeInstanceName (manifestInstance));
219+ } else if (manifestInstance.format () == vintf::HalFormat::AIDL) {
220+ names.push_back (getAidlInstanceName (manifestInstance));
221+ }
178222 }
179223 return true ; // continue (libvintf uses opposite convention)
180224 });
181225 return false ; // continue
182226 });
183227
184- return instances ;
228+ return names ;
185229}
186230
187231static std::optional<ConnectionInfo> getVintfConnectionInfo (const std::string& name) {
@@ -216,6 +260,18 @@ static std::optional<ConnectionInfo> getVintfConnectionInfo(const std::string& n
216260static std::vector<std::string> getVintfInstances (const std::string& interface) {
217261 size_t lastDot = interface.rfind (' .' );
218262 if (lastDot == std::string::npos) {
263+ // This might be a package for native instance.
264+ std::vector<std::string> ret;
265+ (void )forEachManifest ([&](const ManifestWithDescription& mwd) {
266+ auto instances = mwd.manifest ->getNativeInstances (interface);
267+ ret.insert (ret.end (), instances.begin (), instances.end ());
268+ return false ; // continue
269+ });
270+ // If found, return it without error log.
271+ if (!ret.empty ()) {
272+ return ret;
273+ }
274+
219275 ALOGE (" VINTF interfaces require names in Java package format (e.g. some.package.foo.IFoo) "
220276 " but got: %s" ,
221277 interface.c_str ());
@@ -593,20 +649,20 @@ Status ServiceManager::getUpdatableNames([[maybe_unused]] const std::string& ape
593649 std::vector<std::string>* outReturn) {
594650 auto ctx = mAccess ->getCallingContext ();
595651
596- std::vector<std::string> apexUpdatableInstances ;
652+ std::vector<std::string> apexUpdatableNames ;
597653#ifndef VENDORSERVICEMANAGER
598- apexUpdatableInstances = getVintfUpdatableInstances (apexName);
654+ apexUpdatableNames = getVintfUpdatableNames (apexName);
599655#endif
600656
601657 outReturn->clear ();
602658
603- for (const std::string& instance : apexUpdatableInstances ) {
604- if (mAccess ->canFind (ctx, instance )) {
605- outReturn->push_back (instance );
659+ for (const std::string& name : apexUpdatableNames ) {
660+ if (mAccess ->canFind (ctx, name )) {
661+ outReturn->push_back (name );
606662 }
607663 }
608664
609- if (outReturn->size () == 0 && apexUpdatableInstances .size () != 0 ) {
665+ if (outReturn->size () == 0 && apexUpdatableNames .size () != 0 ) {
610666 return Status::fromExceptionCode (Status::EX_SECURITY, " SELinux denied." );
611667 }
612668
0 commit comments