added Hotspot.apk
Bug: 144126362
Test: sts-tradefed
Change-Id: I144d746a9d070c68613985bdcf9f7029ddbd79d7
(cherry picked from commit 81968d2654508f51949dd8713d65e6f168d218eb)
(cherry picked from commit 8786a089be27181028afc6f059c3eb1ddc00f67a)
diff --git a/apps/hotspot/Android.mk b/apps/hotspot/Android.mk
new file mode 100644
index 0000000..ae93979
--- /dev/null
+++ b/apps/hotspot/Android.mk
@@ -0,0 +1,18 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := hotspot
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
+
+LOCAL_COMPATIBILITY_SUITE := cts sts vts
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/apps/hotspot/AndroidManifest.xml b/apps/hotspot/AndroidManifest.xml
new file mode 100644
index 0000000..277be5f
--- /dev/null
+++ b/apps/hotspot/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.cts.hotspot">
+
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+ <application>
+ <activity android:name=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <receiver android:name=".Notify" android:exported="true">
+ <intent-filter>
+ <action android:name="com.android.cts.hotspot.TEST_ACTION" />
+ </intent-filter>
+ </receiver>
+ </application>
+
+</manifest>
diff --git a/apps/hotspot/src/com/android/cts/hotspot/MainActivity.java b/apps/hotspot/src/com/android/cts/hotspot/MainActivity.java
new file mode 100644
index 0000000..2e0ed87
--- /dev/null
+++ b/apps/hotspot/src/com/android/cts/hotspot/MainActivity.java
@@ -0,0 +1,20 @@
+package com.android.cts.hotspot;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.support.v4.app.ActivityCompat;
+
+public class MainActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(
+ this, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION}, 2);
+ }
+ }
+}
diff --git a/apps/hotspot/src/com/android/cts/hotspot/Notify.java b/apps/hotspot/src/com/android/cts/hotspot/Notify.java
new file mode 100644
index 0000000..a56a390
--- /dev/null
+++ b/apps/hotspot/src/com/android/cts/hotspot/Notify.java
@@ -0,0 +1,57 @@
+package com.android.cts.hotspot;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
+
+public class Notify extends BroadcastReceiver {
+
+ private static final String EXTRA_HOTSPOT_KEY = "HOTSPOT";
+ private static WifiManager.LocalOnlyHotspotReservation mReservation;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if ("com.android.cts.hotspot.TEST_ACTION".equals(intent.getAction())) {
+ if (intent.hasExtra(EXTRA_HOTSPOT_KEY)) {
+ if ("turnOn".equals(intent.getStringExtra(EXTRA_HOTSPOT_KEY))) {
+ turnOnHotspot(context);
+ } else if ("turnOff".equals(intent.getStringExtra(EXTRA_HOTSPOT_KEY))) {
+ turnOffHotspot();
+ }
+ }
+ }
+ }
+
+ private void turnOnHotspot(Context x) {
+ WifiManager manager = (WifiManager) x.getSystemService(Context.WIFI_SERVICE);
+
+ manager.startLocalOnlyHotspot(
+ new WifiManager.LocalOnlyHotspotCallback() {
+
+ @Override
+ public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
+ mReservation = reservation;
+ super.onStarted(reservation);
+ }
+
+ @Override
+ public void onStopped() {
+ super.onStopped();
+ }
+
+ @Override
+ public void onFailed(int reason) {
+ super.onFailed(reason);
+ }
+ },
+ new Handler());
+ }
+
+ private void turnOffHotspot() {
+ if (mReservation != null) {
+ mReservation.close();
+ }
+ }
+}
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index d1551d0..ca1499f 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -206,6 +206,7 @@
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="OomCatcher.apk" />
<option name="test-file-name" value="MainlineModuleDetector.apk" />
+ <option name="test-file-name" value="hotspot.apk" />
</target_preparer>
<test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >