Add Copy-On-Write mode to InputMethodSettings.

This is a preparation for File-Based Encryption (FBE) support in IMMS.

In order to support File-Based Encryption (FBE), IMMS needs to reset
its internal state exactly when the device is unlocked by user first
time. This is important because IMMS would recognize only
encryption-aware input method services until the the device is unlocked
by the current user.

Even if we reset the internal state when the device is unlocked by the
current user, there are still two tricky points.

 1. Except for the initial boot, IMMS uses Secure Settings to determine
    what IMEs are enabled and what IME is currently selected.  These
    persistent state may not be suitable for the situation where the
    device is not unlocked yet, because some of IMEs referenced there
    may or may not be encryption-aware.  Depending on the situations,
    we may need to enable at least one encryption-aware IME to ensure
    that the user is able to type password to unlock the device, even if
    such an IME is not Settings.Secure.ENABLED_INPUT_METHODS.  We have
    to be careful when doing this because we don't want non
    pre-installed IMEs to be enabled until the user approves it.
 2. IMMS tends to save its internal state into Secure Settings.
    However, because of the point 1, we may need to automatically enable
    a certain IME to make sure the user is able to type even when the
    device is not unlocked yet.  We don't want such a temporary state
    to be persistent in Secure Settings.

The basic idea of this CL is to implement Copy-On-Write (COW) mode in
InputMethodSettings so that we can later discard any changes made before
the device is unlocked.  As the initial step, we start using this COW
mode until the the ActivityManager becomes ready.  With this change we
can revert a previous commit [1] for Bug 6685037, where forward-locked
encrypted apks need to be taken care of an early boot phase.

  [1] Ifb311f85154beadd4787ec73669bedfdf1f5172d
      4c0e7152e74d091eb78af8baacd38287ba95a1a1

Bug: 26279466
Change-Id: I9c6f9bb3d51174198e5f73588637f87ea0d90e11
2 files changed