1 /*
2  * Copyright (C) 2019 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.shell;
18 
19 import static com.android.shell.BugreportProgressService.EXTRA_ORIGINAL_INTENT;
20 import static com.android.shell.BugreportProgressService.dumpIntent;
21 
22 import android.annotation.RequiresPermission;
23 import android.content.BroadcastReceiver;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.util.Log;
27 
28 /**
29  * Receiver that listens to {@link Intent#INTENT_BUGREPORT_REQUESTED}
30  * and starts up BugreportProgressService to start a new bugreport
31  */
32 public class BugreportRequestedReceiver extends BroadcastReceiver {
33     private static final String TAG = "BugreportRequestedReceiver";
34 
35     @Override
36     @RequiresPermission(android.Manifest.permission.TRIGGER_SHELL_BUGREPORT)
onReceive(Context context, Intent intent)37     public void onReceive(Context context, Intent intent) {
38         Log.d(TAG, "onReceive(): " + dumpIntent(intent));
39 
40         // Delegate intent handling to service.
41         Intent serviceIntent = new Intent(context, BugreportProgressService.class);
42         Log.d(TAG, "onReceive() ACTION: " + serviceIntent.getAction());
43         serviceIntent.setAction(intent.getAction());
44         serviceIntent.putExtra(EXTRA_ORIGINAL_INTENT, intent);
45         context.startService(serviceIntent);
46     }
47 }
48