Commit graph

125 commits

Author SHA1 Message Date
Steven Moreland
e192a6721d Log VINTF manifest success/failure cases.
These logs are critical to understand the operation of the system, and
do not spam (1/hal start or 1/hal request). Most importantly, if a
manifest fails to be read for whatever reason, this is logged (null
manifest case).

Bug: 151696835
Test: boot, and verify logs of successful hal retrivals
Test: boot, and verify logs w/ patch which causes VINTF to fail the
  first time, and verify that this causes a single crash which gives us
  the ability to still find and detect a critical error, but allows the
  system functionality to continue to work.
Change-Id: I0a26b875947878656d6eda03ffebce97ebb6139e
Merged-In: I0a26b875947878656d6eda03ffebce97ebb6139e
2020-04-30 17:51:34 -07:00
Steven Moreland
d221c25182 servicemanager: remove performance hack
See details in TODO.

This hack is either causing a bug or may be preventing us from solving
another bug. Until the more critical bug can be fixed, avoiding
early-boot reads of VINTF manifest files.

Bug: 151696835
Test: run, boot, check manifest logs that HAL services register
Change-Id: Iba34afe451026a30e695d6728b4172007aaf7fbd
Merged-In: Iba34afe451026a30e695d6728b4172007aaf7fbd
2020-04-30 17:51:33 -07:00
TreeHugger Robot
edbc86de05 Merge "ServiceManager: Check guaranteeClient before unregistering services" into rvc-dev 2020-03-28 00:33:39 +00:00
Jon Spivack
bb108a1839 ServiceManager: Check guaranteeClient before unregistering services
If tryUnregisterService is called while a service has set guaranteeClient to true, it should not succeed. The flag means that a client exists and is about to be counted. Not checking this flag can lead to a race.

Bug: 151485917
Test: aidl_lazy_test
Change-Id: If7ef7a5c7521ea40521bd351385fb8bd650aba08
2020-03-16 17:01:26 -07:00
Jon Spivack
e17055a1c8 LazyServiceRegistrar: Add flag to prevent shutdown
This flag can be used to temporarily prevent dynamic services from being killed. For example, if a service needs to perform a task in the background it can set this flag and then disable it once the task is complete. The service will then go back to standard lazy behavior.

Bug: 150967269
Test: aidl_lazy_test
Change-Id: I840bbe4b6b0406f0e4de610367290448e7edd3de
2020-03-10 17:40:13 -07:00
Jon Spivack
d9533c21d3 Revert^2 "Dynamically stop services with multiple interfaces"
37f70cc102

Reason for revert: This undoes the previous reversion, which was made to fix b/148282665.

Change-Id: Ie855de284969af5dc937dc95daae84c3df107d32
2020-01-29 05:09:14 +00:00
Jon Spivack
37f70cc102 Revert "Dynamically stop services with multiple interfaces"
Revert "Add aidl_lazy_test_server to Cuttlefish"

Revert "Move aidl_lazy_test_server to system_ext"

Revert submission 1209453-aidl-lazy-presubmit

Reason for revert: b/148282665. A test has begun to fail on git_stage-aosp-master, and I need to verify whether these changes are responsible.

Reverted Changes:
Ib09a2460e: Add aidl_lazy_test to general-tests
Ib08989356: Move aidl_lazy_test_server to system_ext
I694e6ad35: Add aidl_lazy_test_server to Cuttlefish
I65db12c63: Add aidl_lazy_test to presubmit
I7ec80a280: Dynamically stop services with multiple interfaces...

Change-Id: I6d3b589bf2861f68d2852c8def7a1f51eea7cf97
2020-01-25 02:55:04 +00:00
Jon Spivack
5de798e910 Dynamically stop services with multiple interfaces
This fixes a couple workflow bugs with dynamic services that had multiple interfaces in use at once. Attempting to stop one could affect the reference count of the other, and re-adding it after a failed removal yielded duplicate registrations.

Bug: 146903840
Test: aidl_lazy_test
Change-Id: I7ec80a280dabf7c576b7b00dff404a68c24ae5f1
2020-01-16 18:46:23 -08:00
Jon Spivack
f288b1da59 ServiceManager: Internal renames
Renamed CallbackMap as ServiceCallbackMap to better distinguish it from the newly added ClientCallbackMap.

