Merge "Alternative to @hide FLAG_RECEIVER_INCLUDE_BACKGROUND" into rvc-dev am: 0a2c6864e7 am: 5a0b0fb17c

Change-Id: Ia6a2f678fd9aec1378e04e0d1ac2b1581faf2b3b
This commit is contained in:
Automerger Merge Worker
2020-02-26 17:37:56 +00:00

View File

@@ -21,11 +21,13 @@ import android.app.AlarmManager;
import android.app.AlarmManager.OnAlarmListener; import android.app.AlarmManager.OnAlarmListener;
import android.app.StatsManager; import android.app.StatsManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Binder; import android.os.Binder;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@@ -85,12 +87,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
public static final int DEATH_THRESHOLD = 10; public static final int DEATH_THRESHOLD = 10;
// TODO(b/149090705): Implement an alternative to sending broadcast with @hide flag
// FLAG_RECEIVER_INCLUDE_BACKGROUND. Instead of using the flag, find the
// list of registered broadcast receivers and send them directed broadcasts
// to wake them up. See b/147374337.
private static final int FLAG_RECEIVER_INCLUDE_BACKGROUND = 0x01000000;
static final class CompanionHandler extends Handler { static final class CompanionHandler extends Handler {
CompanionHandler(Looper looper) { CompanionHandler(Looper looper) {
super(looper); super(looper);
@@ -498,9 +494,25 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
Log.d(TAG, "learned that statsdReady"); Log.d(TAG, "learned that statsdReady");
} }
sayHiToStatsd(); // tell statsd that we're ready too and link to it sayHiToStatsd(); // tell statsd that we're ready too and link to it
mContext.sendBroadcastAsUser(new Intent(StatsManager.ACTION_STATSD_STARTED)
.addFlags(FLAG_RECEIVER_INCLUDE_BACKGROUND), final Intent intent = new Intent(StatsManager.ACTION_STATSD_STARTED);
UserHandle.SYSTEM, android.Manifest.permission.DUMP); // Retrieve list of broadcast receivers for this broadcast & send them directed broadcasts
// to wake them up (if they're in background).
List<ResolveInfo> resolveInfos =
mContext.getPackageManager().queryBroadcastReceiversAsUser(
intent, 0, UserHandle.SYSTEM);
if (resolveInfos == null || resolveInfos.isEmpty()) {
return; // No need to send broadcast.
}
for (ResolveInfo resolveInfo : resolveInfos) {
Intent intentToSend = new Intent(intent);
intentToSend.setComponent(new ComponentName(
resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name));
mContext.sendBroadcastAsUser(intentToSend, UserHandle.SYSTEM,
android.Manifest.permission.DUMP);
}
} }
@Override @Override