Skip to content

Commit 1227233

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Bugreport in Quick Settings (if you turn it on)." into jb-mr1-dev
2 parents a2facc3 + c19d448 commit 1227233

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 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+
<TextView
17+
xmlns:android="http://schemas.android.com/apk/res/android"
18+
style="@style/TextAppearance.QuickSettings.TileView"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:layout_gravity="center"
22+
android:gravity="center"
23+
android:drawableTop="@*android:drawable/stat_sys_adb"
24+
android:text="@*android:string/bugreport_title"
25+
/>

packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
package com.android.systemui.statusbar.phone;
1818

19+
import android.app.AlertDialog;
1920
import android.app.Dialog;
2021
import android.app.PendingIntent;
22+
import android.app.AlertDialog.Builder;
2123
import android.bluetooth.BluetoothDevice;
2224
import android.content.BroadcastReceiver;
2325
import android.content.ComponentName;
2426
import android.content.Context;
2527
import android.content.CursorLoader;
2628
import android.content.DialogInterface;
29+
import android.content.DialogInterface.OnClickListener;
2730
import android.content.Intent;
2831
import android.content.IntentFilter;
2932
import android.content.Loader;
@@ -37,6 +40,7 @@
3740
import android.hardware.display.WifiDisplayStatus;
3841
import android.net.Uri;
3942
import android.os.Debug;
43+
import android.os.SystemProperties;
4044
import android.provider.ContactsContract;
4145
import android.provider.Settings;
4246
import android.view.LayoutInflater;
@@ -521,6 +525,24 @@ public void refreshView(QuickSettingsTileView view, State state) {
521525
});
522526
parent.addView(imeTile);
523527

528+
// Bug reports
529+
QuickSettingsTileView bugreportTile = (QuickSettingsTileView)
530+
inflater.inflate(R.layout.quick_settings_tile, parent, false);
531+
bugreportTile.setContent(R.layout.quick_settings_tile_bugreport, inflater);
532+
bugreportTile.setOnClickListener(new View.OnClickListener() {
533+
@Override
534+
public void onClick(View v) {
535+
mBar.collapseAllPanels(true);
536+
showBugreportDialog();
537+
}
538+
});
539+
mModel.addBugreportTile(bugreportTile, new QuickSettingsModel.RefreshCallback() {
540+
@Override
541+
public void refreshView(QuickSettingsTileView view, State state) {
542+
view.setVisibility(state.enabled ? View.VISIBLE : View.GONE);
543+
}
544+
});
545+
parent.addView(bugreportTile);
524546
/*
525547
QuickSettingsTileView mediaTile = (QuickSettingsTileView)
526548
inflater.inflate(R.layout.quick_settings_tile, parent, false);
@@ -575,6 +597,24 @@ public void onDismiss(DialogInterface dialog) {
575597
}
576598
}
577599

600+
private void showBugreportDialog() {
601+
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
602+
builder.setPositiveButton(com.android.internal.R.string.report, new OnClickListener() {
603+
@Override
604+
public void onClick(DialogInterface dialog, int which) {
605+
if (which == DialogInterface.BUTTON_POSITIVE) {
606+
SystemProperties.set("ctl.start", "bugreport");
607+
}
608+
}
609+
});
610+
builder.setMessage(com.android.internal.R.string.bugreport_message);
611+
builder.setTitle(com.android.internal.R.string.bugreport_title);
612+
builder.setCancelable(true);
613+
final Dialog dialog = builder.create();
614+
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
615+
dialog.show();
616+
}
617+
578618
private void updateWifiDisplayStatus() {
579619
mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
580620
applyWifiDisplayStatus();
@@ -595,4 +635,4 @@ public void onReceive(Context context, Intent intent) {
595635
}
596636
}
597637
};
598-
}
638+
}

packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.hardware.display.WifiDisplayStatus;
3131
import android.os.Handler;
3232
import android.provider.Settings;
33+
import android.provider.Settings.SettingNotFoundException;
3334
import android.text.TextUtils;
3435
import android.view.View;
3536
import android.view.inputmethod.InputMethodInfo;
@@ -107,9 +108,26 @@ public void startObserving() {
107108
}
108109
}
109110

111+
/** ContentObserver to watch adb */
112+
private class BugreportObserver extends ContentObserver {
113+
public BugreportObserver(Handler handler) {
114+
super(handler);
115+
}
116+
117+
@Override public void onChange(boolean selfChange) {
118+
onBugreportChanged();
119+
}
120+
121+
public void startObserving() {
122+
final ContentResolver cr = mContext.getContentResolver();
123+
cr.registerContentObserver(
124+
Settings.Secure.getUriFor(Settings.Secure.BUGREPORT_IN_POWER_MENU), false, this);
125+
}
126+
}
110127
private Context mContext;
111128
private Handler mHandler;
112129
private NextAlarmObserver mNextAlarmObserver;
130+
private BugreportObserver mBugreportObserver;
113131

114132
private QuickSettingsTileView mUserTile;
115133
private RefreshCallback mUserCallback;
@@ -159,11 +177,17 @@ public void startObserving() {
159177
private RefreshCallback mBrightnessCallback;
160178
private BrightnessState mBrightnessState = new BrightnessState();
161179

180+
private QuickSettingsTileView mBugreportTile;
181+
private RefreshCallback mBugreportCallback;
182+
private State mBugreportState = new State();
183+
162184
public QuickSettingsModel(Context context) {
163185
mContext = context;
164186
mHandler = new Handler();
165187
mNextAlarmObserver = new NextAlarmObserver(mHandler);
166188
mNextAlarmObserver.startObserving();
189+
mBugreportObserver = new BugreportObserver(mHandler);
190+
mBugreportObserver.startObserving();
167191

168192
IntentFilter alarmIntentFilter = new IntentFilter();
169193
alarmIntentFilter.addAction(Intent.ACTION_ALARM_CHANGED);
@@ -341,6 +365,25 @@ public void onLocationGpsStateChanged(boolean inUse, String description) {
341365
mLocationCallback.refreshView(mLocationTile, mLocationState);
342366
}
343367

368+
// Bug report
369+
void addBugreportTile(QuickSettingsTileView view, RefreshCallback cb) {
370+
mBugreportTile = view;
371+
mBugreportCallback = cb;
372+
onBugreportChanged();
373+
}
374+
// SettingsObserver callback
375+
public void onBugreportChanged() {
376+
final ContentResolver cr = mContext.getContentResolver();
377+
boolean enabled = false;
378+
try {
379+
enabled = (Settings.Secure.getInt(cr, Settings.Secure.BUGREPORT_IN_POWER_MENU) != 0);
380+
} catch (SettingNotFoundException e) {
381+
}
382+
383+
mBugreportState.enabled = enabled;
384+
mBugreportCallback.refreshView(mBugreportTile, mBugreportState);
385+
}
386+
344387
// Wifi Display
345388
void addWifiDisplayTile(QuickSettingsTileView view, RefreshCallback cb) {
346389
mWifiDisplayTile = view;

0 commit comments

Comments
 (0)