Bug: N/A
Test: aidl_lazy_test
Change-Id: I890ddbed5734dfeb9f7265fd424098f2bac2ffca
2019-12-23 20:05:29 +00:00
Jon Spivack
9f503a4285 Dynamically stop lazy services
Services can choose to register with the new LazyServiceRegistrar.
ServiceManager perpetually checks the reference counts of services
registered in this way. If ServiceManager detects that a service no
longer has any clients, it will notify the LazyServiceRegistrar, which
will attempt to shut down the service.

Bug: 143108344
Test: aidl_lazy_test
Change-Id: Ic01981b767ab4402e7aecdf1cdf9ed64df1f5af4
2019-12-19 20:17:06 -08:00
Jon Spivack
73f4c61ceb Merge "Fix iterator in ServiceManager::removeCallback" 2019-11-20 01:51:48 +00:00
Jon Spivack
e223f08add Fix iterator in ServiceManager::removeCallback
The pointer to the iterator in this function wasn't properly dereferenced, leading to an inifinite loop in ServiceManager::binderDied.

Bug: 144534962
Test: Manual (boot and dynamically start services)
Change-Id: Ie7b8685b5de31ab7c9ba5877b6df3af08aab0c0f
2019-11-19 16:21:20 -08:00
Steven Moreland
d13f08beac servicemanager: preload vintf manifest
Doing this asynchronously since it was delaying first client by ~6ms on
crosshatch and other devices.

Bug: 144282062
Test: on walleye, StartVibratorService ~9ms -> ~4ms.
Change-Id: I6cc65e74922b32c2e7135f583fa892fa26f85e2b
2019-11-18 14:23:09 -08:00
Steven Moreland
97d1d4522d servicemanager: avoid segfault on null manifest.
A device like this should fail VTS or other tests, but a segfault is
counterproductive.

Bug: 143744480
Test: TH
Change-Id: I71c42f1f8d5288152c6db43c33f44a7235df1265
2019-11-01 10:09:45 -07:00
Steven Moreland
b82b8f84b4 ServiceManager: add isDeclared
Most of the time, AIDL services exist in client/service pairs. In this
context, `while(true) getService` or `waitForService` makes sense.
However, for VINTF services, this client/server coupling isn't
guaranteed. A device may or may not have specific hardware. So, now
IServiceManager can tell a client when a server will exist so it will
know if it needs to wait for this service during boot-up. The function
waitForDeclaredService is provided for this.

These functions are generic (not referring to VINTF specifically)
because they may be expanded to include information about APEX services
in the future OR the infrastructure may be made generic to work, if
desired, on system services.

Bug: 141828236
Test: binderStabilityTest, using waitForDeclaredService function
Change-Id: Ia230625e44e1685cc3fa9230ece8f0a25c88585e
2019-10-28 15:45:14 -07:00
Steven Moreland
46f380b947 servicemanager: self-register
So that servicemanager isn't treated any differently for things like
dumpsys or other utilities that need to iterate over all services.

Bug: 136027762
Test: dumpsys -l
Change-Id: I82cc5e5261ff86d36da4fe49b434e88aa5368005
2019-10-17 14:07:13 -07:00
Tri Vo
6ea2698df4 servicemanager: lookup service labels using "service" backend
Type 0 actually corresponds file_contexts backend. Use type
SELABEL_CTX_ANDROID_SERVICE instead.
d4828b3ba4/include/selinux/label.h (27)

Test: boot cuttlefish; no denials to any service
Change-Id: I1c33c31ecbd46168998606c3463837a9c6f39f3a
2019-10-04 12:48:33 -07:00
Steven Moreland
86a17f87f6 servicemanager: check VINTF manifest for VINTF ifs
For interfaces that are exported API to vendor, check that the
interfaces are declared in the manifest before allowing them to
register.

Implements this relationship:
    Device using VINTF instance => instance in manifest

The manifest is used for two things:
- understand which HAL interfaces are used so that we don't deprecate
  them too early.
- understand which interfaces are on the device: this allows clients to
  depend on a HAL interface IFF it is installed.

Bug: 136027762
Test: try registering interface that is and isn't in the VINTF manifest
Change-Id: I8aa09a56c638a6cc3aa93f102caf09da401a143b
2019-09-17 11:21:18 -07:00
Treehugger Robot
6ae4e4c182 Merge "sm: use logcat over dmesg" 2019-09-10 18:41:31 +00:00
Steven Moreland
71486c1290 sm: use logcat over dmesg
For log visibility.

