Loading AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -476,7 +476,7 @@ </intent-filter> </activity> <service android:name=".TetherService" <service android:name=".wifi.tether.TetherService" android:exported="true" android:permission="android.permission.TETHER_PRIVILEGED" /> Loading src/com/android/settings/HotspotOffReceiver.java→src/com/android/settings/wifi/tether/HotspotOffReceiver.java +1 −1 Original line number Diff line number Diff line package com.android.settings; package com.android.settings.wifi.tether; import android.content.BroadcastReceiver; import android.content.Context; Loading src/com/android/settings/TetherService.java→src/com/android/settings/wifi/tether/TetherService.java +7 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.settings; package com.android.settings.wifi.tether; import android.app.Activity; import android.app.AlarmManager; Loading Loading @@ -167,11 +167,16 @@ public class TetherService extends Service { SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); prefs.edit().putString(KEY_TETHERS, tethersToString(mCurrentTethers)).commit(); unregisterReceivers(); if (DEBUG) Log.d(TAG, "Destroying TetherService"); unregisterReceiver(mReceiver); super.onDestroy(); } private void unregisterReceivers() { unregisterReceiver(mReceiver); mHotspotReceiver.unregister(); } private void removeTypeAtIndex(int index) { mCurrentTethers.remove(index); // If we are currently in the middle of a check, we may need to adjust the Loading tests/robotests/src/com/android/settings/TetherServiceTest.java→tests/robotests/src/com/android/settings/wifi/tether/TetherServiceTest.java +25 −1 Original line number Diff line number Diff line Loading @@ -13,17 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings; package com.android.settings.wifi.tether; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.wifi.WifiManager; import com.android.settings.TestConfig; import com.android.settings.testutils.SettingsRobolectricTestRunner; import java.util.ArrayList; Loading Loading @@ -87,4 +93,22 @@ public class TetherServiceTest { mService.cancelAlarmIfNecessary(); verify(mContext).unregisterReceiver(any(HotspotOffReceiver.class)); } @Test public void onDestroy_shouldUnregisterReceiver() { final ArrayList<Integer> tethers = new ArrayList<>(); ReflectionHelpers.setField(mService, "mCurrentTethers", tethers); ReflectionHelpers.setField(mService, "mBase", mContext); final SharedPreferences prefs = mock(SharedPreferences .class); final SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class); when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(prefs); when(prefs.edit()).thenReturn(editor); when(editor.putString(anyString(), anyString())).thenReturn(editor); final HotspotOffReceiver hotspotOffReceiver = mock(HotspotOffReceiver.class); mService.setHotspotOffReceiver(hotspotOffReceiver); mService.onDestroy(); verify(hotspotOffReceiver).unregister(); } } tests/unit/src/com/android/settings/TetherServiceTest.java→tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java +1 −5 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.settings; package com.android.settings.wifi.tether; import static org.junit.Assert.*; import static org.mockito.Matchers.*; Loading Loading @@ -49,17 +49,13 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Resources; import android.net.ConnectivityManager; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.ResultReceiver; import android.os.SystemClock; import android.test.ServiceTestCase; import android.test.mock.MockResources; import android.util.Log; import com.android.settings.TetherService; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; Loading Loading
AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -476,7 +476,7 @@ </intent-filter> </activity> <service android:name=".TetherService" <service android:name=".wifi.tether.TetherService" android:exported="true" android:permission="android.permission.TETHER_PRIVILEGED" /> Loading
src/com/android/settings/HotspotOffReceiver.java→src/com/android/settings/wifi/tether/HotspotOffReceiver.java +1 −1 Original line number Diff line number Diff line package com.android.settings; package com.android.settings.wifi.tether; import android.content.BroadcastReceiver; import android.content.Context; Loading
src/com/android/settings/TetherService.java→src/com/android/settings/wifi/tether/TetherService.java +7 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.settings; package com.android.settings.wifi.tether; import android.app.Activity; import android.app.AlarmManager; Loading Loading @@ -167,11 +167,16 @@ public class TetherService extends Service { SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); prefs.edit().putString(KEY_TETHERS, tethersToString(mCurrentTethers)).commit(); unregisterReceivers(); if (DEBUG) Log.d(TAG, "Destroying TetherService"); unregisterReceiver(mReceiver); super.onDestroy(); } private void unregisterReceivers() { unregisterReceiver(mReceiver); mHotspotReceiver.unregister(); } private void removeTypeAtIndex(int index) { mCurrentTethers.remove(index); // If we are currently in the middle of a check, we may need to adjust the Loading
tests/robotests/src/com/android/settings/TetherServiceTest.java→tests/robotests/src/com/android/settings/wifi/tether/TetherServiceTest.java +25 −1 Original line number Diff line number Diff line Loading @@ -13,17 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings; package com.android.settings.wifi.tether; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.wifi.WifiManager; import com.android.settings.TestConfig; import com.android.settings.testutils.SettingsRobolectricTestRunner; import java.util.ArrayList; Loading Loading @@ -87,4 +93,22 @@ public class TetherServiceTest { mService.cancelAlarmIfNecessary(); verify(mContext).unregisterReceiver(any(HotspotOffReceiver.class)); } @Test public void onDestroy_shouldUnregisterReceiver() { final ArrayList<Integer> tethers = new ArrayList<>(); ReflectionHelpers.setField(mService, "mCurrentTethers", tethers); ReflectionHelpers.setField(mService, "mBase", mContext); final SharedPreferences prefs = mock(SharedPreferences .class); final SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class); when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(prefs); when(prefs.edit()).thenReturn(editor); when(editor.putString(anyString(), anyString())).thenReturn(editor); final HotspotOffReceiver hotspotOffReceiver = mock(HotspotOffReceiver.class); mService.setHotspotOffReceiver(hotspotOffReceiver); mService.onDestroy(); verify(hotspotOffReceiver).unregister(); } }
tests/unit/src/com/android/settings/TetherServiceTest.java→tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java +1 −5 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.settings; package com.android.settings.wifi.tether; import static org.junit.Assert.*; import static org.mockito.Matchers.*; Loading Loading @@ -49,17 +49,13 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Resources; import android.net.ConnectivityManager; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.ResultReceiver; import android.os.SystemClock; import android.test.ServiceTestCase; import android.test.mock.MockResources; import android.util.Log; import com.android.settings.TetherService; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; Loading