diff options
35 files changed, 487 insertions, 748 deletions
diff --git a/Android.bp b/Android.bp index 5cb28f8507aa..3c47d1bb3cbb 100644 --- a/Android.bp +++ b/Android.bp @@ -1628,7 +1628,6 @@ filegroup { "core/java/android/util/LocalLog.java", "core/java/android/util/TimeUtils.java", "core/java/com/android/internal/os/SomeArgs.java", - "core/java/com/android/internal/util/DumpUtils.java", "core/java/com/android/internal/util/FastXmlSerializer.java", "core/java/com/android/internal/util/HexDump.java", "core/java/com/android/internal/util/IndentingPrintWriter.java", @@ -1636,6 +1635,5 @@ filegroup { "core/java/com/android/internal/util/State.java", "core/java/com/android/internal/util/StateMachine.java", "core/java/com/android/internal/util/UserIcons.java", - "core/java/com/android/internal/util/XmlUtils.java", ], } diff --git a/api/system-current.txt b/api/system-current.txt index 5725763ba6c2..52e5255609c9 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -75,6 +75,7 @@ package android { field public static final String GET_TOP_ACTIVITY_INFO = "android.permission.GET_TOP_ACTIVITY_INFO"; field public static final String GRANT_PROFILE_OWNER_DEVICE_IDS_ACCESS = "android.permission.GRANT_PROFILE_OWNER_DEVICE_IDS_ACCESS"; field public static final String GRANT_RUNTIME_PERMISSIONS = "android.permission.GRANT_RUNTIME_PERMISSIONS"; + field public static final String GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS = "android.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS"; field public static final String HANDLE_CAR_MODE_CHANGES = "android.permission.HANDLE_CAR_MODE_CHANGES"; field public static final String HARDWARE_TEST = "android.permission.HARDWARE_TEST"; field public static final String HDMI_CEC = "android.permission.HDMI_CEC"; @@ -1395,7 +1396,9 @@ package android.bluetooth { } public final class BluetoothHearingAid implements android.bluetooth.BluetoothProfile { + method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH) public java.util.List<android.bluetooth.BluetoothDevice> getActiveDevices(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice); + method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public long getHiSyncId(@Nullable android.bluetooth.BluetoothDevice); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int); } @@ -8947,6 +8950,7 @@ package android.telephony { method public void updateServiceLocation(); method @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void updateTestOtaEmergencyNumberDbFilePath(@NonNull String); field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final String ACTION_ANOMALY_REPORTED = "android.telephony.action.ANOMALY_REPORTED"; + field public static final String ACTION_EMERGENCY_ASSISTANCE = "android.telephony.action.EMERGENCY_ASSISTANCE"; field public static final String ACTION_SIM_APPLICATION_STATE_CHANGED = "android.telephony.action.SIM_APPLICATION_STATE_CHANGED"; field public static final String ACTION_SIM_CARD_STATE_CHANGED = "android.telephony.action.SIM_CARD_STATE_CHANGED"; field public static final String ACTION_SIM_SLOT_STATUS_CHANGED = "android.telephony.action.SIM_SLOT_STATUS_CHANGED"; diff --git a/core/java/android/app/role/IRoleManager.aidl b/core/java/android/app/role/IRoleManager.aidl index d8cea2860aa8..6d790b381ace 100644 --- a/core/java/android/app/role/IRoleManager.aidl +++ b/core/java/android/app/role/IRoleManager.aidl @@ -19,7 +19,6 @@ package android.app.role; import android.app.role.IOnRoleHoldersChangedListener; import android.os.Bundle; import android.os.RemoteCallback; -import android.telephony.IFinancialSmsCallback; /** * @hide @@ -55,9 +54,4 @@ interface IRoleManager { List<String> getHeldRolesFromController(in String packageName); String getDefaultSmsPackage(int userId); - - /** - * Get filtered SMS messages for financial app. - */ - void getSmsMessagesForFinancialApp(in String callingPkg, in Bundle params, in IFinancialSmsCallback callback); } diff --git a/core/java/android/bluetooth/BluetoothHearingAid.java b/core/java/android/bluetooth/BluetoothHearingAid.java index ead8429e4a75..b4521c623ec2 100644 --- a/core/java/android/bluetooth/BluetoothHearingAid.java +++ b/core/java/android/bluetooth/BluetoothHearingAid.java @@ -335,9 +335,9 @@ public final class BluetoothHearingAid implements BluetoothProfile { * is not active, it will be null on that position. Returns empty list on error. * @hide */ - @UnsupportedAppUsage + @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH) - public List<BluetoothDevice> getActiveDevices() { + public @NonNull List<BluetoothDevice> getActiveDevices() { if (VDBG) log("getActiveDevices()"); final IBluetoothHearingAid service = getService(); try { @@ -559,8 +559,9 @@ public final class BluetoothHearingAid implements BluetoothProfile { * @return the CustomerId of the device * @hide */ + @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH) - public long getHiSyncId(BluetoothDevice device) { + public long getHiSyncId(@Nullable BluetoothDevice device) { if (VDBG) { log("getCustomerId(" + device + ")"); } diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java index ebdde0a54a86..066ba6e8678e 100644 --- a/core/java/android/provider/Telephony.java +++ b/core/java/android/provider/Telephony.java @@ -25,7 +25,6 @@ import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; -import android.app.job.JobService; import android.content.ComponentName; import android.content.ContentResolver; import android.content.ContentValues; @@ -4119,20 +4118,6 @@ public final class Telephony { public static final String CID = "cid"; /** - * Message code. <em>OBSOLETE: merged into SERIAL_NUMBER.</em> - * <P>Type: INTEGER</P> - * @hide - */ - public static final String V1_MESSAGE_CODE = "message_code"; - - /** - * Message identifier. <em>OBSOLETE: renamed to SERVICE_CATEGORY.</em> - * <P>Type: INTEGER</P> - * @hide - */ - public static final String V1_MESSAGE_IDENTIFIER = "message_id"; - - /** * Service category which represents the general topic of the message. * <p> * For GSM/UMTS: message identifier (see 3GPP TS 23.041 section 9.4.1.2.2) @@ -4380,9 +4365,11 @@ public final class Telephony { * ServiceState provider. * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the - * {@link ServiceState} while your app is running. You can also use a {@link JobService} to + * {@link ServiceState} while your app is running. + * You can also use a {@link android.app.job.JobService} to * ensure your app is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of + * Note, however, that using a {@link android.app.job.JobService} + * does not guarantee timely delivery of * updates to the {@link Uri}. * * @param subscriptionId the subscriptionId to receive updates on @@ -4399,9 +4386,11 @@ public final class Telephony { * ServiceState provider. * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the - * {@link ServiceState} while your app is running. You can also use a {@link JobService} to + * {@link ServiceState} while your app is running. You can also use a + * {@link android.app.job.JobService} to * ensure your app is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of + * Note, however, that using a {@link android.app.job.JobService} + * does not guarantee timely delivery of * updates to the {@link Uri}. * * @param subscriptionId the subscriptionId to receive updates on @@ -4479,7 +4468,7 @@ public final class Telephony { /** * The current registered voice network operator name in long alphanumeric format. * <p> - * This is the same as {@link ServiceState#getVoiceOperatorAlphaLong()}. + * This is the same as {@link ServiceState#getOperatorAlphaLong()}. * @hide */ public static final String VOICE_OPERATOR_ALPHA_LONG = "voice_operator_alpha_long"; @@ -4490,12 +4479,11 @@ public final class Telephony { * In GSM/UMTS, short format can be up to 8 characters long. The current registered voice * network operator name in long alphanumeric format. * <p> - * This is the same as {@link ServiceState#getVoiceOperatorAlphaShort()}. + * This is the same as {@link ServiceState#getOperatorAlphaShort()}. * @hide */ public static final String VOICE_OPERATOR_ALPHA_SHORT = "voice_operator_alpha_short"; - /** * The current registered operator numeric id. * <p> @@ -4509,7 +4497,7 @@ public final class Telephony { /** * The current registered data network operator name in long alphanumeric format. * <p> - * This is the same as {@link ServiceState#getDataOperatorAlphaLong()}. + * This is the same as {@link ServiceState#getOperatorAlphaLong()}. * @hide */ public static final String DATA_OPERATOR_ALPHA_LONG = "data_operator_alpha_long"; @@ -4517,7 +4505,7 @@ public final class Telephony { /** * The current registered data network operator name in short alphanumeric format. * <p> - * This is the same as {@link ServiceState#getDataOperatorAlphaShort()}. + * This is the same as {@link ServiceState#getOperatorAlphaShort()}. * @hide */ public static final String DATA_OPERATOR_ALPHA_SHORT = "data_operator_alpha_short"; @@ -4525,7 +4513,7 @@ public final class Telephony { /** * The current registered data network operator numeric id. * <p> - * This is the same as {@link ServiceState#getDataOperatorNumeric()}. + * This is the same as {@link ServiceState#getOperatorNumeric()}. * @hide */ public static final String DATA_OPERATOR_NUMERIC = "data_operator_numeric"; @@ -4656,10 +4644,11 @@ public final class Telephony { * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * carrier identity {@link TelephonyManager#getSimCarrierId()} - * while your app is running. You can also use a {@link JobService} to ensure your app + * while your app is running. You can also use a {@link android.app.job.JobService} + * to ensure your app * is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee + * timely delivery of updates to the {@link Uri}. * * @param subscriptionId the subscriptionId to receive updates on * @return the Uri used to observe carrier identity changes @@ -4677,10 +4666,11 @@ public final class Telephony { * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * specific carrier identity {@link TelephonyManager#getSimSpecificCarrierId()} - * while your app is running. You can also use a {@link JobService} to ensure your app + * while your app is running. You can also use a {@link android.app.job.JobService} + * to ensure your app * is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee timely + * delivery of updates to the {@link Uri}. * * @param subscriptionId the subscriptionId to receive updates on * @return the Uri used to observe specific carrier identity changes diff --git a/core/java/android/service/carrier/ApnService.java b/core/java/android/service/carrier/ApnService.java index 57e4b1b40748..0c12fd409078 100644 --- a/core/java/android/service/carrier/ApnService.java +++ b/core/java/android/service/carrier/ApnService.java @@ -26,7 +26,7 @@ import android.content.Intent; import android.os.IBinder; import android.util.Log; -import com.android.internal.telephony.IApnSourceService; +import android.service.carrier.IApnSourceService; import java.util.List; diff --git a/telephony/java/com/android/internal/telephony/IApnSourceService.aidl b/core/java/android/service/carrier/IApnSourceService.aidl index 34c9067c3f2f..fadd2ff1a772 100644 --- a/telephony/java/com/android/internal/telephony/IApnSourceService.aidl +++ b/core/java/android/service/carrier/IApnSourceService.aidl @@ -14,10 +14,11 @@ * limitations under the License. */ -package com.android.internal.telephony; +package android.service.carrier; import android.content.ContentValues; +/** @hide */ interface IApnSourceService { /** Retreive APNs. */ ContentValues[] getApns(int subId); diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index a35c4dbdf383..8dc84c804055 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -2030,6 +2030,11 @@ <!-- =========================================== --> <eat-comment /> + <!-- @SystemApi Allows granting runtime permissions to telephony related components. + @hide Used internally. --> + <permission android:name="android.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS" + android:protectionLevel="signature|telephony" /> + <!-- Allows modification of the telephony state - power on, mmi, etc. Does not include placing calls. <p>Not for use by third-party applications. --> diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 3455c4f01ff9..1033e56776b9 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.media.audiofx.AudioEffect; import android.media.audiopolicy.AudioMix; +import android.telephony.TelephonyManager; import android.util.Log; import java.lang.annotation.Retention; @@ -1239,7 +1240,8 @@ public class AudioSystem * </ul> */ public static int getPlatformType(Context context) { - if (context.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable)) { + if (((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)) + .isVoiceCapable()) { return PLATFORM_VOICE; } else if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { return PLATFORM_TELEVISION; diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index 5e2b7c86ee93..6821942111f1 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -949,8 +949,7 @@ class DatabaseHelper extends SQLiteOpenHelper { (1 << AudioManager.STREAM_NOTIFICATION) | (1 << AudioManager.STREAM_SYSTEM) | (1 << AudioManager.STREAM_SYSTEM_ENFORCED); - if (!mContext.getResources().getBoolean( - com.android.internal.R.bool.config_voice_capable)) { + if (!getTelephonyManager().isVoiceCapable()) { ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC); } db.execSQL("DELETE FROM system WHERE name='" @@ -2579,7 +2578,7 @@ class DatabaseHelper extends SQLiteOpenHelper { String val = ""; String mode; for (int phoneId = 0; - phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { + phoneId < getTelephonyManager().getPhoneCount(); phoneId++) { mode = TelephonyManager.getTelephonyProperty(phoneId, "ro.telephony.default_network", Integer.toString(RILConstants.PREFERRED_NETWORK_MODE)); @@ -2693,4 +2692,9 @@ class DatabaseHelper extends SQLiteOpenHelper { private String getDefaultDeviceName() { return mContext.getResources().getString(R.string.def_device_name_simple, Build.MODEL); } + + private TelephonyManager getTelephonyManager() { + return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); + } + } diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java index 4dbca47c2f0a..9d9cad825444 100644 --- a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java +++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java @@ -163,8 +163,7 @@ public class CarrierTextController { public CarrierTextController(Context context, CharSequence separator, boolean showAirplaneMode, boolean showMissingSim) { mContext = context; - mIsEmergencyCallCapable = context.getResources().getBoolean( - com.android.internal.R.bool.config_voice_capable); + mIsEmergencyCallCapable = getTelephonyManager().isVoiceCapable(); mShowAirplaneMode = showAirplaneMode; mShowMissingSim = showMissingSim; diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java index 210b82d1d69c..1acccf90c0eb 100644 --- a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java +++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java @@ -26,6 +26,7 @@ import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.telecom.TelecomManager; +import android.telephony.TelephonyManager; import android.util.AttributeSet; import android.util.Slog; import android.view.MotionEvent; @@ -92,13 +93,16 @@ public class EmergencyButton extends Button { public EmergencyButton(Context context, AttributeSet attrs) { super(context, attrs); - mIsVoiceCapable = context.getResources().getBoolean( - com.android.internal.R.bool.config_voice_capable); + mIsVoiceCapable = getTelephonyManager().isVoiceCapable(); mEnableEmergencyCallWhileSimLocked = mContext.getResources().getBoolean( com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked); mEmergencyAffordanceManager = new EmergencyAffordanceManager(context); } + private TelephonyManager getTelephonyManager() { + return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java index 75231448ccfc..0278258ea4b2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java @@ -51,8 +51,8 @@ import com.android.systemui.statusbar.policy.NetworkControllerImpl.SubscriptionD import java.io.PrintWriter; import java.util.BitSet; -import java.util.Objects; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -556,8 +556,8 @@ public class MobileSignalController extends SignalController< // If this is the data subscription, update the currentState data name if (mCurrentState.networkNameData.equals(mNetworkNameDefault) && mServiceState != null && mCurrentState.dataSim - && !TextUtils.isEmpty(mServiceState.getDataOperatorAlphaShort())) { - mCurrentState.networkNameData = mServiceState.getDataOperatorAlphaShort(); + && !TextUtils.isEmpty(mServiceState.getOperatorAlphaShort())) { + mCurrentState.networkNameData = mServiceState.getOperatorAlphaShort(); } notifyListenersIfNecessary(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java index aa4723acba62..99e5a76b3a11 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java @@ -500,7 +500,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest { public void testUpdateDataNetworkName() { setupDefaultSignal(); String newDataName = "TestDataName"; - when(mServiceState.getDataOperatorAlphaShort()).thenReturn(newDataName); + when(mServiceState.getOperatorAlphaShort()).thenReturn(newDataName); updateServiceState(); assertDataNetworkNameEquals(newDataName); } diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 87b1bdfbe2ba..b71943504bf6 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -5864,19 +5864,6 @@ public class ConnectivityService extends IConnectivityManager.Stub return INetd.PERMISSION_NONE; } - private void updateNetworkPermissions(@NonNull final NetworkAgentInfo nai, - @NonNull final NetworkCapabilities newNc) { - final int oldPermission = getNetworkPermission(nai.networkCapabilities); - final int newPermission = getNetworkPermission(newNc); - if (oldPermission != newPermission && nai.created && !nai.isVPN()) { - try { - mNMS.setNetworkPermission(nai.network.netId, newPermission); - } catch (RemoteException e) { - loge("Exception in setNetworkPermission: " + e); - } - } - } - /** * Augments the NetworkCapabilities passed in by a NetworkAgent with capabilities that are * maintained here that the NetworkAgent is not aware of (e.g., validated, captive portal, @@ -5948,11 +5935,21 @@ public class ConnectivityService extends IConnectivityManager.Stub * @param nai the network having its capabilities updated. * @param nc the new network capabilities. */ - private void updateCapabilities(final int oldScore, @NonNull final NetworkAgentInfo nai, - @NonNull final NetworkCapabilities nc) { + private void updateCapabilities(int oldScore, NetworkAgentInfo nai, NetworkCapabilities nc) { NetworkCapabilities newNc = mixInCapabilities(nai, nc); + if (Objects.equals(nai.networkCapabilities, newNc)) return; - updateNetworkPermissions(nai, nc); + + final int oldPermission = getNetworkPermission(nai.networkCapabilities); + final int newPermission = getNetworkPermission(newNc); + if (oldPermission != newPermission && nai.created && !nai.isVPN()) { + try { + mNMS.setNetworkPermission(nai.network.netId, newPermission); + } catch (RemoteException e) { + loge("Exception in setNetworkPermission: " + e); + } + } + final NetworkCapabilities prevNc = nai.getAndSetNetworkCapabilities(newNc); updateUids(nai, prevNc, newNc); @@ -6299,52 +6296,6 @@ public class ConnectivityService extends IConnectivityManager.Stub } } - // An accumulator class to gather the list of changes that result from a rematch. - // TODO : enrich to represent an entire set of changes to apply. - private static class NetworkReassignment { - static class NetworkBgStatePair { - @NonNull final NetworkAgentInfo mNetwork; - final boolean mOldBackground; - NetworkBgStatePair(@NonNull final NetworkAgentInfo network, - final boolean oldBackground) { - mNetwork = network; - mOldBackground = oldBackground; - } - } - - static class RequestReassignment { - @NonNull public final NetworkRequestInfo mRequest; - @Nullable public final NetworkAgentInfo mOldNetwork; - @Nullable public final NetworkAgentInfo mNewNetwork; - RequestReassignment(@NonNull final NetworkRequestInfo request, - @Nullable final NetworkAgentInfo oldNetwork, - @Nullable final NetworkAgentInfo newNetwork) { - mRequest = request; - mOldNetwork = oldNetwork; - mNewNetwork = newNetwork; - } - } - - @NonNull private final Set<NetworkBgStatePair> mRematchedNetworks = new ArraySet<>(); - @NonNull private final List<RequestReassignment> mReassignments = new ArrayList<>(); - - @NonNull Iterable<NetworkBgStatePair> getRematchedNetworks() { - return mRematchedNetworks; - } - - @NonNull Iterable<RequestReassignment> getRequestReassignments() { - return mReassignments; - } - - void addRequestReassignment(@NonNull final RequestReassignment reassignment) { - mReassignments.add(reassignment); - } - - void addRematchedNetwork(@NonNull final NetworkBgStatePair network) { - mRematchedNetworks.add(network); - } - } - private ArrayMap<NetworkRequestInfo, NetworkAgentInfo> computeRequestReassignmentForNetwork( @NonNull final NetworkAgentInfo newNetwork) { final int score = newNetwork.getCurrentScore(); @@ -6390,8 +6341,8 @@ public class ConnectivityService extends IConnectivityManager.Stub // needed. A network is needed if it is the best network for // one or more NetworkRequests, or if it is a VPN. // - // - Writes into the passed reassignment object all changes that should be done for - // rematching this network with all requests, to be applied later. + // - Tears down newNetwork if it just became validated + // but turns out to be unneeded. // // NOTE: This function only adds NetworkRequests that "newNetwork" could satisfy, // it does not remove NetworkRequests that other Networks could better satisfy. @@ -6399,29 +6350,29 @@ public class ConnectivityService extends IConnectivityManager.Stub // This function should be used when possible instead of {@code rematchAllNetworksAndRequests} // as it performs better by a factor of the number of Networks. // - // TODO : stop writing to the passed reassignment. This is temporarily more useful, but - // it's unidiomatic Java and it's hard to read. - // - // @param changes a currently-building list of changes to write to // @param newNetwork is the network to be matched against NetworkRequests. // @param now the time the rematch starts, as returned by SystemClock.elapsedRealtime(); - private void rematchNetworkAndRequests(@NonNull final NetworkReassignment changes, - @NonNull final NetworkAgentInfo newNetwork, final long now) { + private void rematchNetworkAndRequests(NetworkAgentInfo newNetwork, long now) { ensureRunningOnConnectivityServiceThread(); if (!newNetwork.everConnected) return; boolean isNewDefault = false; NetworkAgentInfo oldDefaultNetwork = null; - changes.addRematchedNetwork(new NetworkReassignment.NetworkBgStatePair(newNetwork, - newNetwork.isBackgroundNetwork())); + final boolean wasBackgroundNetwork = newNetwork.isBackgroundNetwork(); + final int score = newNetwork.getCurrentScore(); if (VDBG || DDBG) log("rematching " + newNetwork.name()); final ArrayMap<NetworkRequestInfo, NetworkAgentInfo> reassignedRequests = computeRequestReassignmentForNetwork(newNetwork); + NetworkCapabilities nc = newNetwork.networkCapabilities; + if (VDBG) log(" network has: " + nc); + // Find and migrate to this Network any NetworkRequests for // which this network is now the best. + final ArrayList<NetworkAgentInfo> removedRequests = new ArrayList<>(); + final ArrayList<NetworkRequestInfo> addedRequests = new ArrayList<>(); for (final Map.Entry<NetworkRequestInfo, NetworkAgentInfo> entry : reassignedRequests.entrySet()) { final NetworkRequestInfo nri = entry.getKey(); @@ -6435,6 +6386,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } previousSatisfier.removeRequest(nri.request.requestId); previousSatisfier.lingerRequest(nri.request, now, mLingerDelayMs); + removedRequests.add(previousSatisfier); } else { if (VDBG || DDBG) log(" accepting network in place of null"); } @@ -6443,8 +6395,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (!newSatisfier.addRequest(nri.request)) { Slog.wtf(TAG, "BUG: " + newSatisfier.name() + " already has " + nri.request); } - changes.addRequestReassignment(new NetworkReassignment.RequestReassignment( - nri, previousSatisfier, newSatisfier)); + addedRequests.add(nri); // Tell NetworkFactories about the new score, so they can stop // trying to connect if they know they cannot match it. // TODO - this could get expensive if we have a lot of requests for this @@ -6501,6 +6452,48 @@ public class ConnectivityService extends IConnectivityManager.Stub // Have a new default network, release the transition wakelock in scheduleReleaseNetworkTransitionWakelock(); } + + if (!newNetwork.networkCapabilities.equalRequestableCapabilities(nc)) { + Slog.wtf(TAG, String.format( + "BUG: %s changed requestable capabilities during rematch: %s -> %s", + newNetwork.name(), nc, newNetwork.networkCapabilities)); + } + if (newNetwork.getCurrentScore() != score) { + Slog.wtf(TAG, String.format( + "BUG: %s changed score during rematch: %d -> %d", + newNetwork.name(), score, newNetwork.getCurrentScore())); + } + + // Notify requested networks are available after the default net is switched, but + // before LegacyTypeTracker sends legacy broadcasts + for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri); + + // Finally, process listen requests and update capabilities if the background state has + // changed for this network. For consistency with previous behavior, send onLost callbacks + // before onAvailable. + processNewlyLostListenRequests(newNetwork); + + // Maybe the network changed background states. Update its capabilities. + final boolean backgroundChanged = wasBackgroundNetwork != newNetwork.isBackgroundNetwork(); + if (backgroundChanged) { + final NetworkCapabilities newNc = mixInCapabilities(newNetwork, + newNetwork.networkCapabilities); + + final int oldPermission = getNetworkPermission(newNetwork.networkCapabilities); + final int newPermission = getNetworkPermission(newNc); + if (oldPermission != newPermission) { + try { + mNMS.setNetworkPermission(newNetwork.network.netId, newPermission); + } catch (RemoteException e) { + loge("Exception in setNetworkPermission: " + e); + } + } + + newNetwork.getAndSetNetworkCapabilities(newNc); + notifyNetworkCallbacks(newNetwork, ConnectivityManager.CALLBACK_CAP_CHANGED); + } + + processNewlySatisfiedListenRequests(newNetwork); } /** @@ -6522,33 +6515,12 @@ public class ConnectivityService extends IConnectivityManager.Stub // scoring network and then a higher scoring network, which could produce multiple // callbacks. Arrays.sort(nais); - final NetworkReassignment changes = new NetworkReassignment(); for (final NetworkAgentInfo nai : nais) { - rematchNetworkAndRequests(changes, nai, now); + rematchNetworkAndRequests(nai, now); } final NetworkAgentInfo newDefaultNetwork = getDefaultNetwork(); - // Notify requested networks are available after the default net is switched, but - // before LegacyTypeTracker sends legacy broadcasts - for (final NetworkReassignment.RequestReassignment event : - changes.getRequestReassignments()) { - if (null != event.mNewNetwork) { - notifyNetworkAvailable(event.mNewNetwork, event.mRequest); - } - } - - for (final NetworkReassignment.NetworkBgStatePair event : changes.getRematchedNetworks()) { - // Process listen requests and update capabilities if the background state has - // changed for this network. For consistency with previous behavior, send onLost - // callbacks before onAvailable. - processNewlyLostListenRequests(event.mNetwork); - if (event.mOldBackground != event.mNetwork.isBackgroundNetwork()) { - applyBackgroundChangeForRematch(event.mNetwork); - } - processNewlySatisfiedListenRequests(event.mNetwork); - } - for (final NetworkAgentInfo nai : nais) { // Rematching may have altered the linger state of some networks, so update all linger // timers. updateLingerState reads the state from the network agent and does nothing @@ -6580,24 +6552,6 @@ public class ConnectivityService extends IConnectivityManager.Stub } } - /** - * Apply a change in background state resulting from rematching networks with requests. - * - * During rematch, a network may change background states by starting to satisfy or stopping - * to satisfy a foreground request. Listens don't count for this. When a network changes - * background states, its capabilities need to be updated and callbacks fired for the - * capability change. - * - * @param nai The network that changed background states - */ - private void applyBackgroundChangeForRematch(@NonNull final NetworkAgentInfo nai) { - final NetworkCapabilities newNc = mixInCapabilities(nai, nai.networkCapabilities); - if (Objects.equals(nai.networkCapabilities, newNc)) return; - updateNetworkPermissions(nai, newNc); - nai.getAndSetNetworkCapabilities(newNc); - notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_CAP_CHANGED); - } - private void updateLegacyTypeTrackerAndVpnLockdownForRematch( @Nullable final NetworkAgentInfo oldDefaultNetwork, @Nullable final NetworkAgentInfo newDefaultNetwork, diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 9791ff3e02ba..7e7822cd978e 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -17474,8 +17474,7 @@ public class PackageManagerService extends IPackageManager.Stub if (new File(signaturePath).exists() && !VerityUtils.hasFsverity(filePath)) { try { VerityUtils.setUpFsverity(filePath, signaturePath); - } catch (IOException | DigestException | NoSuchAlgorithmException - | SecurityException e) { + } catch (IOException e) { throw new PrepareFailure(PackageManager.INSTALL_FAILED_BAD_SIGNATURE, "Failed to enable fs-verity: " + e); } diff --git a/services/core/java/com/android/server/role/RoleManagerService.java b/services/core/java/com/android/server/role/RoleManagerService.java index fff9ec7f02c5..0caf8f835752 100644 --- a/services/core/java/com/android/server/role/RoleManagerService.java +++ b/services/core/java/com/android/server/role/RoleManagerService.java @@ -50,7 +50,6 @@ import android.os.ShellCallback; import android.os.UserHandle; import android.os.UserManagerInternal; import android.service.sms.FinancialSmsService; -import android.telephony.IFinancialSmsCallback; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; @@ -675,40 +674,6 @@ public class RoleManagerService extends SystemService implements RoleUserState.C dumpOutputStream.flush(); } - /** - * Get filtered SMS messages for financial app. - */ - @Override - public void getSmsMessagesForFinancialApp( - String callingPkg, Bundle params, IFinancialSmsCallback callback) { - int mode = PermissionChecker.checkCallingOrSelfPermissionForDataDelivery( - getContext(), - AppOpsManager.OPSTR_SMS_FINANCIAL_TRANSACTIONS); - - if (mode == PermissionChecker.PERMISSION_GRANTED) { - FinancialSmsManager financialSmsManager = new FinancialSmsManager(getContext()); - financialSmsManager.getSmsMessages(new RemoteCallback((result) -> { - CursorWindow messages = null; - if (result == null) { - Slog.w(LOG_TAG, "result is null."); - } else { - messages = result.getParcelable(FinancialSmsService.EXTRA_SMS_MSGS); - } - try { - callback.onGetSmsMessagesForFinancialApp(messages); - } catch (RemoteException e) { - // do nothing - } - }), params); - } else { - try { - callback.onGetSmsMessagesForFinancialApp(null); - } catch (RemoteException e) { - // do nothing - } - } - } - private int getUidForPackage(String packageName) { long ident = Binder.clearCallingIdentity(); try { diff --git a/services/core/java/com/android/server/security/VerityUtils.java b/services/core/java/com/android/server/security/VerityUtils.java index b1db46fb3276..856a40f3ef12 100644 --- a/services/core/java/com/android/server/security/VerityUtils.java +++ b/services/core/java/com/android/server/security/VerityUtils.java @@ -26,27 +26,19 @@ import android.util.Slog; import android.util.apk.ApkSignatureVerifier; import android.util.apk.ByteBufferFactory; import android.util.apk.SignatureNotFoundException; -import android.util.apk.VerityBuilder; import libcore.util.HexEncoding; import java.io.File; import java.io.FileDescriptor; import java.io.IOException; -import java.io.RandomAccessFile; import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.channels.FileChannel; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.security.DigestException; -import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; -import sun.security.pkcs.PKCS7; - /** Provides fsverity related operations. */ abstract public class VerityUtils { private static final String TAG = "VerityUtils"; @@ -60,8 +52,6 @@ abstract public class VerityUtils { /** The maximum size of signature file. This is just to avoid potential abuse. */ private static final int MAX_SIGNATURE_FILE_SIZE_BYTES = 8192; - private static final int COMMON_LINUX_PAGE_SIZE_IN_BYTES = 4096; - private static final boolean DEBUG = false; /** Returns true if the given file looks like containing an fs-verity signature. */ @@ -74,42 +64,15 @@ abstract public class VerityUtils { return filePath + FSVERITY_SIGNATURE_FILE_EXTENSION; } - /** Generates Merkle tree and fs-verity metadata then enables fs-verity. */ - public static void setUpFsverity(@NonNull String filePath, String signaturePath) - throws IOException, DigestException, NoSuchAlgorithmException { - final PKCS7 pkcs7 = new PKCS7(Files.readAllBytes(Paths.get(signaturePath))); - final byte[] expectedMeasurement = pkcs7.getContentInfo().getContentBytes(); - if (DEBUG) { - Slog.d(TAG, "Enabling fs-verity with signed fs-verity measurement " - + bytesToString(expectedMeasurement)); - Slog.d(TAG, "PKCS#7 info: " + pkcs7); - } - - final TrackedBufferFactory bufferFactory = new TrackedBufferFactory(); - final byte[] actualMeasurement = generateFsverityMetadata(filePath, signaturePath, - bufferFactory); - try (RandomAccessFile raf = new RandomAccessFile(filePath, "rw")) { - FileChannel ch = raf.getChannel(); - ch.position(roundUpToNextMultiple(ch.size(), COMMON_LINUX_PAGE_SIZE_IN_BYTES)); - ByteBuffer buffer = bufferFactory.getBuffer(); - - long offset = buffer.position(); - long size = buffer.limit(); - while (offset < size) { - long s = ch.write(buffer); - offset += s; - size -= s; - } + /** Enables fs-verity for the file with a PKCS#7 detached signature file. */ + public static void setUpFsverity(@NonNull String filePath, @NonNull String signaturePath) + throws IOException { + if (Files.size(Paths.get(signaturePath)) > MAX_SIGNATURE_FILE_SIZE_BYTES) { + throw new SecurityException("Signature file is unexpectedly large: " + signaturePath); } - - if (!Arrays.equals(expectedMeasurement, actualMeasurement)) { - throw new SecurityException("fs-verity measurement mismatch: " - + bytesToString(actualMeasurement) + " != " - + bytesToString(expectedMeasurement)); - } - - // This can fail if the public key is not already in .fs-verity kernel keyring. - int errno = enableFsverityNative(filePath); + byte[] pkcs7Signature = Files.readAllBytes(Paths.get(signaturePath)); + // This will fail if the public key is not already in .fs-verity kernel keyring. + int errno = enableFsverityNative(filePath, pkcs7Signature); if (errno != 0) { throw new IOException("Failed to enable fs-verity on " + filePath + ": " + Os.strerror(errno)); @@ -131,12 +94,19 @@ abstract public class VerityUtils { return true; } + private static native int enableFsverityNative(@NonNull String filePath, + @NonNull byte[] pkcs7Signature); + private static native int measureFsverityNative(@NonNull String filePath); + /** * Generates legacy Merkle tree and fs-verity metadata with Signing Block skipped. * + * @deprecated This is only used for previous fs-verity implementation, and should never be used + * on new devices. * @return {@code SetupResult} that contains the result code, and when success, the * {@code FileDescriptor} to read all the data from. */ + @Deprecated public static SetupResult generateApkVeritySetupData(@NonNull String apkPath) { if (DEBUG) { Slog.d(TAG, "Trying to install legacy apk verity to " + apkPath); @@ -173,7 +143,10 @@ abstract public class VerityUtils { /** * {@see ApkSignatureVerifier#generateApkVerityRootHash(String)}. + * @deprecated This is only used for previous fs-verity implementation, and should never be used + * on new devices. */ + @Deprecated public static byte[] generateApkVerityRootHash(@NonNull String apkPath) throws NoSuchAlgorithmException, DigestException, IOException { return ApkSignatureVerifier.generateApkVerityRootHash(apkPath); @@ -181,104 +154,16 @@ abstract public class VerityUtils { /** * {@see ApkSignatureVerifier#getVerityRootHash(String)}. + * @deprecated This is only used for previous fs-verity implementation, and should never be used + * on new devices. */ + @Deprecated public static byte[] getVerityRootHash(@NonNull String apkPath) throws IOException, SignatureNotFoundException { return ApkSignatureVerifier.getVerityRootHash(apkPath); } /** - * Generates fs-verity metadata for {@code filePath} in the buffer created by {@code - * trackedBufferFactory}. The metadata contains the Merkle tree, fs-verity descriptor and - * extensions, including a PKCS#7 signature provided in {@code signaturePath}. - * - * <p>It is worthy to note that {@code trackedBufferFactory} generates a "tracked" {@code - * ByteBuffer}. The data will be used outside this method via the factory itself. - * - * @return fs-verity signed data (struct fsverity_digest_disk) of {@code filePath}, which - * includes SHA-256 of fs-verity descriptor and authenticated extensions. - */ - private static byte[] generateFsverityMetadata(String filePath, String signaturePath, - @NonNull ByteBufferFactory trackedBufferFactory) - throws IOException, DigestException, NoSuchAlgorithmException { - try (RandomAccessFile file = new RandomAccessFile(filePath, "r")) { - VerityBuilder.VerityResult result = VerityBuilder.generateFsVerityTree( - file, trackedBufferFactory); - - ByteBuffer buffer = result.verityData; - buffer.position(result.merkleTreeSize); - - final byte[] measurement = generateFsverityDescriptorAndMeasurement(file, - result.rootHash, signaturePath, buffer); - buffer.flip(); - return constructFsveritySignedDataNative(measurement); - } - } - - /** - * Generates fs-verity descriptor including the extensions to the {@code output} and returns the - * fs-verity measurement. - * - * @return fs-verity measurement, which is a SHA-256 of fs-verity descriptor and authenticated - * extensions. - */ - private static byte[] generateFsverityDescriptorAndMeasurement( - @NonNull RandomAccessFile file, @NonNull byte[] rootHash, - @NonNull String pkcs7SignaturePath, @NonNull ByteBuffer output) - throws IOException, NoSuchAlgorithmException, DigestException { - final short kRootHashExtensionId = 1; - final short kPkcs7SignatureExtensionId = 3; - final int origPosition = output.position(); - - // For generating fs-verity file measurement, which consists of the descriptor and - // authenticated extensions (but not unauthenticated extensions and the footer). - MessageDigest md = MessageDigest.getInstance("SHA-256"); - - // 1. Generate fs-verity descriptor. - final byte[] desc = constructFsverityDescriptorNative(file.length()); - output.put(desc); - md.update(desc); - - // 2. Generate authenticated extensions. - final byte[] authExt = - constructFsverityExtensionNative(kRootHashExtensionId, rootHash.length); - output.put(authExt); - output.put(rootHash); - md.update(authExt); - md.update(rootHash); - - // 3. Generate unauthenticated extensions. - ByteBuffer header = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN); - output.putShort((short) 1); // number of unauthenticated extensions below - output.position(output.position() + 6); - - // Generate PKCS#7 extension. NB: We do not verify agaist trusted certificate (should be - // done by the caller if needed). - Path path = Paths.get(pkcs7SignaturePath); - if (Files.size(path) > MAX_SIGNATURE_FILE_SIZE_BYTES) { - throw new IllegalArgumentException("Signature size is unexpectedly large: " - + pkcs7SignaturePath); - } - final byte[] pkcs7Signature = Files.readAllBytes(path); - output.put(constructFsverityExtensionNative(kPkcs7SignatureExtensionId, - pkcs7Signature.length)); - output.put(pkcs7Signature); - - // 4. Generate the footer. - output.put(constructFsverityFooterNative(output.position() - origPosition)); - - return md.digest(); - } - - private static native int enableFsverityNative(@NonNull String filePath); - private static native int measureFsverityNative(@NonNull String filePath); - private static native byte[] constructFsveritySignedDataNative(@NonNull byte[] measurement); - private static native byte[] constructFsverityDescriptorNative(long fileSize); - private static native byte[] constructFsverityExtensionNative(short extensionId, - int extensionDataSize); - private static native byte[] constructFsverityFooterNative(int offsetToDescriptorHead); - - /** * Returns a pair of {@code SharedMemory} and {@code Integer}. The {@code SharedMemory} contains * Merkle tree and fsverity headers for the given apk, in the form that can immediately be used * for fsverity setup. The data is aligned to the beginning of {@code SharedMemory}, and has @@ -313,6 +198,11 @@ abstract public class VerityUtils { return HexEncoding.encodeToString(bytes); } + /** + * @deprecated This is only used for previous fs-verity implementation, and should never be used + * on new devices. + */ + @Deprecated public static class SetupResult { /** Result code if verity is set up correctly. */ private static final int RESULT_OK = 1; @@ -401,30 +291,4 @@ abstract public class VerityUtils { return mBuffer == null ? -1 : mBuffer.limit(); } } - - /** A {@code ByteBufferFactory} that tracks the {@code ByteBuffer} it creates. */ - private static class TrackedBufferFactory implements ByteBufferFactory { - private ByteBuffer mBuffer; - - @Override - public ByteBuffer create(int capacity) { - if (mBuffer != null) { - throw new IllegalStateException("Multiple instantiation from this factory"); - } - mBuffer = ByteBuffer.allocate(capacity); - return mBuffer; - } - - public ByteBuffer getBuffer() { - return mBuffer; - } - } - - /** Round up the number to the next multiple of the divisor. */ - private static long roundUpToNextMultiple(long number, long divisor) { - if (number > (Long.MAX_VALUE - divisor)) { - throw new IllegalArgumentException("arithmetic overflow"); - } - return ((number + (divisor - 1)) / divisor) * divisor; - } } diff --git a/services/core/jni/com_android_server_security_VerityUtils.cpp b/services/core/jni/com_android_server_security_VerityUtils.cpp index 6cd9f2c718ee..9ceb7706628a 100644 --- a/services/core/jni/com_android_server_security_VerityUtils.cpp +++ b/services/core/jni/com_android_server_security_VerityUtils.cpp @@ -36,61 +36,33 @@ #include <linux/fsverity.h> #else -// Before fs-verity is upstreamed, use the current snapshot for development. -// https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/tree/include/uapi/linux/fsverity.h?h=fsverity - #include <linux/limits.h> #include <linux/ioctl.h> #include <linux/types.h> +#define FS_VERITY_HASH_ALG_SHA256 1 + +struct fsverity_enable_arg { + __u32 version; + __u32 hash_algorithm; + __u32 block_size; + __u32 salt_size; + __u64 salt_ptr; + __u32 sig_size; + __u32 __reserved1; + __u64 sig_ptr; + __u64 __reserved2[11]; +}; + struct fsverity_digest { __u16 digest_algorithm; __u16 digest_size; /* input/output */ __u8 digest[]; }; -#define FS_IOC_ENABLE_VERITY _IO('f', 133) +#define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) #define FS_IOC_MEASURE_VERITY _IOWR('f', 134, struct fsverity_digest) -#define FS_VERITY_MAGIC "FSVerity" - -#define FS_VERITY_ALG_SHA256 1 - -struct fsverity_descriptor { - __u8 magic[8]; /* must be FS_VERITY_MAGIC */ - __u8 major_version; /* must be 1 */ - __u8 minor_version; /* must be 0 */ - __u8 log_data_blocksize;/* log2(data-bytes-per-hash), e.g. 12 for 4KB */ - __u8 log_tree_blocksize;/* log2(tree-bytes-per-hash), e.g. 12 for 4KB */ - __le16 data_algorithm; /* hash algorithm for data blocks */ - __le16 tree_algorithm; /* hash algorithm for tree blocks */ - __le32 flags; /* flags */ - __le32 __reserved1; /* must be 0 */ - __le64 orig_file_size; /* size of the original file data */ - __le16 auth_ext_count; /* number of authenticated extensions */ - __u8 __reserved2[30]; /* must be 0 */ -}; - -#define FS_VERITY_EXT_ROOT_HASH 1 -#define FS_VERITY_EXT_PKCS7_SIGNATURE 3 - -struct fsverity_extension { - __le32 length; - __le16 type; /* Type of this extension (see codes above) */ - __le16 __reserved; /* Reserved, must be 0 */ -}; - -struct fsverity_digest_disk { - __le16 digest_algorithm; - __le16 digest_size; - __u8 digest[]; -}; - -struct fsverity_footer { - __le32 desc_reverse_offset; /* distance to fsverity_descriptor */ - __u8 magic[8]; /* FS_VERITY_MAGIC */ -} __packed; - #endif const int kSha256Bytes = 32; @@ -99,52 +71,24 @@ namespace android { namespace { -class JavaByteArrayHolder { - public: - JavaByteArrayHolder(const JavaByteArrayHolder &other) = delete; - JavaByteArrayHolder(JavaByteArrayHolder &&other) - : mEnv(other.mEnv), mBytes(other.mBytes), mElements(other.mElements) { - other.mElements = nullptr; - } - - static JavaByteArrayHolder newArray(JNIEnv* env, jsize size) { - return JavaByteArrayHolder(env, size); - } - - jbyte* getRaw() { - return mElements; - } - - jbyteArray release() { - mEnv->ReleaseByteArrayElements(mBytes, mElements, 0); - mElements = nullptr; - return mBytes; - } - - ~JavaByteArrayHolder() { - LOG_ALWAYS_FATAL_IF(mElements != nullptr, "Elements are not released"); - } - - private: - JavaByteArrayHolder(JNIEnv* env, jsize size) { - mEnv = env; - mBytes = mEnv->NewByteArray(size); - mElements = mEnv->GetByteArrayElements(mBytes, nullptr); - memset(mElements, 0, size); - } - - JNIEnv* mEnv; - jbyteArray mBytes; - jbyte* mElements; -}; - -int enableFsverity(JNIEnv* env, jobject /* clazz */, jstring filePath) { +int enableFsverity(JNIEnv* env, jobject /* clazz */, jstring filePath, jbyteArray signature) { const char* path = env->GetStringUTFChars(filePath, nullptr); ::android::base::unique_fd rfd(open(path, O_RDONLY | O_CLOEXEC)); + env->ReleaseStringUTFChars(filePath, path); if (rfd.get() < 0) { return errno; } - if (ioctl(rfd.get(), FS_IOC_ENABLE_VERITY, nullptr) < 0) { + + fsverity_enable_arg arg = {}; + arg.version = 1; + arg.hash_algorithm = FS_VERITY_HASH_ALG_SHA256; + arg.block_size = 4096; + arg.salt_size = 0; + arg.salt_ptr = reinterpret_cast<uintptr_t>(nullptr); + arg.sig_size = env->GetArrayLength(signature); + arg.sig_ptr = reinterpret_cast<uintptr_t>(signature); + + if (ioctl(rfd.get(), FS_IOC_ENABLE_VERITY, &arg) < 0) { return errno; } return 0; @@ -159,6 +103,7 @@ int measureFsverity(JNIEnv* env, jobject /* clazz */, jstring filePath) { const char* path = env->GetStringUTFChars(filePath, nullptr); ::android::base::unique_fd rfd(open(path, O_RDONLY | O_CLOEXEC)); + env->ReleaseStringUTFChars(filePath, path); if (rfd.get() < 0) { return errno; } @@ -168,71 +113,9 @@ int measureFsverity(JNIEnv* env, jobject /* clazz */, jstring filePath) { return 0; } -jbyteArray constructFsveritySignedData(JNIEnv* env, jobject /* clazz */, jbyteArray digest) { - auto raii = JavaByteArrayHolder::newArray(env, sizeof(fsverity_digest_disk) + kSha256Bytes); - fsverity_digest_disk* data = reinterpret_cast<fsverity_digest_disk*>(raii.getRaw()); - - data->digest_algorithm = FS_VERITY_ALG_SHA256; - data->digest_size = kSha256Bytes; - if (env->GetArrayLength(digest) != kSha256Bytes) { - jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "Invalid hash size of %d", - env->GetArrayLength(digest)); - return 0; - } - const jbyte* src = env->GetByteArrayElements(digest, nullptr); - memcpy(data->digest, src, kSha256Bytes); - - return raii.release(); -} - - -jbyteArray constructFsverityDescriptor(JNIEnv* env, jobject /* clazz */, jlong fileSize) { - auto raii = JavaByteArrayHolder::newArray(env, sizeof(fsverity_descriptor)); - fsverity_descriptor* desc = reinterpret_cast<fsverity_descriptor*>(raii.getRaw()); - - memcpy(desc->magic, FS_VERITY_MAGIC, sizeof(desc->magic)); - desc->major_version = 1; - desc->minor_version = 0; - desc->log_data_blocksize = 12; - desc->log_tree_blocksize = 12; - desc->data_algorithm = FS_VERITY_ALG_SHA256; - desc->tree_algorithm = FS_VERITY_ALG_SHA256; - desc->flags = 0; - desc->orig_file_size = fileSize; - desc->auth_ext_count = 1; - - return raii.release(); -} - -jbyteArray constructFsverityExtension(JNIEnv* env, jobject /* clazz */, jshort extensionId, - jint extensionDataSize) { - auto raii = JavaByteArrayHolder::newArray(env, sizeof(fsverity_extension)); - fsverity_extension* ext = reinterpret_cast<fsverity_extension*>(raii.getRaw()); - - ext->length = sizeof(fsverity_extension) + extensionDataSize; - ext->type = extensionId; - - return raii.release(); -} - -jbyteArray constructFsverityFooter(JNIEnv* env, jobject /* clazz */, - jint offsetToDescriptorHead) { - auto raii = JavaByteArrayHolder::newArray(env, sizeof(fsverity_footer)); - fsverity_footer* footer = reinterpret_cast<fsverity_footer*>(raii.getRaw()); - - footer->desc_reverse_offset = offsetToDescriptorHead + sizeof(fsverity_footer); - memcpy(footer->magic, FS_VERITY_MAGIC, sizeof(footer->magic)); - - return raii.release(); -} - const JNINativeMethod sMethods[] = { - { "enableFsverityNative", "(Ljava/lang/String;)I", (void *)enableFsverity }, + { "enableFsverityNative", "(Ljava/lang/String;[B)I", (void *)enableFsverity }, { "measureFsverityNative", "(Ljava/lang/String;)I", (void *)measureFsverity }, - { "constructFsveritySignedDataNative", "([B)[B", (void *)constructFsveritySignedData }, - { "constructFsverityDescriptorNative", "(J)[B", (void *)constructFsverityDescriptor }, - { "constructFsverityExtensionNative", "(SI)[B", (void *)constructFsverityExtension }, - { "constructFsverityFooterNative", "(I)[B", (void *)constructFsverityFooter }, }; } // namespace diff --git a/telephony/java/com/android/internal/telephony/EncodeException.java b/telephony/common/com/android/internal/telephony/EncodeException.java index cdc853e09895..cdc853e09895 100644 --- a/telephony/java/com/android/internal/telephony/EncodeException.java +++ b/telephony/common/com/android/internal/telephony/EncodeException.java diff --git a/telephony/common/com/android/internal/telephony/SmsApplication.java b/telephony/common/com/android/internal/telephony/SmsApplication.java index 7cf4eebabec9..df668ea2313d 100644 --- a/telephony/common/com/android/internal/telephony/SmsApplication.java +++ b/telephony/common/com/android/internal/telephony/SmsApplication.java @@ -305,7 +305,7 @@ public final class SmsApplication { Uri.fromParts(SCHEME_SMSTO, "", null)); List<ResolveInfo> respondServices = packageManager.queryIntentServicesAsUser(intent, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, - UserHandle.getUserHandleForUid(userId)); + UserHandle.of(userId)); for (ResolveInfo resolveInfo : respondServices) { final ServiceInfo serviceInfo = resolveInfo.serviceInfo; if (serviceInfo == null) { diff --git a/telephony/java/android/telephony/CbGeoUtils.java b/telephony/java/android/telephony/CbGeoUtils.java index f4ce6e75769c..ce5e3f38e78b 100644 --- a/telephony/java/android/telephony/CbGeoUtils.java +++ b/telephony/java/android/telephony/CbGeoUtils.java @@ -18,6 +18,7 @@ package android.telephony; import android.annotation.NonNull; import android.annotation.SystemApi; +import android.os.Build; import android.text.TextUtils; import java.util.ArrayList; @@ -257,6 +258,15 @@ public class CbGeoUtils { return new Point(x - p.x, y - p.y); } } + + @Override + public String toString() { + String str = "Polygon: "; + if (Build.IS_DEBUGGABLE) { + str += mVertices; + } + return str; + } } /** @@ -284,6 +294,16 @@ public class CbGeoUtils { public boolean contains(LatLng p) { return mCenter.distance(p) <= mRadiusMeter; } + + @Override + public String toString() { + String str = "Circle: "; + if (Build.IS_DEBUGGABLE) { + str += mCenter + ", radius = " + mRadiusMeter; + } + + return str; + } } /** diff --git a/telephony/java/android/telephony/IFinancialSmsCallback.aidl b/telephony/java/android/telephony/IFinancialSmsCallback.aidl deleted file mode 100644 index aa88615c15cf..000000000000 --- a/telephony/java/android/telephony/IFinancialSmsCallback.aidl +++ /dev/null @@ -1,34 +0,0 @@ -/* -** Copyright 2019, 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 android.telephony; - -import android.app.PendingIntent; -import android.database.CursorWindow; -import android.net.Uri; -import android.os.Bundle; -import com.android.internal.telephony.SmsRawData; - -/** Interface for returning back the financial sms messages asynchrously. - * @hide - */ -interface IFinancialSmsCallback { - /** - * Return sms messages back to calling financial app. - * - * @param messages the sms messages returned for cinancial app. - */ - oneway void onGetSmsMessagesForFinancialApp(in CursorWindow messages); -} diff --git a/telephony/java/android/telephony/ServiceState.java b/telephony/java/android/telephony/ServiceState.java index 9ace86cea0c1..d2c851789b96 100644 --- a/telephony/java/android/telephony/ServiceState.java +++ b/telephony/java/android/telephony/ServiceState.java @@ -278,12 +278,9 @@ public class ServiceState implements Parcelable { */ public static final int UNKNOWN_ID = -1; - private String mVoiceOperatorAlphaLong; - private String mVoiceOperatorAlphaShort; - private String mVoiceOperatorNumeric; - private String mDataOperatorAlphaLong; - private String mDataOperatorAlphaShort; - private String mDataOperatorNumeric; + private String mOperatorAlphaLong; + private String mOperatorAlphaShort; + private String mOperatorNumeric; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) private boolean mIsManualNetworkSelection; @@ -379,12 +376,9 @@ public class ServiceState implements Parcelable { protected void copyFrom(ServiceState s) { mVoiceRegState = s.mVoiceRegState; mDataRegState = s.mDataRegState; - mVoiceOperatorAlphaLong = s.mVoiceOperatorAlphaLong; - mVoiceOperatorAlphaShort = s.mVoiceOperatorAlphaShort; - mVoiceOperatorNumeric = s.mVoiceOperatorNumeric; - mDataOperatorAlphaLong = s.mDataOperatorAlphaLong; - mDataOperatorAlphaShort = s.mDataOperatorAlphaShort; - mDataOperatorNumeric = s.mDataOperatorNumeric; + mOperatorAlphaLong = s.mOperatorAlphaLong; + mOperatorAlphaShort = s.mOperatorAlphaShort; + mOperatorNumeric = s.mOperatorNumeric; mIsManualNetworkSelection = s.mIsManualNetworkSelection; mCssIndicator = s.mCssIndicator; mNetworkId = s.mNetworkId; @@ -418,12 +412,9 @@ public class ServiceState implements Parcelable { public ServiceState(Parcel in) { mVoiceRegState = in.readInt(); mDataRegState = in.readInt(); - mVoiceOperatorAlphaLong = in.readString(); - mVoiceOperatorAlphaShort = in.readString(); - mVoiceOperatorNumeric = in.readString(); - mDataOperatorAlphaLong = in.readString(); - mDataOperatorAlphaShort = in.readString(); - mDataOperatorNumeric = in.readString(); + mOperatorAlphaLong = in.readString(); + mOperatorAlphaShort = in.readString(); + mOperatorNumeric = in.readString(); mIsManualNetworkSelection = in.readInt() != 0; mCssIndicator = (in.readInt() != 0); mNetworkId = in.readInt(); @@ -448,12 +439,9 @@ public class ServiceState implements Parcelable { public void writeToParcel(Parcel out, int flags) { out.writeInt(mVoiceRegState); out.writeInt(mDataRegState); - out.writeString(mVoiceOperatorAlphaLong); - out.writeString(mVoiceOperatorAlphaShort); - out.writeString(mVoiceOperatorNumeric); - out.writeString(mDataOperatorAlphaLong); - out.writeString(mDataOperatorAlphaShort); - out.writeString(mDataOperatorNumeric); + out.writeString(mOperatorAlphaLong); + out.writeString(mOperatorAlphaShort); + out.writeString(mOperatorNumeric); out.writeInt(mIsManualNetworkSelection ? 1 : 0); out.writeInt(mCssIndicator ? 1 : 0); out.writeInt(mNetworkId); @@ -691,7 +679,7 @@ public class ServiceState implements Parcelable { * @return long name of operator, null if unregistered or unknown */ public String getOperatorAlphaLong() { - return mVoiceOperatorAlphaLong; + return mOperatorAlphaLong; } /** @@ -699,18 +687,10 @@ public class ServiceState implements Parcelable { * @return long name of operator * @hide */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, + publicAlternatives = "Use {@link #getOperatorAlphaLong} instead.") public String getVoiceOperatorAlphaLong() { - return mVoiceOperatorAlphaLong; - } - - /** - * Get current registered data network operator name in long alphanumeric format. - * @return long name of voice operator - * @hide - */ - public String getDataOperatorAlphaLong() { - return mDataOperatorAlphaLong; + return mOperatorAlphaLong; } /** @@ -721,7 +701,7 @@ public class ServiceState implements Parcelable { * @return short name of operator, null if unregistered or unknown */ public String getOperatorAlphaShort() { - return mVoiceOperatorAlphaShort; + return mOperatorAlphaShort; } /** @@ -729,9 +709,10 @@ public class ServiceState implements Parcelable { * @return short name of operator, null if unregistered or unknown * @hide */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, + publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.") public String getVoiceOperatorAlphaShort() { - return mVoiceOperatorAlphaShort; + return mOperatorAlphaShort; } /** @@ -739,9 +720,10 @@ public class ServiceState implements Parcelable { * @return short name of operator, null if unregistered or unknown * @hide */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, + publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.") public String getDataOperatorAlphaShort() { - return mDataOperatorAlphaShort; + return mOperatorAlphaShort; } /** @@ -755,11 +737,11 @@ public class ServiceState implements Parcelable { * @hide */ public String getOperatorAlpha() { - if (TextUtils.isEmpty(mVoiceOperatorAlphaLong)) { - return mVoiceOperatorAlphaShort; + if (TextUtils.isEmpty(mOperatorAlphaLong)) { + return mOperatorAlphaShort; } - return mVoiceOperatorAlphaLong; + return mOperatorAlphaLong; } /** @@ -775,7 +757,7 @@ public class ServiceState implements Parcelable { * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}. */ public String getOperatorNumeric() { - return mVoiceOperatorNumeric; + return mOperatorNumeric; } /** @@ -785,7 +767,7 @@ public class ServiceState implements Parcelable { */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) public String getVoiceOperatorNumeric() { - return mVoiceOperatorNumeric; + return mOperatorNumeric; } /** @@ -793,9 +775,10 @@ public class ServiceState implements Parcelable { * @return numeric format of operator, null if unregistered or unknown * @hide */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, + publicAlternatives = "Use {@link #getOperatorNumeric} instead.") public String getDataOperatorNumeric() { - return mDataOperatorNumeric; + return mOperatorNumeric; } /** @@ -815,12 +798,9 @@ public class ServiceState implements Parcelable { mDataRegState, mChannelNumber, Arrays.hashCode(mCellBandwidths), - mVoiceOperatorAlphaLong, - mVoiceOperatorAlphaShort, - mVoiceOperatorNumeric, - mDataOperatorAlphaLong, - mDataOperatorAlphaShort, - mDataOperatorNumeric, + mOperatorAlphaLong, + mOperatorAlphaShort, + mOperatorNumeric, mIsManualNetworkSelection, mCssIndicator, mNetworkId, @@ -850,12 +830,9 @@ public class ServiceState implements Parcelable { && mIsManualNetworkSelection == s.mIsManualNetworkSelection && mChannelNumber == s.mChannelNumber && Arrays.equals(mCellBandwidths, s.mCellBandwidths) - && equalsHandlesNulls(mVoiceOperatorAlphaLong, s.mVoiceOperatorAlphaLong) - && equalsHandlesNulls(mVoiceOperatorAlphaShort, s.mVoiceOperatorAlphaShort) - && equalsHandlesNulls(mVoiceOperatorNumeric, s.mVoiceOperatorNumeric) - && equalsHandlesNulls(mDataOperatorAlphaLong, s.mDataOperatorAlphaLong) - && equalsHandlesNulls(mDataOperatorAlphaShort, s.mDataOperatorAlphaShort) - && equalsHandlesNulls(mDataOperatorNumeric, s.mDataOperatorNumeric) + && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong) + && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort) + && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric) && equalsHandlesNulls(mCssIndicator, s.mCssIndicator) && equalsHandlesNulls(mNetworkId, s.mNetworkId) && equalsHandlesNulls(mSystemId, s.mSystemId) @@ -1007,10 +984,8 @@ public class ServiceState implements Parcelable { .append(", mChannelNumber=").append(mChannelNumber) .append(", duplexMode()=").append(getDuplexMode()) .append(", mCellBandwidths=").append(Arrays.toString(mCellBandwidths)) - .append(", mVoiceOperatorAlphaLong=").append(mVoiceOperatorAlphaLong) - .append(", mVoiceOperatorAlphaShort=").append(mVoiceOperatorAlphaShort) - .append(", mDataOperatorAlphaLong=").append(mDataOperatorAlphaLong) - .append(", mDataOperatorAlphaShort=").append(mDataOperatorAlphaShort) + .append(", mOperatorAlphaLong=").append(mOperatorAlphaLong) + .append(", mOperatorAlphaShort=").append(mOperatorAlphaShort) .append(", isManualNetworkSelection=").append(mIsManualNetworkSelection) .append(mIsManualNetworkSelection ? "(manual)" : "(automatic)") .append(", getRilVoiceRadioTechnology=").append(getRilVoiceRadioTechnology()) @@ -1040,12 +1015,9 @@ public class ServiceState implements Parcelable { mDataRegState = STATE_OUT_OF_SERVICE; mChannelNumber = -1; mCellBandwidths = new int[0]; - mVoiceOperatorAlphaLong = null; - mVoiceOperatorAlphaShort = null; - mVoiceOperatorNumeric = null; - mDataOperatorAlphaLong = null; - mDataOperatorAlphaShort = null; - mDataOperatorNumeric = null; + mOperatorAlphaLong = null; + mOperatorAlphaShort = null; + mOperatorNumeric = null; mIsManualNetworkSelection = false; mCssIndicator = false; mNetworkId = -1; @@ -1204,26 +1176,9 @@ public class ServiceState implements Parcelable { } public void setOperatorName(String longName, String shortName, String numeric) { - mVoiceOperatorAlphaLong = longName; - mVoiceOperatorAlphaShort = shortName; - mVoiceOperatorNumeric = numeric; - mDataOperatorAlphaLong = longName; - mDataOperatorAlphaShort = shortName; - mDataOperatorNumeric = numeric; - } - - /** @hide */ - public void setVoiceOperatorName(String longName, String shortName, String numeric) { - mVoiceOperatorAlphaLong = longName; - mVoiceOperatorAlphaShort = shortName; - mVoiceOperatorNumeric = numeric; - } - - /** @hide */ - public void setDataOperatorName(String longName, String shortName, String numeric) { - mDataOperatorAlphaLong = longName; - mDataOperatorAlphaShort = shortName; - mDataOperatorNumeric = numeric; + mOperatorAlphaLong = longName; + mOperatorAlphaShort = shortName; + mOperatorNumeric = numeric; } /** @@ -1233,19 +1188,8 @@ public class ServiceState implements Parcelable { * @hide */ @UnsupportedAppUsage - public void setOperatorAlphaLong(String longName) { - mVoiceOperatorAlphaLong = longName; - mDataOperatorAlphaLong = longName; - } - - /** @hide */ - public void setVoiceOperatorAlphaLong(String longName) { - mVoiceOperatorAlphaLong = longName; - } - - /** @hide */ - public void setDataOperatorAlphaLong(String longName) { - mDataOperatorAlphaLong = longName; + public void setOperatorAlphaLong(@Nullable String longName) { + mOperatorAlphaLong = longName; } public void setIsManualSelection(boolean isManual) { @@ -1293,12 +1237,12 @@ public class ServiceState implements Parcelable { m.putInt("dataRegState", mDataRegState); m.putInt("dataRoamingType", getDataRoamingType()); m.putInt("voiceRoamingType", getVoiceRoamingType()); - m.putString("operator-alpha-long", mVoiceOperatorAlphaLong); - m.putString("operator-alpha-short", mVoiceOperatorAlphaShort); - m.putString("operator-numeric", mVoiceOperatorNumeric); - m.putString("data-operator-alpha-long", mDataOperatorAlphaLong); - m.putString("data-operator-alpha-short", mDataOperatorAlphaShort); - m.putString("data-operator-numeric", mDataOperatorNumeric); + m.putString("operator-alpha-long", mOperatorAlphaLong); + m.putString("operator-alpha-short", mOperatorAlphaShort); + m.putString("operator-numeric", mOperatorNumeric); + m.putString("data-operator-alpha-long", mOperatorAlphaLong); + m.putString("data-operator-alpha-short", mOperatorAlphaShort); + m.putString("data-operator-numeric", mOperatorNumeric); m.putBoolean("manual", mIsManualNetworkSelection); m.putInt("radioTechnology", getRilVoiceRadioTechnology()); m.putInt("dataRadioTechnology", getRadioTechnology()); @@ -1933,12 +1877,9 @@ public class ServiceState implements Parcelable { } if (!removeCoarseLocation) return state; - state.mDataOperatorAlphaLong = null; - state.mDataOperatorAlphaShort = null; - state.mDataOperatorNumeric = null; - state.mVoiceOperatorAlphaLong = null; - state.mVoiceOperatorAlphaShort = null; - state.mVoiceOperatorNumeric = null; + state.mOperatorAlphaLong = null; + state.mOperatorAlphaShort = null; + state.mOperatorNumeric = null; return state; } diff --git a/telephony/java/android/telephony/SmsCbMessage.java b/telephony/java/android/telephony/SmsCbMessage.java index c7f952954d5f..045d1ebb5640 100644 --- a/telephony/java/android/telephony/SmsCbMessage.java +++ b/telephony/java/android/telephony/SmsCbMessage.java @@ -533,7 +533,8 @@ public final class SmsCbMessage implements Parcelable { + ", priority=" + mPriority + (mEtwsWarningInfo != null ? (", " + mEtwsWarningInfo.toString()) : "") + (mCmasWarningInfo != null ? (", " + mCmasWarningInfo.toString()) : "") - + ", maximumWaitingTime = " + mMaximumWaitTimeSec + + ", maximumWaitingTime=" + mMaximumWaitTimeSec + + ", received time=" + mReceivedTimeMillis + ", slotIndex = " + mSlotIndex + ", geo=" + (mGeometries != null ? CbGeoUtils.encodeGeometriesToString(mGeometries) : "null") diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index daeacf8206b4..5b49117be532 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -32,6 +32,7 @@ import android.content.pm.PackageManager; import android.database.CursorWindow; import android.net.Uri; import android.os.Binder; +import android.os.BaseBundle; import android.os.Build; import android.os.Bundle; import android.os.RemoteException; @@ -79,11 +80,6 @@ public final class SmsManager { SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); private static final Object sLockObject = new Object(); - /** @hide */ - public static final int CELL_BROADCAST_RAN_TYPE_GSM = 0; - /** @hide */ - public static final int CELL_BROADCAST_RAN_TYPE_CDMA = 1; - /** SMS record length from TS 51.011 10.5.3 * @hide */ @@ -2457,7 +2453,9 @@ public final class SmsManager { } } - /** callback for providing asynchronous sms messages for financial app. */ + /** + * callback for providing asynchronous sms messages for financial app. + */ public abstract static class FinancialSmsCallback { /** * Callback to send sms messages back to financial app asynchronously. @@ -2483,24 +2481,14 @@ public final class SmsManager { * @param params the parameters to filter SMS messages returned. * @param executor the executor on which callback will be invoked. * @param callback a callback to receive CursorWindow with SMS messages. + * */ @RequiresPermission(android.Manifest.permission.SMS_FINANCIAL_TRANSACTIONS) public void getSmsMessagesForFinancialApp( Bundle params, @NonNull @CallbackExecutor Executor executor, @NonNull FinancialSmsCallback callback) { - try { - ISms iccSms = getISmsServiceOrThrow(); - iccSms.getSmsMessagesForFinancialApp( - getSubscriptionId(), ActivityThread.currentPackageName(), params, - new IFinancialSmsCallback.Stub() { - public void onGetSmsMessagesForFinancialApp(CursorWindow msgs) { - Binder.withCleanCallingIdentity(() -> executor.execute( - () -> callback.onFinancialSmsMessages(msgs))); - }}); - } catch (RemoteException ex) { - ex.rethrowFromSystemServer(); - } + // This API is not functional and thus removed to avoid future confusion. } /** diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index 9eff809eaf5d..ebb517596b6c 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -89,8 +89,8 @@ public class SubscriptionInfo implements Parcelable { private int mCarrierId; /** - * The source of the name, NAME_SOURCE_DEFAULT_SOURCE, NAME_SOURCE_SIM_SOURCE or - * NAME_SOURCE_USER_INPUT. + * The source of the name, NAME_SOURCE_DEFAULT_SOURCE, NAME_SOURCE_SIM_SPN, + * NAME_SOURCE_SIM_PNN, or NAME_SOURCE_USER_INPUT. */ private int mNameSource; @@ -334,7 +334,7 @@ public class SubscriptionInfo implements Parcelable { } /** - * @return the source of the name, eg NAME_SOURCE_DEFAULT_SOURCE, NAME_SOURCE_SIM_SOURCE or + * @return the source of the name, eg NAME_SOURCE_DEFAULT_SOURCE, NAME_SOURCE_SIM_SPN or * NAME_SOURCE_USER_INPUT. * @hide */ diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index fbbc9518065d..4f908408506b 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -35,7 +35,6 @@ import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; import android.app.BroadcastOptions; import android.app.PendingIntent; -import android.app.job.JobService; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; @@ -148,10 +147,11 @@ public class SubscriptionManager { * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * subscription wfc enabled {@link ImsMmTelManager#isVoWiFiSettingEnabled()} - * while your app is running. You can also use a {@link JobService} to ensure your app + * while your app is running. You can also use a {@link android.app.job.JobService} + * to ensure your app * is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee timely + * delivery of updates to the {@link Uri}. * To be notified of changes to a specific subId, append subId to the URI * {@link Uri#withAppendedPath(Uri, String)}. * @hide @@ -168,10 +168,10 @@ public class SubscriptionManager { * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * subscription advanced calling enabled * {@link ImsMmTelManager#isAdvancedCallingSettingEnabled()} while your app is running. - * You can also use a {@link JobService} to ensure your app is notified of changes to the - * {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * You can also use a {@link android.app.job.JobService} to ensure your app is notified of + * changes to the {@link Uri} even when it is not running. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee timely + * delivery of updates to the {@link Uri}. * To be notified of changes to a specific subId, append subId to the URI * {@link Uri#withAppendedPath(Uri, String)}. * @hide @@ -187,10 +187,10 @@ public class SubscriptionManager { * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * subscription wfc mode {@link ImsMmTelManager#getVoWiFiModeSetting()} - * while your app is running. You can also use a {@link JobService} to ensure your app - * is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * while your app is running. You can also use a {@link android.app.job.JobService} to ensure + * your app is notified of changes to the {@link Uri} even when it is not running. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee timely + * delivery of updates to the {@link Uri}. * To be notified of changes to a specific subId, append subId to the URI * {@link Uri#withAppendedPath(Uri, String)}. * @hide @@ -205,10 +205,10 @@ public class SubscriptionManager { * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * subscription wfc roaming mode {@link ImsMmTelManager#getVoWiFiRoamingModeSetting()} - * while your app is running. You can also use a {@link JobService} to ensure your app - * is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * while your app is running. You can also use a {@link android.app.job.JobService} + * to ensure your app is notified of changes to the {@link Uri} even when it is not running. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee timely + * delivery of updates to the {@link Uri}. * To be notified of changes to a specific subId, append subId to the URI * {@link Uri#withAppendedPath(Uri, String)}. * @hide @@ -225,10 +225,10 @@ public class SubscriptionManager { * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * subscription vt enabled {@link ImsMmTelManager#isVtSettingEnabled()} - * while your app is running. You can also use a {@link JobService} to ensure your app - * is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * while your app is running. You can also use a {@link android.app.job.JobService} to ensure + * your app is notified of changes to the {@link Uri} even when it is not running. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee timely + * delivery of updates to the {@link Uri}. * To be notified of changes to a specific subId, append subId to the URI * {@link Uri#withAppendedPath(Uri, String)}. * @hide @@ -244,10 +244,10 @@ public class SubscriptionManager { * <p> * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the * subscription wfc roaming enabled {@link ImsMmTelManager#isVoWiFiRoamingSettingEnabled()} - * while your app is running. You can also use a {@link JobService} to ensure your app - * is notified of changes to the {@link Uri} even when it is not running. - * Note, however, that using a {@link JobService} does not guarantee timely delivery of - * updates to the {@link Uri}. + * while your app is running. You can also use a {@link android.app.job.JobService} to ensure + * your app is notified of changes to the {@link Uri} even when it is not running. + * Note, however, that using a {@link android.app.job.JobService} does not guarantee timely + * delivery of updates to the {@link Uri}. * To be notified of changes to a specific subId, append subId to the URI * {@link Uri#withAppendedPath(Uri, String)}. * @hide @@ -400,19 +400,19 @@ public class SubscriptionManager { public static final String NAME_SOURCE = "name_source"; /** - * The name_source is the default + * The name_source is the default, which is from the carrier id. * @hide */ public static final int NAME_SOURCE_DEFAULT_SOURCE = 0; /** - * The name_source is from the SIM + * The name_source is from SIM EF_SPN. * @hide */ - public static final int NAME_SOURCE_SIM_SOURCE = 1; + public static final int NAME_SOURCE_SIM_SPN = 1; /** - * The name_source is from the user + * The name_source is from user input * @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @@ -425,6 +425,24 @@ public class SubscriptionManager { public static final int NAME_SOURCE_CARRIER = 3; /** + * The name_source is from SIM EF_PNN. + * @hide + */ + public static final int NAME_SOURCE_SIM_PNN = 4; + + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = {"NAME_SOURCE_"}, + value = { + NAME_SOURCE_DEFAULT_SOURCE, + NAME_SOURCE_SIM_SPN, + NAME_SOURCE_USER_INPUT, + NAME_SOURCE_CARRIER, + NAME_SOURCE_SIM_PNN + }) + public @interface SimDisplayNameSource {} + + /** * TelephonyProvider column name for the color of a SIM. * <P>Type: INTEGER (int)</P> */ @@ -1660,13 +1678,12 @@ public class SubscriptionManager { * Set display name by simInfo index with name source * @param displayName the display name of SIM card * @param subId the unique SubscriptionInfo index in database - * @param nameSource 0: NAME_SOURCE_DEFAULT_SOURCE, 1: NAME_SOURCE_SIM_SOURCE, - * 2: NAME_SOURCE_USER_INPUT + * @param nameSource SIM display name source * @return the number of records updated or < 0 if invalid subId * @hide */ @UnsupportedAppUsage - public int setDisplayName(String displayName, int subId, int nameSource) { + public int setDisplayName(String displayName, int subId, @SimDisplayNameSource int nameSource) { if (VDBG) { logd("[setDisplayName]+ displayName:" + displayName + " subId:" + subId + " nameSource:" + nameSource); @@ -2897,8 +2914,7 @@ public class SubscriptionManager { * * @throws SecurityException if the caller doesn't meet the requirements * outlined above. - * @throws IllegalArgumentException if the some subscriptions in the list doesn't exist, - * or the groupUuid doesn't exist. + * @throws IllegalArgumentException if the some subscriptions in the list doesn't exist. * @throws IllegalStateException if Telephony service is in bad state. * * @param subIdList list of subId that need adding into the group diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 4fb26fdf1d2c..7232ea714180 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -416,14 +416,14 @@ public class TelephonyManager { int modemCount = 1; switch (getMultiSimConfiguration()) { case UNKNOWN: - ConnectivityManager cm = mContext == null ? null : (ConnectivityManager) mContext - .getSystemService(Context.CONNECTIVITY_SERVICE); + modemCount = MODEM_COUNT_SINGLE_MODEM; // check for voice and data support, 0 if not supported - if (!isVoiceCapable() && !isSmsCapable() && cm != null - && !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { - modemCount = MODEM_COUNT_NO_MODEM; - } else { - modemCount = MODEM_COUNT_SINGLE_MODEM; + if (!isVoiceCapable() && !isSmsCapable() && mContext != null) { + ConnectivityManager cm = (ConnectivityManager) mContext + .getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm != null && !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { + modemCount = MODEM_COUNT_NO_MODEM; + } } break; case DSDS: @@ -592,6 +592,7 @@ public class TelephonyManager { * * @hide */ + @SystemApi @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) public static final String ACTION_EMERGENCY_ASSISTANCE = "android.telephony.action.EMERGENCY_ASSISTANCE"; @@ -2366,6 +2367,8 @@ public class TelephonyManager { * * @return the lowercase 2 character ISO-3166 country code, or empty string if not available. * + * @throws IllegalArgumentException when the slotIndex is invalid. + * * {@hide} */ @SystemApi @@ -2373,6 +2376,10 @@ public class TelephonyManager { @NonNull public String getNetworkCountryIso(int slotIndex) { try { + if (!SubscriptionManager.isValidSlotIndex(slotIndex)) { + throw new IllegalArgumentException("invalid slot index " + slotIndex); + } + ITelephony telephony = getITelephony(); if (telephony == null) return ""; return telephony.getNetworkCountryIsoForPhone(slotIndex); diff --git a/telephony/java/com/android/internal/telephony/ISms.aidl b/telephony/java/com/android/internal/telephony/ISms.aidl index c1d700a2d190..91aa3ce62cf2 100644 --- a/telephony/java/com/android/internal/telephony/ISms.aidl +++ b/telephony/java/com/android/internal/telephony/ISms.aidl @@ -19,7 +19,6 @@ package com.android.internal.telephony; import android.app.PendingIntent; import android.net.Uri; import android.os.Bundle; -import android.telephony.IFinancialSmsCallback; import com.android.internal.telephony.SmsRawData; /** @@ -570,17 +569,6 @@ interface ISms { int subId, String callingPkg, String prefixes, in PendingIntent intent); /** - * Get sms inbox messages for the calling financial app. - * - * @param subId the SIM id. - * @param callingPkg the package name of the calling app. - * @param params parameters to filter the sms messages. - * @param callback the callback interface to deliver the result. - */ - void getSmsMessagesForFinancialApp( - int subId, String callingPkg, in Bundle params, in IFinancialSmsCallback callback); - - /** * Check if the destination is a possible premium short code. * * @param destAddress the destination address to test for possible short code diff --git a/telephony/java/com/android/internal/telephony/ISmsImplBase.java b/telephony/java/com/android/internal/telephony/ISmsImplBase.java index ff816f24667e..d9d4b6002206 100644 --- a/telephony/java/com/android/internal/telephony/ISmsImplBase.java +++ b/telephony/java/com/android/internal/telephony/ISmsImplBase.java @@ -19,7 +19,6 @@ package com.android.internal.telephony; import android.app.PendingIntent; import android.net.Uri; import android.os.Bundle; -import android.telephony.IFinancialSmsCallback; import java.util.List; @@ -198,12 +197,6 @@ public class ISmsImplBase extends ISms.Stub { } @Override - public void getSmsMessagesForFinancialApp( - int subId, String callingPkg, Bundle params, IFinancialSmsCallback callback) { - throw new UnsupportedOperationException(); - } - - @Override public int checkSmsShortCodeDestination( int subid, String callingApk, String destAddress, String countryIso) { throw new UnsupportedOperationException(); diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java index 03ea9208d064..4421c77dbbb1 100644 --- a/telephony/java/com/android/internal/telephony/RILConstants.java +++ b/telephony/java/com/android/internal/telephony/RILConstants.java @@ -485,6 +485,8 @@ public interface RILConstants { int RIL_REQUEST_EMERGENCY_DIAL = 205; int RIL_REQUEST_GET_PHONE_CAPABILITY = 206; int RIL_REQUEST_SWITCH_DUAL_SIM_CONFIG = 207; + int RIL_REQUEST_ENABLE_UICC_APPLICATIONS = 208; + int RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT = 209; /* Responses begin */ int RIL_RESPONSE_ACKNOWLEDGEMENT = 800; @@ -548,4 +550,5 @@ public interface RILConstants { int RIL_UNSOL_ICC_SLOT_STATUS = 1100; int RIL_UNSOL_PHYSICAL_CHANNEL_CONFIG = 1101; int RIL_UNSOL_EMERGENCY_NUMBER_LIST = 1102; + int RIL_UNSOL_UICC_APPLICATIONS_ENABLEMENT_CHANGED = 1103; } diff --git a/telephony/java/com/android/internal/telephony/Sms7BitEncodingTranslator.java b/telephony/java/com/android/internal/telephony/Sms7BitEncodingTranslator.java index 2cdf2f63e02f..dcea9bb72c01 100644 --- a/telephony/java/com/android/internal/telephony/Sms7BitEncodingTranslator.java +++ b/telephony/java/com/android/internal/telephony/Sms7BitEncodingTranslator.java @@ -23,7 +23,7 @@ import android.telephony.Rlog; import android.util.SparseIntArray; import com.android.internal.telephony.cdma.sms.UserData; -import com.android.internal.util.XmlUtils; +import com.android.internal.telephony.util.XmlUtils; import dalvik.annotation.compat.UnsupportedAppUsage; diff --git a/telephony/java/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/java/com/android/internal/telephony/util/TelephonyUtils.java new file mode 100644 index 000000000000..a28d65c9abb6 --- /dev/null +++ b/telephony/java/com/android/internal/telephony/util/TelephonyUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2019 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.internal.telephony.util; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.Context; +import android.content.pm.ComponentInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.Binder; +import android.os.RemoteException; +import android.os.SystemProperties; + +import java.io.PrintWriter; + +/** + * This class provides various util functions + */ +public final class TelephonyUtils { + public static boolean IS_USER = "user".equals(android.os.Build.TYPE); + public static boolean IS_DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1; + + /** + * Verify that caller holds {@link android.Manifest.permission#DUMP}. + * + * @return true if access should be granted. + */ + public static boolean checkDumpPermission(Context context, String tag, PrintWriter pw) { + if (context.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) + != PackageManager.PERMISSION_GRANTED) { + pw.println("Permission Denial: can't dump " + tag + " from from pid=" + + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + + " due to missing android.permission.DUMP permission"); + return false; + } else { + return true; + } + } + + /** Returns an empty string if the input is {@code null}. */ + public static String emptyIfNull(@Nullable String str) { + return str == null ? "" : str; + } + + /** Throws a {@link RuntimeException} that wrapps the {@link RemoteException}. */ + public static RuntimeException rethrowAsRuntimeException(RemoteException remoteException) { + throw new RuntimeException(remoteException); + } + + /** + * Returns a {@link ComponentInfo} from the {@link ResolveInfo}, + * or throws an {@link IllegalStateException} if not available. + */ + public static ComponentInfo getComponentInfo(@NonNull ResolveInfo resolveInfo) { + if (resolveInfo.activityInfo != null) return resolveInfo.activityInfo; + if (resolveInfo.serviceInfo != null) return resolveInfo.serviceInfo; + if (resolveInfo.providerInfo != null) return resolveInfo.providerInfo; + throw new IllegalStateException("Missing ComponentInfo!"); + } +} diff --git a/telephony/java/com/android/internal/telephony/util/XmlUtils.java b/telephony/java/com/android/internal/telephony/util/XmlUtils.java new file mode 100644 index 000000000000..72c5d3a8e31b --- /dev/null +++ b/telephony/java/com/android/internal/telephony/util/XmlUtils.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2019 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.internal.telephony.util; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; + +/** Utility methods for XML operations. */ +public final class XmlUtils { + private XmlUtils() {} + + /** + * Moves parser to the first start tag, and expects the tag name being {@code firstElementName}. + */ + public static void beginDocument(XmlPullParser parser, String firstElementName) + throws XmlPullParserException, IOException { + int type; + while ((type = parser.next()) != parser.START_TAG && type != parser.END_DOCUMENT) { + // no-op + } + + if (type != parser.START_TAG) { + throw new XmlPullParserException("No start tag found"); + } + + if (!parser.getName().equals(firstElementName)) { + throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() + + ", expected " + firstElementName); + } + } + + /** + * Moves parser to the next start tag. + */ + public static void nextElement(XmlPullParser parser) + throws XmlPullParserException, IOException { + int type; + while ((type = parser.next()) != parser.START_TAG && type != parser.END_DOCUMENT) { + // no-op + } + } + + /** + * Moves parser to the next start tag within the {@code outerDepth}. + */ + public static boolean nextElementWithin(XmlPullParser parser, int outerDepth) + throws IOException, XmlPullParserException { + for (;;) { + int type = parser.next(); + if (type == XmlPullParser.END_DOCUMENT + || (type == XmlPullParser.END_TAG && parser.getDepth() == outerDepth)) { + return false; + } + if (type == XmlPullParser.START_TAG && parser.getDepth() == outerDepth + 1) { + return true; + } + } + } +} |