Merge "Validating service components after reading them from resources" into tm-dev am: 19a8270160
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17969082 Change-Id: I36d5fe4f54c0a9e351bfc8684e8ff5ed143d6118 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -20,7 +20,11 @@ import android.annotation.NonNull;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.StringRes;
|
import android.annotation.StringRes;
|
||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
|
import android.app.AppGlobals;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ServiceInfo;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@@ -34,7 +38,9 @@ import android.util.TimeUtils;
|
|||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the service name using a framework resources, temporarily changing the service if necessary
|
* Gets the service name using a framework resources, temporarily changing the service if necessary
|
||||||
@@ -49,10 +55,14 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR
|
|||||||
/** Handler message to {@link #resetTemporaryService(int)} */
|
/** Handler message to {@link #resetTemporaryService(int)} */
|
||||||
private static final int MSG_RESET_TEMPORARY_SERVICE = 0;
|
private static final int MSG_RESET_TEMPORARY_SERVICE = 0;
|
||||||
|
|
||||||
@NonNull private final Context mContext;
|
@NonNull
|
||||||
@NonNull private final Object mLock = new Object();
|
private final Context mContext;
|
||||||
@StringRes private final int mStringResourceId;
|
@NonNull
|
||||||
@ArrayRes private final int mArrayResourceId;
|
private final Object mLock = new Object();
|
||||||
|
@StringRes
|
||||||
|
private final int mStringResourceId;
|
||||||
|
@ArrayRes
|
||||||
|
private final int mArrayResourceId;
|
||||||
private final boolean mIsMultiple;
|
private final boolean mIsMultiple;
|
||||||
/**
|
/**
|
||||||
* Map of temporary service name list set by {@link #setTemporaryServices(int, String[], int)},
|
* Map of temporary service name list set by {@link #setTemporaryServices(int, String[], int)},
|
||||||
@@ -71,7 +81,8 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR
|
|||||||
*/
|
*/
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private final SparseBooleanArray mDefaultServicesDisabled = new SparseBooleanArray();
|
private final SparseBooleanArray mDefaultServicesDisabled = new SparseBooleanArray();
|
||||||
@Nullable private NameResolverListener mOnSetCallback;
|
@Nullable
|
||||||
|
private NameResolverListener mOnSetCallback;
|
||||||
/**
|
/**
|
||||||
* When the temporary service will expire (and reset back to the default).
|
* When the temporary service will expire (and reset back to the default).
|
||||||
*/
|
*/
|
||||||
@@ -160,10 +171,33 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR
|
|||||||
public String[] getDefaultServiceNameList(int userId) {
|
public String[] getDefaultServiceNameList(int userId) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mIsMultiple) {
|
if (mIsMultiple) {
|
||||||
return mContext.getResources().getStringArray(mArrayResourceId);
|
String[] serviceNameList = mContext.getResources().getStringArray(mArrayResourceId);
|
||||||
|
// Filter out unimplemented services
|
||||||
|
// Initialize the validated array as null because we do not know the final size.
|
||||||
|
List<String> validatedServiceNameList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < serviceNameList.length; i++) {
|
||||||
|
if (TextUtils.isEmpty(serviceNameList[i])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ComponentName serviceComponent = ComponentName.unflattenFromString(
|
||||||
|
serviceNameList[i]);
|
||||||
|
ServiceInfo serviceInfo = AppGlobals.getPackageManager().getServiceInfo(
|
||||||
|
serviceComponent,
|
||||||
|
PackageManager.MATCH_DIRECT_BOOT_AWARE
|
||||||
|
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId);
|
||||||
|
if (serviceInfo != null) {
|
||||||
|
validatedServiceNameList.add(serviceNameList[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Slog.e(TAG, "Could not validate provided services.", e);
|
||||||
|
}
|
||||||
|
String[] validatedServiceNameArray = new String[validatedServiceNameList.size()];
|
||||||
|
return validatedServiceNameList.toArray(validatedServiceNameArray);
|
||||||
} else {
|
} else {
|
||||||
final String name = mContext.getString(mStringResourceId);
|
final String name = mContext.getString(mStringResourceId);
|
||||||
return TextUtils.isEmpty(name) ? new String[0] : new String[] { name };
|
return TextUtils.isEmpty(name) ? new String[0] : new String[]{name};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user