diff options
41 files changed, 132 insertions, 515 deletions
diff --git a/Android.bp b/Android.bp index 891ee91f7ed9..543e65601517 100644 --- a/Android.bp +++ b/Android.bp @@ -865,28 +865,6 @@ python_binary_host { ], } -// TODO: Don't rely on this list by switching package.html into package-info.java -frameworks_base_subdirs = [ - "core/java", - "graphics/java", - "location/java", - "media/java", - "media/mca/effect/java", - "media/mca/filterfw/java", - "media/mca/filterpacks/java", - "drm/java", - "mms/java", - "opengl/java", - "sax/java", - "telecomm/java", - "telephony/common", - "telephony/java", - "wifi/java", - "lowpan/java", - "keystore/java", - "rs/java", -] - // Make the api/current.txt file available for use by modules in other // directories. filegroup { @@ -998,7 +976,6 @@ stubs_defaults { "test-runner/src/**/*.java", ], libs: framework_docs_only_libs, - local_sourcepaths: frameworks_base_subdirs, create_doc_stubs: true, annotations_enabled: true, api_levels_annotations_enabled: true, @@ -1059,7 +1036,6 @@ stubs_defaults { ":updatable-media-srcs", ], libs: ["framework-internal-utils"], - local_sourcepaths: frameworks_base_subdirs, installable: false, annotations_enabled: true, previous_api: ":last-released-public-api", diff --git a/api/current.txt b/api/current.txt index 1a87b2257d27..19fd711f1f44 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4244,8 +4244,8 @@ package android.app { method public android.app.AlertDialog show(); } - public class AliasActivity extends android.app.Activity { - ctor public AliasActivity(); + @Deprecated public class AliasActivity extends android.app.Activity { + ctor @Deprecated public AliasActivity(); } public class AppComponentFactory { @@ -8357,6 +8357,7 @@ package android.bluetooth { method public int describeContents(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean fetchUuidsWithSdp(); method public String getAddress(); + method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH) public String getAlias(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public android.bluetooth.BluetoothClass getBluetoothClass(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getBondState(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public String getName(); @@ -8368,6 +8369,7 @@ package android.bluetooth { field public static final String ACTION_ACL_CONNECTED = "android.bluetooth.device.action.ACL_CONNECTED"; field public static final String ACTION_ACL_DISCONNECTED = "android.bluetooth.device.action.ACL_DISCONNECTED"; field public static final String ACTION_ACL_DISCONNECT_REQUESTED = "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"; + field public static final String ACTION_ALIAS_CHANGED = "android.bluetooth.action.ALIAS_CHANGED"; field public static final String ACTION_BOND_STATE_CHANGED = "android.bluetooth.device.action.BOND_STATE_CHANGED"; field public static final String ACTION_CLASS_CHANGED = "android.bluetooth.device.action.CLASS_CHANGED"; field public static final String ACTION_FOUND = "android.bluetooth.device.action.FOUND"; diff --git a/api/system-current.txt b/api/system-current.txt index 6ce444e4bec7..2a8fb6341da3 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -1264,6 +1264,7 @@ package android.bluetooth { method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean isEncrypted(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean isInSilenceMode(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean removeBond(); + method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setAlias(@NonNull String); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setMetadata(int, @NonNull byte[]); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setPhonebookAccessPermission(int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setSilenceMode(boolean); @@ -4704,6 +4705,7 @@ package android.net.wifi { method public boolean isPortableHotspotSupported(); method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public boolean isWifiApEnabled(); method public boolean isWifiScannerSupported(); + method @RequiresPermission("android.permission.NETWORK_SETTINGS") public void registerSoftApCallback(@NonNull android.net.wifi.WifiManager.SoftApCallback, @Nullable java.util.concurrent.Executor); method @RequiresPermission("android.permission.WIFI_UPDATE_USABILITY_STATS_SCORE") public void removeOnWifiUsabilityStatsListener(@NonNull android.net.wifi.WifiManager.OnWifiUsabilityStatsListener); method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void save(@NonNull android.net.wifi.WifiConfiguration, @Nullable android.net.wifi.WifiManager.ActionListener); method @RequiresPermission("android.permission.WIFI_SET_DEVICE_MOBILITY_STATE") public void setDeviceMobilityState(int); @@ -4762,6 +4764,11 @@ package android.net.wifi { method public void onWifiUsabilityStats(int, boolean, @NonNull android.net.wifi.WifiUsabilityStatsEntry); } + public static interface WifiManager.SoftApCallback { + method public void onConnectedClientsChanged(@NonNull java.util.List<android.net.wifi.WifiClient>); + method public void onStateChanged(int, int); + } + public class WifiNetworkConnectionStatistics implements android.os.Parcelable { ctor public WifiNetworkConnectionStatistics(int, int); ctor public WifiNetworkConnectionStatistics(); diff --git a/core/java/android/app/AliasActivity.java b/core/java/android/app/AliasActivity.java index 37565298c8cb..37be90160d9a 100644 --- a/core/java/android/app/AliasActivity.java +++ b/core/java/android/app/AliasActivity.java @@ -39,7 +39,10 @@ import java.io.IOException; * To use this activity, you should include in the manifest for the associated * component an entry named "android.app.alias". It is a reference to an XML * resource describing an intent that launches the real application. + * + * @deprecated Use {@code <activity-alias>} or subclass Activity directly. */ +@Deprecated public class AliasActivity extends Activity { /** * This is the name under which you should store in your component the diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 646f0dc71b15..46a128a2cd01 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -173,8 +173,6 @@ import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.euicc.EuiccCardManager; import android.telephony.euicc.EuiccManager; -import android.telephony.ims.ImsManager; -import android.telephony.ims.RcsMessageManager; import android.util.ArrayMap; import android.util.Log; import android.view.ContextThemeWrapper; @@ -623,22 +621,6 @@ final class SystemServiceRegistry { return new SubscriptionManager(ctx.getOuterContext()); }}); - registerService(Context.TELEPHONY_RCS_MESSAGE_SERVICE, RcsMessageManager.class, - new CachedServiceFetcher<RcsMessageManager>() { - @Override - public RcsMessageManager createService(ContextImpl ctx) { - return new RcsMessageManager(ctx.getOuterContext()); - } - }); - - registerService(Context.TELEPHONY_IMS_SERVICE, ImsManager.class, - new CachedServiceFetcher<ImsManager>() { - @Override - public ImsManager createService(ContextImpl ctx) { - return new ImsManager(ctx.getOuterContext()); - } - }); - registerService(Context.CARRIER_CONFIG_SERVICE, CarrierConfigManager.class, new CachedServiceFetcher<CarrierConfigManager>() { @Override diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index c6160446c798..19f42b6a4c9e 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -173,13 +173,10 @@ public final class BluetoothDevice implements Parcelable { * changed. * <p>Always contains the extra field {@link #EXTRA_DEVICE}. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. - * - * @hide */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) - @UnsupportedAppUsage public static final String ACTION_ALIAS_CHANGED = - "android.bluetooth.device.action.ALIAS_CHANGED"; + "android.bluetooth.action.ALIAS_CHANGED"; /** * Broadcast Action: Indicates a change in the bond state of a remote @@ -1048,10 +1045,11 @@ public final class BluetoothDevice implements Parcelable { * Get the Bluetooth alias of the remote device. * <p>Alias is the locally modified name of a remote device. * - * @return the Bluetooth alias, or null if no alias or there was a problem - * @hide + * @return the Bluetooth alias, the friendly device name if no alias, or + * null if there was a problem */ - @UnsupportedAppUsage(publicAlternatives = "Use {@link #getName()} instead.") + @Nullable + @RequiresPermission(Manifest.permission.BLUETOOTH) public String getAlias() { final IBluetooth service = sService; if (service == null) { @@ -1059,7 +1057,11 @@ public final class BluetoothDevice implements Parcelable { return null; } try { - return service.getRemoteAlias(this); + String alias = service.getRemoteAlias(this); + if (alias == null) { + return getName(); + } + return alias; } catch (RemoteException e) { Log.e(TAG, "", e); } @@ -1076,8 +1078,9 @@ public final class BluetoothDevice implements Parcelable { * @return true on success, false on error * @hide */ - @UnsupportedAppUsage - public boolean setAlias(String alias) { + @SystemApi + @RequiresPermission(Manifest.permission.BLUETOOTH) + public boolean setAlias(@NonNull String alias) { final IBluetooth service = sService; if (service == null) { Log.e(TAG, "BT not enabled. Cannot set Remote Device name"); diff --git a/core/java/android/companion/BluetoothDeviceFilterUtils.java b/core/java/android/companion/BluetoothDeviceFilterUtils.java index 75e726bfad0d..0f67f6b50251 100644 --- a/core/java/android/companion/BluetoothDeviceFilterUtils.java +++ b/core/java/android/companion/BluetoothDeviceFilterUtils.java @@ -129,7 +129,7 @@ public class BluetoothDeviceFilterUtils { @UnsupportedAppUsage public static String getDeviceDisplayNameInternal(@NonNull BluetoothDevice device) { - return firstNotEmpty(device.getAliasName(), device.getAddress()); + return firstNotEmpty(device.getAlias(), device.getAddress()); } @UnsupportedAppUsage diff --git a/core/java/android/net/util/MultinetworkPolicyTracker.java b/core/java/android/net/util/MultinetworkPolicyTracker.java index 4e88149b8095..aa0f6220036c 100644 --- a/core/java/android/net/util/MultinetworkPolicyTracker.java +++ b/core/java/android/net/util/MultinetworkPolicyTracker.java @@ -94,7 +94,8 @@ public class MultinetworkPolicyTracker { } }; - TelephonyManager.from(ctx).listen(new PhoneStateListener(handler.getLooper()) { + ctx.getSystemService(TelephonyManager.class).listen( + new PhoneStateListener(handler.getLooper()) { @Override public void onActiveDataSubscriptionIdChanged(int subId) { mActiveSubId = subId; diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 9c9829fb08e2..c15618bdaa78 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -1295,8 +1295,11 @@ public class UserManager { mContext.getContentResolver(), Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0; boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); - boolean inCall = TelephonyManager.getDefault().getCallState() - != TelephonyManager.CALL_STATE_IDLE; + boolean inCall = false; + TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class); + if (telephonyManager != null) { + inCall = telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE; + } boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH); return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall && !isUserSwitchDisallowed; diff --git a/core/java/com/android/internal/app/LocaleStore.java b/core/java/com/android/internal/app/LocaleStore.java index c11089ba19bd..49f77e11cf80 100644 --- a/core/java/com/android/internal/app/LocaleStore.java +++ b/core/java/com/android/internal/app/LocaleStore.java @@ -194,7 +194,7 @@ public class LocaleStore { private static Set<String> getSimCountries(Context context) { Set<String> result = new HashSet<>(); - TelephonyManager tm = TelephonyManager.from(context); + TelephonyManager tm = context.getSystemService(TelephonyManager.class); if (tm != null) { String iso = tm.getSimCountryIso().toUpperCase(Locale.US); diff --git a/core/java/com/android/internal/package-info.java b/core/java/com/android/internal/package-info.java new file mode 100644 index 000000000000..8a226dbdc9fe --- /dev/null +++ b/core/java/com/android/internal/package-info.java @@ -0,0 +1,4 @@ +/** + * @hide + */ +package com.android.internal; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 1f20d7afb983..b8c6cf64f9db 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -142,7 +142,7 @@ <protected-broadcast android:name="android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED" /> <protected-broadcast android:name="android.bluetooth.device.action.UUID" /> <protected-broadcast android:name="android.bluetooth.device.action.MAS_INSTANCE" /> - <protected-broadcast android:name="android.bluetooth.device.action.ALIAS_CHANGED" /> + <protected-broadcast android:name="android.bluetooth.action.ALIAS_CHANGED" /> <protected-broadcast android:name="android.bluetooth.device.action.FOUND" /> <protected-broadcast android:name="android.bluetooth.device.action.CLASS_CHANGED" /> <protected-broadcast android:name="android.bluetooth.device.action.ACL_CONNECTED" /> diff --git a/media/java/android/media/tv/OWNER b/media/java/android/media/tv/OWNERS index 64c0bb53e894..64c0bb53e894 100644 --- a/media/java/android/media/tv/OWNER +++ b/media/java/android/media/tv/OWNERS diff --git a/packages/SettingsLib/src/com/android/settingslib/DeviceInfoUtils.java b/packages/SettingsLib/src/com/android/settingslib/DeviceInfoUtils.java index bc5a2c05e379..69bd0ed0c59c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/DeviceInfoUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/DeviceInfoUtils.java @@ -29,6 +29,8 @@ import android.system.StructUtsname; import android.telephony.PhoneNumberUtils; import android.telephony.SubscriptionInfo; import android.telephony.TelephonyManager; +import android.text.BidiFormatter; +import android.text.TextDirectionHeuristics; import android.text.TextUtils; import android.text.format.DateFormat; import android.util.Log; @@ -206,4 +208,15 @@ public class DeviceInfoUtils { return sb.toString(); } + /** + * To get the formatting text for display in a potentially opposite-directionality context + * without garbling. + * @param subscriptionInfo {@link SubscriptionInfo} subscription information. + * @return Returns phone number with Bidi format. + */ + public static String getBidiFormattedPhoneNumber(Context context, + SubscriptionInfo subscriptionInfo) { + final String phoneNumber = getFormattedPhoneNumber(context, subscriptionInfo); + return BidiFormatter.getInstance().unicodeWrap(phoneNumber, TextDirectionHeuristics.LTR); + } } diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 9a95288a69ae..ec5bc96f574c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -363,12 +363,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> /** * Get name from remote device - * @return {@link BluetoothDevice#getAliasName()} if - * {@link BluetoothDevice#getAliasName()} is not null otherwise return + * @return {@link BluetoothDevice#getAlias()} if + * {@link BluetoothDevice#getAlias()} is not null otherwise return * {@link BluetoothDevice#getAddress()} */ public String getName() { - final String aliasName = mDevice.getAliasName(); + final String aliasName = mDevice.getAlias(); return TextUtils.isEmpty(aliasName) ? getAddress() : aliasName; } @@ -426,7 +426,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> * @return true if device's alias name is not null nor empty, false otherwise */ public boolean hasHumanReadableName() { - return !TextUtils.isEmpty(mDevice.getAliasName()); + return !TextUtils.isEmpty(mDevice.getAlias()); } /** @@ -573,7 +573,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } if (BluetoothUtils.D) { - Log.e(TAG, "updating profiles for " + mDevice.getAliasName() + ", " + mDevice); + Log.e(TAG, "updating profiles for " + mDevice.getAlias() + ", " + mDevice); BluetoothClass bluetoothClass = mDevice.getBluetoothClass(); if (bluetoothClass != null) Log.v(TAG, "Class: " + bluetoothClass.toString()); diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java index 33e754044873..7050db14bfb1 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java @@ -166,7 +166,7 @@ public class CachedBluetoothDeviceManager { return cachedDevice.getName(); } - String name = device.getAliasName(); + String name = device.getAlias(); if (name != null) { return name; } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManagerTest.java index dc47de8546db..c37509b55f7f 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManagerTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManagerTest.java @@ -95,9 +95,9 @@ public class CachedBluetoothDeviceManagerTest { when(mDevice1.getName()).thenReturn(DEVICE_NAME_1); when(mDevice2.getName()).thenReturn(DEVICE_NAME_2); when(mDevice3.getName()).thenReturn(DEVICE_NAME_3); - when(mDevice1.getAliasName()).thenReturn(DEVICE_ALIAS_1); - when(mDevice2.getAliasName()).thenReturn(DEVICE_ALIAS_2); - when(mDevice3.getAliasName()).thenReturn(DEVICE_ALIAS_3); + when(mDevice1.getAlias()).thenReturn(DEVICE_ALIAS_1); + when(mDevice2.getAlias()).thenReturn(DEVICE_ALIAS_2); + when(mDevice3.getAlias()).thenReturn(DEVICE_ALIAS_3); when(mDevice1.getBluetoothClass()).thenReturn(DEVICE_CLASS_1); when(mDevice2.getBluetoothClass()).thenReturn(DEVICE_CLASS_2); when(mDevice3.getBluetoothClass()).thenReturn(DEVICE_CLASS_2); @@ -224,7 +224,7 @@ public class CachedBluetoothDeviceManagerTest { assertThat(cachedDevice1.getName()).isEqualTo(DEVICE_ALIAS_1); final String newAliasName = "NewAliasName"; - when(mDevice1.getAliasName()).thenReturn(newAliasName); + when(mDevice1.getAlias()).thenReturn(newAliasName); mCachedDeviceManager.onDeviceNameUpdated(mDevice1); assertThat(cachedDevice1.getName()).isEqualTo(newAliasName); } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java index 93dcbfeab172..999916d39cd0 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java @@ -699,7 +699,7 @@ public class CachedBluetoothDeviceTest { @Test public void deviceName_testAliasNameAvailable() { - when(mDevice.getAliasName()).thenReturn(DEVICE_ALIAS); + when(mDevice.getAlias()).thenReturn(DEVICE_ALIAS); when(mDevice.getName()).thenReturn(DEVICE_NAME); CachedBluetoothDevice cachedBluetoothDevice = new CachedBluetoothDevice(mContext, mProfileManager, mDevice); @@ -722,7 +722,7 @@ public class CachedBluetoothDeviceTest { @Test public void deviceName_testRenameDevice() { final String[] alias = {DEVICE_ALIAS}; - doAnswer(invocation -> alias[0]).when(mDevice).getAliasName(); + doAnswer(invocation -> alias[0]).when(mDevice).getAlias(); doAnswer(invocation -> { alias[0] = (String) invocation.getArguments()[0]; return true; @@ -839,14 +839,14 @@ public class CachedBluetoothDeviceTest { @Test public void getName_aliasNameNotNull_returnAliasName() { - when(mDevice.getAliasName()).thenReturn(DEVICE_NAME); + when(mDevice.getAlias()).thenReturn(DEVICE_NAME); assertThat(mCachedDevice.getName()).isEqualTo(DEVICE_NAME); } @Test public void getName_aliasNameIsNull_returnAddress() { - when(mDevice.getAliasName()).thenReturn(null); + when(mDevice.getAlias()).thenReturn(null); assertThat(mCachedDevice.getName()).isEqualTo(DEVICE_ADDRESS); } @@ -854,7 +854,7 @@ public class CachedBluetoothDeviceTest { @Test public void setName_setDeviceNameIsNotNull() { final String name = "test name"; - when(mDevice.getAliasName()).thenReturn(DEVICE_NAME); + when(mDevice.getAlias()).thenReturn(DEVICE_NAME); mCachedDevice.setName(name); diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/HearingAidDeviceManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/HearingAidDeviceManagerTest.java index 2b5466c4161f..7be176a37bb4 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/HearingAidDeviceManagerTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/HearingAidDeviceManagerTest.java @@ -75,8 +75,8 @@ public class HearingAidDeviceManagerTest { when(mDevice2.getAddress()).thenReturn(DEVICE_ADDRESS_2); when(mDevice1.getName()).thenReturn(DEVICE_NAME_1); when(mDevice2.getName()).thenReturn(DEVICE_NAME_2); - when(mDevice1.getAliasName()).thenReturn(DEVICE_ALIAS_1); - when(mDevice2.getAliasName()).thenReturn(DEVICE_ALIAS_2); + when(mDevice1.getAlias()).thenReturn(DEVICE_ALIAS_1); + when(mDevice2.getAlias()).thenReturn(DEVICE_ALIAS_2); when(mDevice1.getBluetoothClass()).thenReturn(DEVICE_CLASS); when(mDevice2.getBluetoothClass()).thenReturn(DEVICE_CLASS); when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java index 4b56f037f8ed..f73ca1c36005 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java @@ -24,6 +24,7 @@ import android.net.ConnectivityManager; import android.net.wifi.WifiClient; import android.net.wifi.WifiManager; import android.os.Handler; +import android.os.HandlerExecutor; import android.os.UserManager; import android.util.Log; @@ -109,7 +110,8 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof mCallbacks.add(callback); if (mWifiManager != null) { if (mCallbacks.size() == 1) { - mWifiManager.registerSoftApCallback(this, mMainHandler); + mWifiManager.registerSoftApCallback(this, + new HandlerExecutor(mMainHandler)); } else { // mWifiManager#registerSoftApCallback triggers a call to // onConnectedClientsChanged on the Main Handler. In order to always update diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java index 7f32ad5c6c1f..7496e3ade351 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java @@ -43,6 +43,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import java.util.ArrayList; +import java.util.concurrent.Executor; @SmallTest @RunWith(AndroidTestingRunner.class) @@ -73,7 +74,7 @@ public class HotspotControllerImplTest extends SysuiTestCase { .onConnectedClientsChanged(new ArrayList<>()); return null; }).when(mWifiManager).registerSoftApCallback(any(WifiManager.SoftApCallback.class), - any(Handler.class)); + any(Executor.class)); mController = new HotspotControllerImpl(mContext, new Handler(mLooper.getLooper())); } diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index b3804c4d7ec5..acedc3635730 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -286,8 +286,8 @@ public class Tethering extends BaseNetworkObserver { private void startStateMachineUpdaters(Handler handler) { mCarrierConfigChange.startListening(); - TelephonyManager.from(mContext).listen(mPhoneStateListener, - PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE); + mContext.getSystemService(TelephonyManager.class).listen( + mPhoneStateListener, PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE); IntentFilter filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_STATE); diff --git a/services/core/java/com/android/server/location/GnssNetworkConnectivityHandler.java b/services/core/java/com/android/server/location/GnssNetworkConnectivityHandler.java index 2e72fbd95931..93227bd78a81 100644 --- a/services/core/java/com/android/server/location/GnssNetworkConnectivityHandler.java +++ b/services/core/java/com/android/server/location/GnssNetworkConnectivityHandler.java @@ -321,7 +321,11 @@ class GnssNetworkConnectivityHandler { private void handleUpdateNetworkState(Network network, boolean isConnected, NetworkCapabilities capabilities) { - boolean networkAvailable = isConnected && TelephonyManager.getDefault().getDataEnabled(); + boolean networkAvailable = false; + TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class); + if (telephonyManager != null) { + networkAvailable = isConnected && telephonyManager.getDataEnabled(); + } NetworkAttributes networkAttributes = updateTrackedNetworksState(isConnected, network, capabilities); String apn = networkAttributes.mApn; diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index 41806cabef3f..08c94267e969 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -337,7 +337,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); NetworkStatsService service = new NetworkStatsService(context, networkManager, alarmManager, - wakeLock, getDefaultClock(), TelephonyManager.getDefault(), + wakeLock, getDefaultClock(), context.getSystemService(TelephonyManager.class), new DefaultNetworkStatsSettings(context), new NetworkStatsFactory(), new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir()); service.registerLocalService(); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 0d9dcff51b49..faac78d68879 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -7234,7 +7234,7 @@ public class NotificationManagerService extends SystemService { } private void listenForCallState() { - TelephonyManager.from(getContext()).listen(new PhoneStateListener() { + getContext().getSystemService(TelephonyManager.class).listen(new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (mCallState == state) return; diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 37931be4eb10..2e56fb096e3b 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -1939,7 +1939,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } TelephonyManager getTelephonyManager() { - return TelephonyManager.from(mContext); + return mContext.getSystemService(TelephonyManager.class); } TrustManager getTrustManager() { diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java index f34c7a8543ab..4dad01f9d5c0 100644 --- a/telephony/java/android/telephony/CarrierConfigManager.java +++ b/telephony/java/android/telephony/CarrierConfigManager.java @@ -828,13 +828,6 @@ public class CarrierConfigManager { "disable_severe_when_extreme_disabled_bool"; /** - * The message expiration time in milliseconds for duplicate detection purposes. - * @hide - */ - public static final String KEY_MESSAGE_EXPIRATION_TIME_LONG = - "message_expiration_time_long"; - - /** * The data call retry configuration for different types of APN. * @hide */ @@ -3387,7 +3380,6 @@ public class CarrierConfigManager { sDefaults.putBoolean(KEY_BROADCAST_EMERGENCY_CALL_STATE_CHANGES_BOOL, false); sDefaults.putBoolean(KEY_ALWAYS_SHOW_EMERGENCY_ALERT_ONOFF_BOOL, false); sDefaults.putBoolean(KEY_DISABLE_SEVERE_WHEN_EXTREME_DISABLED_BOOL, true); - sDefaults.putLong(KEY_MESSAGE_EXPIRATION_TIME_LONG, 86400000L); sDefaults.putStringArray(KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[]{ "default:default_randomization=2000,5000,10000,20000,40000,80000:5000,160000:5000," + "320000:5000,640000:5000,1280000:5000,1800000:5000", diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index 54e87afb2da9..daeacf8206b4 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -520,7 +520,6 @@ public final class SmsManager { throw new IllegalArgumentException("Invalid message body"); } - final Context context = ActivityThread.currentApplication().getApplicationContext(); // We will only show the SMS disambiguation dialog in the case that the message is being // persisted. This is for two reasons: // 1) Messages that are not persisted are sent by carrier/OEM apps for a specific @@ -629,7 +628,6 @@ public final class SmsManager { final int finalPriority = priority; final int finalValidity = validityPeriod; - final Context context = ActivityThread.currentApplication().getApplicationContext(); // We will only show the SMS disambiguation dialog in the case that the message is being // persisted. This is for two reasons: // 1) Messages that are not persisted are sent by carrier/OEM apps for a specific @@ -933,7 +931,6 @@ public final class SmsManager { } if (parts.size() > 1) { - final Context context = ActivityThread.currentApplication().getApplicationContext(); // We will only show the SMS disambiguation dialog in the case that the message is being // persisted. This is for two reasons: // 1) Messages that are not persisted are sent by carrier/OEM apps for a specific @@ -1174,7 +1171,6 @@ public final class SmsManager { if (parts.size() > 1) { final int finalPriority = priority; final int finalValidity = validityPeriod; - final Context context = ActivityThread.currentApplication().getApplicationContext(); if (persistMessage) { resolveSubscriptionForOperation(new SubscriptionResolverResult() { @Override @@ -1331,7 +1327,6 @@ public final class SmsManager { throw new IllegalArgumentException("Invalid message data"); } - final Context context = ActivityThread.currentApplication().getApplicationContext(); resolveSubscriptionForOperation(new SubscriptionResolverResult() { @Override public void onSuccess(int subId) { diff --git a/tests/PlatformCompatGating/Android.bp b/tests/PlatformCompatGating/Android.bp deleted file mode 100644 index 5e9ef8efc402..000000000000 --- a/tests/PlatformCompatGating/Android.bp +++ /dev/null @@ -1,33 +0,0 @@ -// -// 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. -// - -android_test { - name: "PlatformCompatGating", - // Only compile source java files in this apk. - srcs: ["src/**/*.java"], - certificate: "platform", - libs: [ - "android.test.runner", - "android.test.base", - ], - static_libs: [ - "junit", - "android-support-test", - "mockito-target-minus-junit4", - "truth-prebuilt", - "platform-compat-test-rules" - ], -} diff --git a/tests/PlatformCompatGating/AndroidManifest.xml b/tests/PlatformCompatGating/AndroidManifest.xml deleted file mode 100644 index 7f14b83fbc75..000000000000 --- a/tests/PlatformCompatGating/AndroidManifest.xml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> - -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.android.tests.gating"> - <application android:label="GatingTest"> - <uses-library android:name="android.test.runner" /> - </application> - - <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner" - android:targetPackage="com.android.tests.gating"/> -</manifest> diff --git a/tests/PlatformCompatGating/AndroidTest.xml b/tests/PlatformCompatGating/AndroidTest.xml deleted file mode 100644 index c62684837332..000000000000 --- a/tests/PlatformCompatGating/AndroidTest.xml +++ /dev/null @@ -1,30 +0,0 @@ -<!-- Copyright (C) 2018 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. ---> -<configuration description="Test compatibility change gating."> - <target_preparer class="com.android.tradefed.targetprep.TestFilePushSetup"/> - <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup"> - <option name="test-file-name" value="PlatformCompatGating.apk"/> - </target_preparer> - <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"/> - <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer"/> - <option name="test-suite-tag" value="apct"/> - <option name="test-tag" value="Gating"/> - - <test class="com.android.tradefed.testtype.AndroidJUnitTest"> - <option name="package" value="com.android.tests.gating"/> - <option name="runner" value="android.support.test.runner.AndroidJUnitRunner"/> - <option name="hidden-api-checks" value="false"/> - </test> -</configuration> diff --git a/tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java b/tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java deleted file mode 100644 index 731be8e3d9f0..000000000000 --- a/tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2016 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.compat.testing; - -import android.compat.Compatibility; -import android.content.Context; -import android.os.RemoteException; -import android.os.ServiceManager; - -import com.android.internal.compat.IPlatformCompat; - -/** - * This is a dummy API to test gating - * - * @hide - */ -public class DummyApi { - - public static final long CHANGE_ID = 666013; - public static final long CHANGE_ID_1 = 666014; - public static final long CHANGE_ID_2 = 666015; - public static final long CHANGE_SYSTEM_SERVER = 666016; - - /** - * Dummy method - * @return "A" if change is enabled, "B" otherwise. - */ - public static String dummyFunc() { - if (Compatibility.isChangeEnabled(CHANGE_ID)) { - return "A"; - } - return "B"; - } - - /** - * Dummy combined method - * @return "0" if {@link CHANGE_ID_1} is disabled and {@link CHANGE_ID_2} is disabled, - "1" if {@link CHANGE_ID_1} is disabled and {@link CHANGE_ID_2} is enabled, - "2" if {@link CHANGE_ID_1} is enabled and {@link CHANGE_ID_2} is disabled, - "3" if {@link CHANGE_ID_1} is enabled and {@link CHANGE_ID_2} is enabled. - */ - public static String dummyCombinedFunc() { - if (!Compatibility.isChangeEnabled(CHANGE_ID_1) - && !Compatibility.isChangeEnabled(CHANGE_ID_2)) { - return "0"; - } else if (!Compatibility.isChangeEnabled(CHANGE_ID_1) - && Compatibility.isChangeEnabled(CHANGE_ID_2)) { - return "1"; - } else if (Compatibility.isChangeEnabled(CHANGE_ID_1) - && !Compatibility.isChangeEnabled(CHANGE_ID_2)) { - return "2"; - } - return "3"; - } - - /** - * Dummy api using system server API. - */ - public static boolean dummySystemServer(Context context) { - IPlatformCompat platformCompat = IPlatformCompat.Stub - .asInterface(ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); - if (platformCompat == null) { - throw new RuntimeException("Could not obtain IPlatformCompat instance!"); - } - String packageName = context.getPackageName(); - try { - return platformCompat.isChangeEnabledByPackageName(CHANGE_SYSTEM_SERVER, packageName, - context.getUserId()); - } catch (RemoteException e) { - throw new RuntimeException("Could not get change value!", e); - } - } -} diff --git a/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatGatingTest.java b/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatGatingTest.java deleted file mode 100644 index dc317f1941c7..000000000000 --- a/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatGatingTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2018 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.tests.gating; - -import static com.google.common.truth.Truth.assertThat; - -import android.compat.testing.PlatformCompatChangeRule; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import com.android.compat.testing.DummyApi; - -import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; -import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.runner.RunWith; - -/** - * Tests for platform compatibility change gating. - */ -@RunWith(AndroidJUnit4.class) -public class PlatformCompatGatingTest { - - @Rule - public TestRule compatChangeRule = new PlatformCompatChangeRule(); - - @Test - @EnableCompatChanges({DummyApi.CHANGE_ID}) - public void testDummyGatingPositive() { - assertThat(DummyApi.dummyFunc()).isEqualTo("A"); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_ID}) - public void testDummyGatingNegative() { - assertThat(DummyApi.dummyFunc()).isEqualTo("B"); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_ID_1, DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined0() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("0"); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_ID_1}) - @EnableCompatChanges({DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined1() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("1"); - } - - @Test - @EnableCompatChanges({DummyApi.CHANGE_ID_1}) - @DisableCompatChanges({DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined2() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("2"); - } - - @Test - @EnableCompatChanges({DummyApi.CHANGE_ID_1, DummyApi.CHANGE_ID_2}) - public void testDummyGatingCombined3() { - assertThat(DummyApi.dummyCombinedFunc()).isEqualTo("3"); - } - - @Test - @EnableCompatChanges({DummyApi.CHANGE_SYSTEM_SERVER}) - public void testDummyGatingPositiveSystemServer() { - assertThat( - DummyApi.dummySystemServer(InstrumentationRegistry.getTargetContext())).isTrue(); - } - - @Test - @DisableCompatChanges({DummyApi.CHANGE_SYSTEM_SERVER}) - public void testDummyGatingNegativeSystemServer() { - assertThat( - DummyApi.dummySystemServer(InstrumentationRegistry.getTargetContext())).isFalse(); - } -} diff --git a/tests/PlatformCompatGating/test-rules/Android.bp b/tests/PlatformCompatGating/test-rules/Android.bp deleted file mode 100644 index 8211ef523ee7..000000000000 --- a/tests/PlatformCompatGating/test-rules/Android.bp +++ /dev/null @@ -1,26 +0,0 @@ -// -// 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. -// - -java_library { - name: "platform-compat-test-rules", - srcs: ["src/**/*.java"], - static_libs: [ - "junit", - "android-support-test", - "truth-prebuilt", - "core-compat-test-rules" - ], -}
\ No newline at end of file diff --git a/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java b/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java deleted file mode 100644 index 4e61862a0083..000000000000 --- a/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 android.compat.testing; - -import android.app.Instrumentation; -import android.compat.Compatibility; -import android.compat.Compatibility.ChangeConfig; -import android.content.Context; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.support.test.InstrumentationRegistry; - -import com.android.internal.compat.CompatibilityChangeConfig; -import com.android.internal.compat.IPlatformCompat; - -import libcore.junit.util.compat.CoreCompatChangeRule; - -import org.junit.runners.model.Statement; - -/** - * Allows tests to specify the which change to disable. - * - * <p>To use add the following to the test class. It will only change the behavior of a test method - * if it is annotated with - * {@link libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges} and/or - * {@link libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges}. - * </p> - * <pre> - * @Rule - * public TestRule compatChangeRule = new PlatformCompatChangeRule(); - * </pre> - * - * <p>Each test method that needs to disable a specific change needs to be annotated - * with {@link libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges} and/or - * {@link libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges} specifying the change - * id. e.g.: - * </p> - * <pre> - * @Test - * @DisableCompatChanges({42}) - * public void testAsIfChange42Disabled() { - * // check behavior - * } - * - * @Test - * @EnableCompatChanges({42}) - * public void testAsIfChange42Enabled() { - * // check behavior - * - * </pre> - */ -public class PlatformCompatChangeRule extends CoreCompatChangeRule { - - @Override - protected Statement createStatementForConfig(final Statement statement, ChangeConfig config) { - return new CompatChangeStatement(statement, config); - } - - - private static class CompatChangeStatement extends Statement { - private final Statement mTestStatement; - private final ChangeConfig mConfig; - - private CompatChangeStatement(Statement testStatement, ChangeConfig config) { - this.mTestStatement = testStatement; - this.mConfig = config; - } - - @Override - public void evaluate() throws Throwable { - Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); - String packageName = instrumentation.getTargetContext().getPackageName(); - IPlatformCompat platformCompat = IPlatformCompat.Stub - .asInterface(ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); - if (platformCompat == null) { - throw new IllegalStateException("Could not get IPlatformCompat service!"); - } - Compatibility.setOverrides(mConfig); - try { - platformCompat.setOverrides(new CompatibilityChangeConfig(mConfig), packageName); - try { - mTestStatement.evaluate(); - } finally { - platformCompat.clearOverrides(packageName); - } - } catch (RemoteException e) { - throw new RuntimeException("Could not call IPlatformCompat binder method!", e); - } finally { - Compatibility.clearOverrides(); - } - } - } -} diff --git a/tests/net/java/com/android/server/connectivity/TetheringTest.java b/tests/net/java/com/android/server/connectivity/TetheringTest.java index 5f62c08f55f3..9e5717b4bd64 100644 --- a/tests/net/java/com/android/server/connectivity/TetheringTest.java +++ b/tests/net/java/com/android/server/connectivity/TetheringTest.java @@ -208,6 +208,12 @@ public class TetheringTest { if (Context.TELEPHONY_SERVICE.equals(name)) return mTelephonyManager; return super.getSystemService(name); } + + @Override + public String getSystemServiceName(Class<?> serviceClass) { + if (TelephonyManager.class.equals(serviceClass)) return Context.TELEPHONY_SERVICE; + return super.getSystemServiceName(serviceClass); + } } public class MockIpServerDependencies extends IpServer.Dependencies { diff --git a/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java b/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java index 1d29a824d10d..4d42a612030d 100644 --- a/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java +++ b/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java @@ -192,8 +192,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest { mService = new NetworkStatsService( mServiceContext, mNetManager, mAlarmManager, wakeLock, mClock, - TelephonyManager.getDefault(), mSettings, mStatsFactory, - new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir)); + mServiceContext.getSystemService(TelephonyManager.class), mSettings, + mStatsFactory, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir)); mHandlerThread = new HandlerThread("HandlerThread"); mHandlerThread.start(); Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService); diff --git a/tools/hiddenapi/generate_hiddenapi_lists.py b/tools/hiddenapi/generate_hiddenapi_lists.py index e883c6bed755..46105f4d66b0 100755 --- a/tools/hiddenapi/generate_hiddenapi_lists.py +++ b/tools/hiddenapi/generate_hiddenapi_lists.py @@ -241,8 +241,6 @@ class FlagsDict: flags = csv[1:] if (FLAG_PUBLIC_API in flags) or (FLAG_SYSTEM_API in flags): flags.append(FLAG_WHITELIST) - elif FLAG_TEST_API in flags: - flags.append(FLAG_GREYLIST) self._dict[csv[0]].update(flags) def assign_flag(self, flag, apis, source="<unknown>"): diff --git a/tools/hiddenapi/generate_hiddenapi_lists_test.py b/tools/hiddenapi/generate_hiddenapi_lists_test.py index 4dc880b107d3..55c3a7d718db 100755 --- a/tools/hiddenapi/generate_hiddenapi_lists_test.py +++ b/tools/hiddenapi/generate_hiddenapi_lists_test.py @@ -53,14 +53,22 @@ class TestHiddenapiListGeneration(unittest.TestCase): # Test new additions. flags.parse_and_merge_csv([ 'A,' + FLAG_GREYLIST, - 'B,' + FLAG_BLACKLIST + ',' + FLAG_GREYLIST_MAX_O ]) - self.assertEqual(flags.generate_csv(), - [ 'A,' + FLAG_GREYLIST, - 'B,' + FLAG_BLACKLIST + "," + FLAG_GREYLIST_MAX_O ]) + 'B,' + FLAG_BLACKLIST + ',' + FLAG_GREYLIST_MAX_O, + 'C,' + FLAG_SYSTEM_API + ',' + FLAG_WHITELIST, + 'D,' + FLAG_GREYLIST+ ',' + FLAG_TEST_API, + 'E,' + FLAG_BLACKLIST+ ',' + FLAG_TEST_API, + ]) + self.assertEqual(flags.generate_csv(), [ + 'A,' + FLAG_GREYLIST, + 'B,' + FLAG_BLACKLIST + "," + FLAG_GREYLIST_MAX_O, + 'C,' + FLAG_SYSTEM_API + ',' + FLAG_WHITELIST, + 'D,' + FLAG_GREYLIST+ ',' + FLAG_TEST_API, + 'E,' + FLAG_BLACKLIST+ ',' + FLAG_TEST_API, + ]) # Test unknown flag. with self.assertRaises(AssertionError): - flags.parse_and_merge_csv([ 'C,foo' ]) + flags.parse_and_merge_csv([ 'Z,foo' ]) def test_assign_flag(self): flags = FlagsDict() diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index d9c1bf22d477..68355c603914 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -3121,6 +3121,7 @@ public class WifiManager { * * @hide */ + @SystemApi public interface SoftApCallback { /** * Called when soft AP state changes. @@ -3149,11 +3150,11 @@ public class WifiManager { * @hide */ private class SoftApCallbackProxy extends ISoftApCallback.Stub { - private final Handler mHandler; + private final Executor mExecutor; private final SoftApCallback mCallback; - SoftApCallbackProxy(Looper looper, SoftApCallback callback) { - mHandler = new Handler(looper); + SoftApCallbackProxy(Executor executor, SoftApCallback callback) { + mExecutor = executor; mCallback = callback; } @@ -3164,7 +3165,8 @@ public class WifiManager { + ", failureReason=" + failureReason); } - mHandler.post(() -> { + Binder.clearCallingIdentity(); + mExecutor.execute(() -> { mCallback.onStateChanged(state, failureReason); }); } @@ -3176,7 +3178,8 @@ public class WifiManager { + clients.size() + " clients"); } - mHandler.post(() -> { + Binder.clearCallingIdentity(); + mExecutor.execute(() -> { mCallback.onConnectedClientsChanged(clients); }); } @@ -3195,21 +3198,22 @@ public class WifiManager { * <p> * * @param callback Callback for soft AP events - * @param handler The Handler on whose thread to execute the callbacks of the {@code callback} - * object. If null, then the application's main thread will be used. + * @param executor The executor to execute the callbacks of the {@code executor} + * object. If null, then the application's main executor will be used. * * @hide */ + @SystemApi @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void registerSoftApCallback(@NonNull SoftApCallback callback, - @Nullable Handler handler) { + @Nullable @CallbackExecutor Executor executor) { if (callback == null) throw new IllegalArgumentException("callback cannot be null"); - Log.v(TAG, "registerSoftApCallback: callback=" + callback + ", handler=" + handler); + Log.v(TAG, "registerSoftApCallback: callback=" + callback + ", executor=" + executor); - Looper looper = (handler == null) ? mContext.getMainLooper() : handler.getLooper(); + executor = (executor == null) ? mContext.getMainExecutor() : executor; Binder binder = new Binder(); try { - mService.registerSoftApCallback(binder, new SoftApCallbackProxy(looper, callback), + mService.registerSoftApCallback(binder, new SoftApCallbackProxy(executor, callback), callback.hashCode()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java index e14919452ba7..cfdb6f1dd304 100644 --- a/wifi/tests/src/android/net/wifi/WifiManagerTest.java +++ b/wifi/tests/src/android/net/wifi/WifiManagerTest.java @@ -66,6 +66,7 @@ import android.net.wifi.WifiManager.SoftApCallback; import android.net.wifi.WifiManager.TrafficStateCallback; import android.os.Build; import android.os.Handler; +import android.os.HandlerExecutor; import android.os.IBinder; import android.os.Message; import android.os.Messenger; @@ -685,7 +686,7 @@ public class WifiManagerTest { @Test public void registerSoftApCallbackThrowsIllegalArgumentExceptionOnNullArgumentForCallback() { try { - mWifiManager.registerSoftApCallback(null, mHandler); + mWifiManager.registerSoftApCallback(null, new HandlerExecutor(mHandler)); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } @@ -710,7 +711,7 @@ public class WifiManagerTest { public void registerSoftApCallbackUsesMainLooperOnNullArgumentForHandler() { when(mContext.getMainLooper()).thenReturn(mLooper.getLooper()); mWifiManager.registerSoftApCallback(mSoftApCallback, null); - verify(mContext).getMainLooper(); + verify(mContext).getMainExecutor(); } /** @@ -718,7 +719,7 @@ public class WifiManagerTest { */ @Test public void registerSoftApCallbackCallGoesToWifiServiceImpl() throws Exception { - mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); + mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler)); verify(mWifiService).registerSoftApCallback(any(IBinder.class), any(ISoftApCallback.Stub.class), anyInt()); } @@ -729,7 +730,7 @@ public class WifiManagerTest { @Test public void unregisterSoftApCallbackCallGoesToWifiServiceImpl() throws Exception { ArgumentCaptor<Integer> callbackIdentifier = ArgumentCaptor.forClass(Integer.class); - mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); + mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler)); verify(mWifiService).registerSoftApCallback(any(IBinder.class), any(ISoftApCallback.Stub.class), callbackIdentifier.capture()); @@ -744,7 +745,7 @@ public class WifiManagerTest { public void softApCallbackProxyCallsOnStateChanged() throws Exception { ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor = ArgumentCaptor.forClass(ISoftApCallback.Stub.class); - mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); + mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler)); verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), anyInt()); @@ -760,7 +761,7 @@ public class WifiManagerTest { public void softApCallbackProxyCallsOnConnectedClientsChanged() throws Exception { ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor = ArgumentCaptor.forClass(ISoftApCallback.Stub.class); - mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); + mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler)); verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), anyInt()); @@ -777,7 +778,7 @@ public class WifiManagerTest { public void softApCallbackProxyCallsOnMultipleUpdates() throws Exception { ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor = ArgumentCaptor.forClass(ISoftApCallback.Stub.class); - mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); + mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler)); verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), anyInt()); @@ -801,7 +802,7 @@ public class WifiManagerTest { ArgumentCaptor.forClass(ISoftApCallback.Stub.class); TestLooper altLooper = new TestLooper(); Handler altHandler = new Handler(altLooper.getLooper()); - mWifiManager.registerSoftApCallback(mSoftApCallback, altHandler); + mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(altHandler)); verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), anyInt()); @@ -815,7 +816,7 @@ public class WifiManagerTest { */ @Test public void testCorrectLooperIsUsedForSoftApCallbackHandler() throws Exception { - mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); + mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler)); mLooper.dispatchAll(); verify(mWifiService).registerSoftApCallback(any(IBinder.class), any(ISoftApCallback.Stub.class), anyInt()); |