|
20 | 20 | import android.content.ContentResolver; |
21 | 21 | import android.content.Context; |
22 | 22 | import android.content.Intent; |
| 23 | +import android.database.ContentObserver; |
| 24 | +import android.os.Handler; |
23 | 25 | import android.provider.Settings; |
24 | 26 | import android.util.Log; |
25 | 27 |
|
|
29 | 31 | */ |
30 | 32 | public class BootReceiver extends BroadcastReceiver { |
31 | 33 | private static final String TAG = "SystemUIBootReceiver"; |
| 34 | + private Handler mHandler = new Handler(); |
| 35 | + private SettingsObserver mSettingsObserver; |
| 36 | + private Context mContext; |
| 37 | + |
| 38 | + private class SettingsObserver extends ContentObserver { |
| 39 | + SettingsObserver(Handler handler) { |
| 40 | + super(handler); |
| 41 | + } |
| 42 | + |
| 43 | + void observe() { |
| 44 | + mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor( |
| 45 | + Settings.Global.SHOW_CPU_OVERLAY), |
| 46 | + false, this); |
| 47 | + mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor( |
| 48 | + Settings.System.SHOW_FPS_OVERLAY), |
| 49 | + false, this); |
| 50 | + update(); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void onChange(boolean selfChange) { |
| 55 | + update(); |
| 56 | + } |
| 57 | + |
| 58 | + public void update() { |
| 59 | + Intent cpuinfo = new Intent(mContext, com.android.systemui.CPUInfoService.class); |
| 60 | + Intent fpsinfo = new Intent(mContext, com.android.systemui.FPSInfoService.class); |
| 61 | + if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SHOW_CPU_OVERLAY, 0) != 0) { |
| 62 | + mContext.startService(cpuinfo); |
| 63 | + } else { |
| 64 | + mContext.stopService(cpuinfo); |
| 65 | + } |
| 66 | + if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.SHOW_FPS_OVERLAY, 0) != 0) { |
| 67 | + mContext.startService(fpsinfo); |
| 68 | + } else { |
| 69 | + mContext.stopService(fpsinfo); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
32 | 73 |
|
33 | 74 | @Override |
34 | 75 | public void onReceive(final Context context, Intent intent) { |
35 | 76 | try { |
| 77 | + mContext = context; |
| 78 | + if (mSettingsObserver == null) { |
| 79 | + mSettingsObserver = new SettingsObserver(mHandler); |
| 80 | + mSettingsObserver.observe(); |
| 81 | + } |
| 82 | + |
36 | 83 | // Start the cpu info overlay, if activated |
37 | | - ContentResolver res = context.getContentResolver(); |
38 | | - if (Settings.Global.getInt(res, Settings.Global.SHOW_CPU_OVERLAY, 0) != 0) { |
39 | | - Intent cpuinfo = new Intent(context, com.android.systemui.CPUInfoService.class); |
40 | | - context.startService(cpuinfo); |
| 84 | + if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.SHOW_CPU_OVERLAY, 0) != 0) { |
| 85 | + Intent cpuinfo = new Intent(mContext, com.android.systemui.CPUInfoService.class); |
| 86 | + mContext.startService(cpuinfo); |
41 | 87 | } |
42 | 88 |
|
| 89 | + // Start the fps info overlay, if activated |
| 90 | + if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.SHOW_FPS_OVERLAY, 0) != 0) { |
| 91 | + Intent fpsinfo = new Intent(mContext, com.android.systemui.FPSInfoService.class); |
| 92 | + mContext.startService(fpsinfo); |
| 93 | + } |
| 94 | + |
43 | 95 | } catch (Exception e) { |
44 | | - Log.e(TAG, "Can't start cpuinfo service", e); |
| 96 | + Log.e(TAG, "Can't start load average service", e); |
45 | 97 | } |
46 | 98 | } |
47 | 99 | } |
0 commit comments