Bug: 140810300
Test: can see logs
Change-Id: I92e7f4c55f62f3a7cb6a3da04d0db7b4ca35d74b
2019-09-10 17:48:38 +00:00
Jon Spivack
0d84430bbc ServiceManager signals init to start lazy services
This allows services to be disabled at boot and dynamically enabled as
they are needed. When servicemanager receives a getService request,
it will check whether the service is running. If it is not,
servicemanager will attempt to start the service by signaling init with
the ctl.interface_start control message.

Bug: 138756857
Test: Manual (using mediaextractor as a test service), test_sm
Change-Id: Ic2d47d21769b936381e3fae2f2cf739d3b7501a4
2019-09-09 13:46:03 -07:00
Steven Moreland
27cfab02a0 servicemanager: notifications
You can now register and receive notifications for new services.

Eye towards:
- avoiding while(true) getService loops
- need it to make AIDL dynamic HALs
- need it for feature parity w/ HIDL

Bug: 136027762
Test: servicemanager_test
Change-Id: Iffbf984e87214aa9c9b7af8a5ae682e127ba40a5
2019-08-29 16:51:48 -07:00
Steven Moreland
130242db90 servicemanager: add sanity check in destructor
Documenting some invariants. Since I am adding some more APIs, I want
this to be explicit.

Bug: 136027762
Test: servicemanager_test
Change-Id: I67da9d92c3a457926739fb1f02411a57caefa5b8
2019-08-26 17:56:24 -07:00
Steven Moreland
bb7951d252 servicemanager: Allow '/' character in service names.
To work as instance name separater consistently w/ HIDL.

In HIDL, people are used to writing something like:
    android.hardware.light@2.0::ILight/default

In AIDL, the same thing would look like:
    android.hardware.light.ILight/default

Bug: 136027762
Test: use '/' in service name
Change-Id: Ie108029bd37b09647b761c5c5ce3a901dbfd4f19
2019-08-20 16:58:25 -07:00
Steven Moreland
88860b02b3 servicemanager: rely on auto unlinkToDeath
unlinkToDeath happens automatically when the last strong ref to a proxy
goes away (see 80d23935ff).

Bug: 136027762
Test: boot and check for log:
    "onLastStrongRef automatically unlinking death recipients"

Change-Id: Iec16013548d9bda24f6e96d5cf80c69071953cb0
2019-08-12 14:24:14 -07:00
Steven Moreland
cd551fab41 servicemanager: remove move check TODO
We won't move the check up because doing so doesn't appear to add much
of a benefit.

Fixes: 136023468
Test: N/A
Change-Id: Id3dea9e5a3a8bcc19c21b31ae7e4af0c3017e2a1
2019-08-01 18:29:23 -07:00
Steven Moreland
68039a1700 Expose service context name in denial.
In order to better debug errors!

Bug: 136023468
Test: boot, make and check denials
Change-Id: I97a0b29b2b9a96fa4f2f53b9cbecfafb56ee2d0f
2019-08-01 02:47:59 +00:00
Steven Moreland
a9fe474392 CallingContext doesn't have a name in it.
This makes checking multiple things in the policy painful (which we may
need to do in the future). Also, it makes the APIs around listing
services somewhat bad.

Bug: 135768100
Test: servicemanager_test
Change-Id: I29cac39f6b63934740aa07a192e06b74ce8580ed
2019-07-18 14:45:20 -07:00
Steven Moreland
905e2e8534 servicemanager: restrict service name characters
This is in order to, in the future, potentially have special policy
like:
vendor$vendor_service u:object_r:...:s0
universal$hal_foo_service u:object_r:...:s0

Currently, there are no special characters that could be used for this
purpose.

How safe is this? In all context files in our internal tree, only the
following characters are used in service names:
-._12aAbBcCdDeEfFgGhHiIjkKlmMnNoOpPqQrsStTuUvwWxyz

'.' appears everywhere to mean '\.'.

Test: servicemanager_test
Bug: 136027762
Change-Id: Idd6698a68bbbe825dd5a25d92baf81fae473ea2a
2019-07-17 11:05:45 -07:00
Steven Moreland
d2fe5c5dc0 Merge "servicemanager: TEST_MAPPING += libbinder tests" into stage-aosp-master 2019-07-15 15:49:36 +00:00
Steven Moreland
e4ae09fe85 servicemanager: TEST_MAPPING += libbinder tests
Import libbinder tests. Due to the global nature of the SM, these tests
frequently make use of the servicemanager.

Bug: 137203409
Test: TH
Change-Id: I40777d7e859ac7fdba686e12ef515406eace2c07
2019-07-11 10:58:46 -07:00
Steven Moreland
1ac84c46e8 Init ProcessState w/ initWithDriver.
vndservicemanager was calling 'self' before 'initWithDriver':
ProcessState::self()->initWithDriver(...);

