1 /* 2 * Copyright (C) 2023 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 17 package com.android.pandora 18 19 import android.content.Context 20 import android.telephony.SmsManager 21 import android.telephony.SubscriptionManager 22 import android.telephony.TelephonyManager 23 import com.google.protobuf.Empty 24 import io.grpc.stub.StreamObserver 25 import kotlinx.coroutines.CoroutineScope 26 import kotlinx.coroutines.Dispatchers 27 import pandora.MapGrpc.MapImplBase 28 import pandora.MapProto.* 29 30 private const val TAG = "PandoraMap" 31 32 class Map(context: Context) : MapImplBase() { 33 private val DEFAULT_MESSAGE_LEN = 130 34 35 private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1)) 36 private var telephonyManager = context.getSystemService(TelephonyManager::class.java)!! 37 sendSMSnull38 override fun sendSMS(request: Empty, responseObserver: StreamObserver<Empty>) { 39 grpcUnary<Empty>(scope, responseObserver) { 40 val smsManager = SmsManager.getDefault() 41 val defaultSmsSub = SubscriptionManager.getDefaultSmsSubscriptionId() 42 telephonyManager = telephonyManager.createForSubscriptionId(defaultSmsSub) 43 val avdPhoneNumber = telephonyManager.getLine1Number() 44 45 smsManager.sendTextMessage( 46 avdPhoneNumber, 47 avdPhoneNumber, 48 generateAlphanumericString(DEFAULT_MESSAGE_LEN), 49 null, 50 null 51 ) 52 Empty.getDefaultInstance() 53 } 54 } 55 } 56