From 35e1bfad098f65db344d4d6fd7abb5830d8aa7a2 Mon Sep 17 00:00:00 2001 From: Ang Li Date: Fri, 11 Jan 2019 12:51:57 -0800 Subject: Migrate to androidx packages (#105) --- .../mobly/snippet/bundled/AccountSnippet.java | 8 +-- .../mobly/snippet/bundled/AudioSnippet.java | 44 ++++++++-------- .../android/mobly/snippet/bundled/FileSnippet.java | 4 +- .../mobly/snippet/bundled/NetworkingSnippet.java | 11 ++-- .../mobly/snippet/bundled/NotificationSnippet.java | 8 ++- .../android/mobly/snippet/bundled/SmsSnippet.java | 4 +- .../mobly/snippet/bundled/TelephonySnippet.java | 11 ++-- .../mobly/snippet/bundled/WifiManagerSnippet.java | 60 ++++++++++------------ .../bundled/bluetooth/BluetoothAdapterSnippet.java | 16 +++--- .../bluetooth/profiles/BluetoothA2dpSnippet.java | 11 ++-- 10 files changed, 82 insertions(+), 95 deletions(-) (limited to 'src/main/java/com/google/android/mobly') diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java index f8499b4..c7f576b 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java @@ -24,7 +24,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.SyncAdapterType; import android.os.Bundle; -import android.support.test.InstrumentationRegistry; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.rpc.Rpc; import com.google.android.mobly.snippet.util.Log; @@ -68,7 +68,7 @@ public class AccountSnippet implements Snippet { private final ReentrantReadWriteLock mLock; public AccountSnippet() { - Context context = InstrumentationRegistry.getContext(); + Context context = InstrumentationRegistry.getInstrumentation().getContext(); mAccountManager = AccountManager.get(context); mSyncStatusObserverHandles = new LinkedList<>(); mSyncWhitelist = new HashMap<>(); @@ -86,8 +86,8 @@ public class AccountSnippet implements Snippet { * @param password Password of the account to add. */ @Rpc( - description = "Add a Google (GMail) account to the device, with account data sync disabled." - ) + description = + "Add a Google (GMail) account to the device, with account data sync disabled.") public void addAccount(String username, String password) throws AccountSnippetException, AccountsException, IOException { // Check for existing account. If we try to re-add an existing account, Android throws an diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/AudioSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/AudioSnippet.java index e435a72..fbdb5d0 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/AudioSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/AudioSnippet.java @@ -18,7 +18,7 @@ package com.google.android.mobly.snippet.bundled; import android.content.Context; import android.media.AudioManager; -import android.support.test.InstrumentationRegistry; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.rpc.Rpc; import java.lang.reflect.Method; @@ -29,7 +29,7 @@ public class AudioSnippet implements Snippet { private final AudioManager mAudioManager; public AudioSnippet() { - Context context = InstrumentationRegistry.getContext(); + Context context = InstrumentationRegistry.getInstrumentation().getContext(); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } @@ -44,7 +44,7 @@ public class AudioSnippet implements Snippet { } @Rpc(description = "Gets the music stream volume.") - public int getMusicVolume() { + public Integer getMusicVolume() { return mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); } @@ -54,17 +54,16 @@ public class AudioSnippet implements Snippet { } @Rpc( - description = - "Sets the music stream volume. The minimum value is 0. Use 'getMusicMaxVolume'" - + " to determine the maximum." - ) + description = + "Sets the music stream volume. The minimum value is 0. Use 'getMusicMaxVolume'" + + " to determine the maximum.") public void setMusicVolume(Integer value) { mAudioManager.setStreamVolume( AudioManager.STREAM_MUSIC, value, 0 /* flags, 0 = no flags */); } @Rpc(description = "Gets the ringer volume.") - public int getRingVolume() { + public Integer getRingVolume() { return mAudioManager.getStreamVolume(AudioManager.STREAM_RING); } @@ -74,16 +73,15 @@ public class AudioSnippet implements Snippet { } @Rpc( - description = - "Sets the ringer stream volume. The minimum value is 0. Use 'getRingMaxVolume'" - + " to determine the maximum." - ) + description = + "Sets the ringer stream volume. The minimum value is 0. Use 'getRingMaxVolume'" + + " to determine the maximum.") public void setRingVolume(Integer value) { mAudioManager.setStreamVolume(AudioManager.STREAM_RING, value, 0 /* flags, 0 = no flags */); } - + @Rpc(description = "Gets the voice call volume.") - public int getVoiceCallVolume() { + public Integer getVoiceCallVolume() { return mAudioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL); } @@ -93,13 +91,12 @@ public class AudioSnippet implements Snippet { } @Rpc( - description = - "Sets the voice call stream volume. The minimum value is 0. Use" - + " 'getVoiceCallMaxVolume' to determine the maximum." - ) + description = + "Sets the voice call stream volume. The minimum value is 0. Use" + + " 'getVoiceCallMaxVolume' to determine the maximum.") public void setVoiceCallVolume(Integer value) { - mAudioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, - value, 0 /* flags, 0 = no flags */); + mAudioManager.setStreamVolume( + AudioManager.STREAM_VOICE_CALL, value, 0 /* flags, 0 = no flags */); } @Rpc(description = "Silences all audio streams.") @@ -115,10 +112,9 @@ public class AudioSnippet implements Snippet { } @Rpc( - description = - "Puts the ringer volume at the lowest setting, but does not set it to " - + "DO NOT DISTURB; the phone will vibrate when receiving a call." - ) + description = + "Puts the ringer volume at the lowest setting, but does not set it to " + + "DO NOT DISTURB; the phone will vibrate when receiving a call.") public void muteRing() { setRingVolume(0); } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java index f6b6918..a1e9d83 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java @@ -19,7 +19,7 @@ package com.google.android.mobly.snippet.bundled; import android.content.Context; import android.net.Uri; import android.os.ParcelFileDescriptor; -import android.support.test.InstrumentationRegistry; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.utils.Utils; import com.google.android.mobly.snippet.rpc.Rpc; @@ -34,7 +34,7 @@ public class FileSnippet implements Snippet { private final Context mContext; public FileSnippet() { - mContext = InstrumentationRegistry.getContext(); + mContext = InstrumentationRegistry.getInstrumentation().getContext(); } private static class FileSnippetException extends Exception { diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java index e89fc12..636c0fd 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java @@ -23,7 +23,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.net.Uri; import android.os.Environment; -import android.support.test.InstrumentationRegistry; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.utils.Utils; import com.google.android.mobly.snippet.rpc.Rpc; @@ -44,7 +44,7 @@ public class NetworkingSnippet implements Snippet { private volatile long mReqid = 0; public NetworkingSnippet() { - mContext = InstrumentationRegistry.getContext(); + mContext = InstrumentationRegistry.getInstrumentation().getContext(); mDownloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); } @@ -78,10 +78,9 @@ public class NetworkingSnippet implements Snippet { } @Rpc( - description = - "Download a file using HTTP. Return content Uri (file remains on device). " - + "The Uri should be treated as an opaque handle for further operations." - ) + description = + "Download a file using HTTP. Return content Uri (file remains on device). " + + "The Uri should be treated as an opaque handle for further operations.") public String networkHttpDownload(String url) throws IllegalArgumentException, NetworkingSnippetException { diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/NotificationSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/NotificationSnippet.java index a07b231..1c34264 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/NotificationSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/NotificationSnippet.java @@ -16,8 +16,8 @@ package com.google.android.mobly.snippet.bundled; -import android.support.test.InstrumentationRegistry; import android.widget.Toast; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.rpc.Rpc; import com.google.android.mobly.snippet.rpc.RunOnUiThread; @@ -28,7 +28,11 @@ public class NotificationSnippet implements Snippet { @RunOnUiThread @Rpc(description = "Make a toast on screen.") public void makeToast(String message) { - Toast.makeText(InstrumentationRegistry.getContext(), message, Toast.LENGTH_LONG).show(); + Toast.makeText( + InstrumentationRegistry.getInstrumentation().getContext(), + message, + Toast.LENGTH_LONG) + .show(); } @Override diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java index ec6d470..be41e9e 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/SmsSnippet.java @@ -26,9 +26,9 @@ import android.content.IntentFilter; import android.os.Build; import android.os.Bundle; import android.provider.Telephony.Sms.Intents; -import android.support.test.InstrumentationRegistry; import android.telephony.SmsManager; import android.telephony.SmsMessage; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.utils.Utils; import com.google.android.mobly.snippet.event.EventCache; @@ -62,7 +62,7 @@ public class SmsSnippet implements Snippet { private final SmsManager mSmsManager; public SmsSnippet() { - this.mContext = InstrumentationRegistry.getContext(); + this.mContext = InstrumentationRegistry.getInstrumentation().getContext(); this.mSmsManager = SmsManager.getDefault(); } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java index 431456d..fbb3041 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/TelephonySnippet.java @@ -17,8 +17,8 @@ package com.google.android.mobly.snippet.bundled; import android.content.Context; -import android.support.test.InstrumentationRegistry; import android.telephony.TelephonyManager; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.rpc.Rpc; @@ -28,7 +28,7 @@ public class TelephonySnippet implements Snippet { private final TelephonyManager mTelephonyManager; public TelephonySnippet() { - Context context = InstrumentationRegistry.getContext(); + Context context = InstrumentationRegistry.getInstrumentation().getContext(); mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); } @@ -43,10 +43,9 @@ public class TelephonySnippet implements Snippet { } @Rpc( - description = - "Gets the call state for the default subscription. Call state values are" - + "0: IDLE, 1: RINGING, 2: OFFHOOK" - ) + description = + "Gets the call state for the default subscription. Call state values are" + + "0: IDLE, 1: RINGING, 2: OFFHOOK") public int getTelephonyCallState() { return mTelephonyManager.getCallState(); } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java index 768fb4c..3d96e4d 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java @@ -25,8 +25,8 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; -import android.support.annotation.Nullable; -import android.support.test.InstrumentationRegistry; +import androidx.annotation.Nullable; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.utils.JsonDeserializer; import com.google.android.mobly.snippet.bundled.utils.JsonSerializer; @@ -57,17 +57,16 @@ public class WifiManagerSnippet implements Snippet { private volatile boolean mIsScanResultAvailable = false; public WifiManagerSnippet() { - mContext = InstrumentationRegistry.getContext(); + mContext = InstrumentationRegistry.getInstrumentation().getContext(); mWifiManager = (WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE); } @Rpc( - description = - "Clears all configured networks. This will only work if all configured " - + "networks were added through this MBS instance" - ) + description = + "Clears all configured networks. This will only work if all configured " + + "networks were added through this MBS instance") public void wifiClearConfiguredNetworks() throws WifiManagerSnippetException { List unremovedConfigs = mWifiManager.getConfiguredNetworks(); List failedConfigs = new ArrayList<>(); @@ -148,9 +147,8 @@ public class WifiManagerSnippet implements Snippet { } @Rpc( - description = - "Get Wi-Fi scan results, which is a list of serialized WifiScanResult objects." - ) + description = + "Get Wi-Fi scan results, which is a list of serialized WifiScanResult objects.") public JSONArray wifiGetCachedScanResults() throws JSONException { JSONArray results = new JSONArray(); for (ScanResult result : mWifiManager.getScanResults()) { @@ -160,10 +158,9 @@ public class WifiManagerSnippet implements Snippet { } @Rpc( - description = - "Start scan, wait for scan to complete, and return results, which is a list of " - + "serialized WifiScanResult objects." - ) + description = + "Start scan, wait for scan to complete, and return results, which is a list of " + + "serialized WifiScanResult objects.") public JSONArray wifiScanAndGetResults() throws InterruptedException, JSONException, WifiManagerSnippetException { mContext.registerReceiver( @@ -179,10 +176,9 @@ public class WifiManagerSnippet implements Snippet { } @Rpc( - description = - "Connects to a Wi-Fi network. This covers the common network types like open and " - + "WPA2." - ) + description = + "Connects to a Wi-Fi network. This covers the common network types like open and " + + "WPA2.") public void wifiConnectSimple(String ssid, @Nullable String password) throws InterruptedException, JSONException, WifiManagerSnippetException { JSONObject config = new JSONObject(); @@ -277,10 +273,9 @@ public class WifiManagerSnippet implements Snippet { } @Rpc( - description = - "Forget a configured Wi-Fi network by its network ID, which is part of the" - + " WifiConfiguration." - ) + description = + "Forget a configured Wi-Fi network by its network ID, which is part of the" + + " WifiConfiguration.") public void wifiRemoveNetwork(Integer networkId) throws WifiManagerSnippetException { if (!mWifiManager.removeNetwork(networkId)) { throw new WifiManagerSnippetException("Failed to remove network of ID: " + networkId); @@ -288,10 +283,9 @@ public class WifiManagerSnippet implements Snippet { } @Rpc( - description = - "Get the list of configured Wi-Fi networks, each is a serialized " - + "WifiConfiguration object." - ) + description = + "Get the list of configured Wi-Fi networks, each is a serialized " + + "WifiConfiguration object.") public List wifiGetConfiguredNetworks() throws JSONException { List networks = new ArrayList<>(); for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) { @@ -307,19 +301,17 @@ public class WifiManagerSnippet implements Snippet { } @Rpc( - description = - "Get the information about the active Wi-Fi connection, which is a serialized " - + "WifiInfo object." - ) + description = + "Get the information about the active Wi-Fi connection, which is a serialized " + + "WifiInfo object.") public JSONObject wifiGetConnectionInfo() throws JSONException { return mJsonSerializer.toJson(mWifiManager.getConnectionInfo()); } @Rpc( - description = - "Get the info from last successful DHCP request, which is a serialized DhcpInfo " - + "object." - ) + description = + "Get the info from last successful DHCP request, which is a serialized DhcpInfo " + + "object.") public JSONObject wifiGetDhcpInfo() throws JSONException { return mJsonSerializer.toJson(mWifiManager.getDhcpInfo()); } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java index 37e7c5f..14393be 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java @@ -23,7 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; -import android.support.test.InstrumentationRegistry; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.utils.JsonSerializer; import com.google.android.mobly.snippet.bundled.utils.Utils; @@ -55,7 +55,7 @@ public class BluetoothAdapterSnippet implements Snippet { private volatile boolean mIsDiscoveryFinished = false; public BluetoothAdapterSnippet() { - mContext = InstrumentationRegistry.getContext(); + mContext = InstrumentationRegistry.getInstrumentation().getContext(); } /** @@ -138,9 +138,8 @@ public class BluetoothAdapterSnippet implements Snippet { } @Rpc( - description = - "Get bluetooth discovery results, which is a list of serialized BluetoothDevice objects." - ) + description = + "Get bluetooth discovery results, which is a list of serialized BluetoothDevice objects.") public ArrayList btGetCachedScanResults() { return mJsonSerializer.serializeBluetoothDeviceList(mDiscoveryResults.values()); } @@ -168,10 +167,9 @@ public class BluetoothAdapterSnippet implements Snippet { } @Rpc( - description = - "Start discovery, wait for discovery to complete, and return results, which is a list of " - + "serialized BluetoothDevice objects." - ) + description = + "Start discovery, wait for discovery to complete, and return results, which is a list of " + + "serialized BluetoothDevice objects.") public List btDiscoverAndGetResults() throws InterruptedException, BluetoothAdapterSnippetException { IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/profiles/BluetoothA2dpSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/profiles/BluetoothA2dpSnippet.java index b218723..ec148ca 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/profiles/BluetoothA2dpSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/profiles/BluetoothA2dpSnippet.java @@ -9,7 +9,7 @@ import android.content.Context; import android.content.IntentFilter; import android.os.Build; import android.os.Bundle; -import android.support.test.InstrumentationRegistry; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.bluetooth.BluetoothAdapterSnippet; import com.google.android.mobly.snippet.bundled.bluetooth.PairingBroadcastReceiver; @@ -34,7 +34,7 @@ public class BluetoothA2dpSnippet implements Snippet { private final JsonSerializer mJsonSerializer = new JsonSerializer(); public BluetoothA2dpSnippet() { - mContext = InstrumentationRegistry.getContext(); + mContext = InstrumentationRegistry.getInstrumentation().getContext(); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.getProfileProxy( mContext, new A2dpServiceListener(), BluetoothProfile.A2DP); @@ -55,10 +55,9 @@ public class BluetoothA2dpSnippet implements Snippet { @TargetApi(Build.VERSION_CODES.KITKAT) @RpcMinSdk(Build.VERSION_CODES.KITKAT) @Rpc( - description = - "Connects to a paired or discovered device with A2DP profile." - + "If a device has been discovered but not paired, this will pair it." - ) + description = + "Connects to a paired or discovered device with A2DP profile." + + "If a device has been discovered but not paired, this will pair it.") public void btA2dpConnect(String deviceAddress) throws Throwable { BluetoothDevice device = BluetoothAdapterSnippet.getKnownDeviceByAddress(deviceAddress); IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); -- cgit v1.2.3