mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-10-01 01:35:54 -04:00
a53062ca0b
Adds ptrace_scope and timeout options to 17.1, tested working Also adds hardened_malloc to 15.1, but failing to compile: external/hardened_malloc/h_malloc.c:1688:18: error: use of undeclared identifier 'M_PURGE' if (param == M_PURGE) { ^ external/hardened_malloc/h_malloc.c:1743:30: error: missing field 'ordblks' initializer [-Werror,-Wmissing-field-initializers] struct mallinfo info = {0}; ^ Signed-off-by: Tad <tad@spotco.us>
125 lines
5.3 KiB
Diff
125 lines
5.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Pratyush <codelab@pratyush.dev>
|
|
Date: Tue, 6 Jul 2021 18:18:06 +0530
|
|
Subject: [PATCH] Wi-Fi auto turn off
|
|
|
|
---
|
|
core/java/android/provider/Settings.java | 6 ++
|
|
.../server/net/NetworkStatsService.java | 70 +++++++++++++++++++
|
|
2 files changed, 76 insertions(+)
|
|
|
|
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
|
|
index a91f3db2c133..9afbe9750e94 100644
|
|
--- a/core/java/android/provider/Settings.java
|
|
+++ b/core/java/android/provider/Settings.java
|
|
@@ -15127,6 +15127,12 @@ public final class Settings {
|
|
*/
|
|
public static final String BLUETOOTH_OFF_TIMEOUT = "bluetooth_off_timeout";
|
|
|
|
+ /**
|
|
+ * The amount of time in milliseconds before Wi-Fi is turned off
|
|
+ * @hide
|
|
+ */
|
|
+ public static final String WIFI_OFF_TIMEOUT = "wifi_off_timeout";
|
|
+
|
|
/**
|
|
* Whether to automatically reboot the device after a user defined timeout
|
|
*
|
|
diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java
|
|
index d1b5534e3777..831f26a63e97 100644
|
|
--- a/services/core/java/com/android/server/net/NetworkStatsService.java
|
|
+++ b/services/core/java/com/android/server/net/NetworkStatsService.java
|
|
@@ -82,6 +82,7 @@ import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.content.pm.ApplicationInfo;
|
|
import android.content.pm.PackageManager;
|
|
+import android.database.ContentObserver;
|
|
import android.net.DataUsageRequest;
|
|
import android.net.INetworkManagementEventObserver;
|
|
import android.net.INetworkStatsService;
|
|
@@ -97,8 +98,10 @@ import android.net.NetworkStats.NonMonotonicObserver;
|
|
import android.net.NetworkStatsHistory;
|
|
import android.net.NetworkTemplate;
|
|
import android.net.TrafficStats;
|
|
+import android.net.wifi.WifiManager;
|
|
import android.os.BestClock;
|
|
import android.os.Binder;
|
|
+import android.os.Bundle;
|
|
import android.os.DropBoxManager;
|
|
import android.os.Environment;
|
|
import android.os.Handler;
|
|
@@ -366,6 +369,73 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|
mSystemDir = checkNotNull(systemDir, "missing systemDir");
|
|
mBaseDir = checkNotNull(baseDir, "missing baseDir");
|
|
mUseBpfTrafficStats = new File("/sys/fs/bpf/map_netd_app_uid_stats_map").exists();
|
|
+
|
|
+ IntentFilter wifiFilter = new IntentFilter();
|
|
+ wifiFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
+ wifiFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
|
+
|
|
+ context.registerReceiver(
|
|
+ new BroadcastReceiver() {
|
|
+ @Override
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
+ if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
|
+ Bundle bundle = intent.getExtras();
|
|
+ NetworkInfo networkInfo = bundle.getParcelable(WifiManager.EXTRA_NETWORK_INFO);
|
|
+ isWifiConnected = networkInfo != null && networkInfo.isConnected();
|
|
+ }
|
|
+ reconfigureWiFiTimeoutListener();
|
|
+ }
|
|
+ }, wifiFilter
|
|
+ );
|
|
+
|
|
+ context.getContentResolver().registerContentObserver(
|
|
+ Global.getUriFor(Global.WIFI_OFF_TIMEOUT),
|
|
+ false,
|
|
+ new ContentObserver(new Handler(context.getMainLooper())) {
|
|
+ @Override
|
|
+ public void onChange(boolean selfChange) {
|
|
+ super.onChange(selfChange);
|
|
+ reconfigureWiFiTimeoutListener();
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+
|
|
+ private static boolean isWifiConnected = false;
|
|
+ private final AlarmManager.OnAlarmListener listener = this::turnOffWifi;
|
|
+
|
|
+ private void turnOffWifi() {
|
|
+ WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
|
+ if (isWifiTimeoutEnabled(mContext) && wifiManager.isWifiEnabled()) {
|
|
+ // setWifiEnabled(enabled) is deprecated, though AOSP still uses
|
|
+ // it internally and system apps/services are exempted
|
|
+ wifiManager.setWifiEnabled(false);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void reconfigureWiFiTimeoutListener() {
|
|
+ if (isWifiTimeoutEnabled(mContext) && !isWifiConnected) {
|
|
+ final long timeout = SystemClock.elapsedRealtime() + wifiTimeoutDurationInMilli(mContext);
|
|
+ mAlarmManager.cancel(listener);
|
|
+ mAlarmManager.setExact(
|
|
+ AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
|
+ timeout,
|
|
+ "Wi-Fi Idle Timeout",
|
|
+ listener,
|
|
+ new Handler(mContext.getMainLooper())
|
|
+ );
|
|
+ } else {
|
|
+ mAlarmManager.cancel(listener);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static long wifiTimeoutDurationInMilli(Context mContext) {
|
|
+ return Settings.Global.getLong(mContext.getContentResolver(),
|
|
+ Global.WIFI_OFF_TIMEOUT, 0);
|
|
+ }
|
|
+
|
|
+ /** Zero is default and means disabled */
|
|
+ private static boolean isWifiTimeoutEnabled(Context mContext) {
|
|
+ return 0 != wifiTimeoutDurationInMilli(mContext);
|
|
}
|
|
|
|
private void registerLocalService() {
|