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

Commit 344698b5 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Don't use SMS database until after the phone is unlocked

When the device is encrypted and a passcode is set,
the SMS database isn't available and the MAP service
crashes when trying to access it. The service will now
respond with OBEX_SERVICE_UNAVAILABLE until the phone
is unlocked. At this point, the SMS database will
notify the content observer that all the messages are
available, and send corresponding events.

Bug: 29990836
Change-Id: I53f12d0e114212d94f16b56df7c7dbe73f6254df
(cherry picked from commit 21ca2d8a)
Merged-In: I53f12d0e114212d94f16b56df7c7dbe73f6254df
parent df35235b
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserManager;
import android.provider.Telephony;
import android.provider.Telephony.Mms;
import android.provider.Telephony.MmsSms;
@@ -1180,9 +1181,10 @@ public class BluetoothMapContentObserver {

    private void initMsgList() throws RemoteException {
        if (V) Log.d(TAG, "initMsgList");
        UserManager manager = UserManager.get(mContext);
        if (manager == null || manager.isUserUnlocked()) return;

        if (mEnableSmsMms) {

            HashMap<Long, Msg> msgListSms = new HashMap<Long, Msg>();

            Cursor c = mResolver.query(Sms.CONTENT_URI,
@@ -3332,6 +3334,8 @@ public class BluetoothMapContentObserver {
    private void resendPendingMessages() {
        /* Send pending messages in outbox */
        String where = "type = " + Sms.MESSAGE_TYPE_OUTBOX;
        UserManager manager = UserManager.get(mContext);
        if (manager == null || !manager.isUserUnlocked()) return;
        Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null,
                null);
        try {
+33 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.UserManager;
import android.text.format.DateUtils;
import android.util.Log;

@@ -397,6 +398,11 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
        return ResponseCodes.OBEX_HTTP_OK;
    }

    private boolean isUserUnlocked() {
        UserManager manager = UserManager.get(mContext);
        return (manager == null || manager.isUserUnlocked());
    }

    @Override
    public int onPut(final Operation op) {
        if (D) Log.d(TAG, "onPut(): enter");
@@ -432,6 +438,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    Log.d(TAG,"TYPE_SET_NOTIFICATION_FILTER: NotificationFilter: "
                            + appParams.getNotificationFilter());
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
                    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
                }
                mObserver.setNotificationFilter(appParams.getNotificationFilter());
                return ResponseCodes.OBEX_HTTP_OK;
            } else if (type.equals(TYPE_SET_MESSAGE_STATUS)) {
@@ -441,6 +451,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                            + ", StatusValue: " + appParams.getStatusValue()
                            + ", ExtentedData: " + "" ); // TODO:   appParams.getExtendedImData());
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
                    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
                }
                return setMessageStatus(name, appParams);
            } else if (type.equals(TYPE_MESSAGE)) {
                if(V) {
@@ -448,6 +462,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                            + ", retry: " + appParams.getRetry()
                            + ", charset: " + appParams.getCharset());
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
                    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
                }
                return pushMessage(op, name, appParams, mMessageVersion);
            } else if (type.equals(TYPE_SET_OWNER_STATUS)) {
                if(V) {
@@ -881,6 +899,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    Log.d(TAG,"FilterConvoId = " + ((tmpLongLong == null) ? "" :
                        Long.toHexString(tmpLongLong.getLeastSignificantBits()) ) );
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " +  type + " failed");
                    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
                }
                // Block until all packets have been send.
                return sendMessageListingRsp(op, appParams, name);

@@ -895,6 +917,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    Log.d(TAG,"FilterReadStatus = " + appParams.getFilterReadStatus());
                    Log.d(TAG,"FilterRecipient = " + appParams.getFilterRecipient());
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
                    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
                }
                // Block until all packets have been send.
                return sendConvoListingRsp(op, appParams,name);
            } else if (type.equals(TYPE_GET_MAS_INSTANCE_INFORMATION)) {
@@ -912,6 +938,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                            ", Charset = " + appParams.getCharset() +
                            ", FractionRequest = " + appParams.getFractionRequest());
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
                    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
                }
                // Block until all packets have been send.
                return sendGetMessageRsp(op, name, appParams, mMessageVersion);
            } else {