Merge "Add API to RuntimePermissionPresenter" into oc-dr1-dev
This commit is contained in:
@@ -25,4 +25,5 @@ import android.os.RemoteCallback;
|
|||||||
*/
|
*/
|
||||||
oneway interface IRuntimePermissionPresenter {
|
oneway interface IRuntimePermissionPresenter {
|
||||||
void getAppPermissions(String packageName, in RemoteCallback callback);
|
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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -31,6 +30,7 @@ import android.os.RemoteCallback;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.permissionpresenterservice.RuntimePermissionPresenterService;
|
import android.permissionpresenterservice.RuntimePermissionPresenterService;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.os.SomeArgs;
|
import com.android.internal.os.SomeArgs;
|
||||||
|
|
||||||
@@ -118,6 +118,22 @@ public final class RuntimePermissionPresenter {
|
|||||||
mRemoteService.processMessage(message);
|
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
|
private static final class RemoteService
|
||||||
extends Handler implements ServiceConnection {
|
extends Handler implements ServiceConnection {
|
||||||
private static final long UNBIND_TIMEOUT_MILLIS = 10000;
|
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_APP_PERMISSIONS = 1;
|
||||||
public static final int MSG_GET_APPS_USING_PERMISSIONS = 2;
|
public static final int MSG_GET_APPS_USING_PERMISSIONS = 2;
|
||||||
public static final int MSG_UNBIND = 3;
|
public static final int MSG_UNBIND = 3;
|
||||||
|
public static final int MSG_REVOKE_APP_PERMISSIONS = 4;
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
@@ -231,6 +248,25 @@ public final class RuntimePermissionPresenter {
|
|||||||
mRemoteInstance = null;
|
mRemoteInstance = null;
|
||||||
}
|
}
|
||||||
} break;
|
} 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) {
|
synchronized (mLock) {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import android.annotation.SystemApi;
|
|||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.permission.IRuntimePermissionPresenter;
|
import android.content.pm.permission.IRuntimePermissionPresenter;
|
||||||
import android.content.pm.permission.RuntimePermissionPresentationInfo;
|
import android.content.pm.permission.RuntimePermissionPresentationInfo;
|
||||||
import android.content.pm.permission.RuntimePermissionPresenter;
|
import android.content.pm.permission.RuntimePermissionPresenter;
|
||||||
@@ -30,6 +29,7 @@ import android.os.IBinder;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteCallback;
|
import android.os.RemoteCallback;
|
||||||
|
|
||||||
import com.android.internal.os.SomeArgs;
|
import com.android.internal.os.SomeArgs;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -72,6 +72,16 @@ public abstract class RuntimePermissionPresenterService extends Service {
|
|||||||
*/
|
*/
|
||||||
public abstract List<RuntimePermissionPresentationInfo> onGetAppPermissions(String packageName);
|
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
|
@Override
|
||||||
public final IBinder onBind(Intent intent) {
|
public final IBinder onBind(Intent intent) {
|
||||||
return new IRuntimePermissionPresenter.Stub() {
|
return new IRuntimePermissionPresenter.Stub() {
|
||||||
@@ -83,12 +93,22 @@ public abstract class RuntimePermissionPresenterService extends Service {
|
|||||||
mHandler.obtainMessage(MyHandler.MSG_GET_APP_PERMISSIONS,
|
mHandler.obtainMessage(MyHandler.MSG_GET_APP_PERMISSIONS,
|
||||||
args).sendToTarget();
|
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 {
|
private final class MyHandler extends Handler {
|
||||||
public static final int MSG_GET_APP_PERMISSIONS = 1;
|
public static final int MSG_GET_APP_PERMISSIONS = 1;
|
||||||
public static final int MSG_GET_APPS_USING_PERMISSIONS = 2;
|
public static final int MSG_GET_APPS_USING_PERMISSIONS = 2;
|
||||||
|
public static final int MSG_REVOKE_APP_PERMISSION = 3;
|
||||||
|
|
||||||
public MyHandler(Looper looper) {
|
public MyHandler(Looper looper) {
|
||||||
super(looper, null, false);
|
super(looper, null, false);
|
||||||
@@ -113,6 +133,14 @@ public abstract class RuntimePermissionPresenterService extends Service {
|
|||||||
callback.sendResult(null);
|
callback.sendResult(null);
|
||||||
}
|
}
|
||||||
} break;
|
} 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