Commit Graph

18 Commits

Author SHA1 Message Date
Remi NGUYEN VAN
383151a7e0 Add tests for NetworkStack failure notifications
The test adds a dependency on mockito extended to be able to mock the
Context, PackageManager etc.

Test: atest PackageWatchdogTest#testNetworkStackFailure (+rest of class)
Bug: 133725814
Change-Id: Iba8a47f5e94b5dba49d6d395085e77285305ee7c
2019-05-30 23:27:39 +09:00
Remi NGUYEN VAN
6a135107ff PackageWatchdog listens for NetworkStack failures
In addition to the NetworkStack app monitoring, have PackageWatchdog
register an observer to NetworkStackClient to receive severe failure
notifications, and attempt a rollback if available.

The callback is registered in onPackagesReady(), which is called in the
boot sequence just before starting the NetworkStack.

Test: installed new networkstack, killed it twice, observe rollback
Test: unit test in change on top
Bug: 133725814
Change-Id: I2cb4200b78c2482cacc4bfe2ace1581b869be512
2019-05-30 21:52:51 +09:00
shafik
8296290f46 Update PackageWatchdogTest
Make PackageWatchdogTest compatible to the changes that added
DeviceConfig flags to PackageWatchdog. This includes:
    * Make PackageWatchdog#setExplicitHealthCheckEnabled private and
    use DeviceConfig mechanism for changing that value instead
    * Disable TestLooper#startAutoDispatch
    * Other minor refinements that solve compatibility issues

Bug: 129335707
Test: atest com.android.server.PackageWatchdogTest
Merged-In: I7323dc65ec2957aeab128224864441bdf63c6f81

Change-Id: I7323dc65ec2957aeab128224864441bdf63c6f81
2019-05-01 12:31:05 +00:00
Zimuzo
1a9aac7b33 Change watchdog PackageInfo to PackageConfig
Test: atest PackageWatchdogTest
Bug: 131165818
Change-Id: Ie3a385468a0de05bc55862e6f71513077d44bbc0
2019-04-24 20:44:52 +01:00
Zimuzo
6997f3c852 Fixed PackageWatchdog health check state
1. Receiving List<PackageInfo>:
Since I29e2d619a5296716c29893ab3aa2f35f69bfb4d7, we now receive a
List of PackageInfo instead of Strings for packages supporting
explicit health checks. Now, we parse this List<PackageInfo> from
ExtServices instead of trying to parse List<String> and we use the
health check timeout in the PackageInfo as the health check expiry
deadline instead of using the total package expiry time.

2. Updating health check durations onSupportedPackages:
Before, we always updated the health check duration for a
package if the package is supported and the health check state is
not PASSED, this caused the health check duration for a package to
never reduce as long as we kept getting onSupportedPackages. Now, we
improved the readability of the state transitions onSupportedPackages.
We now correctly only update the health check duration for supported
packages in the INACTIVE state.

3. FAILED state:
Before we only had INACTIVE, ACTIVE and PASSED states. When a package
has failed the health check we could notify the observer multiple
times in quick succession and get into a bad internal state with
negative health check durations. Now we added check to ensure we
don't try to schedule with a Handler with a negative duration and we
defined a negative health check duration to be a new FAILED state if the
health check is not passed. This clearly defines the state transitions
as seen below:

+----------+     +---------+    +------+
|          |     |         |    |      |
| INACTIVE +---->+ ACTIVE  +--->+PASSED|
|          |     |         |    |      |
+-----+----+     +----+----+    +------+
      |               |
      |               |
      |               |
      |               |
      |          +----v----+
      |          |         |
      +----------> FAILED  |
                 |         |
                 +---------+

4. Uptime state:
Everytime we pruned observers, we scheduled the next prune and stored
the current SystemClock#uptimeMillis. This allowed us determine how
much time had elapsed for the next prune. The uptime was not correclty
updated when starting to observe already observed packages. With the
following sequence of events:

-monitor package A for 1hr
-30mins elapsed
-monitor package A again for 1hr

