1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.bluetooth.mapclient; 17 18 import android.os.SystemProperties; 19 import android.os.UserHandle; 20 21 import com.android.bluetooth.Utils; 22 import com.android.internal.annotations.VisibleForTesting; 23 24 class MapUtils { 25 private static MnsService sMnsService = null; 26 private static final String FETCH_MESSAGE_TYPE = 27 "persist.bluetooth.pts.mapclient.fetchmessagetype"; 28 private static final String SEND_MESSAGE_TYPE = 29 "persist.bluetooth.pts.mapclient.sendmessagetype"; 30 31 @VisibleForTesting setMnsService(MnsService service)32 static void setMnsService(MnsService service) { 33 sMnsService = service; 34 } 35 isSystemUser()36 static boolean isSystemUser() { 37 return UserHandle.getCallingUserId() == UserHandle.USER_SYSTEM; 38 } 39 newMnsServiceInstance(MapClientService mapClientService)40 static MnsService newMnsServiceInstance(MapClientService mapClientService) { 41 return (sMnsService == null) ? new MnsService(mapClientService) : sMnsService; 42 } fetchMessageType()43 static byte fetchMessageType() { 44 if (Utils.isPtsTestMode()) { 45 return (byte) SystemProperties.getInt(FETCH_MESSAGE_TYPE, 46 MessagesFilter.MESSAGE_TYPE_ALL); 47 } else { 48 return MessagesFilter.MESSAGE_TYPE_ALL; 49 } 50 } 51 sendMessageType()52 static Bmessage.Type sendMessageType() { 53 if (Utils.isPtsTestMode()) { 54 int messageType = SystemProperties.getInt(SEND_MESSAGE_TYPE, -1); 55 if (messageType > 0 && messageType < Bmessage.Type.values().length) { 56 return Bmessage.Type.values()[messageType]; 57 } 58 } 59 return Bmessage.Type.MMS; 60 } 61 } 62