aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKolin Lu <kolinlu@google.com>2023-06-02 10:14:23 -0700
committerGitHub <noreply@github.com>2023-06-02 10:14:23 -0700
commitce2fd0fc57ccc2f21aae2cf0841688009340efb6 (patch)
tree28e20d487768ea1326a8d007d3bd5b599e12596d
parenta90f9834693f240ec8d9af0e7c45bca3f6f46313 (diff)
parentf0aff98beeb54fe9063550dc805e97bf6c6e1c45 (diff)
downloadmobly-bundled-snippets-ce2fd0fc57ccc2f21aae2cf0841688009340efb6.tar.gz
Merge pull request #168 from ko1in1u/master
Update permission and flag for Android O+
-rw-r--r--src/main/AndroidManifest.xml1
-rw-r--r--src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java36
2 files changed, 29 insertions, 8 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index adf6c64..075fbe8 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java
index be41e9e..e8a84c9 100644
--- a/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java
+++ b/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java
@@ -16,6 +16,8 @@
package com.google.android.mobly.snippet.bundled;
+import static java.util.stream.Collectors.toCollection;
+
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.PendingIntent;
@@ -36,6 +38,7 @@ import com.google.android.mobly.snippet.event.SnippetEvent;
import com.google.android.mobly.snippet.rpc.AsyncRpc;
import com.google.android.mobly.snippet.rpc.Rpc;
import java.util.ArrayList;
+import java.util.stream.IntStream;
import org.json.JSONObject;
/** Snippet class for SMS RPCs. */
@@ -80,20 +83,37 @@ public class SmsSnippet implements Snippet {
if (message.length() > MAX_CHAR_COUNT_PER_SMS) {
ArrayList<String> parts = mSmsManager.divideMessage(message);
- ArrayList<PendingIntent> sIntents = new ArrayList<>();
- for (int i = 0; i < parts.size(); i++) {
- sIntents.add(
- PendingIntent.getBroadcast(mContext, 0, new Intent(SMS_SENT_ACTION), 0));
- }
receiver.setExpectedMessageCount(parts.size());
mContext.registerReceiver(receiver, new IntentFilter(SMS_SENT_ACTION));
- mSmsManager.sendMultipartTextMessage(phoneNumber, null, parts, sIntents, null);
+ mSmsManager.sendMultipartTextMessage(
+ /* destinationAddress= */ phoneNumber,
+ /* scAddress= */ null,
+ /* parts= */ parts,
+ /* sentIntents= */ IntStream.range(0, parts.size())
+ .mapToObj(
+ i ->
+ PendingIntent.getBroadcast(
+ /* context= */ mContext,
+ /* requestCode= */ 0,
+ /* intent= */ new Intent(SMS_SENT_ACTION),
+ /* flags= */ PendingIntent.FLAG_IMMUTABLE))
+ .collect(toCollection(ArrayList::new)),
+ /* deliveryIntents= */ null);
} else {
PendingIntent sentIntent =
- PendingIntent.getBroadcast(mContext, 0, new Intent(SMS_SENT_ACTION), 0);
+ PendingIntent.getBroadcast(
+ /* context= */ mContext,
+ /* requestCode= */ 0,
+ /* intent= */ new Intent(SMS_SENT_ACTION),
+ /* flags= */ PendingIntent.FLAG_IMMUTABLE);
receiver.setExpectedMessageCount(1);
mContext.registerReceiver(receiver, new IntentFilter(SMS_SENT_ACTION));
- mSmsManager.sendTextMessage(phoneNumber, null, message, sentIntent, null);
+ mSmsManager.sendTextMessage(
+ /* destinationAddress= */ phoneNumber,
+ /* scAddress= */ null,
+ /* text= */ message,
+ /* sentIntent= */ sentIntent,
+ /* deliveryIntent= */ null);
}
SnippetEvent result =