Merge "Put two way binder calls on new thread" into rvc-dev am: 32d9a6bbcc
Change-Id: I682bb52721b0cba14c2e459e0664c1293eeceeed
This commit is contained in:
@@ -38,6 +38,7 @@ import android.os.IStatsCompanionService;
|
|||||||
import android.os.IStatsd;
|
import android.os.IStatsd;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.StatsFrameworkInitializer;
|
import android.os.StatsFrameworkInitializer;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@@ -99,9 +100,9 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
private static IStatsd sStatsd;
|
private static IStatsd sStatsd;
|
||||||
private static final Object sStatsdLock = new Object();
|
private static final Object sStatsdLock = new Object();
|
||||||
|
|
||||||
private final OnAlarmListener mAnomalyAlarmListener = new AnomalyAlarmListener();
|
private final OnAlarmListener mAnomalyAlarmListener;
|
||||||
private final OnAlarmListener mPullingAlarmListener = new PullingAlarmListener();
|
private final OnAlarmListener mPullingAlarmListener;
|
||||||
private final OnAlarmListener mPeriodicAlarmListener = new PeriodicAlarmListener();
|
private final OnAlarmListener mPeriodicAlarmListener;
|
||||||
|
|
||||||
private StatsManagerService mStatsManagerService;
|
private StatsManagerService mStatsManagerService;
|
||||||
|
|
||||||
@@ -120,6 +121,9 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
handlerThread.start();
|
handlerThread.start();
|
||||||
mHandler = new CompanionHandler(handlerThread.getLooper());
|
mHandler = new CompanionHandler(handlerThread.getLooper());
|
||||||
|
|
||||||
|
mAnomalyAlarmListener = new AnomalyAlarmListener(context);
|
||||||
|
mPullingAlarmListener = new PullingAlarmListener(context);
|
||||||
|
mPeriodicAlarmListener = new PeriodicAlarmListener(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int[] toIntArray(List<Integer> list) {
|
private final static int[] toIntArray(List<Integer> list) {
|
||||||
@@ -232,6 +236,31 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class WakelockThread extends Thread {
|
||||||
|
private final PowerManager.WakeLock mWl;
|
||||||
|
private final Runnable mRunnable;
|
||||||
|
|
||||||
|
WakelockThread(Context context, String wakelockName, Runnable runnable) {
|
||||||
|
PowerManager powerManager = (PowerManager)
|
||||||
|
context.getSystemService(Context.POWER_SERVICE);
|
||||||
|
mWl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, wakelockName);
|
||||||
|
mRunnable = runnable;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
mRunnable.run();
|
||||||
|
} finally {
|
||||||
|
mWl.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
mWl.acquire();
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final static class AppUpdateReceiver extends BroadcastReceiver {
|
private final static class AppUpdateReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -307,6 +336,12 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class AnomalyAlarmListener implements OnAlarmListener {
|
public static final class AnomalyAlarmListener implements OnAlarmListener {
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
AnomalyAlarmListener(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAlarm() {
|
public void onAlarm() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -318,17 +353,30 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
Log.w(TAG, "Could not access statsd to inform it of anomaly alarm firing");
|
Log.w(TAG, "Could not access statsd to inform it of anomaly alarm firing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
// Two-way call to statsd to retain AlarmManager wakelock
|
// Wakelock needs to be retained while calling statsd.
|
||||||
statsd.informAnomalyAlarmFired();
|
Thread thread = new WakelockThread(mContext,
|
||||||
} catch (RemoteException e) {
|
AnomalyAlarmListener.class.getCanonicalName(), new Runnable() {
|
||||||
Log.w(TAG, "Failed to inform statsd of anomaly alarm firing", e);
|
@Override
|
||||||
}
|
public void run() {
|
||||||
// AlarmManager releases its own wakelock here.
|
try {
|
||||||
|
statsd.informAnomalyAlarmFired();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Failed to inform statsd of anomaly alarm firing", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static class PullingAlarmListener implements OnAlarmListener {
|
public final static class PullingAlarmListener implements OnAlarmListener {
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
PullingAlarmListener(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAlarm() {
|
public void onAlarm() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -339,16 +387,30 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
Log.w(TAG, "Could not access statsd to inform it of pulling alarm firing.");
|
Log.w(TAG, "Could not access statsd to inform it of pulling alarm firing.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
// Two-way call to statsd to retain AlarmManager wakelock
|
// Wakelock needs to be retained while calling statsd.
|
||||||
statsd.informPollAlarmFired();
|
Thread thread = new WakelockThread(mContext,
|
||||||
} catch (RemoteException e) {
|
PullingAlarmListener.class.getCanonicalName(), new Runnable() {
|
||||||
Log.w(TAG, "Failed to inform statsd of pulling alarm firing.", e);
|
@Override
|
||||||
}
|
public void run() {
|
||||||
|
try {
|
||||||
|
statsd.informPollAlarmFired();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Failed to inform statsd of pulling alarm firing.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static class PeriodicAlarmListener implements OnAlarmListener {
|
public final static class PeriodicAlarmListener implements OnAlarmListener {
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
PeriodicAlarmListener(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAlarm() {
|
public void onAlarm() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -359,13 +421,20 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
Log.w(TAG, "Could not access statsd to inform it of periodic alarm firing.");
|
Log.w(TAG, "Could not access statsd to inform it of periodic alarm firing.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
// Two-way call to statsd to retain AlarmManager wakelock
|
// Wakelock needs to be retained while calling statsd.
|
||||||
statsd.informAlarmForSubscriberTriggeringFired();
|
Thread thread = new WakelockThread(mContext,
|
||||||
} catch (RemoteException e) {
|
PeriodicAlarmListener.class.getCanonicalName(), new Runnable() {
|
||||||
Log.w(TAG, "Failed to inform statsd of periodic alarm firing.", e);
|
@Override
|
||||||
}
|
public void run() {
|
||||||
// AlarmManager releases its own wakelock here.
|
try {
|
||||||
|
statsd.informAlarmForSubscriberTriggeringFired();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Failed to inform statsd of periodic alarm firing.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user