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"],
}
filegroup {
name: "SettingsLibRestrictedLockUtilsSrc",
srcs: ["src/**/*.java"],
visibility: ["//frameworks/base/services/accessibility"],
}
android_library {
name: "SettingsLibRestrictedLockUtils",
use_resource_processor: true,
defaults: [
"SettingsLintDefaults",
],
srcs: ["src/**/*.java"],
resource_dirs: ["res"],
libs: [
"androidx.annotation_annotation",
],
sdk_version: "system_current",
min_sdk_version: "21",
apex_available: [
"//apex_available:platform",
"com.android.permission",
],
lint: {
baseline_filename: "lint-baseline.xml",
},
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 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.restricted">
</manifest>

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.4.0-alpha01" type="baseline" client="" dependencies="true" name="" variant="all" version="8.4.0-alpha01">
<issue
id="NewApi"
message="Call requires API level 28 (current min is 23): `android.content.Context#createPackageContextAsUser`"
errorLine1=" userContext = context.createPackageContextAsUser(context.getPackageName(), 0, user);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="frameworks/base/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java"
line="64"
column="35"/>
</issue>
<issue
id="NewApi"
message="Call requires API level 29 (current min is 23): `android.app.admin.DevicePolicyManager#getDeviceOwnerUser`"
errorLine1=" if (Objects.equals(dpm.getDeviceOwnerUser(), user)) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~">
<location
file="frameworks/base/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java"
line="74"
column="32"/>
</issue>
<issue
id="NewApi"
message="Call requires API level 26 (current min is 23): `android.app.admin.DevicePolicyManager#getDeviceOwnerComponentOnAnyUser`"
errorLine1=" adminComponent = dpm.getDeviceOwnerComponentOnAnyUser();"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="frameworks/base/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java"
line="75"
column="34"/>
</issue>
<issue
id="NewApi"
message="Call requires API level 24 (current min is 23): `android.os.UserHandle#of`"
errorLine1=" context.startActivityAsUser(intent, UserHandle.of(targetUserId));"
errorLine2=" ~~">
<location
file="frameworks/base/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java"
line="97"
column="56"/>
</issue>
<issue
id="NewApi"
message="Call requires API level 29 (current min is 23): `android.content.Context#startActivityAsUser`"
errorLine1=" context.startActivityAsUser(intent, UserHandle.of(targetUserId));"
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="frameworks/base/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java"
line="97"
column="17"/>
</issue>
<issue
id="NewApi"
message="Call requires API level 24 (current min is 23): `android.os.UserHandle#of`"
errorLine1=" return um.getUserProfiles().contains(UserHandle.of(userId));"
errorLine2=" ~~">
<location
file="frameworks/base/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java"
line="120"
column="57"/>
</issue>
</issues>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 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.
-->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/restricted_icon"
android:layout_width="@*android:dimen/config_restrictedIconSize"
android:layout_height="@*android:dimen/config_restrictedIconSize"
android:tint="?android:attr/colorAccent"
android:src="@*android:drawable/ic_info" />

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 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.
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="enabled_by_admin" msgid="6630472777476410137">"已被管理员启用"</string>
<string name="disabled_by_admin" msgid="4023569940620832713">"已被管理员停用"</string>
</resources>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Summary for switch preference to denote it is switched on [CHAR LIMIT=50] -->
<string name="enabled_by_admin">Enabled by admin</string>
<!-- Summary for switch preference to denote it is switched off [CHAR LIMIT=50] -->
<string name="disabled_by_admin">Disabled by admin</string>
</resources>

View File

@@ -0,0 +1,251 @@
/*
* Copyright (C) 2018 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;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import java.util.Objects;
/**
* Utility class to host methods usable in adding a restricted padlock icon and showing admin
* support message dialog.
*/
public class RestrictedLockUtils {
/**
* Gets EnforcedAdmin from DevicePolicyManager
*/
@RequiresApi(Build.VERSION_CODES.M)
public static EnforcedAdmin getProfileOrDeviceOwner(Context context, UserHandle user) {
return getProfileOrDeviceOwner(context, null, user);
}
/**
* Gets EnforcedAdmin from DevicePolicyManager
*/
@RequiresApi(Build.VERSION_CODES.M)
public static EnforcedAdmin getProfileOrDeviceOwner(
Context context, String enforcedRestriction, UserHandle user) {
if (user == null) {
return null;
}
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
Context userContext;
try {
userContext = context.createPackageContextAsUser(context.getPackageName(), 0, user);
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalStateException(e);
}
ComponentName adminComponent = userContext.getSystemService(
DevicePolicyManager.class).getProfileOwner();
if (adminComponent != null) {
return new EnforcedAdmin(adminComponent, enforcedRestriction, user);
}
if (Objects.equals(dpm.getDeviceOwnerUser(), user)) {
adminComponent = dpm.getDeviceOwnerComponentOnAnyUser();
if (adminComponent != null) {
return new EnforcedAdmin(adminComponent, enforcedRestriction, user);
}
}
return null;
}
/**
* Sends the intent to trigger the {@code android.settings.ShowAdminSupportDetailsDialog}.
*/
@RequiresApi(Build.VERSION_CODES.M)
public static void sendShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) {
final Intent intent = getShowAdminSupportDetailsIntent(context, admin);
int targetUserId = UserHandle.myUserId();
if (admin != null) {
if (admin.user != null
&& isCurrentUserOrProfile(context, admin.user.getIdentifier())) {
targetUserId = admin.user.getIdentifier();
}
intent.putExtra(DevicePolicyManager.EXTRA_RESTRICTION, admin.enforcedRestriction);
}
context.startActivityAsUser(intent, UserHandle.of(targetUserId));
}
/**
* Gets the intent to trigger the {@code android.settings.ShowAdminSupportDetailsDialog}.
*/
public static Intent getShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) {
final Intent intent = new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
if (admin != null) {
if (admin.component != null) {
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin.component);
}
intent.putExtra(Intent.EXTRA_USER, admin.user);
}
return intent;
}
/**
* Checks if current user is profile or not
*/
@RequiresApi(Build.VERSION_CODES.M)
public static boolean isCurrentUserOrProfile(Context context, int userId) {
UserManager um = context.getSystemService(UserManager.class);
return um.getUserProfiles().contains(UserHandle.of(userId));
}
/**
* A admin for the restriction enforced.
*/
public static class EnforcedAdmin {
@Nullable
public ComponentName component = null;
/**
* The restriction enforced by admin. It could be any user restriction or policy like
* {@link DevicePolicyManager#POLICY_DISABLE_CAMERA}.
*/
@Nullable
public String enforcedRestriction = null;
@Nullable
public UserHandle user = null;
/**
* We use this to represent the case where a policy is enforced by multiple admins.
*/
public static final EnforcedAdmin MULTIPLE_ENFORCED_ADMIN = new EnforcedAdmin();
/**
* The restriction enforced by admin with restriction.
*/
public static EnforcedAdmin createDefaultEnforcedAdminWithRestriction(
String enforcedRestriction) {
final EnforcedAdmin enforcedAdmin = new EnforcedAdmin();
enforcedAdmin.enforcedRestriction = enforcedRestriction;
return enforcedAdmin;
}
public EnforcedAdmin(ComponentName component, UserHandle user) {
this.component = component;
this.user = user;
}
public EnforcedAdmin(ComponentName component, String enforcedRestriction, UserHandle user) {
this.component = component;
this.enforcedRestriction = enforcedRestriction;
this.user = user;
}
public EnforcedAdmin(EnforcedAdmin other) {
if (other == null) {
throw new IllegalArgumentException();
}
this.component = other.component;
this.enforcedRestriction = other.enforcedRestriction;
this.user = other.user;
}
public EnforcedAdmin() {}
/**
* Combines two {@link EnforcedAdmin} into one: if one of them is null, then just return
* the other. If both of them are the same, then return that. Otherwise return the symbolic
* {@link #MULTIPLE_ENFORCED_ADMIN}
*/
public static EnforcedAdmin combine(EnforcedAdmin admin1, EnforcedAdmin admin2) {
if (admin1 == null) {
return admin2;
}
if (admin2 == null) {
return admin1;
}
if (admin1.equals(admin2)) {
return admin1;
}
if (!admin1.enforcedRestriction.equals(admin2.enforcedRestriction)) {
throw new IllegalArgumentException(
"Admins with different restriction cannot be combined");
}
return MULTIPLE_ENFORCED_ADMIN;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EnforcedAdmin that = (EnforcedAdmin) o;
return Objects.equals(user, that.user)
&& Objects.equals(component, that.component)
&& Objects.equals(enforcedRestriction, that.enforcedRestriction);
}
@Override
public int hashCode() {
return Objects.hash(component, enforcedRestriction, user);
}
@Override
public String toString() {
return "EnforcedAdmin{"
+ "component=" + component
+ ", enforcedRestriction='" + enforcedRestriction
+ ", user=" + user
+ '}';
}
}
/**
* Shows restricted setting dialog.
*
* @deprecated TODO(b/308921175): This will be deleted with the
* {@link android.security.Flags#extendEcmToAllSettings} feature flag. Do not use for any new
* code.
*/
@Deprecated
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
public static void sendShowRestrictedSettingDialogIntent(Context context,
String packageName, int uid) {
final Intent intent = getShowRestrictedSettingsIntent(packageName, uid);
context.startActivity(intent);
}
/**
* Gets restricted settings dialog intent.
*
* @deprecated TODO(b/308921175): This will be deleted with the
* {@link android.security.Flags#extendEcmToAllSettings} feature flag. Do not use for any new
* code.
*/
@Deprecated
private static Intent getShowRestrictedSettingsIntent(String packageName, int uid) {
final Intent intent = new Intent(Settings.ACTION_SHOW_RESTRICTED_SETTING_DIALOG);
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
intent.putExtra(Intent.EXTRA_UID, uid);
return intent;
}
}