Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c9a3501 authored by Adrian Roos's avatar Adrian Roos
Browse files

Pass initiatedByUser to TrustListeners

Bug: 16840500
Change-Id: I8d9bd8fe9a305066f33ac5c888d8a41ce219a6f1
parent 04e5f72c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,6 +22,6 @@ package android.app.trust;
 * {@hide}
 */
oneway interface ITrustListener {
    void onTrustChanged(boolean enabled, int userId);
    void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser);
    void onTrustManagedChanged(boolean managed, int userId);
}
 No newline at end of file
+17 −7
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ public class TrustManager {
    private static final int MSG_TRUST_MANAGED_CHANGED = 2;

    private static final String TAG = "TrustManager";
    private static final String DATA_INITIATED_BY_USER = "initiatedByUser";

    private final ITrustManager mService;
    private final ArrayMap<TrustListener, ITrustListener> mTrustListeners;
@@ -95,14 +96,17 @@ public class TrustManager {
        try {
            ITrustListener.Stub iTrustListener = new ITrustListener.Stub() {
                @Override
                public void onTrustChanged(boolean enabled, int userId) throws RemoteException {
                    mHandler.obtainMessage(MSG_TRUST_CHANGED, (enabled ? 1 : 0), userId,
                            trustListener).sendToTarget();
                public void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser) {
                    Message m = mHandler.obtainMessage(MSG_TRUST_CHANGED, (enabled ? 1 : 0), userId,
                            trustListener);
                    if (initiatedByUser) {
                        m.getData().putBoolean(DATA_INITIATED_BY_USER, initiatedByUser);
                    }
                    m.sendToTarget();
                }

                @Override
                public void onTrustManagedChanged(boolean managed, int userId)
                        throws RemoteException {
                public void onTrustManagedChanged(boolean managed, int userId) {
                    mHandler.obtainMessage(MSG_TRUST_MANAGED_CHANGED, (managed ? 1 : 0), userId,
                            trustListener).sendToTarget();
                }
@@ -139,7 +143,11 @@ public class TrustManager {
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case MSG_TRUST_CHANGED:
                    ((TrustListener)msg.obj).onTrustChanged(msg.arg1 != 0, msg.arg2);
                    boolean initiatedByUser = msg.peekData() != null &&
                            msg.peekData().getBoolean(DATA_INITIATED_BY_USER);
                    ((TrustListener)msg.obj).onTrustChanged(
                            msg.arg1 != 0, msg.arg2, initiatedByUser);

                    break;
                case MSG_TRUST_MANAGED_CHANGED:
                    ((TrustListener)msg.obj).onTrustManagedChanged(msg.arg1 != 0, msg.arg2);
@@ -153,8 +161,10 @@ public class TrustManager {
         * Reports that the trust state has changed.
         * @param enabled if true, the system believes the environment to be trusted.
         * @param userId the user, for which the trust changed.
         * @param initiatedByUser indicates that the user has explicitly initiated an action that
         *                        proves the user is about to use the device.
         */
        void onTrustChanged(boolean enabled, int userId);
        void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser);

        /**
         * Reports that whether trust is managed has changed
+4 −1
Original line number Diff line number Diff line
@@ -229,13 +229,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
    private SparseBooleanArray mUserFingerprintRecognized = new SparseBooleanArray();

    @Override
    public void onTrustChanged(boolean enabled, int userId) {
    public void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser) {
        mUserHasTrust.put(userId, enabled);

        for (int i = 0; i < mCallbacks.size(); i++) {
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
            if (cb != null) {
                cb.onTrustChanged(userId);
                if (enabled && initiatedByUser) {
                    cb.onTrustInitiatedByUser(userId);
                }
            }
        }
    }
+5 −0
Original line number Diff line number Diff line
@@ -178,6 +178,11 @@ public class KeyguardUpdateMonitorCallback {
     */
    public void onTrustManagedChanged(int userId) { }

    /**
     * Called when the user has proved to a trust agent that they want to use the device.
     */
    public void onTrustInitiatedByUser(int userId) { }

    /**
     * Called when a fingerprint is recognized.
     * @param userId
+5 −6
Original line number Diff line number Diff line
@@ -93,7 +93,6 @@ public class TrustAgentWrapper {
                    mTrusted = true;
                    mMessage = (CharSequence) msg.obj;
                    boolean initiatedByUser = msg.arg1 != 0;
                    // TODO: Handle initiatedByUser.
                    long durationMs = msg.getData().getLong(DATA_DURATION);
                    if (durationMs > 0) {
                        mHandler.removeMessages(MSG_TRUST_TIMEOUT);
@@ -102,7 +101,7 @@ public class TrustAgentWrapper {
                    mTrustManagerService.mArchive.logGrantTrust(mUserId, mName,
                            (mMessage != null ? mMessage.toString() : null),
                            durationMs, initiatedByUser);
                    mTrustManagerService.updateTrust(mUserId);
                    mTrustManagerService.updateTrust(mUserId, initiatedByUser);
                    break;
                case MSG_TRUST_TIMEOUT:
                    if (DEBUG) Slog.v(TAG, "Trust timed out : " + mName.flattenToShortString());
@@ -115,7 +114,7 @@ public class TrustAgentWrapper {
                    if (msg.what == MSG_REVOKE_TRUST) {
                        mTrustManagerService.mArchive.logRevokeTrust(mUserId, mName);
                    }
                    mTrustManagerService.updateTrust(mUserId);
                    mTrustManagerService.updateTrust(mUserId, false);
                    break;
                case MSG_RESTART_TIMEOUT:
                    unbind();
@@ -130,7 +129,7 @@ public class TrustAgentWrapper {
                            if (DEBUG) Log.v(TAG, "Re-enabling agent because it acknowledged "
                                    + "enabled features: " + mName);
                            mTrustDisabledByDpm = false;
                            mTrustManagerService.updateTrust(mUserId);
                            mTrustManagerService.updateTrust(mUserId, false);
                        }
                    } else {
                        if (DEBUG) Log.w(TAG, "Ignoring MSG_SET_TRUST_AGENT_FEATURES_COMPLETED "
@@ -144,7 +143,7 @@ public class TrustAgentWrapper {
                        mMessage = null;
                    }
                    mTrustManagerService.mArchive.logManagingTrust(mUserId, mName, mManagingTrust);
                    mTrustManagerService.updateTrust(mUserId);
                    mTrustManagerService.updateTrust(mUserId, false);
                    break;
            }
        }
@@ -282,7 +281,7 @@ public class TrustAgentWrapper {
        }
        if (mTrustDisabledByDpm != trustDisabled) {
            mTrustDisabledByDpm = trustDisabled;
            mTrustManagerService.updateTrust(mUserId);
            mTrustManagerService.updateTrust(mUserId, false);
        }
        return trustDisabled;
    }
Loading