Merge changes from topic "presubmit-am-a857ce8919bc4bb7802485a10b458590" into sc-v2-dev-plus-aosp
* changes:
[automerge] Secure REMOTE_BUGREPORT_DISPATCH 2p: f62904fd70
Secure REMOTE_BUGREPORT_DISPATCH
This commit is contained in:
@@ -445,7 +445,7 @@ interface IActivityManager {
|
|||||||
|
|
||||||
void requestInteractiveBugReport();
|
void requestInteractiveBugReport();
|
||||||
void requestFullBugReport();
|
void requestFullBugReport();
|
||||||
void requestRemoteBugReport();
|
void requestRemoteBugReport(long nonce);
|
||||||
boolean launchBugReportHandlerApp();
|
boolean launchBugReportHandlerApp();
|
||||||
List<String> getBugreportWhitelistedPackages();
|
List<String> getBugreportWhitelistedPackages();
|
||||||
|
|
||||||
|
|||||||
@@ -498,6 +498,14 @@ public class DevicePolicyManager {
|
|||||||
public static final String EXTRA_REMOTE_BUGREPORT_HASH =
|
public static final String EXTRA_REMOTE_BUGREPORT_HASH =
|
||||||
"android.intent.extra.REMOTE_BUGREPORT_HASH";
|
"android.intent.extra.REMOTE_BUGREPORT_HASH";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra for shared bugreport's nonce in long integer type.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_REMOTE_BUGREPORT_NONCE =
|
||||||
|
"android.intent.extra.REMOTE_BUGREPORT_NONCE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra for remote bugreport notification shown type.
|
* Extra for remote bugreport notification shown type.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ public class BugreportProgressService extends Service {
|
|||||||
|
|
||||||
static final String EXTRA_BUGREPORT = "android.intent.extra.BUGREPORT";
|
static final String EXTRA_BUGREPORT = "android.intent.extra.BUGREPORT";
|
||||||
static final String EXTRA_BUGREPORT_TYPE = "android.intent.extra.BUGREPORT_TYPE";
|
static final String EXTRA_BUGREPORT_TYPE = "android.intent.extra.BUGREPORT_TYPE";
|
||||||
|
static final String EXTRA_BUGREPORT_NONCE = "android.intent.extra.BUGREPORT_NONCE";
|
||||||
static final String EXTRA_SCREENSHOT = "android.intent.extra.SCREENSHOT";
|
static final String EXTRA_SCREENSHOT = "android.intent.extra.SCREENSHOT";
|
||||||
static final String EXTRA_ID = "android.intent.extra.ID";
|
static final String EXTRA_ID = "android.intent.extra.ID";
|
||||||
static final String EXTRA_NAME = "android.intent.extra.NAME";
|
static final String EXTRA_NAME = "android.intent.extra.NAME";
|
||||||
@@ -415,7 +416,7 @@ public class BugreportProgressService extends Service {
|
|||||||
final String bugreportFilePath = mInfo.bugreportFile.getAbsolutePath();
|
final String bugreportFilePath = mInfo.bugreportFile.getAbsolutePath();
|
||||||
if (mInfo.type == BugreportParams.BUGREPORT_MODE_REMOTE) {
|
if (mInfo.type == BugreportParams.BUGREPORT_MODE_REMOTE) {
|
||||||
sendRemoteBugreportFinishedBroadcast(mContext, bugreportFilePath,
|
sendRemoteBugreportFinishedBroadcast(mContext, bugreportFilePath,
|
||||||
mInfo.bugreportFile);
|
mInfo.bugreportFile, mInfo.nonce);
|
||||||
} else {
|
} else {
|
||||||
cleanupOldFiles(MIN_KEEP_COUNT, MIN_KEEP_AGE, mBugreportsDir);
|
cleanupOldFiles(MIN_KEEP_COUNT, MIN_KEEP_AGE, mBugreportsDir);
|
||||||
final Intent intent = new Intent(INTENT_BUGREPORT_FINISHED);
|
final Intent intent = new Intent(INTENT_BUGREPORT_FINISHED);
|
||||||
@@ -428,7 +429,7 @@ public class BugreportProgressService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void sendRemoteBugreportFinishedBroadcast(Context context,
|
private static void sendRemoteBugreportFinishedBroadcast(Context context,
|
||||||
String bugreportFileName, File bugreportFile) {
|
String bugreportFileName, File bugreportFile, long nonce) {
|
||||||
cleanupOldFiles(REMOTE_BUGREPORT_FILES_AMOUNT, REMOTE_MIN_KEEP_AGE,
|
cleanupOldFiles(REMOTE_BUGREPORT_FILES_AMOUNT, REMOTE_MIN_KEEP_AGE,
|
||||||
bugreportFile.getParentFile());
|
bugreportFile.getParentFile());
|
||||||
final Intent intent = new Intent(DevicePolicyManager.ACTION_REMOTE_BUGREPORT_DISPATCH);
|
final Intent intent = new Intent(DevicePolicyManager.ACTION_REMOTE_BUGREPORT_DISPATCH);
|
||||||
@@ -439,6 +440,7 @@ public class BugreportProgressService extends Service {
|
|||||||
}
|
}
|
||||||
intent.setDataAndType(bugreportUri, BUGREPORT_MIMETYPE);
|
intent.setDataAndType(bugreportUri, BUGREPORT_MIMETYPE);
|
||||||
intent.putExtra(DevicePolicyManager.EXTRA_REMOTE_BUGREPORT_HASH, bugreportHash);
|
intent.putExtra(DevicePolicyManager.EXTRA_REMOTE_BUGREPORT_HASH, bugreportHash);
|
||||||
|
intent.putExtra(DevicePolicyManager.EXTRA_REMOTE_BUGREPORT_NONCE, nonce);
|
||||||
intent.putExtra(EXTRA_BUGREPORT, bugreportFileName);
|
intent.putExtra(EXTRA_BUGREPORT, bugreportFileName);
|
||||||
context.sendBroadcastAsUser(intent, UserHandle.SYSTEM,
|
context.sendBroadcastAsUser(intent, UserHandle.SYSTEM,
|
||||||
android.Manifest.permission.DUMP);
|
android.Manifest.permission.DUMP);
|
||||||
@@ -613,11 +615,12 @@ public class BugreportProgressService extends Service {
|
|||||||
String shareDescription = intent.getStringExtra(EXTRA_DESCRIPTION);
|
String shareDescription = intent.getStringExtra(EXTRA_DESCRIPTION);
|
||||||
int bugreportType = intent.getIntExtra(EXTRA_BUGREPORT_TYPE,
|
int bugreportType = intent.getIntExtra(EXTRA_BUGREPORT_TYPE,
|
||||||
BugreportParams.BUGREPORT_MODE_INTERACTIVE);
|
BugreportParams.BUGREPORT_MODE_INTERACTIVE);
|
||||||
|
long nonce = intent.getLongExtra(EXTRA_BUGREPORT_NONCE, 0);
|
||||||
String baseName = getBugreportBaseName(bugreportType);
|
String baseName = getBugreportBaseName(bugreportType);
|
||||||
String name = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
|
String name = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
|
||||||
|
|
||||||
BugreportInfo info = new BugreportInfo(mContext, baseName, name,
|
BugreportInfo info = new BugreportInfo(mContext, baseName, name,
|
||||||
shareTitle, shareDescription, bugreportType, mBugreportsDir);
|
shareTitle, shareDescription, bugreportType, mBugreportsDir, nonce);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (info.bugreportFile.exists()) {
|
if (info.bugreportFile.exists()) {
|
||||||
Log.e(TAG, "Failed to start bugreport generation, the requested bugreport file "
|
Log.e(TAG, "Failed to start bugreport generation, the requested bugreport file "
|
||||||
@@ -1915,6 +1918,11 @@ public class BugreportProgressService extends Service {
|
|||||||
*/
|
*/
|
||||||
final int type;
|
final int type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nonce of the bugreport
|
||||||
|
*/
|
||||||
|
final long nonce;
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1922,12 +1930,13 @@ public class BugreportProgressService extends Service {
|
|||||||
*/
|
*/
|
||||||
BugreportInfo(Context context, String baseName, String name,
|
BugreportInfo(Context context, String baseName, String name,
|
||||||
@Nullable String shareTitle, @Nullable String shareDescription,
|
@Nullable String shareTitle, @Nullable String shareDescription,
|
||||||
@BugreportParams.BugreportMode int type, File bugreportsDir) {
|
@BugreportParams.BugreportMode int type, File bugreportsDir, long nonce) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.name = this.initialName = name;
|
this.name = this.initialName = name;
|
||||||
this.shareTitle = shareTitle == null ? "" : shareTitle;
|
this.shareTitle = shareTitle == null ? "" : shareTitle;
|
||||||
this.shareDescription = shareDescription == null ? "" : shareDescription;
|
this.shareDescription = shareDescription == null ? "" : shareDescription;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.nonce = nonce;
|
||||||
this.baseName = baseName;
|
this.baseName = baseName;
|
||||||
this.bugreportFile = new File(bugreportsDir, getFileName(this, ".zip"));
|
this.bugreportFile = new File(bugreportsDir, getFileName(this, ".zip"));
|
||||||
}
|
}
|
||||||
@@ -2167,6 +2176,7 @@ public class BugreportProgressService extends Service {
|
|||||||
screenshotCounter = in.readInt();
|
screenshotCounter = in.readInt();
|
||||||
shareDescription = in.readString();
|
shareDescription = in.readString();
|
||||||
type = in.readInt();
|
type = in.readInt();
|
||||||
|
nonce = in.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2195,6 +2205,7 @@ public class BugreportProgressService extends Service {
|
|||||||
dest.writeInt(screenshotCounter);
|
dest.writeInt(screenshotCounter);
|
||||||
dest.writeString(shareDescription);
|
dest.writeString(shareDescription);
|
||||||
dest.writeInt(type);
|
dest.writeInt(type);
|
||||||
|
dest.writeLong(nonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -544,6 +544,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
static final String EXTRA_TITLE = "android.intent.extra.TITLE";
|
static final String EXTRA_TITLE = "android.intent.extra.TITLE";
|
||||||
static final String EXTRA_DESCRIPTION = "android.intent.extra.DESCRIPTION";
|
static final String EXTRA_DESCRIPTION = "android.intent.extra.DESCRIPTION";
|
||||||
static final String EXTRA_BUGREPORT_TYPE = "android.intent.extra.BUGREPORT_TYPE";
|
static final String EXTRA_BUGREPORT_TYPE = "android.intent.extra.BUGREPORT_TYPE";
|
||||||
|
static final String EXTRA_BUGREPORT_NONCE = "android.intent.extra.BUGREPORT_NONCE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of bytes that {@link #setProcessStateSummary} accepts.
|
* The maximum number of bytes that {@link #setProcessStateSummary} accepts.
|
||||||
@@ -6598,7 +6599,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void requestBugReport(@BugreportParams.BugreportMode int bugreportType) {
|
public void requestBugReport(@BugreportParams.BugreportMode int bugreportType) {
|
||||||
requestBugReportWithDescription(null, null, bugreportType);
|
requestBugReportWithDescription(null, null, bugreportType, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6608,6 +6609,15 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public void requestBugReportWithDescription(@Nullable String shareTitle,
|
public void requestBugReportWithDescription(@Nullable String shareTitle,
|
||||||
@Nullable String shareDescription, int bugreportType) {
|
@Nullable String shareDescription, int bugreportType) {
|
||||||
|
requestBugReportWithDescription(shareTitle, shareDescription, bugreportType, /*nonce*/ 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a bugreport using bug report API ({@code BugreportManager}) which gets
|
||||||
|
* triggered by sending a broadcast to Shell.
|
||||||
|
*/
|
||||||
|
public void requestBugReportWithDescription(@Nullable String shareTitle,
|
||||||
|
@Nullable String shareDescription, int bugreportType, long nonce) {
|
||||||
String type = null;
|
String type = null;
|
||||||
switch (bugreportType) {
|
switch (bugreportType) {
|
||||||
case BugreportParams.BUGREPORT_MODE_FULL:
|
case BugreportParams.BUGREPORT_MODE_FULL:
|
||||||
@@ -6658,6 +6668,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
triggerShellBugreport.setAction(INTENT_BUGREPORT_REQUESTED);
|
triggerShellBugreport.setAction(INTENT_BUGREPORT_REQUESTED);
|
||||||
triggerShellBugreport.setPackage(SHELL_APP_PACKAGE);
|
triggerShellBugreport.setPackage(SHELL_APP_PACKAGE);
|
||||||
triggerShellBugreport.putExtra(EXTRA_BUGREPORT_TYPE, bugreportType);
|
triggerShellBugreport.putExtra(EXTRA_BUGREPORT_TYPE, bugreportType);
|
||||||
|
triggerShellBugreport.putExtra(EXTRA_BUGREPORT_NONCE, nonce);
|
||||||
triggerShellBugreport.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
triggerShellBugreport.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||||
triggerShellBugreport.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
|
triggerShellBugreport.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
|
||||||
if (shareTitle != null) {
|
if (shareTitle != null) {
|
||||||
@@ -6724,8 +6735,8 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
* Takes a bugreport remotely
|
* Takes a bugreport remotely
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void requestRemoteBugReport() {
|
public void requestRemoteBugReport(long nonce) {
|
||||||
requestBugReportWithDescription(null, null, BugreportParams.BUGREPORT_MODE_REMOTE);
|
requestBugReportWithDescription(null, null, BugreportParams.BUGREPORT_MODE_REMOTE, nonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.annotation.IntDef;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.admin.DeviceAdminReceiver;
|
import android.app.admin.DeviceAdminReceiver;
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -54,7 +55,9 @@ import com.android.server.utils.Slogf;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class managing bugreport collection upon device owner's request.
|
* Class managing bugreport collection upon device owner's request.
|
||||||
@@ -78,6 +81,9 @@ public class RemoteBugreportManager {
|
|||||||
private final DevicePolicyManagerService mService;
|
private final DevicePolicyManagerService mService;
|
||||||
private final DevicePolicyManagerService.Injector mInjector;
|
private final DevicePolicyManagerService.Injector mInjector;
|
||||||
|
|
||||||
|
private final SecureRandom mRng = new SecureRandom();
|
||||||
|
|
||||||
|
private final AtomicLong mRemoteBugreportNonce = new AtomicLong();
|
||||||
private final AtomicBoolean mRemoteBugreportServiceIsActive = new AtomicBoolean();
|
private final AtomicBoolean mRemoteBugreportServiceIsActive = new AtomicBoolean();
|
||||||
private final AtomicBoolean mRemoteBugreportSharingAccepted = new AtomicBoolean();
|
private final AtomicBoolean mRemoteBugreportSharingAccepted = new AtomicBoolean();
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -197,8 +203,13 @@ public class RemoteBugreportManager {
|
|||||||
|
|
||||||
final long callingIdentity = mInjector.binderClearCallingIdentity();
|
final long callingIdentity = mInjector.binderClearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
mInjector.getIActivityManager().requestRemoteBugReport();
|
long nonce;
|
||||||
|
do {
|
||||||
|
nonce = mRng.nextLong();
|
||||||
|
} while (nonce == 0);
|
||||||
|
mInjector.getIActivityManager().requestRemoteBugReport(nonce);
|
||||||
|
|
||||||
|
mRemoteBugreportNonce.set(nonce);
|
||||||
mRemoteBugreportServiceIsActive.set(true);
|
mRemoteBugreportServiceIsActive.set(true);
|
||||||
mRemoteBugreportSharingAccepted.set(false);
|
mRemoteBugreportSharingAccepted.set(false);
|
||||||
registerRemoteBugreportReceivers();
|
registerRemoteBugreportReceivers();
|
||||||
@@ -231,6 +242,11 @@ public class RemoteBugreportManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onBugreportFinished(Intent intent) {
|
private void onBugreportFinished(Intent intent) {
|
||||||
|
long nonce = intent.getLongExtra(DevicePolicyManager.EXTRA_REMOTE_BUGREPORT_NONCE, 0);
|
||||||
|
if (nonce == 0 || mRemoteBugreportNonce.get() != nonce) {
|
||||||
|
Slogf.w(LOG_TAG, "Invalid nonce provided, ignoring " + nonce);
|
||||||
|
return;
|
||||||
|
}
|
||||||
mHandler.removeCallbacks(mRemoteBugreportTimeoutRunnable);
|
mHandler.removeCallbacks(mRemoteBugreportTimeoutRunnable);
|
||||||
mRemoteBugreportServiceIsActive.set(false);
|
mRemoteBugreportServiceIsActive.set(false);
|
||||||
final Uri bugreportUri = intent.getData();
|
final Uri bugreportUri = intent.getData();
|
||||||
|
|||||||
Reference in New Issue
Block a user