summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java13
-rw-r--r--api/current.txt6
-rw-r--r--core/java/android/provider/Settings.java71
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java23
4 files changed, 92 insertions, 21 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java
index 4ee46f453bca..dfe7a90ba246 100644
--- a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java
+++ b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java
@@ -1390,8 +1390,10 @@ public class DeviceIdleController extends SystemService
private static final int MSG_FINISH_IDLE_OP = 8;
private static final int MSG_REPORT_TEMP_APP_WHITELIST_CHANGED = 9;
private static final int MSG_SEND_CONSTRAINT_MONITORING = 10;
- private static final int MSG_UPDATE_PRE_IDLE_TIMEOUT_FACTOR = 11;
- private static final int MSG_RESET_PRE_IDLE_TIMEOUT_FACTOR = 12;
+ @VisibleForTesting
+ static final int MSG_UPDATE_PRE_IDLE_TIMEOUT_FACTOR = 11;
+ @VisibleForTesting
+ static final int MSG_RESET_PRE_IDLE_TIMEOUT_FACTOR = 12;
final class MyHandler extends Handler {
MyHandler(Looper looper) {
@@ -3327,8 +3329,7 @@ public class DeviceIdleController extends SystemService
mHandler.sendEmptyMessage(MSG_RESET_PRE_IDLE_TIMEOUT_FACTOR);
}
- @VisibleForTesting
- void updatePreIdleFactor() {
+ private void updatePreIdleFactor() {
synchronized (this) {
if (!shouldUseIdleTimeoutFactorLocked()) {
return;
@@ -3350,8 +3351,7 @@ public class DeviceIdleController extends SystemService
}
}
- @VisibleForTesting
- void maybeDoImmediateMaintenance() {
+ private void maybeDoImmediateMaintenance() {
synchronized (this) {
if (mState == STATE_IDLE) {
long duration = SystemClock.elapsedRealtime() - mIdleStartTime;
@@ -3377,6 +3377,7 @@ public class DeviceIdleController extends SystemService
void setIdleStartTimeForTest(long idleStartTime) {
synchronized (this) {
mIdleStartTime = idleStartTime;
+ maybeDoImmediateMaintenance();
}
}
diff --git a/api/current.txt b/api/current.txt
index 7dccf7f0ecf0..61013e81c473 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -39024,10 +39024,14 @@ package android.provider {
field public static final String ACTION_VPN_SETTINGS = "android.settings.VPN_SETTINGS";
field public static final String ACTION_VR_LISTENER_SETTINGS = "android.settings.VR_LISTENER_SETTINGS";
field public static final String ACTION_WEBVIEW_SETTINGS = "android.settings.WEBVIEW_SETTINGS";
+ field public static final String ACTION_WIFI_ADD_NETWORKS = "android.settings.WIFI_ADD_NETWORKS";
field public static final String ACTION_WIFI_IP_SETTINGS = "android.settings.WIFI_IP_SETTINGS";
field public static final String ACTION_WIFI_SETTINGS = "android.settings.WIFI_SETTINGS";
field public static final String ACTION_WIRELESS_SETTINGS = "android.settings.WIRELESS_SETTINGS";
field public static final String ACTION_ZEN_MODE_PRIORITY_SETTINGS = "android.settings.ZEN_MODE_PRIORITY_SETTINGS";
+ field public static final int ADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED = 1; // 0x1
+ field public static final int ADD_WIFI_RESULT_ALREADY_EXISTS = 2; // 0x2
+ field public static final int ADD_WIFI_RESULT_SUCCESS = 0; // 0x0
field public static final String AUTHORITY = "settings";
field public static final String EXTRA_ACCOUNT_TYPES = "account_types";
field public static final String EXTRA_AIRPLANE_MODE_ENABLED = "airplane_mode_enabled";
@@ -39040,6 +39044,8 @@ package android.provider {
field public static final String EXTRA_INPUT_METHOD_ID = "input_method_id";
field public static final String EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME = "android.provider.extra.NOTIFICATION_LISTENER_COMPONENT_NAME";
field public static final String EXTRA_SUB_ID = "android.provider.extra.SUB_ID";
+ field public static final String EXTRA_WIFI_CONFIGURATION_LIST = "android.provider.extra.WIFI_CONFIGURATION_LIST";
+ field public static final String EXTRA_WIFI_CONFIGURATION_RESULT_LIST = "android.provider.extra.WIFI_CONFIGURATION_RESULT_LIST";
field public static final String INTENT_CATEGORY_USAGE_ACCESS_CONFIG = "android.intent.category.USAGE_ACCESS_CONFIG";
field public static final String METADATA_USAGE_ACCESS_REASON = "android.settings.metadata.USAGE_ACCESS_REASON";
}
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 50dac46d0597..3ac7deb0db08 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -14099,6 +14099,77 @@ public final class Settings {
"android.settings.panel.action.VOLUME";
}
+ /**
+ * Activity Action: Show setting page to process the addition of Wi-Fi networks to the user's
+ * saved network list. The app should send a new intent with an extra that holds a maximum of
+ * five {@link android.net.wifi.WifiConfiguration} that specify credentials for the networks to
+ * be added to the user's database. The Intent should be sent via the {@link
+ * android.app.Activity#startActivityForResult(Intent, int)} API.
+ * <p>
+ * Note: The app sending the Intent to add the credentials doesn't get any ownership over the
+ * newly added network(s). For the Wi-Fi stack, these networks will look like the user
+ * manually added them from the Settings UI.
+ * <p>
+ * Input: The app should put parcelable array list to
+ * {@link android.net.wifi.WifiConfiguration} into the
+ * {@link #EXTRA_WIFI_CONFIGURATION_LIST} extra.
+ * <p>
+ * Output: After {@link android.app.Activity#startActivityForResult(Intent, int)}, the
+ * callback {@link android.app.Activity#onActivityResult(int, int, Intent)} will have a
+ * result code {@link android.app.Activity#RESULT_OK} to indicate user pressed the save
+ * button to save the networks or {@link android.app.Activity#RESULT_CANCELED} to indicate
+ * that the user rejected the request. Additionally, an integer array list, stored in
+ * {@link #EXTRA_WIFI_CONFIGURATION_RESULT_LIST}, will indicate the process result of
+ * each network.
+ */
+ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+ public static final String ACTION_WIFI_ADD_NETWORKS =
+ "android.settings.WIFI_ADD_NETWORKS";
+
+ /**
+ * A bundle extra of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that indicates all the
+ * {@link android.net.wifi.WifiConfiguration} that would be saved.
+ */
+ public static final String EXTRA_WIFI_CONFIGURATION_LIST =
+ "android.provider.extra.WIFI_CONFIGURATION_LIST";
+
+ /**
+ * A bundle extra of the result of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that
+ * indicates the action result of the saved {@link android.net.wifi.WifiConfiguration}. It's
+ * value of AddWifiResult interface, and will be 1:1 mapping to the element in {@link
+ * #EXTRA_WIFI_CONFIGURATION_LIST}.
+ */
+ public static final String EXTRA_WIFI_CONFIGURATION_RESULT_LIST =
+ "android.provider.extra.WIFI_CONFIGURATION_RESULT_LIST";
+
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(prefix = {"ADD_WIFI_RESULT_"}, value = {
+ ADD_WIFI_RESULT_SUCCESS,
+ ADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED,
+ ADD_WIFI_RESULT_ALREADY_EXISTS
+ })
+ public @interface AddWifiResult {
+ }
+
+ /**
+ * A result of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that saving or updating the
+ * corresponding Wi-Fi network was successful.
+ */
+ public static final int ADD_WIFI_RESULT_SUCCESS = 0;
+
+ /**
+ * A result of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that saving the corresponding
+ * Wi-Fi network failed.
+ */
+ public static final int ADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED = 1;
+
+ /**
+ * A result of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that indicates the Wi-Fi network
+ * already exists.
+ */
+ public static final int ADD_WIFI_RESULT_ALREADY_EXISTS = 2;
+
private static final String[] PM_WRITE_SETTINGS = {
android.Manifest.permission.WRITE_SETTINGS
};
diff --git a/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java
index 9c9730501a78..45de451e5bea 100644
--- a/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java
@@ -33,6 +33,8 @@ import static com.android.server.DeviceIdleController.LIGHT_STATE_OVERRIDE;
import static com.android.server.DeviceIdleController.LIGHT_STATE_PRE_IDLE;
import static com.android.server.DeviceIdleController.LIGHT_STATE_WAITING_FOR_NETWORK;
import static com.android.server.DeviceIdleController.MSG_REPORT_STATIONARY_STATUS;
+import static com.android.server.DeviceIdleController.MSG_RESET_PRE_IDLE_TIMEOUT_FACTOR;
+import static com.android.server.DeviceIdleController.MSG_UPDATE_PRE_IDLE_TIMEOUT_FACTOR;
import static com.android.server.DeviceIdleController.STATE_ACTIVE;
import static com.android.server.DeviceIdleController.STATE_IDLE;
import static com.android.server.DeviceIdleController.STATE_IDLE_MAINTENANCE;
@@ -180,7 +182,9 @@ public class DeviceIdleControllerTest {
mHandler = controller.new MyHandler(getContext().getMainLooper());
spyOn(mHandler);
doNothing().when(mHandler).handleMessage(argThat((message) ->
- message.what != MSG_REPORT_STATIONARY_STATUS));
+ message.what != MSG_REPORT_STATIONARY_STATUS
+ && message.what != MSG_UPDATE_PRE_IDLE_TIMEOUT_FACTOR
+ && message.what != MSG_RESET_PRE_IDLE_TIMEOUT_FACTOR));
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
@@ -189,7 +193,9 @@ public class DeviceIdleControllerTest {
return true;
}
}).when(mHandler).sendMessageDelayed(
- argThat((message) -> message.what == MSG_REPORT_STATIONARY_STATUS),
+ argThat((message) -> message.what == MSG_REPORT_STATIONARY_STATUS
+ || message.what == MSG_UPDATE_PRE_IDLE_TIMEOUT_FACTOR
+ || message.what == MSG_RESET_PRE_IDLE_TIMEOUT_FACTOR),
anyLong());
}
@@ -1734,13 +1740,11 @@ public class DeviceIdleControllerTest {
}
//TODO(b/123045185): Mocked Handler of DeviceIdleController to make message loop
//workable in this test class
- mDeviceIdleController.updatePreIdleFactor();
float expectedfactor = mDeviceIdleController.getPreIdleTimeoutByMode(mode);
float curfactor = mDeviceIdleController.getPreIdleTimeoutFactor();
assertEquals("Pre idle time factor of mode [" + mode + "].",
expectedfactor, curfactor, delta);
mDeviceIdleController.resetPreIdleTimeoutMode();
- mDeviceIdleController.updatePreIdleFactor();
checkNextAlarmTimeWithNewPreIdleFactor(expectedfactor, STATE_INACTIVE);
checkNextAlarmTimeWithNewPreIdleFactor(expectedfactor, STATE_IDLE_PENDING);
@@ -2088,14 +2092,11 @@ public class DeviceIdleControllerTest {
mDeviceIdleController.SET_IDLE_FACTOR_RESULT_OK, ret);
}
if (ret == mDeviceIdleController.SET_IDLE_FACTOR_RESULT_OK) {
- mDeviceIdleController.updatePreIdleFactor();
long newAlarm = mDeviceIdleController.getNextAlarmTime();
long newDelay = (long) ((alarm - now) * factor);
assertTrue("setPreIdleTimeoutFactor: " + factor,
Math.abs(newDelay - (newAlarm - now)) < errorTolerance);
mDeviceIdleController.resetPreIdleTimeoutMode();
- mDeviceIdleController.updatePreIdleFactor();
- mDeviceIdleController.maybeDoImmediateMaintenance();
newAlarm = mDeviceIdleController.getNextAlarmTime();
assertTrue("resetPreIdleTimeoutMode from: " + factor,
Math.abs(newAlarm - alarm) < errorTolerance);
@@ -2106,19 +2107,14 @@ public class DeviceIdleControllerTest {
assertTrue("setPreIdleTimeoutFactor: " + factor + " before step to idle",
Math.abs(newDelay - (newAlarm - now)) < errorTolerance);
mDeviceIdleController.resetPreIdleTimeoutMode();
- mDeviceIdleController.updatePreIdleFactor();
- mDeviceIdleController.maybeDoImmediateMaintenance();
}
} else {
mDeviceIdleController.setPreIdleTimeoutFactor(factor);
- mDeviceIdleController.updatePreIdleFactor();
long newAlarm = mDeviceIdleController.getNextAlarmTime();
assertTrue("setPreIdleTimeoutFactor: " + factor
+ " shounld not change next alarm" ,
(newAlarm == alarm));
mDeviceIdleController.resetPreIdleTimeoutMode();
- mDeviceIdleController.updatePreIdleFactor();
- mDeviceIdleController.maybeDoImmediateMaintenance();
}
}
@@ -2138,18 +2134,15 @@ public class DeviceIdleControllerTest {
long alarm = mDeviceIdleController.getNextAlarmTime();
mDeviceIdleController.setIdleStartTimeForTest(
now - (long) (mConstants.IDLE_TIMEOUT * 0.6));
- mDeviceIdleController.maybeDoImmediateMaintenance();
long newAlarm = mDeviceIdleController.getNextAlarmTime();
assertTrue("maintenance not reschedule IDLE_TIMEOUT * 0.6",
newAlarm == alarm);
mDeviceIdleController.setIdleStartTimeForTest(
now - (long) (mConstants.IDLE_TIMEOUT * 1.2));
- mDeviceIdleController.maybeDoImmediateMaintenance();
newAlarm = mDeviceIdleController.getNextAlarmTime();
assertTrue("maintenance not reschedule IDLE_TIMEOUT * 1.2",
(newAlarm - now) < minuteInMillis);
mDeviceIdleController.resetPreIdleTimeoutMode();
- mDeviceIdleController.updatePreIdleFactor();
}
}
}