A would expire 30mins from the last event instead of 1hr.
This was because the second time around, we
saved the new state to disk but did not reschedule so did not update
the uptime at last schedule, so 1hr from the first event, we would
prune packages with the original uptime and incorrectly expire A
earlier. Now we update all internal state, fixed this and added a test
for this case.

5. Readability
Improved method variable names, logging and comments.

Bug: 120598832
Test: Manual testing && atest PackageWatcdogTest
Change-Id: I1512d5938848ad26b668636405fe9b0db50d3a2e
2019-04-11 13:51:58 +01:00
Zimuzo
7c6c28f18b Allow different explicit health and package expiry timeouts
We have always evaluated the explicit health check results on package
expiry. Since I29e2d619a5296716c29893ab3aa2f35f69bfb4d7 we now receive
explicit health check timeouts from ExtServices. This cl doesn't yet
use the timeout but it treats explicit health check timeouts as
different events from package expiry. This is in preparation to use
the timeouts from the cl mentioned above.

Improved readability: Logging, comments, variable and function names

Bug: 120598832
Test: atest PackageWatchdogTest
Change-Id: I8030dae1fef5b8fee42095c1eaf16861cc33ac59
2019-04-08 11:33:14 +01:00
Zimuzo
cb148b2ce0 Refactor PackageWatchdog explicit health checks
Improvements:

1. Queuing PackageWatchdog requests to startObserving packages:
When observing packages with the watchdog, we needed to get
the packages supporting explicit health checks so we can decide if a
package should be passing or not. This prevents us from receiving
requests to monitor packages during early boot, before third party
packages are ready. In this change we don't depend on ExtServices to
be up to startObserving, we initially treat all package as failing a
health check and lazily syncRequests to request or cancel explicit
health checks based on the currently observed packages. When we receive
onSupportedPackages, we mark the packages that don't support health
checks as passing.

2. Lazy binding to the explicit health check service:
We were always bound to the explicit health check
service regardless of whether we are expecting requests or not, we need
to be able to bind and unbind dynamically to improve device resource
usage. In this change, we bind as soon as we make a request and are
expecting results, we unbind otherwise.

3. Fixed Races:
There were a couple of potential races that could lead to exceptions
that could bring the system server down, e.g when the service is
transitioning between disconnected and connected state (maybe it
crashed) or when ExtServices is being upated and is down or early
boot requests when third party apps are not ready. This change fixes such.

4. Logging:
We improved the logging wording and order and made it more consistent

Bug: 120598832
Test: Manual tests. Stress tested behavior by killing extservices and
making requests simultaneously

function killproc {
    while true
    do
        local pid=$(adb shell pidof $1)
        if [[ ! -z $pid ]]
        then
            echo $pid
            adb shell kill $pid
        fi
    done;
}

adb install-multi-package -i com.android.shell --enable-rollback \
NetworkStack.apk ModuleMetadataGoogle.apk

Also switched between enabled and disabled states to verify packages
are handled correctly. Will automate these tests in later cl

atest PackageWatchdogTest
Change-Id: Iafaef553e95d107f700109f9a8328950a5e2bf71
2019-04-04 23:26:49 +00:00
Zimuzo
caa435ef51 Add explicit health check to PackageWatchdog
PackageWatchdog now uses the ExplicitHealthCheckController introduced
in Ia030671c99699bd8d8273f32a97a1d3b7b015d3b when observing packages.

Bug: 120598832
Test: Manually tested that after an APEX update, the network stack
does not pass the explicit health check until WiFi is connected
successfully. If Wi-Fi is never connected and the network stack
monitoring duration is exceeded, the update is rolled back.

Change-Id: I75d3cc909cabb4a4eb34df1d5022d1afc629dac3
2019-04-01 14:02:56 +00:00
Sasha Smundak
89414e1ed5 Convert tests/**/Android.mk files to Android.bp, part II
See build/soong/README.md for more information.

Bug: 122332340
Test: treehugger
Change-Id: I886b6536a0ef1c8d21f15ec7ff9fdb9784d5b865
2019-03-12 09:37:32 -07:00
Zimuzo
ef65fb8424 Fail package if explicit health check does not pass
As part of extending PackageWatchdog with explicit health check support
in Ib4322c327bcb00ca9a3fbdc83579e7b5f2fd633b. Trigger the observers #execute
method if a package never passed explicit health check on expiry.

Bug: 120598832
Test: atest PackageWatchdogTest
Change-Id: I8e916a6ca115d3883fe29f66456da36cd0ed09fb
2019-03-06 14:05:09 +00:00
Zimuzo Ezeozue
101ac58981 Merge "Extend PackageWatchdog with explicit health checks" 2019-03-06 10:25:22 +00:00
Zimuzo
9284e74585 Extend PackageWatchdog with explicit health checks
Allow PackageWatchdog to monitor packages with explicit health checks
enabled. In this case, at the end of a monitoring duration if a
passed-health-check callback is not triggered, the package would be
regarded as failed (in a later cl) and the observer is notified.
If monitoring without explicit health checks, the behavior is the same
as before, packages expire silently.

TODO: Implement the package failure trigger on expiry with failed
explict checks and enable added tests

Removed username from TODO comments

Bug: 120598832
Test: atest PackageWatchdogTest
Change-Id: Ib4322c327bcb00ca9a3fbdc83579e7b5f2fd633b
2019-03-06 05:41:42 +00:00
Brett Chabot
502ec7ae4b Migrate remainder of frameworks/base to androidx.test
See go/jetpack-test-android-migration

Exempt-From-Owner-Approval: automated package name refactoring

Test: m  m -j BroadcastRadioTests KeystoreTests mediaframeworktest ActivityManagerPerfTests AppLaunch AppLaunchWear BackgroundDexOptServiceIntegrationTests AppCompatibilityTest DynamicCodeLoggerIntegrationTests FlickerLibTest InternalTests PackageWatchdogTest RcsTests RollbackTestAppAv1 RollbackTestAppAv2 RollbackTestAppACrashingV2 RollbackTestAppBv1 RollbackTestAppBv2 RollbackTestAppASplitV1 RollbackTestAppASplitV2 RollbackTest ServiceCrashTest UsageStatsPerfTests UsbTests WindowAnimationJank
Change-Id: I32fe3297656eec6060da6c7e24582bcd5315fb16
2019-03-02 00:35:17 +00:00
Zimuzo
71d931e9c8 Refactor PackageWatchdog to use VersionedPackage
We now pass a VersionedPackage argument instead of passing separate
method arguments for packageName and versionCode.

Test: atest PackageWatchdogtest
Bug: 120598832
Change-Id: I8dd7e6d1e144251830108c58f4a752c411d7295b
2019-02-01 13:43:09 +00:00
Zimuzo
972e1cdb2e Notify PackageHealthObservers of the package versionCode on package failure
PackageHealthObservers may need to verify that the package failure
notification they receive matches the expected package version code.
We now pass the version code along with the package name when notifying
observers.

Test: atest com.android.server.PackageWatchdogTest
Bug: 120598832
Change-Id: I272965d08a07240f3bde358039b52187ff2dd3cf
2019-01-29 22:43:04 +00:00
Zimuzo
e5009cd82c Add PackageHealthObserverImpact
When a package fails health check, observers will report the impact of their
action on the user. Only the observer with the least user impact will be
allowed to take action.

Bug: 120598832
Test: atest PackageWatchdogTest
Change-Id: I15f358cd599431e1d7ea211aea5b1391f4aa33ab
2019-01-28 08:24:15 +00:00
Allen Hair
f134eb793b Depend on services.core instead of services to fix coverage build.
Bug: 122839224
Test: EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true SKIP_BOOT_JARS_CHECK=true WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY=true mma
Change-Id: Idfd55f951de60905dc68ada087f23dd670a84ec0
2019-01-14 17:49:51 -08:00
Zimuzo
3eee43845a Fix PackageWatchdog and add PackageWatchdogTest
Fixes:
1. Remove registered observer when removed from persisted file
2. Only call external observers after threshold is exceeded
3. Handle edge case where we reschedule package cleanup and elapsed time
is longer than scheduled duration
4. Modify code to allow easier testing

Bug: 120598832
Test: atest PackageWatchdogTest

Change-Id: I92181136fb5994a4d8ebe976be3138f210e853a5
2019-01-11 14:45:28 +00:00