summaryrefslogtreecommitdiff
path: root/com/android/server/power/batterysaver/BatterySaverLocationPlugin.java
diff options
context:
space:
mode:
authorJustin Klaassen <justinklaassen@google.com>2018-01-03 13:39:41 -0500
committerJustin Klaassen <justinklaassen@google.com>2018-01-03 13:39:41 -0500
commit98fe7819c6d14f4f464a5cac047f9e82dee5da58 (patch)
treea6b8b93eb21e205b27590ab5e2a1fb9efe27f892 /com/android/server/power/batterysaver/BatterySaverLocationPlugin.java
parent4217cf85c20565a3446a662a7f07f26137b26b7f (diff)
downloadandroid-28-98fe7819c6d14f4f464a5cac047f9e82dee5da58.tar.gz
Import Android SDK Platform P [4524038]
/google/data/ro/projects/android/fetch_artifact \ --bid 4524038 \ --target sdk_phone_armv7-win_sdk \ sdk-repo-linux-sources-4524038.zip AndroidVersion.ApiLevel has been modified to appear as 28 Change-Id: Ic193bf1cf0cae78d4f2bfb4fbddfe42025c5c3c2
Diffstat (limited to 'com/android/server/power/batterysaver/BatterySaverLocationPlugin.java')
-rw-r--r--com/android/server/power/batterysaver/BatterySaverLocationPlugin.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/com/android/server/power/batterysaver/BatterySaverLocationPlugin.java b/com/android/server/power/batterysaver/BatterySaverLocationPlugin.java
new file mode 100644
index 00000000..0af19b6f
--- /dev/null
+++ b/com/android/server/power/batterysaver/BatterySaverLocationPlugin.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.server.power.batterysaver;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.provider.Settings.Global;
+import android.util.Slog;
+
+import com.android.server.power.BatterySaverPolicy;
+import com.android.server.power.batterysaver.BatterySaverController.Plugin;
+
+public class BatterySaverLocationPlugin implements Plugin {
+ private static final String TAG = "BatterySaverLocationPlugin";
+
+ private static final boolean DEBUG = BatterySaverController.DEBUG;
+
+ private final Context mContext;
+
+ public BatterySaverLocationPlugin(Context context) {
+ mContext = context;
+ }
+
+ @Override
+ public void onBatterySaverChanged(BatterySaverController caller) {
+ if (DEBUG) {
+ Slog.d(TAG, "onBatterySaverChanged");
+ }
+ updateLocationState(caller);
+ }
+
+ @Override
+ public void onSystemReady(BatterySaverController caller) {
+ if (DEBUG) {
+ Slog.d(TAG, "onSystemReady");
+ }
+ updateLocationState(caller);
+ }
+
+ private void updateLocationState(BatterySaverController caller) {
+ final boolean kill =
+ (caller.getBatterySaverPolicy().getGpsMode()
+ == BatterySaverPolicy.GPS_MODE_ALL_DISABLED_WHEN_SCREEN_OFF) &&
+ caller.isEnabled() && !caller.isInteractive();
+
+ if (DEBUG) {
+ Slog.d(TAG, "Battery saver " + (kill ? "stopping" : "restoring") + " location.");
+ }
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Global.LOCATION_GLOBAL_KILL_SWITCH, kill ? 1 : 0);
+ }
+}