1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.fuelgauge.batterytip; 18 19 import android.app.StatsManager; 20 import android.content.BroadcastReceiver; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.util.Log; 24 25 /** 26 * Receive broadcast when {@link StatsManager} restart, then check the anomaly config and 27 * prepare info for {@link StatsManager} 28 */ 29 public class AnomalyConfigReceiver extends BroadcastReceiver { 30 private static final String TAG = "AnomalyConfigReceiver"; 31 32 @Override onReceive(Context context, Intent intent)33 public void onReceive(Context context, Intent intent) { 34 if (StatsManager.ACTION_STATSD_STARTED.equals(intent.getAction()) 35 || Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { 36 final StatsManager statsManager = context.getSystemService(StatsManager.class); 37 38 // Check whether to update the config 39 AnomalyConfigJobService.scheduleConfigUpdate(context); 40 41 try { 42 BatteryTipUtils.uploadAnomalyPendingIntent(context, statsManager); 43 } catch (StatsManager.StatsUnavailableException e) { 44 Log.w(TAG, "Failed to uploadAnomalyPendingIntent.", e); 45 } 46 47 if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { 48 AnomalyCleanupJobService.scheduleCleanUp(context); 49 } 50 } 51 } 52 } 53