Merge "Refactor SmsManager not to use ActivityThread hidden API in Mainline"
This commit is contained in:
@@ -25,11 +25,12 @@ import android.annotation.RequiresPermission;
|
||||
import android.annotation.SuppressAutoDoc;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.app.ActivityThread;
|
||||
import android.app.PendingIntent;
|
||||
import android.compat.Compatibility;
|
||||
import android.compat.annotation.ChangeId;
|
||||
import android.compat.annotation.EnabledAfter;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.CursorWindow;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
@@ -388,7 +389,7 @@ public final class SmsManager {
|
||||
String destinationAddress, String scAddress, String text,
|
||||
PendingIntent sentIntent, PendingIntent deliveryIntent) {
|
||||
sendTextMessageInternal(destinationAddress, scAddress, text, sentIntent, deliveryIntent,
|
||||
true /* persistMessage*/, ActivityThread.currentPackageName());
|
||||
true /* persistMessage*/, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -598,7 +599,7 @@ public final class SmsManager {
|
||||
String destinationAddress, String scAddress, String text,
|
||||
PendingIntent sentIntent, PendingIntent deliveryIntent) {
|
||||
sendTextMessageInternal(destinationAddress, scAddress, text, sentIntent, deliveryIntent,
|
||||
false /* persistMessage */, ActivityThread.currentPackageName());
|
||||
false /* persistMessage */, null);
|
||||
}
|
||||
|
||||
private void sendTextMessageInternal(
|
||||
@@ -641,7 +642,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsServiceOrThrow();
|
||||
if (iSms != null) {
|
||||
iSms.sendTextForSubscriberWithOptions(subId,
|
||||
ActivityThread.currentPackageName(), destinationAddress,
|
||||
null, destinationAddress,
|
||||
scAddress,
|
||||
text, sentIntent, deliveryIntent, persistMessage, finalPriority,
|
||||
expectMore, finalValidity);
|
||||
@@ -663,7 +664,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsServiceOrThrow();
|
||||
if (iSms != null) {
|
||||
iSms.sendTextForSubscriberWithOptions(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(), destinationAddress,
|
||||
null, destinationAddress,
|
||||
scAddress,
|
||||
text, sentIntent, deliveryIntent, persistMessage, finalPriority,
|
||||
expectMore, finalValidity);
|
||||
@@ -881,7 +882,7 @@ public final class SmsManager {
|
||||
String destinationAddress, String scAddress, ArrayList<String> parts,
|
||||
ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
|
||||
sendMultipartTextMessageInternal(destinationAddress, scAddress, parts, sentIntents,
|
||||
deliveryIntents, true /* persistMessage*/, ActivityThread.currentPackageName());
|
||||
deliveryIntents, true /* persistMessage*/, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -898,8 +899,9 @@ public final class SmsManager {
|
||||
* subscription.
|
||||
* </p>
|
||||
*
|
||||
* @param packageName serves as the default package name if
|
||||
* {@link ActivityThread#currentPackageName()} is null.
|
||||
* @param packageName serves as the default package name if the package name that is
|
||||
* associated with the user id is null.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@@ -909,9 +911,7 @@ public final class SmsManager {
|
||||
@NonNull List<String> parts, @Nullable List<PendingIntent> sentIntents,
|
||||
@Nullable List<PendingIntent> deliveryIntents, @NonNull String packageName) {
|
||||
sendMultipartTextMessageInternal(destinationAddress, scAddress, parts, sentIntents,
|
||||
deliveryIntents, true /* persistMessage*/,
|
||||
ActivityThread.currentPackageName() == null
|
||||
? packageName : ActivityThread.currentPackageName());
|
||||
deliveryIntents, true /* persistMessage*/, packageName);
|
||||
}
|
||||
|
||||
private void sendMultipartTextMessageInternal(
|
||||
@@ -1012,7 +1012,7 @@ public final class SmsManager {
|
||||
String destinationAddress, String scAddress, List<String> parts,
|
||||
List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) {
|
||||
sendMultipartTextMessageInternal(destinationAddress, scAddress, parts, sentIntents,
|
||||
deliveryIntents, false /* persistMessage*/, ActivityThread.currentPackageName());
|
||||
deliveryIntents, false /* persistMessage*/, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1174,7 +1174,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsServiceOrThrow();
|
||||
if (iSms != null) {
|
||||
iSms.sendMultipartTextForSubscriberWithOptions(subId,
|
||||
ActivityThread.currentPackageName(), destinationAddress,
|
||||
null, destinationAddress,
|
||||
scAddress, parts, sentIntents, deliveryIntents,
|
||||
persistMessage, finalPriority, expectMore, finalValidity);
|
||||
}
|
||||
@@ -1196,7 +1196,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsServiceOrThrow();
|
||||
if (iSms != null) {
|
||||
iSms.sendMultipartTextForSubscriberWithOptions(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(), destinationAddress,
|
||||
null, destinationAddress,
|
||||
scAddress, parts, sentIntents, deliveryIntents,
|
||||
persistMessage, finalPriority, expectMore, finalValidity);
|
||||
}
|
||||
@@ -1327,7 +1327,7 @@ public final class SmsManager {
|
||||
public void onSuccess(int subId) {
|
||||
try {
|
||||
ISms iSms = getISmsServiceOrThrow();
|
||||
iSms.sendDataForSubscriber(subId, ActivityThread.currentPackageName(),
|
||||
iSms.sendDataForSubscriber(subId, null,
|
||||
destinationAddress, scAddress, destinationPort & 0xFFFF, data,
|
||||
sentIntent, deliveryIntent);
|
||||
} catch (RemoteException e) {
|
||||
@@ -1453,7 +1453,6 @@ public final class SmsManager {
|
||||
private void resolveSubscriptionForOperation(SubscriptionResolverResult resolverResult) {
|
||||
int subId = getSubscriptionId();
|
||||
boolean isSmsSimPickActivityNeeded = false;
|
||||
final Context context = ActivityThread.currentApplication().getApplicationContext();
|
||||
try {
|
||||
ISms iSms = getISmsService();
|
||||
if (iSms != null) {
|
||||
@@ -1475,14 +1474,14 @@ public final class SmsManager {
|
||||
return;
|
||||
}
|
||||
// We need to ask the user pick an appropriate subid for the operation.
|
||||
Log.d(TAG, "resolveSubscriptionForOperation isSmsSimPickActivityNeeded is true for package "
|
||||
+ context.getPackageName());
|
||||
Log.d(TAG, "resolveSubscriptionForOperation isSmsSimPickActivityNeeded is true for calling"
|
||||
+ " package. ");
|
||||
try {
|
||||
// Create the SMS pick activity and call back once the activity is complete. Can't do
|
||||
// it here because we do not have access to the activity context that is performing this
|
||||
// operation.
|
||||
// Requires that the calling process has the SEND_SMS permission.
|
||||
getITelephony().enqueueSmsPickResult(context.getOpPackageName(),
|
||||
getITelephony().enqueueSmsPickResult(null,
|
||||
new IIntegerConsumer.Stub() {
|
||||
@Override
|
||||
public void accept(int subId) {
|
||||
@@ -1500,6 +1499,13 @@ public final class SmsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To check the SDK version for SmsManager.sendResolverResult method.
|
||||
*/
|
||||
@ChangeId
|
||||
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.P)
|
||||
private static final long GET_TARGET_SDK_VERSION_CODE_CHANGE = 145147528L;
|
||||
|
||||
private void sendResolverResult(SubscriptionResolverResult resolverResult, int subId,
|
||||
boolean pickActivityShown) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
@@ -1507,7 +1513,8 @@ public final class SmsManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getTargetSdkVersion() <= Build.VERSION_CODES.P && !pickActivityShown) {
|
||||
if (!Compatibility.isChangeEnabled(GET_TARGET_SDK_VERSION_CODE_CHANGE)
|
||||
&& !pickActivityShown) {
|
||||
// Do not fail, return a success with an INVALID subid for apps targeting P or below
|
||||
// that tried to perform an operation and the SMS disambiguation dialog was never shown,
|
||||
// as these applications may not have been written to handle the failure case properly.
|
||||
@@ -1520,19 +1527,6 @@ public final class SmsManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getTargetSdkVersion() {
|
||||
final Context context = ActivityThread.currentApplication().getApplicationContext();
|
||||
int targetSdk;
|
||||
try {
|
||||
targetSdk = context.getPackageManager().getApplicationInfo(
|
||||
context.getOpPackageName(), 0).targetSdkVersion;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Default to old behavior if we can not find this.
|
||||
targetSdk = -1;
|
||||
}
|
||||
return targetSdk;
|
||||
}
|
||||
|
||||
private static ITelephony getITelephony() {
|
||||
ITelephony binder = ITelephony.Stub.asInterface(
|
||||
ServiceManager.getService(Context.TELEPHONY_SERVICE));
|
||||
@@ -1616,7 +1610,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsService();
|
||||
if (iSms != null) {
|
||||
success = iSms.copyMessageToIccEfForSubscriber(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(),
|
||||
null,
|
||||
status, pdu, smsc);
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
@@ -1657,7 +1651,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsService();
|
||||
if (iSms != null) {
|
||||
success = iSms.updateMessageOnIccEfForSubscriber(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(),
|
||||
null,
|
||||
messageIndex, STATUS_ON_ICC_FREE, null /* pdu */);
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
@@ -1700,7 +1694,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsService();
|
||||
if (iSms != null) {
|
||||
success = iSms.updateMessageOnIccEfForSubscriber(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(),
|
||||
null,
|
||||
messageIndex, newStatus, pdu);
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
@@ -1752,7 +1746,7 @@ public final class SmsManager {
|
||||
if (iSms != null) {
|
||||
records = iSms.getAllMessagesFromIccEfForSubscriber(
|
||||
getSubscriptionId(),
|
||||
ActivityThread.currentPackageName());
|
||||
null);
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
// ignore it
|
||||
@@ -2495,7 +2489,7 @@ public final class SmsManager {
|
||||
try {
|
||||
ISms iccSms = getISmsServiceOrThrow();
|
||||
return iccSms.createAppSpecificSmsToken(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(), intent);
|
||||
null, intent);
|
||||
|
||||
} catch (RemoteException ex) {
|
||||
ex.rethrowFromSystemServer();
|
||||
@@ -2615,7 +2609,7 @@ public final class SmsManager {
|
||||
try {
|
||||
ISms iccSms = getISmsServiceOrThrow();
|
||||
return iccSms.createAppSpecificSmsTokenWithPackageInfo(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(), prefixes, intent);
|
||||
null, prefixes, intent);
|
||||
|
||||
} catch (RemoteException ex) {
|
||||
ex.rethrowFromSystemServer();
|
||||
@@ -2706,7 +2700,7 @@ public final class SmsManager {
|
||||
ISms iccISms = getISmsServiceOrThrow();
|
||||
if (iccISms != null) {
|
||||
return iccISms.checkSmsShortCodeDestination(getSubscriptionId(),
|
||||
ActivityThread.currentPackageName(), null, destAddress, countryIso);
|
||||
null, null, destAddress, countryIso);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "checkSmsShortCodeDestination() RemoteException", e);
|
||||
@@ -2742,7 +2736,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsService();
|
||||
if (iSms != null) {
|
||||
smsc = iSms.getSmscAddressFromIccEfForSubscriber(
|
||||
getSubscriptionId(), ActivityThread.currentPackageName());
|
||||
getSubscriptionId(), null);
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
// ignore it
|
||||
@@ -2776,7 +2770,7 @@ public final class SmsManager {
|
||||
ISms iSms = getISmsService();
|
||||
if (iSms != null) {
|
||||
return iSms.setSmscAddressOnIccEfForSubscriber(
|
||||
smsc, getSubscriptionId(), ActivityThread.currentPackageName());
|
||||
smsc, getSubscriptionId(), null);
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
// ignore it
|
||||
|
||||
@@ -37,7 +37,6 @@ import android.annotation.SystemApi;
|
||||
import android.annotation.SystemService;
|
||||
import android.annotation.TestApi;
|
||||
import android.annotation.WorkerThread;
|
||||
import android.app.ActivityThread;
|
||||
import android.app.PendingIntent;
|
||||
import android.compat.Compatibility;
|
||||
import android.compat.annotation.ChangeId;
|
||||
@@ -372,8 +371,17 @@ public class TelephonyManager {
|
||||
// effort and get the context from the current activity thread.
|
||||
if (mContext != null) {
|
||||
return mContext.getOpPackageName();
|
||||
} else {
|
||||
ITelephony telephony = getITelephony();
|
||||
if (telephony == null) return null;
|
||||
try {
|
||||
return telephony.getCurrentPackageName();
|
||||
} catch (RemoteException ex) {
|
||||
return null;
|
||||
} catch (NullPointerException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return ActivityThread.currentOpPackageName();
|
||||
}
|
||||
|
||||
private String getFeatureId() {
|
||||
|
||||
@@ -2113,6 +2113,11 @@ interface ITelephony {
|
||||
*/
|
||||
int getRadioHalVersion();
|
||||
|
||||
/**
|
||||
* Get the current calling package name.
|
||||
*/
|
||||
String getCurrentPackageName();
|
||||
|
||||
/**
|
||||
* Returns true if the specified type of application (e.g. {@link #APPTYPE_CSIM} is present
|
||||
* on the UICC card.
|
||||
|
||||
Reference in New Issue
Block a user