1 /* 2 * Copyright (C) 2016 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.traceur; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.SharedPreferences; 22 import android.graphics.drawable.Icon; 23 import android.preference.PreferenceManager; 24 import android.service.quicksettings.Tile; 25 import android.service.quicksettings.TileService; 26 27 public class QsService extends TileService { 28 29 private static QsService sListeningInstance; 30 updateTile()31 public static void updateTile() { 32 if (sListeningInstance != null) { 33 sListeningInstance.update(); 34 } 35 } 36 37 @Override onStartListening()38 public void onStartListening() { 39 sListeningInstance = this; 40 update(); 41 } 42 43 @Override onStopListening()44 public void onStopListening() { 45 if (sListeningInstance == this) { 46 sListeningInstance = null; 47 } 48 } 49 update()50 private void update() { 51 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 52 boolean tracingOn = prefs.getBoolean(getString(R.string.pref_key_tracing_on), false); 53 54 String titleString = getString(tracingOn ? R.string.stop_tracing: R.string.record_trace); 55 56 getQsTile().setIcon(Icon.createWithResource(this, R.drawable.bugfood_icon)); 57 getQsTile().setState(tracingOn ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); 58 getQsTile().setLabel(titleString); 59 getQsTile().updateTile(); 60 Receiver.updateDeveloperOptionsWatcher(this); 61 } 62 63 /** When we click the tile, toggle tracing state. 64 * If tracing is being turned off, dump and offer to share. */ 65 @Override onClick()66 public void onClick() { 67 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 68 boolean newTracingState = !prefs.getBoolean(getString(R.string.pref_key_tracing_on), false); 69 prefs.edit().putBoolean(getString(R.string.pref_key_tracing_on), newTracingState).commit(); 70 71 Receiver.updateTracing(this); 72 } 73 } 74