Merge "Add API to RuntimePermissionPresenter" into oc-dr1-dev
am: a023184bbc
Change-Id: Ibd5d41feaf18aacad79345404c944f365aa19587
This commit is contained in:
@@ -25,4 +25,5 @@ import android.os.RemoteCallback;
|
||||
*/
|
||||
oneway interface IRuntimePermissionPresenter {
|
||||
void getAppPermissions(String packageName, in RemoteCallback callback);
|
||||
void revokeRuntimePermission(String packageName, String permissionName);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -31,6 +30,7 @@ import android.os.RemoteCallback;
|
||||
import android.os.RemoteException;
|
||||
import android.permissionpresenterservice.RuntimePermissionPresenterService;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.os.SomeArgs;
|
||||
|
||||
@@ -118,6 +118,22 @@ public final class RuntimePermissionPresenter {
|
||||
mRemoteService.processMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke the permission {@code permissionName} for app {@code packageName}
|
||||
*
|
||||
* @param packageName The package for which to revoke
|
||||
* @param permissionName The permission to revoke
|
||||
*/
|
||||
public void revokeRuntimePermission(String packageName, String permissionName) {
|
||||
SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = packageName;
|
||||
args.arg2 = permissionName;
|
||||
|
||||
Message message = mRemoteService.obtainMessage(
|
||||
RemoteService.MSG_REVOKE_APP_PERMISSIONS, args);
|
||||
mRemoteService.processMessage(message);
|
||||
}
|
||||
|
||||
private static final class RemoteService
|
||||
extends Handler implements ServiceConnection {
|
||||
private static final long UNBIND_TIMEOUT_MILLIS = 10000;
|
||||
@@ -125,6 +141,7 @@ public final class RuntimePermissionPresenter {
|
||||
public static final int MSG_GET_APP_PERMISSIONS = 1;
|
||||
public static final int MSG_GET_APPS_USING_PERMISSIONS = 2;
|
||||
public static final int MSG_UNBIND = 3;
|
||||
public static final int MSG_REVOKE_APP_PERMISSIONS = 4;
|
||||
|
||||
private final Object mLock = new Object();
|
||||
|
||||
@@ -231,6 +248,25 @@ public final class RuntimePermissionPresenter {
|
||||
mRemoteInstance = null;
|
||||
}
|
||||
} break;
|
||||
|
||||
case MSG_REVOKE_APP_PERMISSIONS: {
|
||||
SomeArgs args = (SomeArgs) msg.obj;
|
||||
final String packageName = (String) args.arg1;
|
||||
final String permissionName = (String) args.arg2;
|
||||
args.recycle();
|
||||
final IRuntimePermissionPresenter remoteInstance;
|
||||
synchronized (mLock) {
|
||||
remoteInstance = mRemoteInstance;
|
||||
}
|
||||
if (remoteInstance == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
remoteInstance.revokeRuntimePermission(packageName, permissionName);
|
||||
} catch (RemoteException re) {
|
||||
Log.e(TAG, "Error getting app permissions", re);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
synchronized (mLock) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.annotation.SystemApi;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.permission.IRuntimePermissionPresenter;
|
||||
import android.content.pm.permission.RuntimePermissionPresentationInfo;
|
||||
import android.content.pm.permission.RuntimePermissionPresenter;
|
||||
@@ -30,6 +29,7 @@ import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteCallback;
|
||||
|
||||
import com.android.internal.os.SomeArgs;
|
||||
|
||||
import java.util.List;
|
||||
@@ -72,6 +72,16 @@ public abstract class RuntimePermissionPresenterService extends Service {
|
||||
*/
|
||||
public abstract List<RuntimePermissionPresentationInfo> onGetAppPermissions(String packageName);
|
||||
|
||||
/**
|
||||
* Revoke the permission {@code permissionName} for app {@code packageName}
|
||||
*
|
||||
* @param packageName The package for which to revoke
|
||||
* @param permissionName The permission to revoke
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public abstract void onRevokeRuntimePermission(String packageName, String permissionName);
|
||||
|
||||
@Override
|
||||
public final IBinder onBind(Intent intent) {
|
||||
return new IRuntimePermissionPresenter.Stub() {
|
||||
@@ -83,12 +93,22 @@ public abstract class RuntimePermissionPresenterService extends Service {
|
||||
mHandler.obtainMessage(MyHandler.MSG_GET_APP_PERMISSIONS,
|
||||
args).sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void revokeRuntimePermission(String packageName, String permissionName) {
|
||||
SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = packageName;
|
||||
args.arg2 = permissionName;
|
||||
mHandler.obtainMessage(MyHandler.MSG_REVOKE_APP_PERMISSION,
|
||||
args).sendToTarget();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final class MyHandler extends Handler {
|
||||
public static final int MSG_GET_APP_PERMISSIONS = 1;
|
||||
public static final int MSG_GET_APPS_USING_PERMISSIONS = 2;
|
||||
public static final int MSG_REVOKE_APP_PERMISSION = 3;
|
||||
|
||||
public MyHandler(Looper looper) {
|
||||
super(looper, null, false);
|
||||
@@ -113,6 +133,14 @@ public abstract class RuntimePermissionPresenterService extends Service {
|
||||
callback.sendResult(null);
|
||||
}
|
||||
} break;
|
||||
case MSG_REVOKE_APP_PERMISSION: {
|
||||
SomeArgs args = (SomeArgs) msg.obj;
|
||||
String packageName = (String) args.arg1;
|
||||
String permissionName = (String) args.arg2;
|
||||
args.recycle();
|
||||
|
||||
onRevokeRuntimePermission(packageName, permissionName);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user