From b98a8acf9bc4f53ecc2c51acc941cdcf2b6670ff Mon Sep 17 00:00:00 2001 From: Pawan Wagh Date: Fri, 3 May 2024 23:02:36 +0000 Subject: [PATCH] Turn off automatic updates in page-agnostic mode Update global settings to disable updates in page-agnostic mode Test: m Settings && adb install -r $ANDROID_PRODUCT_OUT/system_ext/priv-app/Settings/Settings.apk Bug: 295035851 Bug: 302391134 Change-Id: I170bb3ffd50a08a1399bffcde23e5f111d9a5a1d --- .../PageAgnosticNotificationService.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/development/PageAgnosticNotificationService.java b/src/com/android/settings/development/PageAgnosticNotificationService.java index 29bc7767084..bce1dd9e106 100644 --- a/src/com/android/settings/development/PageAgnosticNotificationService.java +++ b/src/com/android/settings/development/PageAgnosticNotificationService.java @@ -23,6 +23,7 @@ import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.os.IBinder; +import android.provider.Settings; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -35,6 +36,8 @@ public class PageAgnosticNotificationService extends Service { "com.android.settings.development.PageAgnosticNotificationService"; private static final int NOTIFICATION_ID = 1; + static final int DISABLE_UPDATES_SETTING = 1; + private NotificationManager mNotificationManager; @Nullable @@ -106,6 +109,22 @@ public class PageAgnosticNotificationService extends Service { return builder.build(); } + private void disableAutomaticUpdates() { + final int currentState = + Settings.Global.getInt( + getApplicationContext().getContentResolver(), + Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, + 0 /* default */); + // 0 means enabled, 1 means disabled + if (currentState == 0) { + // automatic updates are enabled, disable them + Settings.Global.putInt( + getApplicationContext().getContentResolver(), + Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, + DISABLE_UPDATES_SETTING); + } + } + @Override public int onStartCommand(@Nullable Intent intent, int flags, int startId) { Notification notification = buildNotification(); @@ -113,7 +132,8 @@ public class PageAgnosticNotificationService extends Service { mNotificationManager.notify(NOTIFICATION_ID, notification); } - // When clicked on notification, show dialog with full text + // No updates should be allowed in page-agnostic mode + disableAutomaticUpdates(); return Service.START_NOT_STICKY; } }