diff options
Diffstat (limited to 'services/restrictions')
-rw-r--r-- | services/restrictions/java/com/android/server/restrictions/RestrictionsManagerService.java | 136 |
1 files changed, 5 insertions, 131 deletions
diff --git a/services/restrictions/java/com/android/server/restrictions/RestrictionsManagerService.java b/services/restrictions/java/com/android/server/restrictions/RestrictionsManagerService.java index 1db3c5e..4fe30e6 100644 --- a/services/restrictions/java/com/android/server/restrictions/RestrictionsManagerService.java +++ b/services/restrictions/java/com/android/server/restrictions/RestrictionsManagerService.java @@ -23,17 +23,13 @@ import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.admin.IDevicePolicyManager; -import android.content.AbstractRestrictionsProvider; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; -import android.content.IPermissionResponseCallback; -import android.content.IRestrictionsProvider; import android.content.Intent; import android.content.IntentFilter; import android.content.IRestrictionsManager; import android.content.RestrictionsManager; -import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; @@ -127,58 +123,12 @@ public final class RestrictionsManagerService extends SystemService { enforceCallerMatchesPackage(callingUid, packageName, "Package name does not" + " match caller "); // Prepare and broadcast the intent to the provider - Intent intent = new Intent(); + Intent intent = new Intent(RestrictionsManager.ACTION_REQUEST_PERMISSION); intent.setComponent(restrictionsProvider); - new ProviderServiceConnection(intent, null, userHandle) { - @Override - public void run() throws RemoteException { - if (DEBUG) { - Log.i(LOG_TAG, "calling requestPermission for " + packageName - + ", type=" + requestType + ", data=" + requestData); - } - mRestrictionsProvider.requestPermission(packageName, - requestType, requestData); - } - }.bind(); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - } - - @Override - public void getPermissionResponse(final String packageName, final String requestId, - final IPermissionResponseCallback callback) throws RemoteException { - int callingUid = Binder.getCallingUid(); - int userHandle = UserHandle.getUserId(callingUid); - if (mDpm != null) { - long ident = Binder.clearCallingIdentity(); - try { - ComponentName restrictionsProvider = - mDpm.getRestrictionsProvider(userHandle); - // Check if there is a restrictions provider - if (restrictionsProvider == null) { - throw new IllegalStateException( - "Cannot fetch permission without a restrictions provider registered"); - } - // Check that the packageName matches the caller. - enforceCallerMatchesPackage(callingUid, packageName, "Package name does not" + - " match caller "); - // Prepare and broadcast the intent to the provider - Intent intent = new Intent(); - intent.setComponent(restrictionsProvider); - new ProviderServiceConnection(intent, callback.asBinder(), userHandle) { - @Override - public void run() throws RemoteException { - if (DEBUG) { - Log.i(LOG_TAG, "calling getPermissionResponse for " + packageName - + ", id=" + requestId); - } - Bundle response = mRestrictionsProvider.getPermissionResponse( - packageName, requestId); - callback.onResponse(response); - } - }.bind(); + intent.putExtra(RestrictionsManager.EXTRA_PACKAGE_NAME, packageName); + intent.putExtra(RestrictionsManager.EXTRA_REQUEST_TYPE, requestType); + intent.putExtra(RestrictionsManager.EXTRA_REQUEST_BUNDLE, requestData); + mContext.sendBroadcastAsUser(intent, new UserHandle(userHandle)); } finally { Binder.restoreCallingIdentity(ident); } @@ -226,81 +176,5 @@ public final class RestrictionsManagerService extends SystemService { // Shouldn't happen } } - - abstract class ProviderServiceConnection - implements IBinder.DeathRecipient, ServiceConnection { - - protected IRestrictionsProvider mRestrictionsProvider; - private Intent mIntent; - protected int mUserHandle; - protected IBinder mResponse; - private boolean mAbort; - - public ProviderServiceConnection(Intent intent, IBinder response, int userHandle) { - mIntent = intent; - mResponse = response; - mUserHandle = userHandle; - if (mResponse != null) { - try { - mResponse.linkToDeath(this, 0 /* flags */); - } catch (RemoteException re) { - close(); - } - } - } - - /** Bind to the RestrictionsProvider process */ - public void bind() { - if (DEBUG) { - Log.i(LOG_TAG, "binding to service: " + mIntent); - } - mContext.bindServiceAsUser(mIntent, this, Context.BIND_AUTO_CREATE, - new UserHandle(mUserHandle)); - } - - private void close() { - mAbort = true; - unbind(); - } - - private void unbind() { - if (DEBUG) { - Log.i(LOG_TAG, "unbinding from service"); - } - mContext.unbindService(this); - } - - /** Implement this to call the appropriate method on the service */ - public abstract void run() throws RemoteException; - - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - if (DEBUG) { - Log.i(LOG_TAG, "connected to " + name); - } - mRestrictionsProvider = IRestrictionsProvider.Stub.asInterface(service); - if (!mAbort) { - try { - run(); - } catch (RemoteException re) { - Log.w("RestrictionsProvider", "Remote exception: " + re); - } - } - close(); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - if (DEBUG) { - Log.i(LOG_TAG, "disconnected from " + name); - } - mRestrictionsProvider = null; - } - - @Override - public void binderDied() { - mAbort = true; - } - } } } |