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,28 @@
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: "SettingsLibSchedulesProvider",
use_resource_processor: true,
defaults: [
"SettingsLintDefaults",
],
srcs: ["src/**/*.java"],
static_libs: [
"androidx.annotation_annotation",
],
sdk_version: "system_current",
min_sdk_version: "21",
lint: {
baseline_filename: "lint-baseline.xml",
},
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2020 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.schedulesprovider">
<uses-sdk android:minSdkVersion="21" />
</manifest>

View File

@@ -0,0 +1,15 @@
<?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 21): `android.os.SystemProperties#getInt`"
errorLine1=' if (SystemProperties.getInt("ro.debuggable", 0) == 1) {'
errorLine2=" ~~~~~~">
<location
file="frameworks/base/packages/SettingsLib/SchedulesProvider/src/com/android/settingslib/schedulesprovider/SchedulesProvider.java"
line="118"
column="30"/>
</issue>
</issues>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 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>
<!-- Package name for the caller of the Schedules provider. -->
<string name="config_schedules_provider_caller_package" translatable="false">com.android.settings</string>
</resources>

View File

@@ -0,0 +1,165 @@
/*
* Copyright (C) 2020 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.schedulesprovider;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import androidx.annotation.NonNull;
/**
* Schedule data item containing the schedule title text, the summary text which is displayed on the
* summary of the Settings preference and a {@link PendingIntent} which Settings will launch
* when the user clicks on the preference.
*/
public class ScheduleInfo implements Parcelable {
private static final String TAG = "ScheduleInfo";
private final String mTitle;
private final String mSummary;
private final PendingIntent mPendingIntent;
public ScheduleInfo(Builder builder) {
mTitle = builder.mTitle;
mSummary = builder.mSummary;
mPendingIntent = builder.mPendingIntent;
}
private ScheduleInfo(Parcel in) {
mTitle = in.readString();
mSummary = in.readString();
mPendingIntent = in.readParcelable(PendingIntent.class.getClassLoader());
}
/**
* Returns the title text.
*/
public String getTitle() {
return mTitle;
}
/**
* Returns the summary text.
*/
public String getSummary() {
return mSummary;
}
/**
* Returns a {@link PendingIntent} which Settings will launch when the user clicks on a
* schedule preference.
*/
public PendingIntent getPendingIntent() {
return mPendingIntent;
}
/**
* Verify the member variables are valid.
*
* @return {@code true} if all member variables are valid.
*/
public boolean isValid() {
return !TextUtils.isEmpty(mTitle) && !TextUtils.isEmpty(mSummary)
&& (mPendingIntent != null);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mTitle);
dest.writeString(mSummary);
dest.writeParcelable(mPendingIntent, flags);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<ScheduleInfo> CREATOR = new Creator<ScheduleInfo>() {
@Override
public ScheduleInfo createFromParcel(Parcel in) {
return new ScheduleInfo(in);
}
@Override
public ScheduleInfo[] newArray(int size) {
return new ScheduleInfo[size];
}
};
@NonNull
@Override
public String toString() {
return "title: " + mTitle + ", summary: " + mSummary + ", pendingIntent: " + mPendingIntent;
}
/**
* A simple builder for {@link ScheduleInfo}.
*/
public static class Builder {
private String mTitle;
private String mSummary;
private PendingIntent mPendingIntent;
/**
* Sets the title.
*
* @param title The title of the preference item.
* @return This instance.
*/
public Builder setTitle(@NonNull String title) {
mTitle = title;
return this;
}
/**
* Sets the summary.
*
* @param summary The summary of the preference summary.
* @return This instance.
*/
public Builder setSummary(@NonNull String summary) {
mSummary = summary;
return this;
}
/**
* Sets the {@link PendingIntent}.
* <p>The {@link PendingIntent} should be created with
* {@link PendingIntent#getActivity(Context, int, Intent, int)}.
*
* @param pendingIntent The pending intent to send when the user clicks the preference.
* @return This instance.
*/
public Builder setPendingIntent(@NonNull PendingIntent pendingIntent) {
mPendingIntent = pendingIntent;
return this;
}
/**
* Creates an instance of {@link ScheduleInfo}.
*
* @return The instance of {@link ScheduleInfo}.
*/
public ScheduleInfo build() {
return new ScheduleInfo(this);
}
}
}

