OSDN Git Service

Modifying Shell to accomodate remote bugreports
authorMichal Karpinski <mkarpinski@google.com>
Tue, 15 Dec 2015 18:14:26 +0000 (18:14 +0000)
committerMichal Karpinski <mkarpinski@google.com>
Thu, 7 Jan 2016 20:02:13 +0000 (20:02 +0000)
After receiving android.intent.action.REMOTE_BUGREPORT_FINISHED
in newly created RemoteBugreportReceiver, Shell will generate URI
to the bugreport zip file and send the broadcast
android.intent.action.REMOTE_BUGREPORT_DISPATCH.

Bug: 26152603
Change-Id: I058d626e021b488c9347b45467a4e3505134e79c

core/res/AndroidManifest.xml
packages/Shell/AndroidManifest.xml
packages/Shell/src/com/android/shell/BugreportProgressService.java
packages/Shell/src/com/android/shell/BugreportReceiver.java
packages/Shell/src/com/android/shell/RemoteBugreportReceiver.java [new file with mode: 0644]

index 58dfd81..7d9fd93 100644 (file)
     <protected-broadcast android:name="android.intent.action.AIRPLANE_MODE" />
     <protected-broadcast android:name="android.intent.action.ADVANCED_SETTINGS" />
     <protected-broadcast android:name="android.intent.action.APPLICATION_RESTRICTIONS_CHANGED" />
-    <protected-broadcast android:name="android.intent.action.BUGREPORT_FINISHED" />
     <protected-broadcast android:name="android.intent.action.BUGREPORT_STARTED" />
+    <protected-broadcast android:name="android.intent.action.BUGREPORT_FINISHED" />
+    <protected-broadcast android:name="android.intent.action.REMOTE_BUGREPORT_FINISHED" />
+    <protected-broadcast android:name="android.intent.action.REMOTE_BUGREPORT_DISPATCH" />
 
     <protected-broadcast android:name="android.intent.action.ACTION_IDLE_MAINTENANCE_START" />
     <protected-broadcast android:name="android.intent.action.ACTION_IDLE_MAINTENANCE_END" />
index c6d9e98..7416fb5 100644 (file)
             </intent-filter>
         </receiver>
 
+        <receiver
+            android:name=".RemoteBugreportReceiver"
+            android:permission="android.permission.DUMP">
+            <intent-filter>
+                <action android:name="android.intent.action.REMOTE_BUGREPORT_FINISHED" />
+            </intent-filter>
+        </receiver>
+
         <service
             android:name=".BugreportProgressService"
             android:exported="false"/>
index 00a6cbd..5c807e1 100644 (file)
@@ -116,6 +116,10 @@ public class BugreportProgressService extends Service {
     // External intents sent by dumpstate.
     static final String INTENT_BUGREPORT_STARTED = "android.intent.action.BUGREPORT_STARTED";
     static final String INTENT_BUGREPORT_FINISHED = "android.intent.action.BUGREPORT_FINISHED";
+    static final String INTENT_REMOTE_BUGREPORT_FINISHED =
+            "android.intent.action.REMOTE_BUGREPORT_FINISHED";
+    static final String INTENT_REMOTE_BUGREPORT_DISPATCH =
+            "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
 
     // Internal intents used on notification actions.
     static final String INTENT_BUGREPORT_CANCEL = "android.intent.action.BUGREPORT_CANCEL";
@@ -1005,7 +1009,7 @@ public class BugreportProgressService extends Service {
         return foundAccount;
     }
 
-    private static Uri getUri(Context context, File file) {
+    static Uri getUri(Context context, File file) {
         return file != null ? FileProvider.getUriForFile(context, AUTHORITY, file) : null;
     }
 
index b818343..c8898b9 100644 (file)
@@ -52,7 +52,7 @@ public class BugreportReceiver extends BroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
         // Clean up older bugreports in background
-        cleanupOldFiles(intent);
+        cleanupOldFiles(this, intent, INTENT_BUGREPORT_FINISHED, MIN_KEEP_COUNT, MIN_KEEP_AGE);
 
         // Delegate intent handling to service.
         Intent serviceIntent = new Intent(context, BugreportProgressService.class);
@@ -60,8 +60,9 @@ public class BugreportReceiver extends BroadcastReceiver {
         context.startService(serviceIntent);
     }
 
-    private void cleanupOldFiles(Intent intent) {
-        if (!INTENT_BUGREPORT_FINISHED.equals(intent.getAction())) {
+    static void cleanupOldFiles(BroadcastReceiver br, Intent intent, String expectedAction,
+            final int minCount, final long minAge) {
+        if (!expectedAction.equals(intent.getAction())) {
             return;
         }
         final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT);
@@ -69,12 +70,11 @@ public class BugreportReceiver extends BroadcastReceiver {
             Log.e(TAG, "Not deleting old files because file " + bugreportFile + " doesn't exist");
             return;
         }
-        final PendingResult result = goAsync();
+        final PendingResult result = br.goAsync();
         new AsyncTask<Void, Void, Void>() {
             @Override
             protected Void doInBackground(Void... params) {
-                FileUtils.deleteOlderFiles(
-                        bugreportFile.getParentFile(), MIN_KEEP_COUNT, MIN_KEEP_AGE);
+                FileUtils.deleteOlderFiles(bugreportFile.getParentFile(), minCount, minAge);
                 result.finish();
                 return null;
             }
diff --git a/packages/Shell/src/com/android/shell/RemoteBugreportReceiver.java b/packages/Shell/src/com/android/shell/RemoteBugreportReceiver.java
new file mode 100644 (file)
index 0000000..6f783a1
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 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.shell;
+
+import static com.android.shell.BugreportProgressService.EXTRA_BUGREPORT;
+import static com.android.shell.BugreportProgressService.INTENT_REMOTE_BUGREPORT_FINISHED;
+import static com.android.shell.BugreportProgressService.INTENT_REMOTE_BUGREPORT_DISPATCH;
+import static com.android.shell.BugreportProgressService.getFileExtra;
+import static com.android.shell.BugreportProgressService.getUri;
+import static com.android.shell.BugreportReceiver.cleanupOldFiles;
+
+import java.io.File;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.UserHandle;
+
+/**
+ * Receiver that handles finished remote bugreports, by re-sending
+ * the intent with appended bugreport zip file URI.
+ *
+ * <p> Remote bugreport never contains a screenshot.
+ */
+public class RemoteBugreportReceiver extends BroadcastReceiver {
+
+    private static final String BUGREPORT_MIMETYPE = "application/vnd.android.bugreport";
+    private static final String EXTRA_REMOTE_BUGREPORT_HASH =
+            "android.intent.extra.REMOTE_BUGREPORT_HASH";
+
+    /** Always keep just the last remote bugreport zip file */
+    private static final int MIN_KEEP_COUNT = 1;
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        cleanupOldFiles(this, intent, INTENT_REMOTE_BUGREPORT_FINISHED, MIN_KEEP_COUNT, 0);
+
+        final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT);
+        final Uri bugreportUri = getUri(context, bugreportFile);
+        final String bugreportHash = intent.getStringExtra(EXTRA_REMOTE_BUGREPORT_HASH);
+
+        final Intent newIntent = new Intent(INTENT_REMOTE_BUGREPORT_DISPATCH);
+        newIntent.setDataAndType(bugreportUri, BUGREPORT_MIMETYPE);
+        newIntent.putExtra(EXTRA_REMOTE_BUGREPORT_HASH, bugreportHash);
+        context.sendBroadcastAsUser(newIntent, UserHandle.SYSTEM,
+                android.Manifest.permission.DUMP);
+    }
+}