Loading packages/SettingsLib/ActivityEmbedding/src/com/android/settingslib/activityembedding/ActivityEmbeddingUtils.java +43 −11 Original line number Original line Diff line number Diff line Loading @@ -17,10 +17,12 @@ package com.android.settingslib.activityembedding; package com.android.settingslib.activityembedding; import android.app.Activity; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.text.TextUtils; import android.util.Log; import androidx.core.os.BuildCompat; import androidx.core.os.BuildCompat; import androidx.window.embedding.SplitController; import androidx.window.embedding.SplitController; Loading @@ -30,24 +32,52 @@ import com.android.settingslib.utils.BuildCompatUtils; /** /** * An util class collecting all common methods for the embedding activity features. * An util class collecting all common methods for the embedding activity features. */ */ public class ActivityEmbeddingUtils { public final class ActivityEmbeddingUtils { private static final String ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY = private static final String ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY = "android.settings.SETTINGS_EMBED_DEEP_LINK_ACTIVITY"; "android.settings.SETTINGS_EMBED_DEEP_LINK_ACTIVITY"; private static final String PACKAGE_NAME_SETTINGS = "com.android.settings"; private static final String PACKAGE_NAME_SETTINGS = "com.android.settings"; private static final String TAG = "ActivityEmbeddingUtils"; /** /** * Whether to support embedding activity feature. * Whether the embedding activity feature is enabled. * * <p>This returns false if the Android version is below S or if the embedding activity is not * enabled (unsupported devices). */ */ public static boolean isEmbeddingActivityEnabled(Context context) { public static boolean isEmbeddingActivityEnabled(Context context) { if (BuildCompatUtils.isAtLeastS()) { final boolean isEmbeddingActivityEnabled = getEmbeddingActivityComponent(context) != null; final Intent intent = new Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY); Log.d(TAG, "isEmbeddingActivityEnabled : " + isEmbeddingActivityEnabled); intent.setPackage(PACKAGE_NAME_SETTINGS); final boolean isEmbeddingActivityEnabled = intent.resolveActivity(context.getPackageManager()) != null; return isEmbeddingActivityEnabled; return isEmbeddingActivityEnabled; } } return false; /** * Returns a base Intent to the embedding activity (without the extras). * * <p>This returns null if the Android version is below S or if the embedding activity is not * enabled (unsupported devices). */ public static Intent buildEmbeddingActivityBaseIntent(Context context) { ComponentName embeddingActivityComponentName = getEmbeddingActivityComponent(context); if (embeddingActivityComponentName == null) { return null; } return new Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY) .setComponent(embeddingActivityComponentName); } /** * Returns the ComponentName associated with the embedding activity. * * <p>This returns null if the Android version is below S or if the embedding activity is not * enabled (unsupported devices). */ private static ComponentName getEmbeddingActivityComponent(Context context) { if (!BuildCompatUtils.isAtLeastSV2()) { return null; } final Intent intent = new Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY); intent.setPackage(PACKAGE_NAME_SETTINGS); return intent.resolveActivity(context.getPackageManager()); } } /** /** Loading @@ -70,9 +100,11 @@ public class ActivityEmbeddingUtils { if (!BuildCompat.isAtLeastT()) { if (!BuildCompat.isAtLeastT()) { return false; return false; } } if (!isSecondLayerPage) { if (!isSecondLayerPage) { return false; return false; } } final String shouldHideNavigateUpButton = final String shouldHideNavigateUpButton = Settings.Global.getString(activity.getContentResolver(), Settings.Global.getString(activity.getContentResolver(), "settings_hide_second_layer_page_navigate_up_button_in_two_pane"); "settings_hide_second_layer_page_navigate_up_button_in_two_pane"); Loading packages/SettingsLib/Utils/src/com/android/settingslib/utils/BuildCompatUtils.java +34 −10 Original line number Original line Diff line number Diff line Loading @@ -16,14 +16,37 @@ package com.android.settingslib.utils; package com.android.settingslib.utils; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION; import androidx.annotation.ChecksSdkIntAtLeast; /** /** * An util class to check whether the current OS version is higher or equal to sdk version of * An util class to check whether the current OS version is higher or equal to sdk version of * device. * device. */ */ public final class BuildCompatUtils { public final class BuildCompatUtils { /** * Implementation of BuildCompat.isAtLeastS() suitable for use in Settings * * @return Whether the current OS version is higher or equal to S. */ @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S) public static boolean isAtLeastS() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; } /** * Implementation of BuildCompat.isAtLeastS() suitable for use in Settings * * @return Whether the current OS version is higher or equal to Sv2. */ @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S_V2) public static boolean isAtLeastSV2() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2; } /** /** * Implementation of BuildCompat.isAtLeast*() suitable for use in Settings * Implementation of BuildCompat.isAtLeast*() suitable for use in Settings * * Loading @@ -35,26 +58,27 @@ public final class BuildCompatUtils { * <p>Supported configurations: * <p>Supported configurations: * * * <ul> * <ul> * <li>For current Android release: when new API is not finalized yet (CODENAME = "S", SDK_INT * <li>For current Android release: when new API is not finalized yet (CODENAME = "Tiramisu", * = 30|31) * SDK_INT = 32) * <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 31) * <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 33) * <li>For next Android release (CODENAME = "T", SDK_INT = 30+) * <li>For next Android release (CODENAME = "U", SDK_INT = 34+) * </ul> * </ul> * * * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available, because * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available, because * it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API finalization. * it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API finalization. * * * @return Whether the current OS version is higher or equal to S. * @return Whether the current OS version is higher or equal to T. */ */ public static boolean isAtLeastS() { public static boolean isAtLeastT() { if (VERSION.SDK_INT < 30) { if (!isAtLeastS()) { return false; return false; } } return (VERSION.CODENAME.equals("REL") && VERSION.SDK_INT >= 31) return (VERSION.CODENAME.equals("REL") && VERSION.SDK_INT >= 33) || (VERSION.CODENAME.length() >= 1 || (VERSION.CODENAME.length() >= 1 && VERSION.CODENAME.toUpperCase().charAt(0) >= 'S' && VERSION.CODENAME.toUpperCase().charAt(0) >= 'T' && VERSION.CODENAME.toUpperCase().charAt(0) <= 'Z'); && VERSION.CODENAME.toUpperCase().charAt(0) <= 'Z') || (Build.VERSION.CODENAME.equals("Tiramisu") && Build.VERSION.SDK_INT >= 32); } } private BuildCompatUtils() {} private BuildCompatUtils() {} Loading Loading
packages/SettingsLib/ActivityEmbedding/src/com/android/settingslib/activityembedding/ActivityEmbeddingUtils.java +43 −11 Original line number Original line Diff line number Diff line Loading @@ -17,10 +17,12 @@ package com.android.settingslib.activityembedding; package com.android.settingslib.activityembedding; import android.app.Activity; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.text.TextUtils; import android.util.Log; import androidx.core.os.BuildCompat; import androidx.core.os.BuildCompat; import androidx.window.embedding.SplitController; import androidx.window.embedding.SplitController; Loading @@ -30,24 +32,52 @@ import com.android.settingslib.utils.BuildCompatUtils; /** /** * An util class collecting all common methods for the embedding activity features. * An util class collecting all common methods for the embedding activity features. */ */ public class ActivityEmbeddingUtils { public final class ActivityEmbeddingUtils { private static final String ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY = private static final String ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY = "android.settings.SETTINGS_EMBED_DEEP_LINK_ACTIVITY"; "android.settings.SETTINGS_EMBED_DEEP_LINK_ACTIVITY"; private static final String PACKAGE_NAME_SETTINGS = "com.android.settings"; private static final String PACKAGE_NAME_SETTINGS = "com.android.settings"; private static final String TAG = "ActivityEmbeddingUtils"; /** /** * Whether to support embedding activity feature. * Whether the embedding activity feature is enabled. * * <p>This returns false if the Android version is below S or if the embedding activity is not * enabled (unsupported devices). */ */ public static boolean isEmbeddingActivityEnabled(Context context) { public static boolean isEmbeddingActivityEnabled(Context context) { if (BuildCompatUtils.isAtLeastS()) { final boolean isEmbeddingActivityEnabled = getEmbeddingActivityComponent(context) != null; final Intent intent = new Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY); Log.d(TAG, "isEmbeddingActivityEnabled : " + isEmbeddingActivityEnabled); intent.setPackage(PACKAGE_NAME_SETTINGS); final boolean isEmbeddingActivityEnabled = intent.resolveActivity(context.getPackageManager()) != null; return isEmbeddingActivityEnabled; return isEmbeddingActivityEnabled; } } return false; /** * Returns a base Intent to the embedding activity (without the extras). * * <p>This returns null if the Android version is below S or if the embedding activity is not * enabled (unsupported devices). */ public static Intent buildEmbeddingActivityBaseIntent(Context context) { ComponentName embeddingActivityComponentName = getEmbeddingActivityComponent(context); if (embeddingActivityComponentName == null) { return null; } return new Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY) .setComponent(embeddingActivityComponentName); } /** * Returns the ComponentName associated with the embedding activity. * * <p>This returns null if the Android version is below S or if the embedding activity is not * enabled (unsupported devices). */ private static ComponentName getEmbeddingActivityComponent(Context context) { if (!BuildCompatUtils.isAtLeastSV2()) { return null; } final Intent intent = new Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY); intent.setPackage(PACKAGE_NAME_SETTINGS); return intent.resolveActivity(context.getPackageManager()); } } /** /** Loading @@ -70,9 +100,11 @@ public class ActivityEmbeddingUtils { if (!BuildCompat.isAtLeastT()) { if (!BuildCompat.isAtLeastT()) { return false; return false; } } if (!isSecondLayerPage) { if (!isSecondLayerPage) { return false; return false; } } final String shouldHideNavigateUpButton = final String shouldHideNavigateUpButton = Settings.Global.getString(activity.getContentResolver(), Settings.Global.getString(activity.getContentResolver(), "settings_hide_second_layer_page_navigate_up_button_in_two_pane"); "settings_hide_second_layer_page_navigate_up_button_in_two_pane"); Loading
packages/SettingsLib/Utils/src/com/android/settingslib/utils/BuildCompatUtils.java +34 −10 Original line number Original line Diff line number Diff line Loading @@ -16,14 +16,37 @@ package com.android.settingslib.utils; package com.android.settingslib.utils; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION; import androidx.annotation.ChecksSdkIntAtLeast; /** /** * An util class to check whether the current OS version is higher or equal to sdk version of * An util class to check whether the current OS version is higher or equal to sdk version of * device. * device. */ */ public final class BuildCompatUtils { public final class BuildCompatUtils { /** * Implementation of BuildCompat.isAtLeastS() suitable for use in Settings * * @return Whether the current OS version is higher or equal to S. */ @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S) public static boolean isAtLeastS() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; } /** * Implementation of BuildCompat.isAtLeastS() suitable for use in Settings * * @return Whether the current OS version is higher or equal to Sv2. */ @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S_V2) public static boolean isAtLeastSV2() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2; } /** /** * Implementation of BuildCompat.isAtLeast*() suitable for use in Settings * Implementation of BuildCompat.isAtLeast*() suitable for use in Settings * * Loading @@ -35,26 +58,27 @@ public final class BuildCompatUtils { * <p>Supported configurations: * <p>Supported configurations: * * * <ul> * <ul> * <li>For current Android release: when new API is not finalized yet (CODENAME = "S", SDK_INT * <li>For current Android release: when new API is not finalized yet (CODENAME = "Tiramisu", * = 30|31) * SDK_INT = 32) * <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 31) * <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 33) * <li>For next Android release (CODENAME = "T", SDK_INT = 30+) * <li>For next Android release (CODENAME = "U", SDK_INT = 34+) * </ul> * </ul> * * * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available, because * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available, because * it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API finalization. * it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API finalization. * * * @return Whether the current OS version is higher or equal to S. * @return Whether the current OS version is higher or equal to T. */ */ public static boolean isAtLeastS() { public static boolean isAtLeastT() { if (VERSION.SDK_INT < 30) { if (!isAtLeastS()) { return false; return false; } } return (VERSION.CODENAME.equals("REL") && VERSION.SDK_INT >= 31) return (VERSION.CODENAME.equals("REL") && VERSION.SDK_INT >= 33) || (VERSION.CODENAME.length() >= 1 || (VERSION.CODENAME.length() >= 1 && VERSION.CODENAME.toUpperCase().charAt(0) >= 'S' && VERSION.CODENAME.toUpperCase().charAt(0) >= 'T' && VERSION.CODENAME.toUpperCase().charAt(0) <= 'Z'); && VERSION.CODENAME.toUpperCase().charAt(0) <= 'Z') || (Build.VERSION.CODENAME.equals("Tiramisu") && Build.VERSION.SDK_INT >= 32); } } private BuildCompatUtils() {} private BuildCompatUtils() {} Loading