Skip to content

Commit

Permalink
AWS S3 bugreport test
Browse files Browse the repository at this point in the history
Change-Id: I4eb8724f0da5ebe8f3ac411f62749b88a6bbaa5b
  • Loading branch information
pondelion committed Oct 23, 2019
1 parent 2009228 commit 0e58b71
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/Shell/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ LOCAL_AIDL_INCLUDES = frameworks/native/cmds/dumpstate/binder

LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4

LOCAL_STATIC_JAVA_LIBRARIES += aws-android-sdk-core
LOCAL_STATIC_JAVA_LIBRARIES += aws-android-sdk-s3

LOCAL_PACKAGE_NAME := Shell
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
Expand All @@ -22,4 +25,12 @@ LOCAL_JACK_COVERAGE_INCLUDE_FILTER := com.android.shell.*

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
aws-android-sdk-core:../../../../prebuilts/misc/common/aws/aws-android-sdk-core.jar \
aws-android-sdk-s3:../../../../prebuilts/misc/common/aws/aws-android-sdk-s3.jar \

include $(BUILD_MULTI_PREBUILT)

include $(LOCAL_PATH)/tests/Android.mk
2 changes: 2 additions & 0 deletions packages/Shell/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
<uses-permission android:name="android.permission.CHANGE_OVERLAY_PACKAGES" />
<!-- Permission needed to access privileged VR APIs -->
<uses-permission android:name="android.permission.RESTRICTED_VR_ACCESS" />
<!-- AWS -->
<uses-permission android:name="android.permission.INTERNET" />

<application android:label="@string/app_label"
android:defaultToDeviceProtectedStorage="true"
Expand Down
23 changes: 23 additions & 0 deletions packages/Shell/src/com/android/shell/BugreportProgressService.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
import android.widget.EditText;
import android.widget.Toast;

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.PutObjectRequest;

/**
* Service used to keep progress of bugreport processes ({@code dumpstate}).
* <p>
Expand Down Expand Up @@ -791,6 +796,24 @@ private void onBugreportFinished(int id, Intent intent) {
Log.wtf(TAG, "Missing " + EXTRA_BUGREPORT + " on intent " + intent);
return;
}

try {
final String S3_ACCESS_KEY = "YOUR_ACCESS_KEY";
final String S3_SECRET_KEY = "YOUR_SECRET_KEY";
AmazonS3Client S3Client = new AmazonS3Client(
new BasicAWSCredentials(S3_ACCESS_KEY, S3_SECRET_KEY)
);
final String BUCKET_NAME = "aosp_test";
PutObjectRequest por = new PutObjectRequest(
BUCKET_NAME,
bugreportFile.getName(),
bugreportFile
);
S3Client.putObject(por);
} catch (final Exception e) {
Log.e(TAG, "Failed to save bugreport to S3", e);
}

mInfoDialog.onBugreportFinished();
BugreportInfo info = getInfo(id);
if (info == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.provider.Settings.SettingNotFoundException;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.os.Handler;
import android.os.RemoteException;

import com.android.systemui.R;
import com.android.systemui.qs.QSHost;
Expand All @@ -17,6 +19,7 @@ public class LoggingTile extends QSTileImpl<BooleanState> {

public static final String TAG = "LoggingTile";
public static final String LOGGING_SETTING = Settings.System.LOGGING_MODE;
private Handler mHandler = new Handler();

public LoggingTile(QSHost host) {
super(host);
Expand All @@ -29,6 +32,18 @@ public BooleanState newTileState() {

@Override
protected void handleClick() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
try {
ActivityManager.getService().requestBugReport(
ActivityManager.BUGREPORT_OPTION_INTERACTIVE
);
} catch (RemoteException e) {
Log.e(TAG, "requestBugReport() failed");
}
}
}, 500);
try {
boolean isEnabled = isLoggingModeEnabled();
Settings.System.putIntForUser(mContext.getContentResolver(), LOGGING_SETTING,
Expand Down

0 comments on commit 0e58b71

Please sign in to comment.