Merge "Remove uses of SomeArgs, which is a hidden API"
This commit is contained in:
committed by
Android (Google) Code Review
commit
4b19fac10d
@@ -54,6 +54,7 @@ import static com.android.server.SystemService.PHASE_BOOT_COMPLETED;
|
||||
import static com.android.server.SystemService.PHASE_SYSTEM_SERVICES_READY;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AppGlobals;
|
||||
@@ -105,7 +106,6 @@ import com.android.internal.R;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.app.IBatteryStats;
|
||||
import com.android.internal.os.SomeArgs;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.ConcurrentUtils;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
@@ -316,9 +316,30 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
private PackageManager mPackageManager;
|
||||
Injector mInjector;
|
||||
|
||||
static final ArrayList<StandbyUpdateRecord> sStandbyUpdatePool = new ArrayList<>(4);
|
||||
private static class Pool<T> {
|
||||
private final T[] mArray;
|
||||
private int mSize = 0;
|
||||
|
||||
Pool(T[] array) {
|
||||
mArray = array;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
synchronized T obtain() {
|
||||
return mSize > 0 ? mArray[--mSize] : null;
|
||||
}
|
||||
|
||||
synchronized void recycle(T instance) {
|
||||
if (mSize < mArray.length) {
|
||||
mArray[mSize++] = instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class StandbyUpdateRecord {
|
||||
private static final Pool<StandbyUpdateRecord> sPool =
|
||||
new Pool<>(new StandbyUpdateRecord[10]);
|
||||
|
||||
public static class StandbyUpdateRecord {
|
||||
// Identity of the app whose standby state has changed
|
||||
String packageName;
|
||||
int userId;
|
||||
@@ -332,36 +353,48 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
// Reason for bucket change
|
||||
int reason;
|
||||
|
||||
StandbyUpdateRecord(String pkgName, int userId, int bucket, int reason,
|
||||
boolean isInteraction) {
|
||||
this.packageName = pkgName;
|
||||
this.userId = userId;
|
||||
this.bucket = bucket;
|
||||
this.reason = reason;
|
||||
this.isUserInteraction = isInteraction;
|
||||
}
|
||||
|
||||
public static StandbyUpdateRecord obtain(String pkgName, int userId,
|
||||
int bucket, int reason, boolean isInteraction) {
|
||||
synchronized (sStandbyUpdatePool) {
|
||||
final int size = sStandbyUpdatePool.size();
|
||||
if (size < 1) {
|
||||
return new StandbyUpdateRecord(pkgName, userId, bucket, reason, isInteraction);
|
||||
}
|
||||
StandbyUpdateRecord r = sStandbyUpdatePool.remove(size - 1);
|
||||
r.packageName = pkgName;
|
||||
r.userId = userId;
|
||||
r.bucket = bucket;
|
||||
r.reason = reason;
|
||||
r.isUserInteraction = isInteraction;
|
||||
return r;
|
||||
StandbyUpdateRecord r = sPool.obtain();
|
||||
if (r == null) {
|
||||
r = new StandbyUpdateRecord();
|
||||
}
|
||||
r.packageName = pkgName;
|
||||
r.userId = userId;
|
||||
r.bucket = bucket;
|
||||
r.reason = reason;
|
||||
r.isUserInteraction = isInteraction;
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
public void recycle() {
|
||||
synchronized (sStandbyUpdatePool) {
|
||||
sStandbyUpdatePool.add(this);
|
||||
sPool.recycle(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ContentProviderUsageRecord {
|
||||
private static final Pool<ContentProviderUsageRecord> sPool =
|
||||
new Pool<>(new ContentProviderUsageRecord[10]);
|
||||
|
||||
public String name;
|
||||
public String packageName;
|
||||
public int userId;
|
||||
|
||||
public static ContentProviderUsageRecord obtain(String name, String packageName,
|
||||
int userId) {
|
||||
ContentProviderUsageRecord r = sPool.obtain();
|
||||
if (r == null) {
|
||||
r = new ContentProviderUsageRecord();
|
||||
}
|
||||
r.name = name;
|
||||
r.packageName = packageName;
|
||||
r.userId = userId;
|
||||
return r;
|
||||
}
|
||||
|
||||
public void recycle() {
|
||||
sPool.recycle(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +439,6 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1667,11 +1699,9 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
|
||||
@Override
|
||||
public void postReportContentProviderUsage(String name, String packageName, int userId) {
|
||||
SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = name;
|
||||
args.arg2 = packageName;
|
||||
args.arg3 = userId;
|
||||
mHandler.obtainMessage(MSG_REPORT_CONTENT_PROVIDER_USAGE, args)
|
||||
ContentProviderUsageRecord record = ContentProviderUsageRecord.obtain(name, packageName,
|
||||
userId);
|
||||
mHandler.obtainMessage(MSG_REPORT_CONTENT_PROVIDER_USAGE, record)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@@ -1973,11 +2003,9 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
break;
|
||||
|
||||
case MSG_REPORT_CONTENT_PROVIDER_USAGE:
|
||||
SomeArgs args = (SomeArgs) msg.obj;
|
||||
reportContentProviderUsage((String) args.arg1, // authority name
|
||||
(String) args.arg2, // package name
|
||||
(int) args.arg3); // userId
|
||||
args.recycle();
|
||||
ContentProviderUsageRecord record = (ContentProviderUsageRecord) msg.obj;
|
||||
reportContentProviderUsage(record.name, record.packageName, record.userId);
|
||||
record.recycle();
|
||||
break;
|
||||
|
||||
case MSG_PAROLE_STATE_CHANGED:
|
||||
|
||||
Reference in New Issue
Block a user