However, 'self' inits the driver. On devices with the VNDK, this caused
no problem because libbinder automatically inits to the correct driver
node. However, on legacy devices, vndservicemanager tried to use
/dev/binder unsuccessfully.

Bug: 137216568
Test: TH
Change-Id: I8dc9dac0592784a16ae0abd270718ae353aa81c3
2019-07-10 17:54:15 -07:00
Steven Moreland
80e1e6de29 servicemanager: use libbinder
Bug: 135768100
Test: boot
Test: servicemanager_test

Change-Id: I9d657b6c0d0be0f763b6d54e0e6c6bc1c1e3fc7a
(cherry picked from commit 3e092daa14)
2019-07-09 01:54:25 +00:00
Christopher Ferris
f5c0e909b1 Update for kernel headers v5.0.3.
All of the structures in binder_kernel.h are now in the upstream kernel.

Test: Builds.
Change-Id: I3719b1ca48515170eca5834b1a29f15086441b50
2019-03-20 17:28:32 -07:00
Steven Moreland
5516d77f61 SafetyNet logging from vendor.
These weren't enabled because of the below bug causing denials.

Bug: 113083310
Bug: 121035042
Test: no denials
Change-Id: Ie32a5c99f1488fdbfcabb19aff8fa1f3ff2c7b63
2019-01-10 22:02:05 +00:00
Steven Moreland
3d79547d54 Get SID from kernel.
Bug: 121035042
Test: boot
Change-Id: I0941e5a13305859e1b913ec4451173e5408c808e
2019-01-07 10:57:04 -08:00
TreeHugger Robot
878d9253e0 Merge "Add hook into thermalservice" 2018-10-27 00:03:25 +00:00
Wei Wang
13b1877b77 Add hook into thermalservice
1) restart thermalservice if servicemanager dies
2) restart zygote if thermalservice dies as we don't have death notifier
registered for this native service
3) set to foreground task for thermalservice to speed the callback

Fixes: 118495176
Bug: 113037689
Bug: 118509057
Test: kill and see service restarts
Change-Id: I50785592a19b7a667a4f1ff42bc9ea218e81f758
2018-10-26 23:22:55 +00:00
Olivier Gaillard
0e0f1de59b Add worksource support to binder calls.
Unlike android.os.WorkSource, we only support the leaf UID of the work
chain here for performance reasons.

We use a similar mechanism to how we propagate the StrictMode flags. The
enforceInterface and writeInterfaceToken are used to pass the worksource
through the parcel. enforceInterface/writeInterfaceToken is at least
used by all the services using AIDL.

It might break code which is reading/writing raw parcels. For instance,
a client calling an AIDL service and replicating what enforceInterface
is doing, e.g. service_manager.c. This is the only client which seems to
do that.

Here is an example of how this API is supposed to be used:
Binder.setThreadWorkSource(uid);
try {
  // Call an API.
} finally {
  Binder.clearThreadWorkSource();
}

An alternative would be to clear the work source automatically on behalf
of the caller. Manually setting the work source has been chosen to give
more control to callers of the API:
- they might choose to call setThreadWorkSource once and do multiple binder calls
- callers can also decide whether they want to restore the work source
to the orginal
value.

We do not throw an exception when #setThreadWorkSource overrides an
existing work source. It would be really hard to figure when it is safe
to call #setThreadWorkSource. For instance, adding a binder transaction
might make some code down the line that calls #setThreadWorkSource throw
an exception (because the binder transaction would set the work source
on the thread).

Ran the binder performance test suite
(test/vts-testcase/performance/binder_benchmark/binder_performance_test/).

