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

Commit c76e8f76 authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by Gerrit Code Review
Browse files

Merge changes Ib961049c,I15a0b54b

* changes:
  MAP Client: Cleanup fails in some instances
  MapClient clean up at start
parents 344c8a53 b3eb9cd6
Loading
Loading
Loading
Loading
+43 −9
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.provider.Telephony;
import android.provider.Telephony.Mms;
import android.provider.Telephony.Mms;
import android.provider.Telephony.MmsSms;
import android.provider.Telephony.MmsSms;
import android.provider.Telephony.Sms;
import android.provider.Telephony.Sms;
import android.provider.Telephony.Threads;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneNumberUtils;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
@@ -123,12 +124,29 @@ class MapClientContent {
            }
            }
        };
        };


        clearMessages();
        clearMessages(mContext, mSubscriptionId);
        mResolver.registerContentObserver(Sms.CONTENT_URI, true, mContentObserver);
        mResolver.registerContentObserver(Sms.CONTENT_URI, true, mContentObserver);
        mResolver.registerContentObserver(Mms.CONTENT_URI, true, mContentObserver);
        mResolver.registerContentObserver(Mms.CONTENT_URI, true, mContentObserver);
        mResolver.registerContentObserver(MmsSms.CONTENT_URI, true, mContentObserver);
        mResolver.registerContentObserver(MmsSms.CONTENT_URI, true, mContentObserver);
    }
    }


    static void clearAllContent(Context context) {
        SubscriptionManager subscriptionManager = (SubscriptionManager) context
                .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        List<SubscriptionInfo> subscriptions = subscriptionManager.getActiveSubscriptionInfoList();
        for (SubscriptionInfo info : subscriptions) {
            if (info.getSubscriptionType() == SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM) {
                clearMessages(context, info.getSubscriptionId());
                try {
                    subscriptionManager.removeSubscriptionInfoRecord(info.getIccId(),
                            SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
                } catch (Exception e) {
                    Log.w(TAG, "cleanUp failed: " + e.toString());
                }
            }
        }
    }

    private static void logD(String message) {
    private static void logD(String message) {
        if (MapClientService.DBG) {
        if (MapClientService.DBG) {
            Log.d(TAG, message);
            Log.d(TAG, message);
@@ -160,6 +178,7 @@ class MapClientContent {
        } else {
        } else {
            mPhoneNumber = PhoneNumberUtils.extractNetworkPortion(getOriginatorNumber(message));
            mPhoneNumber = PhoneNumberUtils.extractNetworkPortion(getOriginatorNumber(message));
        }
        }

        logV("Found phone number: " + mPhoneNumber);
        logV("Found phone number: " + mPhoneNumber);
    }
    }


@@ -319,6 +338,8 @@ class MapClientContent {
            values.put(Mms.MESSAGE_SIZE, mmsBmessage.getSize());
            values.put(Mms.MESSAGE_SIZE, mmsBmessage.getSize());


            Uri results = mResolver.insert(contentUri, values);
            Uri results = mResolver.insert(contentUri, values);
            mHandleToUriMap.put(handle, results);
            mUriToHandleMap.put(results, new MessageStatus(handle, read));


            logD("Map InsertedThread" + results);
            logD("Map InsertedThread" + results);


@@ -332,7 +353,6 @@ class MapClientContent {


            values.put(Mms.Part.CONTENT_TYPE, "plain/text");
            values.put(Mms.Part.CONTENT_TYPE, "plain/text");
            values.put(Mms.SUBSCRIPTION_ID, mSubscriptionId);
            values.put(Mms.SUBSCRIPTION_ID, mSubscriptionId);
            mUriToHandleMap.put(results, new MessageStatus(handle, read));
        } catch (Exception e) {
        } catch (Exception e) {
            Log.e(TAG, e.toString());
            Log.e(TAG, e.toString());
            throw e;
            throw e;
@@ -387,7 +407,8 @@ class MapClientContent {
     * clear the subscription info and content on shutdown
     * clear the subscription info and content on shutdown
     */
     */
    void cleanUp() {
    void cleanUp() {
        clearMessages();
        mResolver.unregisterContentObserver(mContentObserver);
        clearMessages(mContext, mSubscriptionId);
        try {
        try {
            mSubscriptionManager.removeSubscriptionInfoRecord(mDevice.getAddress(),
            mSubscriptionManager.removeSubscriptionInfoRecord(mDevice.getAddress(),
                    SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
                    SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
@@ -400,12 +421,24 @@ class MapClientContent {
     * clearMessages
     * clearMessages
     * clean up the content provider on startup
     * clean up the content provider on startup
     */
     */
    private void clearMessages() {
    private static void clearMessages(Context context, int subscriptionId) {
        mResolver.unregisterContentObserver(mContentObserver);
        ContentResolver resolver = context.getContentResolver();
        mResolver.delete(Sms.CONTENT_URI, Sms.SUBSCRIPTION_ID + " =? ",
        String threads = new String();
                new String[]{Integer.toString(mSubscriptionId)});

        mResolver.delete(Mms.CONTENT_URI, Mms.SUBSCRIPTION_ID + " =? ",
        Uri uri = Threads.CONTENT_URI.buildUpon().appendQueryParameter("simple", "true").build();
                new String[]{Integer.toString(mSubscriptionId)});
        Cursor threadCursor = resolver.query(uri, null, null, null, null);
        while (threadCursor.moveToNext()) {
            threads += threadCursor.getInt(threadCursor.getColumnIndex(Threads._ID)) + ", ";
        }

        resolver.delete(Sms.CONTENT_URI, Sms.SUBSCRIPTION_ID + " =? ",
                new String[]{Integer.toString(subscriptionId)});
        resolver.delete(Mms.CONTENT_URI, Mms.SUBSCRIPTION_ID + " =? ",
                new String[]{Integer.toString(subscriptionId)});
        if (threads.length() > 2) {
            threads = threads.substring(0, threads.length() - 2);
            resolver.delete(Threads.CONTENT_URI, Threads._ID + " IN (" + threads + ")", null);
        }
    }
    }


    /**
    /**
@@ -479,6 +512,7 @@ class MapClientContent {
        String threadId = Uri.parse(thread).getLastPathSegment();
        String threadId = Uri.parse(thread).getLastPathSegment();


        logD("MATCHING THREAD" + threadId);
        logD("MATCHING THREAD" + threadId);
        logD(MmsSms.CONTENT_CONVERSATIONS_URI + threadId + "/recipients");


        Cursor cursor = mResolver
        Cursor cursor = mResolver
                .query(Uri.withAppendedPath(MmsSms.CONTENT_CONVERSATIONS_URI,
                .query(Uri.withAppendedPath(MmsSms.CONTENT_CONVERSATIONS_URI,
+1 −0
Original line number Original line Diff line number Diff line
@@ -314,6 +314,7 @@ public class MapClientService extends ProfileService {
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        registerReceiver(mMapReceiver, filter);
        registerReceiver(mMapReceiver, filter);
        removeUncleanAccounts();
        removeUncleanAccounts();
        MapClientContent.clearAllContent(this);
        setMapClientService(this);
        setMapClientService(this);
        return true;
        return true;
    }
    }
+9 −8
Original line number Original line Diff line number Diff line
@@ -129,7 +129,7 @@ class MceStateMachine extends StateMachine {
    private final BluetoothDevice mDevice;
    private final BluetoothDevice mDevice;
    private MapClientService mService;
    private MapClientService mService;
    private MasClient mMasClient;
    private MasClient mMasClient;
    private final MapClientContent mDatabase;
    private MapClientContent mDatabase;
    private HashMap<String, Bmessage> mSentMessageLog = new HashMap<>(MAX_MESSAGES);
    private HashMap<String, Bmessage> mSentMessageLog = new HashMap<>(MAX_MESSAGES);
    private HashMap<Bmessage, PendingIntent> mSentReceiptRequested = new HashMap<>(MAX_MESSAGES);
    private HashMap<Bmessage, PendingIntent> mSentReceiptRequested = new HashMap<>(MAX_MESSAGES);
    private HashMap<Bmessage, PendingIntent> mDeliveryReceiptRequested =
    private HashMap<Bmessage, PendingIntent> mDeliveryReceiptRequested =
@@ -196,13 +196,6 @@ class MceStateMachine extends StateMachine {
        mDisconnecting = new Disconnecting();
        mDisconnecting = new Disconnecting();
        mConnected = new Connected();
        mConnected = new Connected();


        MapClientContent.Callbacks callbacks = new MapClientContent.Callbacks(){
            @Override
            public void onMessageStatusChanged(String handle, int status) {
                setMessageStatus(handle, status);
            }
        };
        mDatabase = new MapClientContent(mService, callbacks, mDevice);


        addState(mDisconnected);
        addState(mDisconnected);
        addState(mConnecting);
        addState(mConnecting);
@@ -522,6 +515,14 @@ class MceStateMachine extends StateMachine {
            if (DBG) {
            if (DBG) {
                Log.d(TAG, "Enter Connected: " + getCurrentMessage().what);
                Log.d(TAG, "Enter Connected: " + getCurrentMessage().what);
            }
            }

            MapClientContent.Callbacks callbacks = new MapClientContent.Callbacks(){
                @Override
                public void onMessageStatusChanged(String handle, int status) {
                    setMessageStatus(handle, status);
                }
            };
            mDatabase = new MapClientContent(mService, callbacks, mDevice);
            onConnectionStateChanged(mPreviousState, BluetoothProfile.STATE_CONNECTED);
            onConnectionStateChanged(mPreviousState, BluetoothProfile.STATE_CONNECTED);
            if (Utils.isPtsTestMode()) return;
            if (Utils.isPtsTestMode()) return;


+29 −2
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


@@ -30,9 +31,11 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.database.Cursor;
import android.database.Cursor;
import android.net.Uri;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.provider.Telephony.Mms;
import android.provider.Telephony.Mms;
import android.provider.Telephony.Sms;
import android.provider.Telephony.Sms;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
import android.test.mock.MockContentResolver;
@@ -58,6 +61,7 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;


import java.util.Arrays;
import java.util.HashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Map;


@@ -104,6 +108,8 @@ public class MapClientContentTest {


    @Mock
    @Mock
    private SubscriptionManager mMockSubscriptionManager;
    private SubscriptionManager mMockSubscriptionManager;
    @Mock
    private SubscriptionInfo mMockSubscription;


    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
@@ -128,6 +134,8 @@ public class MapClientContentTest {
                .thenReturn(mMockSubscriptionManager);
                .thenReturn(mMockSubscriptionManager);
        when(mMockContext.getSystemServiceName(SubscriptionManager.class))
        when(mMockContext.getSystemServiceName(SubscriptionManager.class))
                .thenReturn(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
                .thenReturn(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        when(mMockSubscriptionManager.getActiveSubscriptionInfoList())
                .thenReturn(Arrays.asList(mMockSubscription));
        createTestMessages();
        createTestMessages();


    }
    }
@@ -178,6 +186,7 @@ public class MapClientContentTest {


        mMapClientContent.cleanUp();
        mMapClientContent.cleanUp();
        Assert.assertEquals(0, mMockSmsContentProvider.mContentValues.size());
        Assert.assertEquals(0, mMockSmsContentProvider.mContentValues.size());
        Assert.assertEquals(0, mMockThreadContentProvider.mContentValues.size());
    }
    }


    /**
    /**
@@ -339,6 +348,21 @@ public class MapClientContentTest {
        mMapClientContent.cleanUp();
        mMapClientContent.cleanUp();
    }
    }


    /**
     * Test to validate old subscriptions are removed at startup.
     */
    @Test
    public void testCleanUpAtStartup() {
        MapClientContent.clearAllContent(mMockContext);
        verify(mMockSubscriptionManager, never()).removeSubscriptionInfoRecord(any(), anyInt());

        when(mMockSubscription.getSubscriptionType())
                .thenReturn(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
        MapClientContent.clearAllContent(mMockContext);
        verify(mMockSubscriptionManager).removeSubscriptionInfoRecord(any(),
                eq(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM));
    }

    void createTestMessages() {
    void createTestMessages() {
        mOriginator = new VCardEntry();
        mOriginator = new VCardEntry();
        VCardProperty property = new VCardProperty();
        VCardProperty property = new VCardProperty();
@@ -404,7 +428,10 @@ public class MapClientContentTest {
            when(cursor.getInt(anyInt())).thenReturn(READ);
            when(cursor.getInt(anyInt())).thenReturn(READ);
            return cursor;
            return cursor;
        }
        }
    }



        @Override
        public int update(Uri uri, ContentValues values, Bundle extras) {
            return 0;
        }
    }
}
}