diff --git a/res/values/strings.xml b/res/values/strings.xml index bc3706f1590..588223a7599 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3817,9 +3817,9 @@ %1$s will be untethered. - + Ethernet tethering - + Share phone\u2019s internet connection via USB Ethernet @@ -11837,6 +11837,8 @@ Load a Dynamic System Update Image Loading... + + DSU is running Bug report handler diff --git a/src/com/android/settings/development/DSULoader.java b/src/com/android/settings/development/DSULoader.java index 36ce785641f..4727369e5a8 100644 --- a/src/com/android/settings/development/DSULoader.java +++ b/src/com/android/settings/development/DSULoader.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.SystemProperties; +import android.text.TextUtils; import android.util.Slog; import android.view.LayoutInflater; import android.view.View; @@ -40,8 +41,11 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import javax.net.ssl.HttpsURLConnection; @@ -62,6 +66,7 @@ public class DSULoader extends ListActivity { private static final String PROPERTY_KEY_OS = "ro.system.build.version.release"; private static final String PROPERTY_KEY_VNDK = "ro.vndk.version"; private static final String PROPERTY_KEY_LIST = "ro.vendor.dsu.list"; + private static final String PROPERTY_KEY_SPL = "ro.build.version.security_patch"; private static final String DSU_LIST = "https://dl.google.com/developers/android/gsi/gsi-src.json"; @@ -121,7 +126,8 @@ public class DSULoader extends ListActivity { mDsuList = dsuList; } - private void fetch(URL url) throws IOException, JSONException, MalformedURLException { + private void fetch(URL url) + throws IOException, JSONException, MalformedURLException, ParseException { String content = readAll(url); JSONObject jsn = new JSONObject(content); // The include primitive is like below @@ -195,6 +201,8 @@ public class DSULoader extends ListActivity { private static final String OS_VERSION = "os_version"; private static final String VNDK = "vndk"; private static final String PUBKEY = "pubkey"; + private static final String SPL = "spl"; + private static final String SPL_FORMAT = "yyyy-MM-dd"; private static final String TOS = "tos"; String mName = null; @@ -203,10 +211,11 @@ public class DSULoader extends ListActivity { int mOsVersion = -1; int[] mVndk = null; String mPubKey = ""; + Date mSPL = null; URL mTosUrl = null; URL mUri; - DSUPackage(JSONObject jsn) throws JSONException, MalformedURLException { + DSUPackage(JSONObject jsn) throws JSONException, MalformedURLException, ParseException { Slog.i(TAG, "DSUPackage: " + jsn.toString()); mName = jsn.getString(NAME); mDetails = jsn.getString(DETAILS); @@ -228,6 +237,9 @@ public class DSULoader extends ListActivity { if (jsn.has(TOS)) { mTosUrl = new URL(jsn.getString(TOS)); } + if (jsn.has(SPL)) { + mSPL = new SimpleDateFormat(SPL_FORMAT).parse(jsn.getString(SPL)); + } } int dessertNumber(String s, int base) { @@ -265,6 +277,18 @@ public class DSULoader extends ListActivity { return cpu; } + Date getDeviceSPL() { + String spl = SystemProperties.get(PROPERTY_KEY_SPL); + if (TextUtils.isEmpty(spl)) { + return null; + } + try { + return new SimpleDateFormat(SPL_FORMAT).parse(spl); + } catch (ParseException e) { + return null; + } + } + boolean isSupported() { boolean supported = true; String cpu = getDeviceCpu(); @@ -301,6 +325,16 @@ public class DSULoader extends ListActivity { } } } + if (mSPL != null) { + Date spl = getDeviceSPL(); + if (spl == null) { + Slog.i(TAG, "Failed to getDeviceSPL"); + supported = false; + } else if (spl.getTime() > mSPL.getTime()) { + Slog.i(TAG, "Device SPL:" + spl.toString() + " > " + mSPL.toString()); + supported = false; + } + } Slog.i(TAG, mName + " isSupported " + supported); return supported; } diff --git a/src/com/android/settings/development/SelectDSUPreferenceController.java b/src/com/android/settings/development/SelectDSUPreferenceController.java index 72e84472a8f..6498ae752f0 100644 --- a/src/com/android/settings/development/SelectDSUPreferenceController.java +++ b/src/com/android/settings/development/SelectDSUPreferenceController.java @@ -18,6 +18,7 @@ package com.android.settings.development; import android.content.Context; import android.content.Intent; +import android.os.SystemProperties; import androidx.preference.Preference; @@ -37,9 +38,16 @@ class SelectDSUPreferenceController extends DeveloperOptionsPreferenceController return DSU_LOADER_KEY; } + private boolean isDSURunning() { + return SystemProperties.getBoolean("ro.gsid.image_running", false); + } + @Override public boolean handlePreferenceTreeClick(Preference preference) { if (DSU_LOADER_KEY.equals(preference.getKey())) { + if (isDSURunning()) { + return true; + } final Intent intent = new Intent(mContext, DSULoader.class); mContext.startActivity(intent); return true; @@ -49,6 +57,7 @@ class SelectDSUPreferenceController extends DeveloperOptionsPreferenceController @Override public void updateState(Preference preference) { - preference.setSummary(mContext.getResources().getString(R.string.dsu_loader_description)); + int key = isDSURunning() ? R.string.dsu_is_running : R.string.dsu_loader_description; + preference.setSummary(mContext.getResources().getString(key)); } }