fix: 首次提交

This commit is contained in:
2024-12-09 11:25:23 +08:00
parent d0c01071e9
commit 2c2109a5f3
4741 changed files with 290641 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "frameworks_base_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["frameworks_base_license"],
}
android_library {
name: "SettingsLibActivityEmbedding",
use_resource_processor: true,
defaults: [
"SettingsLintDefaults",
],
srcs: ["src/**/*.java"],
static_libs: [
"androidx.annotation_annotation",
"androidx.core_core",
"androidx.window_window",
"SettingsLibUtils",
],
sdk_version: "system_current",
min_sdk_version: "21",
// TODO(b/228508619) Remove the optional uses after fixing upstream
optional_uses_libs: [
"org.apache.http.legacy",
"androidx.window.extensions",
"androidx.window.sidecar",
],
apex_available: [
"//apex_available:platform",
"com.android.permission",
"com.android.healthfitness",
],
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.settingslib.widget.activityembedding">
<uses-sdk android:minSdkVersion="21" />
<application>
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<uses-library android:name="androidx.window.extensions" android:required="false" />
<uses-library android:name="androidx.window.sidecar" android:required="false" />
</application>
</manifest>

View File

@@ -0,0 +1,4 @@
# Default reviewers for this and subdirectories.
sunnyshao@google.com
# Emergency approvers in case the above are not available

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2021 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.settingslib.activityembedding;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import androidx.core.os.BuildCompat;
import androidx.window.embedding.ActivityEmbeddingController;
import com.android.settingslib.utils.BuildCompatUtils;
/**
* An util class collecting all common methods for the embedding activity features.
*/
public final class ActivityEmbeddingUtils {
private static final String ACTION_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 TAG = "ActivityEmbeddingUtils";
/**
* 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) {
final boolean isEmbeddingActivityEnabled = getEmbeddingActivityComponent(context) != null;
Log.d(TAG, "isEmbeddingActivityEnabled : " + isEmbeddingActivityEnabled);
return isEmbeddingActivityEnabled;
}
/**
* 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());
}
/**
* Whether the current activity is embedded in the Settings app or not.
*
* @param activity Activity that needs the check
*/
public static boolean isActivityEmbedded(Activity activity) {
return ActivityEmbeddingController.getInstance(activity).isActivityEmbedded(activity);
}
/**
* Whether the current activity should hide the navigate up button.
*
* @param activity Activity that needs the check
* @param isSecondLayerPage indicates if the activity(page) is shown in the 2nd layer of
* Settings app
*/
public static boolean shouldHideNavigateUpButton(Activity activity, boolean isSecondLayerPage) {
if (!BuildCompat.isAtLeastT()) {
return false;
}
if (!isSecondLayerPage) {
return false;
}
return isActivityEmbedded(activity);
}
private ActivityEmbeddingUtils() {
}
}