Add AnomalyConfigReceiver
This receiver receives the following intent: 1. android.app.action.STATSD_STARTED 2. android.intent.action.BOOT_COMPLETED Also it does: 1. Check whether to upload/update config(future cl) 2. Send PendingIntent to StatsManager Bug: 72385333 Test: Will add robo test once robo framework is updated(b/73172999) Change-Id: Iff7240663ecc1e080581683743b3027093945566
This commit is contained in:
@@ -3299,6 +3299,13 @@
|
|||||||
<receiver android:name=".fuelgauge.batterytip.AnomalyDetectionReceiver"
|
<receiver android:name=".fuelgauge.batterytip.AnomalyDetectionReceiver"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
|
<receiver android:name=".fuelgauge.batterytip.AnomalyConfigReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.app.action.STATSD_STARTED"/>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<!-- This is the longest AndroidManifest.xml ever. -->
|
<!-- This is the longest AndroidManifest.xml ever. -->
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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.settings.fuelgauge.batterytip;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.app.StatsManager;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Process;
|
||||||
|
import android.os.StatsDimensionsValue;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
import com.android.settings.fuelgauge.BatteryUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receive broadcast when {@link StatsManager} restart, then check the anomaly config and
|
||||||
|
* prepare info for {@link StatsManager}
|
||||||
|
*/
|
||||||
|
public class AnomalyConfigReceiver extends BroadcastReceiver {
|
||||||
|
private static final String TAG = "AnomalyConfigReceiver";
|
||||||
|
private static final int REQUEST_CODE = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (StatsManager.ACTION_STATSD_STARTED.equals(intent.getAction())
|
||||||
|
|| Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
||||||
|
final StatsManager statsManager = context.getSystemService(StatsManager.class);
|
||||||
|
|
||||||
|
//TODO(b/72385333): Check whether to update the config
|
||||||
|
final Intent extraIntent = new Intent();
|
||||||
|
extraIntent.setClass(context, AnomalyDetectionReceiver.class);
|
||||||
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
|
||||||
|
extraIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
uploadPendingIntent(statsManager, pendingIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void uploadPendingIntent(StatsManager statsManager, PendingIntent pendingIntent) {
|
||||||
|
Log.i(TAG, "Upload PendingIntent to StatsManager. configKey: "
|
||||||
|
+ StatsManagerConfig.ANOMALY_CONFIG_KEY + " subId: "
|
||||||
|
+ StatsManagerConfig.SUBSCRIBER_ID);
|
||||||
|
statsManager.setBroadcastSubscriber(StatsManagerConfig.ANOMALY_CONFIG_KEY,
|
||||||
|
StatsManagerConfig.SUBSCRIBER_ID, pendingIntent);
|
||||||
|
}
|
||||||
|
}
|
@@ -25,4 +25,9 @@ public class StatsManagerConfig {
|
|||||||
* This value is used in {@link android.app.StatsManager#addConfiguration(long, byte[])}
|
* This value is used in {@link android.app.StatsManager#addConfiguration(long, byte[])}
|
||||||
*/
|
*/
|
||||||
public static final long ANOMALY_CONFIG_KEY = 1;
|
public static final long ANOMALY_CONFIG_KEY = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The key that represents subscriber, which is settings app.
|
||||||
|
*/
|
||||||
|
public static final long SUBSCRIBER_ID = 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user