View File

@@ -0,0 +1,141 @@
/*
* Copyright (C) 2020 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.schedulesprovider;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.stream.Collectors;
/**
* A bridge for client apps to provide the schedule data. Client provider needs to implement
* {@link #getScheduleInfoList()} returning a list of {@link ScheduleInfo}.
*/
public abstract class SchedulesProvider extends ContentProvider {
public static final String METHOD_GENERATE_SCHEDULE_INFO_LIST = "generateScheduleInfoList";
public static final String BUNDLE_SCHEDULE_INFO_LIST = "scheduleInfoList";
private static final String TAG = "SchedulesProvider";
@Override
public boolean onCreate() {
return true;
}
@Override
public final Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
throw new UnsupportedOperationException("Query operation is not supported currently.");
}
@Override
public final String getType(Uri uri) {
throw new UnsupportedOperationException("GetType operation is not supported currently.");
}
@Override
public final Uri insert(Uri uri, ContentValues values) {
throw new UnsupportedOperationException("Insert operation is not supported currently.");
}
@Override
public final int delete(Uri uri, String selection, String[] selectionArgs) {
throw new UnsupportedOperationException("Delete operation not supported currently.");
}
@Override
public final int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
throw new UnsupportedOperationException("Update operation is not supported currently.");
}
/**
* Returns the list of the schedule information.
*/
public abstract ArrayList<ScheduleInfo> getScheduleInfoList();
/**
* Returns a bundle which contains a list of {@link ScheduleInfo}s:
*
* <ul>
* <li>scheduleInfoList: ArrayList<ScheduleInfo>
* </ul>
*/
@Override
public Bundle call(@NonNull String method, @Nullable String arg, @Nullable Bundle extras) {
if (!TextUtils.equals(getCallingPackage(),
getContext().getText(R.string.config_schedules_provider_caller_package))) {
return null;
}
final Bundle bundle = new Bundle();
if (METHOD_GENERATE_SCHEDULE_INFO_LIST.equals(method)) {
final ArrayList<ScheduleInfo> scheduleInfoList = filterInvalidData(
getScheduleInfoList());
if (scheduleInfoList != null) {
bundle.putParcelableArrayList(BUNDLE_SCHEDULE_INFO_LIST, scheduleInfoList);
}
}
return bundle;
}
/**
* Filters our invalid schedule infos from {@code schedulesInfoList}.
*
* @return valid {@link SchedulesInfo}s if {@code schedulesInfoList} is not null. Otherwise,
* null.
*/
@Nullable
private ArrayList<ScheduleInfo> filterInvalidData(
@Nullable ArrayList<ScheduleInfo> scheduleInfoList) {
if (scheduleInfoList == null) {
Log.d(TAG, "package : " + getContext().getPackageName() + " has no scheduling data.");
return null;
}
// Dump invalid data in debug mode.
if (SystemProperties.getInt("ro.debuggable", 0) == 1) {
dumpInvalidData(scheduleInfoList);
}
return scheduleInfoList
.stream()
.filter(ScheduleInfo::isValid)
.collect(Collectors.toCollection(ArrayList::new));
}
private void dumpInvalidData(ArrayList<ScheduleInfo> scheduleInfoList) {
final boolean hasInvalidData = scheduleInfoList
.stream()
.anyMatch(scheduleInfo -> !scheduleInfo.isValid());
if (hasInvalidData) {
Log.w(TAG, "package : " + getContext().getPackageName()
+ " provided some scheduling data that are invalid.");
scheduleInfoList
.stream()
.filter(scheduleInfo -> !scheduleInfo.isValid())
.forEach(scheduleInfo -> Log.w(TAG, scheduleInfo.toString()));
}
}
}