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

Commit ba0f4ca5 authored by David Duarte's avatar David Duarte
Browse files

mapclient: Inline MapUtils

With the removal of `setMnsService`, MapUtils doesn't bring a
lot of value. All the utility methods are called once and the
condition in `sendMessageType` is duplicated at the call site.

So MapUtils is removed and all of it's methods inlined.

Bug: 319112725
Test: m Bluetooth BluetoothInstrumentationTests
Flag: Exempt, mechanical refactor
Change-Id: Ib12d4a67cfe8d3ebaced32feaa4ea84e42d8d0a4
parent e02f96af
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -492,7 +492,7 @@ public class MapClientService extends ProfileService {
                return mService;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !(MapUtils.isSystemUser()
                    || !(getCallingUserHandle().isSystem()
                            || Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG))
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                return null;
+0 −51
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.bluetooth.mapclient;

import android.os.Binder;
import android.os.SystemProperties;

import com.android.bluetooth.Utils;

class MapUtils {
    private static final String FETCH_MESSAGE_TYPE =
            "persist.bluetooth.pts.mapclient.fetchmessagetype";
    private static final String SEND_MESSAGE_TYPE =
            "persist.bluetooth.pts.mapclient.sendmessagetype";

    static boolean isSystemUser() {
        return Binder.getCallingUserHandle().isSystem();
    }

    static byte fetchMessageType() {
        if (Utils.isPtsTestMode()) {
            return (byte) SystemProperties.getInt(FETCH_MESSAGE_TYPE,
                    MessagesFilter.MESSAGE_TYPE_ALL);
        } else {
            return MessagesFilter.MESSAGE_TYPE_ALL;
        }
    }

    static Bmessage.Type sendMessageType() {
        if (Utils.isPtsTestMode()) {
            int messageType = SystemProperties.getInt(SEND_MESSAGE_TYPE, -1);
            if (messageType > 0 && messageType < Bmessage.Type.values().length) {
                return Bmessage.Type.values()[messageType];
            }
        }
        return Bmessage.Type.MMS;
    }
}
+18 −2
Original line number Diff line number Diff line
@@ -140,6 +140,11 @@ class MceStateMachine extends StateMachine {
    // URI Scheme for messages with email contact
    private static final String SCHEME_MAILTO = "mailto";

    private static final String FETCH_MESSAGE_TYPE =
            "persist.bluetooth.pts.mapclient.fetchmessagetype";
    private static final String SEND_MESSAGE_TYPE =
            "persist.bluetooth.pts.mapclient.sendmessagetype";

    // Connectivity States
    private int mPreviousState = BluetoothProfile.STATE_DISCONNECTED;
    private int mMostRecentState = BluetoothProfile.STATE_DISCONNECTED;
@@ -492,7 +497,10 @@ class MceStateMachine extends StateMachine {
    Bmessage.Type getDefaultMessageType() {
        synchronized (mDefaultMessageType) {
            if (Utils.isPtsTestMode()) {
                return MapUtils.sendMessageType();
                int messageType = SystemProperties.getInt(SEND_MESSAGE_TYPE, -1);
                if (messageType > 0 && messageType < Bmessage.Type.values().length) {
                    return Bmessage.Type.values()[messageType];
                }
            }
            return mDefaultMessageType;
        }
@@ -718,7 +726,15 @@ class MceStateMachine extends StateMachine {
                case MSG_GET_MESSAGE_LISTING:
                    // Get latest 50 Unread messages in the last week
                    MessagesFilter filter = new MessagesFilter();
                    filter.setMessageType(MapUtils.fetchMessageType());
                    if (Utils.isPtsTestMode()) {
                        filter.setMessageType(
                                (byte)
                                        SystemProperties.getInt(
                                                FETCH_MESSAGE_TYPE,
                                                MessagesFilter.MESSAGE_TYPE_ALL));
                    } else {
                        filter.setMessageType(MessagesFilter.MESSAGE_TYPE_ALL);
                    }
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.DATE, -7);
                    filter.setPeriod(calendar.getTime(), null);