There is no difference in terms of cpu/real time:
- without patch
{
  "name": "BM_sendVec_binder/4",
  "iterations": 43088,
  "real_time": 3.0151086752702871e+04, // yes, time is higher without patch
  "cpu_time": 1.4715999326958785e+04,
  "time_unit": "ns"
{
  "name": "BM_sendVec_binder/8",
  "iterations": 48335,
  "real_time": 2.8371138740033064e+04,
  "cpu_time": 1.3710703486086690e+04,
  "time_unit": "ns"
},

- with patch
{
  "name": "BM_sendVec_binder/4",
  "iterations": 48214,
  "real_time": 2.8613625191853276e+04,
  "cpu_time": 1.4305279856473226e+04,
  "time_unit": "ns"
},
{
  "name": "BM_sendVec_binder/8",
  "iterations": 49998,
  "real_time": 2.8749066382655215e+04,
  "cpu_time": 1.4422315992639707e+04,
  "time_unit": "ns"
},


Test: unit tests and manually tested on my phone
Change-Id: I167abbbfa6e7c4b0933c4cafa04df810f4814e2b
2018-10-23 14:22:32 +01:00
Steven Moreland
41b69be72c vndservicemanager: use selinux_vendor_log_callback
This function only uses vendor APIs even on non-VNDK devices. This
is to support the usecase of vndservicemanager on a legacy device
which has the VNDK disabled.

Bug: 113083310
Test: boot up device and see usage of /system/etc/event-log-tags
    denials go away.

Change-Id: I0fd86cce303bf169f6d5b1b873221302e5b260b1
2018-09-06 17:07:33 -07:00
Ivan Lozano
43c64c3f03 Merge "Keystore and gatekeeper not working when servicemanager crashed" am: c81d9b84c3 am: d32d93125c
am: 6780e1a578

Change-Id: Id42b9431c97bebd3fb308a455db6d07df66c19bd
2017-12-07 05:52:10 +00:00
Treehugger Robot
c81d9b84c3 Merge "Keystore and gatekeeper not working when servicemanager crashed" 2017-12-06 21:55:50 +00:00
Jiyong Park
0c0da3814e Merge "Remove libselinux_vendor" am: cd4895df08 am: 016e9504ae am: ad119fd2ad
am: 886d5976b4

Change-Id: I5b610cd06b89c14a34b5d42ad7270cf1b8c45a6c
2017-10-20 02:37:24 +00:00
Jiyong Park
016e9504ae Merge "Remove libselinux_vendor"
am: cd4895df08

Change-Id: I461e1ffd3d2f3b7e1ac4027b2a280eb9fc33a047
2017-10-20 01:11:41 +00:00
Jiyong Park
a6974e9e50 Remove libselinux_vendor
libselinux now becomes a vendor_available:true library.

Bug: 66914194
Test: lunch aosp_arm64_ab-userdebug; m vndservicemanager

Change-Id: I9885c8656f42f79cf218d978feff79a47d16e1b3
2017-10-19 17:28:38 +09:00
Vishnu Nair
f56042d6a4 Pass dumpsys priority to IServiceManager
Modify IServiceManger to accept supported dumpsys priority as a bitmask
with NORMAL being the default priority. Change listServices to return
a list of services filtered by the priority or all services when the
priority is set to ALL.

BUG:27429130

Test: mmm -j32 frameworks/native/cmds/dumpsys && \
      adb sync data && adb shell /data/nativetest/dumpsys_test/dumpsys_test && \
      adb shell /data/nativetest64/dumpsys_test/dumpsys_test && \
      printf "\n\n#### ALL TESTS PASSED ####\n"

Change-Id: Ibccba63035ace9970c2967a621ee2ad8d15cbeea
2017-09-25 14:37:18 -07:00
Sandeep Patil
30556fc7e7 vndservicemanager: remove static dependency on libselinux
libselinux_vendor is part of VNDK. No need to statically link
to it anymore.

Bug: 37343404
Test: Build and boot
Test: 'vndservice list' to ensure all services are listed as before

Change-Id: I5b3151f44f7b77ce0f2ff4bba38550a3d7e35375
Signed-off-by: Sandeep Patil <sspatil@google.com>
Merged-In: I5b3151f44f7b77ce0f2ff4bba38550a3d7e35375
2017-09-05 16:38:39 -07:00
Yifan Hong
4b0185e688 Merge "Use cutils/android_filesystem_config.h" into oc-mr1-dev
am: 595ff4798d

Change-Id: I3a8917e1389963f3ae457676eb30300f7526b07c
2017-08-03 23:01:19 +00:00
Yifan Hong
cb4c58bda0 Merge commit '219b580fed7916ed4e02dd634e003073f91c6b93' into manual_merge_219b580fe am: 84548cfbfb
am: 5cd3d789b8

Change-Id: I4476bca7b0b5e0a17af504a2b21a51d26b069587
2017-08-03 20:39:52 +00:00
Yifan Hong
84548cfbfb Merge commit '219b580fed7916ed4e02dd634e003073f91c6b93' into manual_merge_219b580fe
Test: pass
Change-Id: Ic796fced51004d4a716c754fc8c0d347c33af8ff
2017-08-03 12:35:02 -07:00