am 4b655fd1: am b045331f: Merge "Add GTS test to ensure valid default permission grants - framework" into mnc-dev

* commit '4b655fd193992afff948df513c7b9b9a0389972e':
  Add GTS test to ensure valid default permission grants - framework
This commit is contained in:
Svetoslav Ganov
2015-08-14 15:19:47 +00:00
committed by Android Git Automerger
8 changed files with 123 additions and 5 deletions

View File

@@ -43,6 +43,8 @@ interface IUiAutomationConnection {
void clearWindowAnimationFrameStats();
WindowAnimationFrameStats getWindowAnimationFrameStats();
void executeShellCommand(String command, in ParcelFileDescriptor fd);
void grantRuntimePermission(String packageName, String permission, int userId);
void revokeRuntimePermission(String packageName, String permission, int userId);
// Called from the system process.
oneway void shutdown();

View File

@@ -30,6 +30,7 @@ import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Log;
import android.view.Display;
import android.view.InputEvent;
@@ -845,6 +846,62 @@ public final class UiAutomation {
return null;
}
/**
* Grants a runtime permission to a package for a user.
* @param packageName The package to which to grant.
* @param permission The permission to grant.
* @return Whether granting succeeded.
*
* @hide
*/
public boolean grantRuntimePermission(String packageName, String permission,
UserHandle userHandle) {
synchronized (mLock) {
throwIfNotConnectedLocked();
}
try {
if (DEBUG) {
Log.i(LOG_TAG, "Granting runtime permission");
}
// Calling out without a lock held.
mUiAutomationConnection.grantRuntimePermission(packageName,
permission, userHandle.getIdentifier());
// TODO: The package manager API should return boolean.
return true;
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error granting runtime permission", re);
}
return false;
}
/**
* Revokes a runtime permission from a package for a user.
* @param packageName The package from which to revoke.
* @param permission The permission to revoke.
* @return Whether revoking succeeded.
*
* @hide
*/
public boolean revokeRuntimePermission(String packageName, String permission,
UserHandle userHandle) {
synchronized (mLock) {
throwIfNotConnectedLocked();
}
try {
if (DEBUG) {
Log.i(LOG_TAG, "Revoking runtime permission");
}
// Calling out without a lock held.
mUiAutomationConnection.revokeRuntimePermission(packageName,
permission, userHandle.getIdentifier());
// TODO: The package manager API should return boolean.
return true;
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error revoking runtime permission", re);
}
return false;
}
/**
* Executes a shell command. This method returs a file descriptor that points
* to the standard output stream. The command execution is similar to running

View File

@@ -19,6 +19,7 @@ package android.app;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.IAccessibilityServiceClient;
import android.content.Context;
import android.content.pm.IPackageManager;
import android.graphics.Bitmap;
import android.hardware.input.InputManager;
import android.os.Binder;
@@ -60,6 +61,9 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
private final IAccessibilityManager mAccessibilityManager = IAccessibilityManager.Stub
.asInterface(ServiceManager.getService(Service.ACCESSIBILITY_SERVICE));
private final IPackageManager mPackageManager = IPackageManager.Stub
.asInterface(ServiceManager.getService("package"));
private final Object mLock = new Object();
private final Binder mToken = new Binder();
@@ -226,6 +230,38 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
}
}
@Override
public void grantRuntimePermission(String packageName, String permission, int userId)
throws RemoteException {
synchronized (mLock) {
throwIfCalledByNotTrustedUidLocked();
throwIfShutdownLocked();
throwIfNotConnectedLocked();
}
final long identity = Binder.clearCallingIdentity();
try {
mPackageManager.grantRuntimePermission(packageName, permission, userId);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
@Override
public void revokeRuntimePermission(String packageName, String permission, int userId)
throws RemoteException {
synchronized (mLock) {
throwIfCalledByNotTrustedUidLocked();
throwIfShutdownLocked();
throwIfNotConnectedLocked();
}
final long identity = Binder.clearCallingIdentity();
try {
mPackageManager.revokeRuntimePermission(packageName, permission, userId);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
@Override
public void executeShellCommand(final String command, final ParcelFileDescriptor sink)
throws RemoteException {